changing test video
[youtube-dl] / test / test_download.py
1 #!/usr/bin/env python2
2 import unittest
3 import hashlib
4 import os
5
6 from youtube_dl.FileDownloader import FileDownloader
7 from youtube_dl.InfoExtractors  import YoutubeIE
8
9 class DownloadTest(unittest.TestCase):
10     #calculated with the md5sum utility
11     #md5sum (GNU coreutils) 8.19
12     YOUTUBE_MD5 = "8547978241cb87dd6782b10b8e90acc3"
13     YOUTUBE_URL = "http://www.youtube.com/watch?v=BaW_jenozKc"
14     YOUTUBE_FILE = "BaW_jenozKc.flv"
15
16     def test_youtube(self):
17         #let's download a file from youtube
18         global YOUTUBE_URL
19         fd = FileDownloader({})
20         fd.add_info_extractor(YoutubeIE())
21         fd.download([DownloadTest.YOUTUBE_URL])
22         self.assertTrue(os.path.exists(DownloadTest.YOUTUBE_FILE))
23         md5_down_file = md5_for_file(DownloadTest.YOUTUBE_FILE)
24         self.assertEqual(md5_down_file, DownloadTest.YOUTUBE_MD5)
25
26     def cleanUp(self):
27         if os.path.exists(DownloadTest.YOUTUBE_FILE):
28             os.remove(DownloadTest.YOUTUBE_FILE)
29
30 def md5_for_file(f, block_size=2**20):
31     md5 = hashlib.md5()
32     while True:
33         data = f.read(block_size)
34         if not data:
35             break
36         md5.update(data)
37         return md5.digest()