]>
Commit | Line | Data |
---|---|---|
efe8902f | 1 | #!/usr/bin/env python2 |
2 | import unittest | |
3 | import hashlib | |
4 | import os | |
7f60b5aa | 5 | import json |
efe8902f | 6 | |
7 | from youtube_dl.FileDownloader import FileDownloader | |
6da7877b | 8 | from youtube_dl.InfoExtractors import YoutubeIE, DailymotionIE |
fc737601 | 9 | from youtube_dl.InfoExtractors import MetacafeIE, BlipTVIE |
4c9afeca | 10 | |
efe8902f | 11 | |
12 | class DownloadTest(unittest.TestCase): | |
7f60b5aa | 13 | PARAMETERS_FILE = "test/parameters.json" |
137c5803 | 14 | #calculated with md5sum: |
4c9afeca | 15 | #md5sum (GNU coreutils) 8.19 |
7f60b5aa | 16 | |
591bbe9c | 17 | YOUTUBE_SIZE = 1993883 |
137c5803 | 18 | YOUTUBE_URL = "http://www.youtube.com/watch?v=BaW_jenozKc" |
7f60b5aa | 19 | YOUTUBE_FILE = "BaW_jenozKc.mp4" |
efe8902f | 20 | |
7f60b5aa | 21 | DAILYMOTION_MD5 = "d363a50e9eb4f22ce90d08d15695bb47" |
ff089842 | 22 | DAILYMOTION_URL = "http://www.dailymotion.com/video/x33vw9_tutoriel-de-youtubeur-dl-des-video_tech" |
7f60b5aa | 23 | DAILYMOTION_FILE = "x33vw9.mp4" |
ff089842 | 24 | |
97a37c23 | 25 | METACAFE_SIZE = 5754305 |
26 | METACAFE_URL = "http://www.metacafe.com/watch/yt-_aUehQsCQtM/the_electric_company_short_i_pbs_kids_go/" | |
27 | METACAFE_FILE = "_aUehQsCQtM.flv" | |
a4b5f225 | 28 | |
97a37c23 | 29 | BLIP_MD5 = "93c24d2f4e0782af13b8a7606ea97ba7" |
30 | BLIP_URL = "http://blip.tv/cbr/cbr-exclusive-gotham-city-imposters-bats-vs-jokerz-short-3-5796352" | |
31 | BLIP_FILE = "5779306.m4v" | |
4c9afeca | 32 | |
4c9afeca | 33 | XVIDEO_MD5 = "" |
7f60b5aa | 34 | XVIDEO_URL = "" |
4c9afeca | 35 | XVIDEO_FILE = "" |
36 | ||
37 | ||
137c5803 | 38 | def test_youtube(self): |
39 | #let's download a file from youtube | |
7f60b5aa | 40 | with open(DownloadTest.PARAMETERS_FILE) as f: |
41 | fd = FileDownloader(json.load(f)) | |
137c5803 | 42 | fd.add_info_extractor(YoutubeIE()) |
43 | fd.download([DownloadTest.YOUTUBE_URL]) | |
44 | self.assertTrue(os.path.exists(DownloadTest.YOUTUBE_FILE)) | |
591bbe9c | 45 | self.assertEqual(os.path.getsize(DownloadTest.YOUTUBE_FILE), DownloadTest.YOUTUBE_SIZE) |
efe8902f | 46 | |
ff089842 | 47 | def test_dailymotion(self): |
7f60b5aa | 48 | with open(DownloadTest.PARAMETERS_FILE) as f: |
49 | fd = FileDownloader(json.load(f)) | |
ff089842 | 50 | fd.add_info_extractor(DailymotionIE()) |
51 | fd.download([DownloadTest.DAILYMOTION_URL]) | |
52 | self.assertTrue(os.path.exists(DownloadTest.DAILYMOTION_FILE)) | |
53 | md5_down_file = md5_for_file(DownloadTest.DAILYMOTION_FILE) | |
54 | self.assertEqual(md5_down_file, DownloadTest.DAILYMOTION_MD5) | |
55 | ||
a4b5f225 | 56 | def test_metacafe(self): |
4279a0ca | 57 | #this emulate a skip,to be 2.6 compatible |
4279a0ca | 58 | with open(DownloadTest.PARAMETERS_FILE) as f: |
7f60b5aa | 59 | fd = FileDownloader(json.load(f)) |
a4b5f225 | 60 | fd.add_info_extractor(MetacafeIE()) |
97a37c23 | 61 | fd.add_info_extractor(YoutubeIE()) |
a4b5f225 | 62 | fd.download([DownloadTest.METACAFE_URL]) |
63 | self.assertTrue(os.path.exists(DownloadTest.METACAFE_FILE)) | |
97a37c23 | 64 | self.assertEqual(os.path.getsize(DownloadTest.METACAFE_FILE), DownloadTest.METACAFE_SIZE) |
6da7877b | 65 | |
4c9afeca | 66 | def test_blip(self): |
4279a0ca | 67 | with open(DownloadTest.PARAMETERS_FILE) as f: |
68 | fd = FileDownloader(json.load(f)) | |
4c9afeca | 69 | fd.add_info_extractor(BlipTVIE()) |
70 | fd.download([DownloadTest.BLIP_URL]) | |
71 | self.assertTrue(os.path.exists(DownloadTest.BLIP_FILE)) | |
72 | md5_down_file = md5_for_file(DownloadTest.BLIP_FILE) | |
73 | self.assertEqual(md5_down_file, DownloadTest.BLIP_MD5) | |
74 | ||
7f60b5aa | 75 | def tearDown(self): |
137c5803 | 76 | if os.path.exists(DownloadTest.YOUTUBE_FILE): |
77 | os.remove(DownloadTest.YOUTUBE_FILE) | |
ff089842 | 78 | if os.path.exists(DownloadTest.DAILYMOTION_FILE): |
79 | os.remove(DownloadTest.DAILYMOTION_FILE) | |
b4e5de51 | 80 | if os.path.exists(DownloadTest.METACAFE_FILE): |
81 | os.remove(DownloadTest.METACAFE_FILE) | |
4c9afeca | 82 | if os.path.exists(DownloadTest.BLIP_FILE): |
83 | os.remove(DownloadTest.BLIP_FILE) | |
efe8902f | 84 | |
7f60b5aa | 85 | def md5_for_file(filename, block_size=2**20): |
86 | with open(filename) as f: | |
87 | md5 = hashlib.md5() | |
88 | while True: | |
89 | data = f.read(block_size) | |
90 | if not data: | |
91 | break | |
92 | md5.update(data) | |
93 | return md5.hexdigest() |