You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

37 lines
1.2 KiB

  1. #!/usr/bin/env python2
  2. import unittest
  3. import hashlib
  4. import os
  5. from youtube_dl.FileDownloader import FileDownloader
  6. from youtube_dl.InfoExtractors import YoutubeIE
  7. class DownloadTest(unittest.TestCase):
  8. #calculated with the md5sum utility
  9. #md5sum (GNU coreutils) 8.19
  10. YOUTUBE_MD5 = "ba4092da68c9ded8ef3aaace5ffd1860"
  11. YOUTUBE_URL = "http://www.youtube.com/watch?v=u0VbyYcljx8&feature=related"
  12. YOUTUBE_FILE = "u0VbyYcljx8.flv"
  13. def test_youtube(self):
  14. #let's download a file from youtube
  15. global YOUTUBE_URL
  16. fd = FileDownloader({})
  17. fd.add_info_extractor(YoutubeIE())
  18. fd.download([DownloadTest.YOUTUBE_URL])
  19. self.assertTrue(os.path.exists(DownloadTest.YOUTUBE_FILE))
  20. md5_down_file = md5_for_file(DownloadTest.YOUTUBE_FILE)
  21. self.assertEqual(md5_down_file, DownloadTest.YOUTUBE_MD5)
  22. def cleanUp(self):
  23. if os.path.exists(DownloadTest.YOUTUBE_FILE):
  24. os.remove(DownloadTest.YOUTUBE_FILE)
  25. def md5_for_file(f, block_size=2**20):
  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.digest()