]>
Raphaƫl G. Git Repositories - youtubedl/blob - test/test_download.py
3 # DO NOT EDIT THIS FILE BY HAND!
4 # It is auto-generated from tests.json and gentests.py.
14 # Allow direct execution
16 sys
.path
.append(os
.path
.dirname(os
.path
.dirname(os
.path
.abspath(__file__
))))
18 import youtube_dl
.FileDownloader
19 import youtube_dl
.InfoExtractors
20 from youtube_dl
.utils
import *
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)
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
36 with open(fn
, 'rb') as f
:
37 return hashlib
.md5(f
.read()).hexdigest()
39 _skip_unless
= unittest
.skipUnless
40 except AttributeError: # Python 2.6
41 def _skip_unless(cond
, reason
='No reason given'):
43 # Start the function name with test to appease nosetests-2.6
44 def test_wfunc(*args
, **kwargs
):
46 return f(*args
, **kwargs
)
52 _skip
= lambda *args
, **kwargs
: _skip_unless(False, *args
, **kwargs
)
54 class DownloadTest(unittest
.TestCase
):
55 PARAMETERS_FILE
= os
.path
.join(os
.path
.dirname(os
.path
.abspath(__file__
)), "parameters.json")
61 with io
.open(self
.PARAMETERS_FILE
, encoding
='utf-8') as pf
:
62 self
.parameters
= json
.load(pf
)
64 @_skip_unless(youtube_dl
.InfoExtractors
.YoutubeIE
._WORKING
, "IE marked as not _WORKING")
65 def test_Youtube(self
):
66 filename
= u
'BaW_jenozKc.mp4'
67 params
= self
.parameters
68 fd
= FileDownloader(params
)
69 fd
.add_info_extractor(youtube_dl
.InfoExtractors
.YoutubeIE())
70 fd
.download([u
'http://www.youtube.com/watch?v=BaW_jenozKc'])
71 self
.assertTrue(os
.path
.exists(filename
))
73 @_skip_unless(youtube_dl
.InfoExtractors
.DailymotionIE
._WORKING
, "IE marked as not _WORKING")
74 def test_Dailymotion(self
):
75 filename
= u
'x33vw9.mp4'
76 params
= self
.parameters
77 fd
= FileDownloader(params
)
78 fd
.add_info_extractor(youtube_dl
.InfoExtractors
.DailymotionIE())
79 fd
.download([u
'http://www.dailymotion.com/video/x33vw9_tutoriel-de-youtubeur-dl-des-video_tech'])
80 self
.assertTrue(os
.path
.exists(filename
))
81 md5_for_file
= _file_md5(filename
)
82 self
.assertEqual(md5_for_file
, u
'392c4b85a60a90dc4792da41ce3144eb')
84 @_skip_unless(youtube_dl
.InfoExtractors
.MetacafeIE
._WORKING
, "IE marked as not _WORKING")
85 def test_Metacafe(self
):
86 filename
= u
'_aUehQsCQtM.flv'
87 params
= self
.parameters
88 fd
= FileDownloader(params
)
89 fd
.add_info_extractor(youtube_dl
.InfoExtractors
.MetacafeIE())
90 fd
.add_info_extractor(youtube_dl
.InfoExtractors
.YoutubeIE())
91 fd
.download([u
'http://www.metacafe.com/watch/yt-_aUehQsCQtM/the_electric_company_short_i_pbs_kids_go/'])
92 self
.assertTrue(os
.path
.exists(filename
))
94 @_skip_unless(youtube_dl
.InfoExtractors
.BlipTVIE
._WORKING
, "IE marked as not _WORKING")
95 def test_BlipTV(self
):
96 filename
= u
'5779306.m4v'
97 params
= self
.parameters
98 fd
= FileDownloader(params
)
99 fd
.add_info_extractor(youtube_dl
.InfoExtractors
.BlipTVIE())
100 fd
.download([u
'http://blip.tv/cbr/cbr-exclusive-gotham-city-imposters-bats-vs-jokerz-short-3-5796352'])
101 self
.assertTrue(os
.path
.exists(filename
))
102 md5_for_file
= _file_md5(filename
)
103 self
.assertEqual(md5_for_file
, u
'b2d849efcf7ee18917e4b4d9ff37cafe')
105 @_skip_unless(youtube_dl
.InfoExtractors
.XVideosIE
._WORKING
, "IE marked as not _WORKING")
106 def test_XVideos(self
):
107 filename
= u
'939581.flv'
108 params
= self
.parameters
109 fd
= FileDownloader(params
)
110 fd
.add_info_extractor(youtube_dl
.InfoExtractors
.XVideosIE())
111 fd
.download([u
'http://www.xvideos.com/video939581/funny_porns_by_s_-1'])
112 self
.assertTrue(os
.path
.exists(filename
))
113 md5_for_file
= _file_md5(filename
)
114 self
.assertEqual(md5_for_file
, u
'1d0c835822f0a71a7bf011855db929d0')
116 @_skip_unless(youtube_dl
.InfoExtractors
.VimeoIE
._WORKING
, "IE marked as not _WORKING")
117 def test_Vimeo(self
):
118 filename
= u
'14160053.mp4'
119 params
= self
.parameters
120 fd
= FileDownloader(params
)
121 fd
.add_info_extractor(youtube_dl
.InfoExtractors
.VimeoIE())
122 fd
.download([u
'http://vimeo.com/14160053'])
123 self
.assertTrue(os
.path
.exists(filename
))
124 md5_for_file
= _file_md5(filename
)
125 self
.assertEqual(md5_for_file
, u
'60540a4ec7cc378ec84b919c0aed5023')
127 @_skip_unless(youtube_dl
.InfoExtractors
.SoundcloudIE
._WORKING
, "IE marked as not _WORKING")
128 def test_Soundcloud(self
):
129 filename
= u
'62986583.mp3'
130 params
= self
.parameters
131 fd
= FileDownloader(params
)
132 fd
.add_info_extractor(youtube_dl
.InfoExtractors
.SoundcloudIE())
133 fd
.download([u
'http://soundcloud.com/ethmusic/lostin-powers-she-so-heavy'])
134 self
.assertTrue(os
.path
.exists(filename
))
135 md5_for_file
= _file_md5(filename
)
136 self
.assertEqual(md5_for_file
, u
'ebef0a451b909710ed1d7787dddbf0d7')
138 @_skip_unless(youtube_dl
.InfoExtractors
.StanfordOpenClassroomIE
._WORKING
, "IE marked as not _WORKING")
139 def test_StanfordOpenClassroom(self
):
140 filename
= u
'PracticalUnix_intro-environment.mp4'
141 params
= self
.parameters
142 fd
= FileDownloader(params
)
143 fd
.add_info_extractor(youtube_dl
.InfoExtractors
.StanfordOpenClassroomIE())
144 fd
.download([u
'http://openclassroom.stanford.edu/MainFolder/VideoPage.php?course=PracticalUnix&video=intro-environment&speed=100'])
145 self
.assertTrue(os
.path
.exists(filename
))
146 md5_for_file
= _file_md5(filename
)
147 self
.assertEqual(md5_for_file
, u
'544a9468546059d4e80d76265b0443b8')
149 @_skip_unless(youtube_dl
.InfoExtractors
.XNXXIE
._WORKING
, "IE marked as not _WORKING")
151 filename
= u
'1135332.flv'
152 params
= self
.parameters
153 fd
= FileDownloader(params
)
154 fd
.add_info_extractor(youtube_dl
.InfoExtractors
.XNXXIE())
155 fd
.download([u
'http://video.xnxx.com/video1135332/lida_naked_funny_actress_5_'])
156 self
.assertTrue(os
.path
.exists(filename
))
157 md5_for_file
= _file_md5(filename
)
158 self
.assertEqual(md5_for_file
, u
'0831677e2b4761795f68d417e0b7b445')
160 @_skip_unless(youtube_dl
.InfoExtractors
.YoukuIE
._WORKING
, "IE marked as not _WORKING")
161 def test_Youku(self
):
162 filename
= u
'XNDgyMDQ2NTQw_part00.flv'
163 params
= self
.parameters
164 params
["test"] = False
165 fd
= FileDownloader(params
)
166 fd
.add_info_extractor(youtube_dl
.InfoExtractors
.YoukuIE())
167 fd
.download([u
'http://v.youku.com/v_show/id_XNDgyMDQ2NTQw.html'])
168 self
.assertTrue(os
.path
.exists(filename
))
169 md5_for_file
= _file_md5(filename
)
170 self
.assertEqual(md5_for_file
, u
'ffe3f2e435663dc2d1eea34faeff5b5b')
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')
197 if __name__
== '__main__':