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.

93 lines
3.2 KiB

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