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.

208 lines
8.8 KiB

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. from youtube_dl.InfoExtractors import XVideosIE, VimeoIE
  10. from youtube_dl.InfoExtractors import SoundcloudIE, StanfordOpenClassroomIE
  11. from youtube_dl.InfoExtractors import CollegeHumorIE, XNXXIE
  12. class DownloadTest(unittest.TestCase):
  13. PARAMETERS_FILE = "test/parameters.json"
  14. #calculated with md5sum:
  15. #md5sum (GNU coreutils) 8.19
  16. YOUTUBE_SIZE = 1993883
  17. YOUTUBE_URL = "http://www.youtube.com/watch?v=BaW_jenozKc"
  18. YOUTUBE_FILE = "BaW_jenozKc.mp4"
  19. DAILYMOTION_MD5 = "d363a50e9eb4f22ce90d08d15695bb47"
  20. DAILYMOTION_URL = "http://www.dailymotion.com/video/x33vw9_tutoriel-de-youtubeur-dl-des-video_tech"
  21. DAILYMOTION_FILE = "x33vw9.mp4"
  22. METACAFE_SIZE = 5754305
  23. METACAFE_URL = "http://www.metacafe.com/watch/yt-_aUehQsCQtM/the_electric_company_short_i_pbs_kids_go/"
  24. METACAFE_FILE = "aUehQsCQtM.flv"
  25. BLIP_MD5 = "4962f94441605832eb1008eb820ef47a"
  26. BLIP_URL = "http://blip.tv/cbr/cbr-exclusive-gotham-city-imposters-bats-vs-jokerz-short-3-5796352"
  27. BLIP_FILE = "5779306.m4v"
  28. XVIDEO_MD5 = "aecab2ea59b7996110a7e409f0c55da3"
  29. XVIDEO_URL = "http://www.xvideos.com/video939581/funny_porns_by_s_-1"
  30. XVIDEO_FILE = "939581.flv"
  31. VIMEO_MD5 = "1ab4dedc01f771cb2a65e91caa801aaf"
  32. VIMEO_URL = "http://vimeo.com/14160053"
  33. VIMEO_FILE = ""
  34. VIMEO2_MD5 = ""
  35. VIMEO2_URL = "http://player.vimeo.com/video/47019590"
  36. VIMEO2_FILE = ""
  37. SOUNDCLOUD_MD5 = "c1b9b9ea8bfd620b96b2628664576e1c"
  38. SOUNDCLOUD_URL = "http://soundcloud.com/ethmusic/lostin-powers-she-so-heavy"
  39. SOUNDCLOUD_FILE = "n6FLbx6ZzMiu.mp3"
  40. STANDFORD_MD5 = "8aac7873a07dcfaed66b1559ab128514"
  41. STANDFORD_URL = "http://openclassroom.stanford.edu/MainFolder/VideoPage.php?course=PracticalUnix&video=intro-environment&speed=100"
  42. STANDFORD_FILE = "PracticalUnix_intro-environment.mp4"
  43. COLLEGEHUMOR_MD5 = ""
  44. COLLEGEHUMOR_URL = "http://www.collegehumor.com/video/6830834/mitt-romney-style-gangnam-style-parody"
  45. COLLEGEHUMOR_FILE = ""
  46. XNXX_MD5 = "c5c67df477eb0d9b058200351448ba4c"
  47. XNXX_URL = "http://video.xnxx.com/video1135332/lida_naked_funny_actress_5_"
  48. XNXX_FILE = "1135332.flv"
  49. def test_youtube(self):
  50. #let's download a file from youtube
  51. with open(DownloadTest.PARAMETERS_FILE) as f:
  52. fd = FileDownloader(json.load(f))
  53. fd.add_info_extractor(YoutubeIE())
  54. if not YoutubeIE._WORKING: return
  55. fd.download([DownloadTest.YOUTUBE_URL])
  56. self.assertTrue(os.path.exists(DownloadTest.YOUTUBE_FILE))
  57. self.assertEqual(os.path.getsize(DownloadTest.YOUTUBE_FILE), DownloadTest.YOUTUBE_SIZE)
  58. def test_dailymotion(self):
  59. with open(DownloadTest.PARAMETERS_FILE) as f:
  60. fd = FileDownloader(json.load(f))
  61. fd.add_info_extractor(DailymotionIE())
  62. if not DailymotionIE._WORKING: return
  63. fd.download([DownloadTest.DAILYMOTION_URL])
  64. self.assertTrue(os.path.exists(DownloadTest.DAILYMOTION_FILE))
  65. md5_down_file = md5_for_file(DownloadTest.DAILYMOTION_FILE)
  66. self.assertEqual(md5_down_file, DownloadTest.DAILYMOTION_MD5)
  67. def test_metacafe(self):
  68. #this emulate a skip,to be 2.6 compatible
  69. with open(DownloadTest.PARAMETERS_FILE) as f:
  70. fd = FileDownloader(json.load(f))
  71. fd.add_info_extractor(MetacafeIE())
  72. if not MetacafeIE._WORKING: return
  73. fd.add_info_extractor(YoutubeIE())
  74. if not YoutubeIE._WORKING: return
  75. fd.download([DownloadTest.METACAFE_URL])
  76. self.assertTrue(os.path.exists(DownloadTest.METACAFE_FILE))
  77. self.assertEqual(os.path.getsize(DownloadTest.METACAFE_FILE), DownloadTest.METACAFE_SIZE)
  78. def test_blip(self):
  79. with open(DownloadTest.PARAMETERS_FILE) as f:
  80. fd = FileDownloader(json.load(f))
  81. fd.add_info_extractor(BlipTVIE())
  82. if not BlipTVIE._WORKING: return
  83. fd.download([DownloadTest.BLIP_URL])
  84. self.assertTrue(os.path.exists(DownloadTest.BLIP_FILE))
  85. md5_down_file = md5_for_file(DownloadTest.BLIP_FILE)
  86. self.assertEqual(md5_down_file, DownloadTest.BLIP_MD5)
  87. def test_xvideo(self):
  88. with open(DownloadTest.PARAMETERS_FILE) as f:
  89. fd = FileDownloader(json.load(f))
  90. fd.add_info_extractor(XVideosIE())
  91. if not XVideosIE._WORKING: return
  92. fd.download([DownloadTest.XVIDEO_URL])
  93. self.assertTrue(os.path.exists(DownloadTest.XVIDEO_FILE))
  94. md5_down_file = md5_for_file(DownloadTest.XVIDEO_FILE)
  95. self.assertEqual(md5_down_file, DownloadTest.XVIDEO_MD5)
  96. def test_vimeo(self):
  97. #skipped for the moment produce an error
  98. return
  99. with open(DownloadTest.PARAMETERS_FILE) as f:
  100. fd = FileDownloader(json.load(f))
  101. fd.add_info_extractor(VimeoIE())
  102. fd.download([DownloadTest.VIMEO_URL])
  103. self.assertTrue(os.path.exists(DownloadTest.VIMEO_FILE))
  104. md5_down_file = md5_for_file(DownloadTest.VIMEO_FILE)
  105. self.assertEqual(md5_down_file, DownloadTest.VIMEO_MD5)
  106. def test_vimeo2(self):
  107. #skipped for the moment produce an error
  108. return
  109. with open(DownloadTest.PARAMETERS_FILE) as f:
  110. fd = FileDownloader(json.load(f))
  111. fd.add_info_extractor(VimeoIE())
  112. fd.download([DownloadTest.VIMEO2_URL])
  113. self.assertTrue(os.path.exists(DownloadTest.VIMEO2_FILE))
  114. md5_down_file = md5_for_file(DownloadTest.VIMEO2_FILE)
  115. self.assertEqual(md5_down_file, DownloadTest.VIMEO2_MD5)
  116. def test_soundcloud(self):
  117. with open(DownloadTest.PARAMETERS_FILE) as f:
  118. fd = FileDownloader(json.load(f))
  119. fd.add_info_extractor(SoundcloudIE())
  120. if not SoundcloudIE._WORKING: return
  121. fd.download([DownloadTest.SOUNDCLOUD_URL])
  122. self.assertTrue(os.path.exists(DownloadTest.SOUNDCLOUD_FILE))
  123. md5_down_file = md5_for_file(DownloadTest.SOUNDCLOUD_FILE)
  124. self.assertEqual(md5_down_file, DownloadTest.SOUNDCLOUD_MD5)
  125. def test_standford(self):
  126. with open(DownloadTest.PARAMETERS_FILE) as f:
  127. fd = FileDownloader(json.load(f))
  128. fd.add_info_extractor(StanfordOpenClassroomIE())
  129. if not StanfordOpenClassroomIE._WORKING: return
  130. fd.download([DownloadTest.STANDFORD_URL])
  131. self.assertTrue(os.path.exists(DownloadTest.STANDFORD_FILE))
  132. md5_down_file = md5_for_file(DownloadTest.STANDFORD_FILE)
  133. self.assertEqual(md5_down_file, DownloadTest.STANDFORD_MD5)
  134. def test_collegehumor(self):
  135. with open(DownloadTest.PARAMETERS_FILE) as f:
  136. fd = FileDownloader(json.load(f))
  137. fd.add_info_extractor(CollegeHumorIE())
  138. if not CollegeHumorIE._WORKING: return
  139. fd.download([DownloadTest.COLLEGEHUMOR_URL])
  140. self.assertTrue(os.path.exists(DownloadTest.COLLEGEHUMOR_FILE))
  141. md5_down_file = md5_for_file(DownloadTest.COLLEGEHUMOR_FILE)
  142. self.assertEqual(md5_down_file, DownloadTest.COLLEGEHUMOR_MD5)
  143. def test_xnxx(self):
  144. with open(DownloadTest.PARAMETERS_FILE) as f:
  145. fd = FileDownloader(json.load(f))
  146. fd.add_info_extractor(XNXXIE())
  147. if not XNXXIE._WORKING: return
  148. fd.download([DownloadTest.XNXX_URL])
  149. self.assertTrue(os.path.exists(DownloadTest.XNXX_FILE))
  150. md5_down_file = md5_for_file(DownloadTest.XNXX_FILE)
  151. self.assertEqual(md5_down_file, DownloadTest.XNXX_MD5)
  152. def tearDown(self):
  153. if os.path.exists(DownloadTest.YOUTUBE_FILE):
  154. os.remove(DownloadTest.YOUTUBE_FILE)
  155. if os.path.exists(DownloadTest.DAILYMOTION_FILE):
  156. os.remove(DownloadTest.DAILYMOTION_FILE)
  157. if os.path.exists(DownloadTest.METACAFE_FILE):
  158. os.remove(DownloadTest.METACAFE_FILE)
  159. if os.path.exists(DownloadTest.BLIP_FILE):
  160. os.remove(DownloadTest.BLIP_FILE)
  161. if os.path.exists(DownloadTest.XVIDEO_FILE):
  162. os.remove(DownloadTest.XVIDEO_FILE)
  163. if os.path.exists(DownloadTest.VIMEO_FILE):
  164. os.remove(DownloadTest.VIMEO_FILE)
  165. if os.path.exists(DownloadTest.SOUNDCLOUD_FILE):
  166. os.remove(DownloadTest.SOUNDCLOUD_FILE)
  167. if os.path.exists(DownloadTest.STANDFORD_FILE):
  168. os.remove(DownloadTest.STANDFORD_FILE)
  169. if os.path.exists(DownloadTest.COLLEGEHUMOR_FILE):
  170. os.remove(DownloadTest.COLLEGEHUMOR_FILE)
  171. if os.path.exists(DownloadTest.XNXX_FILE):
  172. os.remove(DownloadTest.XNXX_FILE)
  173. def md5_for_file(filename, block_size=2**20):
  174. with open(filename) as f:
  175. md5 = hashlib.md5()
  176. while True:
  177. data = f.read(block_size)
  178. if not data:
  179. break
  180. md5.update(data)
  181. return md5.hexdigest()