7 from youtube_dl.FileDownloader import FileDownloader
8 from youtube_dl.InfoExtractors import YoutubeIE, DailymotionIE
9 from youtube_dl.InfoExtractors import MetacafeIE, PhotobucketIE
10 from youtube_dl.InfoExtractors import FacebookIE, BlipTVIE
11 from youtube_dl.InfoExtractors import VimeoIE, XVideosIE
14 class DownloadTest(unittest.TestCase):
15 PARAMETERS_FILE = "test/parameters.json"
16 #calculated with md5sum:
17 #md5sum (GNU coreutils) 8.19
19 YOUTUBE_MD5 = "ab62e120445e8f68e8c8fddb7bd3ed76"
20 YOUTUBE_URL = "http://www.youtube.com/watch?v=BaW_jenozKc"
21 YOUTUBE_FILE = "BaW_jenozKc.mp4"
24 DAILYMOTION_MD5 = "d363a50e9eb4f22ce90d08d15695bb47"
25 DAILYMOTION_URL = "http://www.dailymotion.com/video/x33vw9_tutoriel-de-youtubeur-dl-des-video_tech"
26 DAILYMOTION_FILE = "x33vw9.mp4"
30 METACAFE_URL = "http://www.metacafe.com/watch/yt-bV9L5Ht9LgY/download_youtube_playlist_with_youtube_dl/"
57 def test_youtube(self):
58 #let's download a file from youtube
59 with open(DownloadTest.PARAMETERS_FILE) as f:
60 fd = FileDownloader(json.load(f))
61 fd.add_info_extractor(YoutubeIE())
62 fd.download([DownloadTest.YOUTUBE_URL])
63 print(os.path.abspath(DownloadTest.YOUTUBE_FILE))
64 self.assertTrue(os.path.exists(DownloadTest.YOUTUBE_FILE))
65 md5_down_file = md5_for_file(DownloadTest.YOUTUBE_FILE)
66 self.assertEqual(md5_down_file, DownloadTest.YOUTUBE_MD5)
68 def test_dailymotion(self):
69 with open(DownloadTest.PARAMETERS_FILE) as f:
70 fd = FileDownloader(json.load(f))
71 fd.add_info_extractor(DailymotionIE())
72 fd.download([DownloadTest.DAILYMOTION_URL])
73 self.assertTrue(os.path.exists(DownloadTest.DAILYMOTION_FILE))
74 md5_down_file = md5_for_file(DownloadTest.DAILYMOTION_FILE)
75 self.assertEqual(md5_down_file, DownloadTest.DAILYMOTION_MD5)
77 def test_metacafe(self):
78 #this emulate a skip,to be 2.6 compatible
80 with open(DownloadTest.PARAMETERS_FILE) as f:
81 fd = FileDownloader(json.load(f))
83 fd.add_info_extractor(MetacafeIE())
84 fd.download([DownloadTest.METACAFE_URL])
85 self.assertTrue(os.path.exists(DownloadTest.METACAFE_FILE))
86 md5_down_file = md5_for_file(DownloadTest.METACAFE_FILE)
87 self.assertEqual(md5_down_file, DownloadTest.METACAFE_MD5)
89 def test_photobucket(self):
91 with open(DownloadTest.PARAMETERS_FILE) as f:
92 fd = FileDownloader(json.load(f))
93 fd.add_info_extractor(PhotobucketIE())
94 fd.download([DownloadTest.PHOTOBUCKET_URL])
95 self.assertTrue(os.path.exists(DownloadTest.PHOTOBUCKET_FILE))
96 md5_down_file = md5_for_file(DownloadTest.PHOTOBUCKET_FILE)
97 self.assertEqual(md5_down_file, DownloadTest.PHOTOBUCKET_MD5)
99 def test_facebook(self):
101 with open(DownloadTest.PARAMETERS_FILE) as f:
102 fd = FileDownloader(json.load(f))
103 fd.add_info_extractor(FacebookIE())
104 fd.download([DownloadTest.FACEBOOK_URL])
105 self.assertTrue(os.path.exists(DownloadTest.FACEBOOK_FILE))
106 md5_down_file = md5_for_file(DownloadTest.FACEBOOK_FILE)
107 self.assertEqual(md5_down_file, DownloadTest.FACEBOOK_MD5)
111 with open(DownloadTest.PARAMETERS_FILE) as f:
112 fd = FileDownloader(json.load(f))
113 fd.add_info_extractor(BlipTVIE())
114 fd.download([DownloadTest.BLIP_URL])
115 self.assertTrue(os.path.exists(DownloadTest.BLIP_FILE))
116 md5_down_file = md5_for_file(DownloadTest.BLIP_FILE)
117 self.assertEqual(md5_down_file, DownloadTest.BLIP_MD5)
119 def test_vimeo(self):
121 with open(DownloadTest.PARAMETERS_FILE) as f:
122 fd = FileDownloader(json.load(f))
123 fd.add_info_extractor(VimeoIE())
124 fd.download([DownloadTest.VIMEO_URL])
125 self.assertTrue(os.path.exists(DownloadTest.VIMEO_FILE))
126 md5_down_file = md5_for_file(DownloadTest.VIMEO_FILE)
127 self.assertEqual(md5_down_file, DownloadTest.VIMEO_MD5)
129 def test_xvideo(self):
131 with open(DownloadTest.PARAMETERS_FILE) as f:
132 fd = FileDownloader(json.load(f))
133 fd.add_info_extractor(XVideosIE())
134 fd.download([DownloadTest.XVIDEO_URL])
135 self.assertTrue(os.path.exists(DownloadTest.XVIDEO_FILE))
136 md5_down_file = md5_for_file(DownloadTest.XVIDEO_FILE)
137 self.assertEqual(md5_down_file, DownloadTest.XVIDEO_MD5)
140 if os.path.exists(DownloadTest.YOUTUBE_FILE):
141 os.remove(DownloadTest.YOUTUBE_FILE)
142 if os.path.exists(DownloadTest.DAILYMOTION_FILE):
143 os.remove(DownloadTest.DAILYMOTION_FILE)
144 if os.path.exists(DownloadTest.METACAFE_FILE):
145 os.remove(DownloadTest.METACAFE_FILE)
146 if os.path.exists(DownloadTest.PHOTOBUCKET_FILE):
147 os.remove(DownloadTest.PHOTOBUCKET_FILE)
148 if os.path.exists(DownloadTest.FACEBOOK_FILE):
149 os.remove(DownloadTest.FACEBOOK_FILE)
150 if os.path.exists(DownloadTest.BLIP_FILE):
151 os.remove(DownloadTest.BLIP_FILE)
152 if os.path.exists(DownloadTest.VIMEO_FILE):
153 os.remove(DownloadTest.VIMEO_FILE)
154 if os.path.exists(DownloadTest.XVIDEO_FILE):
155 os.remove(DownloadTest.XVIDEO_FILE)
157 def md5_for_file(filename, block_size=2**20):
158 with open(filename) as f:
161 data = f.read(block_size)
165 return md5.hexdigest()