Update download tests
[youtube-dl] / test / test_download.py
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
6 import hashlib
7 import io
8 import os
9 import json
10 import unittest
11 import sys
12
13 # Allow direct execution
14 import os
15 sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
16
17 from youtube_dl.FileDownloader import FileDownloader
18 import youtube_dl.InfoExtractors
19
20 def _file_md5(fn):
21     with open(fn, 'rb') as f:
22         return hashlib.md5(f.read()).hexdigest()
23
24 def md5_for_file(filename, block_size=2**20):
25     with open(filename) as f:
26         md5 = hashlib.md5()
27         while True:
28             data = f.read(block_size)
29             if not data:
30                 break
31             md5.update(data)
32             return md5.hexdigest()
33 _file_md5 = md5_for_file
34
35 class DownloadTest(unittest.TestCase):
36     PARAMETERS_FILE = os.path.join(os.path.dirname(os.path.abspath(__file__)), "parameters.json")
37
38     def setUp(self):
39         # Clear old files
40         self.tearDown()
41
42         with io.open(self.PARAMETERS_FILE, encoding='utf-8') as pf:
43             self.parameters = json.load(pf)
44
45     def test_Youtube(self):
46         YoutubeIE = youtube_dl.InfoExtractors.YoutubeIE
47         filename = 'BaW_jenozKc.mp4'
48         fd = FileDownloader(self.parameters)
49         fd.add_info_extractor(YoutubeIE())
50         fd.download(['http://www.youtube.com/watch?v=BaW_jenozKc'])
51         self.assertTrue(os.path.exists(filename))
52         self.assertEqual(os.path.getsize(filename), 1993883)
53
54     def test_Dailymotion(self):
55         DailymotionIE = youtube_dl.InfoExtractors.DailymotionIE
56         filename = 'x33vw9.mp4'
57         fd = FileDownloader(self.parameters)
58         fd.add_info_extractor(DailymotionIE())
59         fd.download(['http://www.dailymotion.com/video/x33vw9_tutoriel-de-youtubeur-dl-des-video_tech'])
60         self.assertTrue(os.path.exists(filename))
61         md5_for_file = _file_md5(filename)
62         self.assertEqual(md5_for_file, 'd363a50e9eb4f22ce90d08d15695bb47')
63
64     def test_Metacafe(self):
65         MetacafeIE = youtube_dl.InfoExtractors.MetacafeIE
66         filename = 'aUehQsCQtM.flv'
67         fd = FileDownloader(self.parameters)
68         fd.add_info_extractor(MetacafeIE())
69         fd.add_info_extractor(youtube_dl.InfoExtractors.YoutubeIE())
70         fd.download(['http://www.metacafe.com/watch/yt-_aUehQsCQtM/the_electric_company_short_i_pbs_kids_go/'])
71         self.assertTrue(os.path.exists(filename))
72         self.assertEqual(os.path.getsize(filename), 5754305)
73
74     def test_BlipTV(self):
75         BlipTVIE = youtube_dl.InfoExtractors.BlipTVIE
76         filename = '5779306.m4v'
77         fd = FileDownloader(self.parameters)
78         fd.add_info_extractor(BlipTVIE())
79         fd.download(['http://blip.tv/cbr/cbr-exclusive-gotham-city-imposters-bats-vs-jokerz-short-3-5796352'])
80         self.assertTrue(os.path.exists(filename))
81         md5_for_file = _file_md5(filename)
82         self.assertEqual(md5_for_file, '93c24d2f4e0782af13b8a7606ea97ba7')
83
84     def test_XVideos(self):
85         XVideosIE = youtube_dl.InfoExtractors.XVideosIE
86         filename = '939581.flv'
87         fd = FileDownloader(self.parameters)
88         fd.add_info_extractor(XVideosIE())
89         fd.download(['http://www.xvideos.com/video939581/funny_porns_by_s_-1'])
90         self.assertTrue(os.path.exists(filename))
91         md5_for_file = _file_md5(filename)
92         self.assertEqual(md5_for_file, '1ab4dedc01f771cb2a65e91caa801aaf')
93
94     @unittest.skip("No output file specified")
95     def test_Vimeo(self):
96         VimeoIE = youtube_dl.InfoExtractors.VimeoIE
97         filename = ''
98         fd = FileDownloader(self.parameters)
99         fd.add_info_extractor(VimeoIE())
100         fd.download(['http://vimeo.com/14160053'])
101         self.assertTrue(os.path.exists(filename))
102         md5_for_file = _file_md5(filename)
103         self.assertEqual(md5_for_file, '1ab4dedc01f771cb2a65e91caa801aaf')
104
105     def test_Soundcloud(self):
106         SoundcloudIE = youtube_dl.InfoExtractors.SoundcloudIE
107         filename = 'n6FLbx6ZzMiu.mp3'
108         fd = FileDownloader(self.parameters)
109         fd.add_info_extractor(SoundcloudIE())
110         fd.download(['http://soundcloud.com/ethmusic/lostin-powers-she-so-heavy'])
111         self.assertTrue(os.path.exists(filename))
112         md5_for_file = _file_md5(filename)
113         self.assertEqual(md5_for_file, 'ce3775768ebb6432fa8495d446a078ed')
114
115     def test_StanfordOpenClassroom(self):
116         StanfordOpenClassroomIE = youtube_dl.InfoExtractors.StanfordOpenClassroomIE
117         filename = 'PracticalUnix_intro-environment.mp4'
118         fd = FileDownloader(self.parameters)
119         fd.add_info_extractor(StanfordOpenClassroomIE())
120         fd.download(['http://openclassroom.stanford.edu/MainFolder/VideoPage.php?course=PracticalUnix&video=intro-environment&speed=100'])
121         self.assertTrue(os.path.exists(filename))
122         md5_for_file = _file_md5(filename)
123         self.assertEqual(md5_for_file, '22c8206291368c4e2c9c1a307f0ea0f4')
124
125     @unittest.skip("IE marked as not _WORKING")
126     def test_CollegeHumor(self):
127         CollegeHumorIE = youtube_dl.InfoExtractors.CollegeHumorIE
128         filename = ''
129         fd = FileDownloader(self.parameters)
130         fd.add_info_extractor(CollegeHumorIE())
131         fd.download(['http://www.collegehumor.com/video/6830834/mitt-romney-style-gangnam-style-parody'])
132         self.assertTrue(os.path.exists(filename))
133         md5_for_file = _file_md5(filename)
134         self.assertEqual(md5_for_file, '')
135
136     def test_XNXX(self):
137         XNXXIE = youtube_dl.InfoExtractors.XNXXIE
138         filename = '1135332.flv'
139         fd = FileDownloader(self.parameters)
140         fd.add_info_extractor(XNXXIE())
141         fd.download(['http://video.xnxx.com/video1135332/lida_naked_funny_actress_5_'])
142         self.assertTrue(os.path.exists(filename))
143         md5_for_file = _file_md5(filename)
144         self.assertEqual(md5_for_file, '5f0469c8d1dfd1bc38c8e6deb5e0a21d')
145
146
147     def tearDown(self):
148         if os.path.exists('BaW_jenozKc.mp4'):
149             os.remove('BaW_jenozKc.mp4')
150         if os.path.exists('x33vw9.mp4'):
151             os.remove('x33vw9.mp4')
152         if os.path.exists('aUehQsCQtM.flv'):
153             os.remove('aUehQsCQtM.flv')
154         if os.path.exists('5779306.m4v'):
155             os.remove('5779306.m4v')
156         if os.path.exists('939581.flv'):
157             os.remove('939581.flv')
158         # No file specified for Vimeo
159         if os.path.exists('n6FLbx6ZzMiu.mp3'):
160             os.remove('n6FLbx6ZzMiu.mp3')
161         if os.path.exists('PracticalUnix_intro-environment.mp4'):
162             os.remove('PracticalUnix_intro-environment.mp4')
163         # No file specified for CollegeHumor
164         if os.path.exists('1135332.flv'):
165             os.remove('1135332.flv')
166
167
168
169 if __name__ == '__main__':
170     unittest.main()