]>
Commit | Line | Data |
---|---|---|
cdab8aa3 PH |
1 | #!/usr/bin/env python |
2 | ||
3 | # DO NOT EDIT THIS FILE BY HAND! | |
4 | # It is auto-generated from tests.json and gentests.py. | |
5 | ||
efe8902f | 6 | import hashlib |
cdab8aa3 | 7 | import io |
efe8902f | 8 | import os |
7f60b5aa | 9 | import json |
cdab8aa3 PH |
10 | import unittest |
11 | import sys | |
4fb1acc2 | 12 | import socket |
cdab8aa3 PH |
13 | |
14 | # Allow direct execution | |
15 | import os | |
16 | sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) | |
efe8902f | 17 | |
4fb1acc2 | 18 | import youtube_dl.FileDownloader |
cdab8aa3 | 19 | import youtube_dl.InfoExtractors |
4fb1acc2 FV |
20 | from youtube_dl.utils import * |
21 | ||
22 | # General configuration (from __init__, not very elegant...) | |
23 | jar = compat_cookiejar.CookieJar() | |
24 | cookie_processor = compat_urllib_request.HTTPCookieProcessor(jar) | |
25 | proxy_handler = compat_urllib_request.ProxyHandler() | |
26 | opener = compat_urllib_request.build_opener(proxy_handler, cookie_processor, YoutubeDLHandler()) | |
27 | compat_urllib_request.install_opener(opener) | |
28 | socket.setdefaulttimeout(300) # 5 minutes should be enough (famous last words) | |
29 | ||
30 | class FileDownloader(youtube_dl.FileDownloader): | |
31 | def __init__(self, *args, **kwargs): | |
32 | youtube_dl.FileDownloader.__init__(self, *args, **kwargs) | |
33 | self.to_stderr = self.to_screen | |
4c9afeca | 34 | |
cdab8aa3 PH |
35 | def _file_md5(fn): |
36 | with open(fn, 'rb') as f: | |
37 | return hashlib.md5(f.read()).hexdigest() | |
81760416 PH |
38 | try: |
39 | _skip_unless = unittest.skipUnless | |
40 | except AttributeError: # Python 2.6 | |
41 | def _skip_unless(cond, reason='No reason given'): | |
42 | def resfunc(f): | |
8af4ed7b PH |
43 | # Start the function name with test to appease nosetests-2.6 |
44 | def test_wfunc(*args, **kwargs): | |
81760416 PH |
45 | if cond: |
46 | return f(*args, **kwargs) | |
47 | else: | |
48 | print('Skipped test') | |
49 | return | |
8af4ed7b | 50 | return test_wfunc |
81760416 PH |
51 | return resfunc |
52 | _skip = lambda *args, **kwargs: _skip_unless(False, *args, **kwargs) | |
53 | ||
efe8902f | 54 | class DownloadTest(unittest.TestCase): |
cdab8aa3 | 55 | PARAMETERS_FILE = os.path.join(os.path.dirname(os.path.abspath(__file__)), "parameters.json") |
59ae15a5 | 56 | |
cdab8aa3 PH |
57 | def setUp(self): |
58 | # Clear old files | |
59 | self.tearDown() | |
60 | ||
61 | with io.open(self.PARAMETERS_FILE, encoding='utf-8') as pf: | |
62 | self.parameters = json.load(pf) | |
63 | ||
81760416 | 64 | @_skip_unless(youtube_dl.InfoExtractors.YoutubeIE._WORKING, "IE marked as not _WORKING") |
cdab8aa3 | 65 | def test_Youtube(self): |
4fb1acc2 FV |
66 | filename = u'BaW_jenozKc.mp4' |
67 | params = self.parameters | |
68 | fd = FileDownloader(params) | |
81760416 | 69 | fd.add_info_extractor(youtube_dl.InfoExtractors.YoutubeIE()) |
4fb1acc2 | 70 | fd.download([u'http://www.youtube.com/watch?v=BaW_jenozKc']) |
cdab8aa3 | 71 | self.assertTrue(os.path.exists(filename)) |
cdab8aa3 | 72 | |
81760416 | 73 | @_skip_unless(youtube_dl.InfoExtractors.DailymotionIE._WORKING, "IE marked as not _WORKING") |
cdab8aa3 | 74 | def test_Dailymotion(self): |
4fb1acc2 FV |
75 | filename = u'x33vw9.mp4' |
76 | params = self.parameters | |
77 | fd = FileDownloader(params) | |
81760416 | 78 | fd.add_info_extractor(youtube_dl.InfoExtractors.DailymotionIE()) |
4fb1acc2 | 79 | fd.download([u'http://www.dailymotion.com/video/x33vw9_tutoriel-de-youtubeur-dl-des-video_tech']) |
cdab8aa3 PH |
80 | self.assertTrue(os.path.exists(filename)) |
81 | md5_for_file = _file_md5(filename) | |
4fb1acc2 | 82 | self.assertEqual(md5_for_file, u'392c4b85a60a90dc4792da41ce3144eb') |
cdab8aa3 | 83 | |
81760416 | 84 | @_skip_unless(youtube_dl.InfoExtractors.MetacafeIE._WORKING, "IE marked as not _WORKING") |
cdab8aa3 | 85 | def test_Metacafe(self): |
4fb1acc2 FV |
86 | filename = u'_aUehQsCQtM.flv' |
87 | params = self.parameters | |
88 | fd = FileDownloader(params) | |
81760416 | 89 | fd.add_info_extractor(youtube_dl.InfoExtractors.MetacafeIE()) |
cdab8aa3 | 90 | fd.add_info_extractor(youtube_dl.InfoExtractors.YoutubeIE()) |
4fb1acc2 | 91 | fd.download([u'http://www.metacafe.com/watch/yt-_aUehQsCQtM/the_electric_company_short_i_pbs_kids_go/']) |
cdab8aa3 | 92 | self.assertTrue(os.path.exists(filename)) |
cdab8aa3 | 93 | |
81760416 | 94 | @_skip_unless(youtube_dl.InfoExtractors.BlipTVIE._WORKING, "IE marked as not _WORKING") |
cdab8aa3 | 95 | def test_BlipTV(self): |
4fb1acc2 FV |
96 | filename = u'5779306.m4v' |
97 | params = self.parameters | |
98 | fd = FileDownloader(params) | |
81760416 | 99 | fd.add_info_extractor(youtube_dl.InfoExtractors.BlipTVIE()) |
4fb1acc2 | 100 | fd.download([u'http://blip.tv/cbr/cbr-exclusive-gotham-city-imposters-bats-vs-jokerz-short-3-5796352']) |
cdab8aa3 PH |
101 | self.assertTrue(os.path.exists(filename)) |
102 | md5_for_file = _file_md5(filename) | |
4fb1acc2 | 103 | self.assertEqual(md5_for_file, u'b2d849efcf7ee18917e4b4d9ff37cafe') |
cdab8aa3 | 104 | |
81760416 | 105 | @_skip_unless(youtube_dl.InfoExtractors.XVideosIE._WORKING, "IE marked as not _WORKING") |
cdab8aa3 | 106 | def test_XVideos(self): |
4fb1acc2 FV |
107 | filename = u'939581.flv' |
108 | params = self.parameters | |
109 | fd = FileDownloader(params) | |
81760416 | 110 | fd.add_info_extractor(youtube_dl.InfoExtractors.XVideosIE()) |
4fb1acc2 | 111 | fd.download([u'http://www.xvideos.com/video939581/funny_porns_by_s_-1']) |
cdab8aa3 PH |
112 | self.assertTrue(os.path.exists(filename)) |
113 | md5_for_file = _file_md5(filename) | |
4fb1acc2 | 114 | self.assertEqual(md5_for_file, u'1d0c835822f0a71a7bf011855db929d0') |
cdab8aa3 | 115 | |
81760416 | 116 | @_skip_unless(youtube_dl.InfoExtractors.VimeoIE._WORKING, "IE marked as not _WORKING") |
cdab8aa3 | 117 | def test_Vimeo(self): |
4fb1acc2 FV |
118 | filename = u'14160053.mp4' |
119 | params = self.parameters | |
120 | fd = FileDownloader(params) | |
81760416 | 121 | fd.add_info_extractor(youtube_dl.InfoExtractors.VimeoIE()) |
4fb1acc2 | 122 | fd.download([u'http://vimeo.com/14160053']) |
cdab8aa3 PH |
123 | self.assertTrue(os.path.exists(filename)) |
124 | md5_for_file = _file_md5(filename) | |
4fb1acc2 | 125 | self.assertEqual(md5_for_file, u'60540a4ec7cc378ec84b919c0aed5023') |
cdab8aa3 | 126 | |
81760416 | 127 | @_skip_unless(youtube_dl.InfoExtractors.SoundcloudIE._WORKING, "IE marked as not _WORKING") |
cdab8aa3 | 128 | def test_Soundcloud(self): |
4fb1acc2 FV |
129 | filename = u'62986583.mp3' |
130 | params = self.parameters | |
131 | fd = FileDownloader(params) | |
81760416 | 132 | fd.add_info_extractor(youtube_dl.InfoExtractors.SoundcloudIE()) |
4fb1acc2 | 133 | fd.download([u'http://soundcloud.com/ethmusic/lostin-powers-she-so-heavy']) |
cdab8aa3 PH |
134 | self.assertTrue(os.path.exists(filename)) |
135 | md5_for_file = _file_md5(filename) | |
4fb1acc2 | 136 | self.assertEqual(md5_for_file, u'ebef0a451b909710ed1d7787dddbf0d7') |
cdab8aa3 | 137 | |
81760416 | 138 | @_skip_unless(youtube_dl.InfoExtractors.StanfordOpenClassroomIE._WORKING, "IE marked as not _WORKING") |
cdab8aa3 | 139 | def test_StanfordOpenClassroom(self): |
4fb1acc2 FV |
140 | filename = u'PracticalUnix_intro-environment.mp4' |
141 | params = self.parameters | |
142 | fd = FileDownloader(params) | |
81760416 | 143 | fd.add_info_extractor(youtube_dl.InfoExtractors.StanfordOpenClassroomIE()) |
4fb1acc2 | 144 | fd.download([u'http://openclassroom.stanford.edu/MainFolder/VideoPage.php?course=PracticalUnix&video=intro-environment&speed=100']) |
cdab8aa3 PH |
145 | self.assertTrue(os.path.exists(filename)) |
146 | md5_for_file = _file_md5(filename) | |
4fb1acc2 | 147 | self.assertEqual(md5_for_file, u'544a9468546059d4e80d76265b0443b8') |
cdab8aa3 | 148 | |
81760416 | 149 | @_skip_unless(youtube_dl.InfoExtractors.XNXXIE._WORKING, "IE marked as not _WORKING") |
cdab8aa3 | 150 | def test_XNXX(self): |
4fb1acc2 FV |
151 | filename = u'1135332.flv' |
152 | params = self.parameters | |
153 | fd = FileDownloader(params) | |
81760416 | 154 | fd.add_info_extractor(youtube_dl.InfoExtractors.XNXXIE()) |
4fb1acc2 | 155 | fd.download([u'http://video.xnxx.com/video1135332/lida_naked_funny_actress_5_']) |
cdab8aa3 PH |
156 | self.assertTrue(os.path.exists(filename)) |
157 | md5_for_file = _file_md5(filename) | |
4fb1acc2 | 158 | self.assertEqual(md5_for_file, u'0831677e2b4761795f68d417e0b7b445') |
59ae15a5 | 159 | |
d78be7e3 PH |
160 | @_skip_unless(youtube_dl.InfoExtractors.YoukuIE._WORKING, "IE marked as not _WORKING") |
161 | def test_Youku(self): | |
4fb1acc2 FV |
162 | filename = u'XNDgyMDQ2NTQw_part00.flv' |
163 | params = self.parameters | |
164 | params["test"] = False | |
165 | fd = FileDownloader(params) | |
d78be7e3 | 166 | fd.add_info_extractor(youtube_dl.InfoExtractors.YoukuIE()) |
4fb1acc2 | 167 | fd.download([u'http://v.youku.com/v_show/id_XNDgyMDQ2NTQw.html']) |
d78be7e3 PH |
168 | self.assertTrue(os.path.exists(filename)) |
169 | md5_for_file = _file_md5(filename) | |
4fb1acc2 | 170 | self.assertEqual(md5_for_file, u'ffe3f2e435663dc2d1eea34faeff5b5b') |
d78be7e3 | 171 | |
efe8902f | 172 | |
cdab8aa3 | 173 | def tearDown(self): |
4fb1acc2 FV |
174 | if os.path.exists(u'BaW_jenozKc.mp4'): |
175 | os.remove(u'BaW_jenozKc.mp4') | |
176 | if os.path.exists(u'x33vw9.mp4'): | |
177 | os.remove(u'x33vw9.mp4') | |
178 | if os.path.exists(u'_aUehQsCQtM.flv'): | |
179 | os.remove(u'_aUehQsCQtM.flv') | |
180 | if os.path.exists(u'5779306.m4v'): | |
181 | os.remove(u'5779306.m4v') | |
182 | if os.path.exists(u'939581.flv'): | |
183 | os.remove(u'939581.flv') | |
184 | if os.path.exists(u'14160053.mp4'): | |
185 | os.remove(u'14160053.mp4') | |
186 | if os.path.exists(u'62986583.mp3'): | |
187 | os.remove(u'62986583.mp3') | |
188 | if os.path.exists(u'PracticalUnix_intro-environment.mp4'): | |
189 | os.remove(u'PracticalUnix_intro-environment.mp4') | |
190 | if os.path.exists(u'1135332.flv'): | |
191 | os.remove(u'1135332.flv') | |
192 | if os.path.exists(u'XNDgyMDQ2NTQw_part00.flv'): | |
193 | os.remove(u'XNDgyMDQ2NTQw_part00.flv') | |
cdab8aa3 PH |
194 | |
195 | ||
196 | ||
197 | if __name__ == '__main__': | |
198 | unittest.main() |