]> gitweb @ CieloNegro.org - youtube-dl.git/blob - test/test_download.py
7de9f2a4897f6f77dbfd3db527bc91144bfe2e1a
[youtube-dl.git] / test / test_download.py
1 #!/usr/bin/env python2
2 import unittest
3 import hashlib
4 import os
5 import json
6
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
12
13
14 class DownloadTest(unittest.TestCase):
15         PARAMETERS_FILE = "test/parameters.json"
16         #calculated with md5sum:
17         #md5sum (GNU coreutils) 8.19
18
19         YOUTUBE_MD5 = "ab62e120445e8f68e8c8fddb7bd3ed76"
20         YOUTUBE_URL = "http://www.youtube.com/watch?v=BaW_jenozKc"
21         YOUTUBE_FILE = "BaW_jenozKc.mp4"
22
23
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"
27
28
29         METACAFE_MD5 = ""
30         METACAFE_URL = "http://www.metacafe.com/watch/yt-bV9L5Ht9LgY/download_youtube_playlist_with_youtube_dl/"
31         METACAFE_FILE = ""
32
33
34         PHOTOBUCKET_MD5 = ""
35         PHOTOBUCKET_URL = ""
36         PHOTOBUCKET_FILE = ""
37
38
39         FACEBOOK_MD5 = ""
40         FACEBOOK_URL = ""
41         FACEBOOK_FILE = ""
42
43
44         BLIP_MD5 = ""
45         BLIP_URL = ""
46         BLIP_FILE = ""
47
48         VIMEO_MD5 = ""
49         VIMEO_URL = ""
50         VIMEO_FILE = ""
51
52         XVIDEO_MD5 = ""
53         XVIDEO_URL = ""
54         XVIDEO_FILE = ""
55
56
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)
67
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)
76
77         def test_metacafe(self):
78                 #this emulate a skip,to be 2.6 compatible
79                 return
80                 with open(DownloadTest.PARAMETERS_FILE) as f:
81                         fd = FileDownloader(json.load(f))
82                         print fd
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)
88
89         def test_photobucket(self):
90                 return
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)
98
99         def test_facebook(self):
100                 return
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)
108
109         def test_blip(self):
110                 return
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)
118
119         def test_vimeo(self):
120                 return
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)
128
129         def test_xvideo(self):
130                 return
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)
138
139         def tearDown(self):
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)
156
157 def md5_for_file(filename, block_size=2**20):
158     with open(filename) as f:
159         md5 = hashlib.md5()
160         while True:
161             data = f.read(block_size)
162             if not data:
163                 break
164             md5.update(data)
165             return md5.hexdigest()