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.

198 lines
7.5 KiB

12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
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. 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 = "93c24d2f4e0782af13b8a7606ea97ba7"
  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 = "1ab4dedc01f771cb2a65e91caa801aaf"
  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 = "ce3775768ebb6432fa8495d446a078ed"
  38. SOUNDCLOUD_URL = "http://soundcloud.com/ethmusic/lostin-powers-she-so-heavy"
  39. SOUNDCLOUD_FILE = "n6FLbx6ZzMiu.mp3"
  40. STANDFORD_MD5 = "22c8206291368c4e2c9c1a307f0ea0f4"
  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 = "5f0469c8d1dfd1bc38c8e6deb5e0a21d"
  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. fd.download([DownloadTest.YOUTUBE_URL])
  55. self.assertTrue(os.path.exists(DownloadTest.YOUTUBE_FILE))
  56. self.assertEqual(os.path.getsize(DownloadTest.YOUTUBE_FILE), DownloadTest.YOUTUBE_SIZE)
  57. def test_dailymotion(self):
  58. with open(DownloadTest.PARAMETERS_FILE) as f:
  59. fd = FileDownloader(json.load(f))
  60. fd.add_info_extractor(DailymotionIE())
  61. fd.download([DownloadTest.DAILYMOTION_URL])
  62. self.assertTrue(os.path.exists(DownloadTest.DAILYMOTION_FILE))
  63. md5_down_file = md5_for_file(DownloadTest.DAILYMOTION_FILE)
  64. self.assertEqual(md5_down_file, DownloadTest.DAILYMOTION_MD5)
  65. def test_metacafe(self):
  66. #this emulate a skip,to be 2.6 compatible
  67. with open(DownloadTest.PARAMETERS_FILE) as f:
  68. fd = FileDownloader(json.load(f))
  69. fd.add_info_extractor(MetacafeIE())
  70. fd.add_info_extractor(YoutubeIE())
  71. fd.download([DownloadTest.METACAFE_URL])
  72. self.assertTrue(os.path.exists(DownloadTest.METACAFE_FILE))
  73. self.assertEqual(os.path.getsize(DownloadTest.METACAFE_FILE), DownloadTest.METACAFE_SIZE)
  74. def test_blip(self):
  75. with open(DownloadTest.PARAMETERS_FILE) as f:
  76. fd = FileDownloader(json.load(f))
  77. fd.add_info_extractor(BlipTVIE())
  78. fd.download([DownloadTest.BLIP_URL])
  79. self.assertTrue(os.path.exists(DownloadTest.BLIP_FILE))
  80. md5_down_file = md5_for_file(DownloadTest.BLIP_FILE)
  81. self.assertEqual(md5_down_file, DownloadTest.BLIP_MD5)
  82. def test_xvideo(self):
  83. with open(DownloadTest.PARAMETERS_FILE) as f:
  84. fd = FileDownloader(json.load(f))
  85. fd.add_info_extractor(XVideosIE())
  86. fd.download([DownloadTest.XVIDEO_URL])
  87. self.assertTrue(os.path.exists(DownloadTest.XVIDEO_FILE))
  88. md5_down_file = md5_for_file(DownloadTest.XVIDEO_FILE)
  89. self.assertEqual(md5_down_file, DownloadTest.XVIDEO_MD5)
  90. def test_vimeo(self):
  91. #skipped for the moment produce an error
  92. return
  93. with open(DownloadTest.PARAMETERS_FILE) as f:
  94. fd = FileDownloader(json.load(f))
  95. fd.add_info_extractor(VimeoIE())
  96. fd.download([DownloadTest.VIMEO_URL])
  97. self.assertTrue(os.path.exists(DownloadTest.VIMEO_FILE))
  98. md5_down_file = md5_for_file(DownloadTest.VIMEO_FILE)
  99. self.assertEqual(md5_down_file, DownloadTest.VIMEO_MD5)
  100. def test_vimeo2(self):
  101. #skipped for the moment produce an error
  102. return
  103. with open(DownloadTest.PARAMETERS_FILE) as f:
  104. fd = FileDownloader(json.load(f))
  105. fd.add_info_extractor(VimeoIE())
  106. fd.download([DownloadTest.VIMEO2_URL])
  107. self.assertTrue(os.path.exists(DownloadTest.VIMEO2_FILE))
  108. md5_down_file = md5_for_file(DownloadTest.VIMEO2_FILE)
  109. self.assertEqual(md5_down_file, DownloadTest.VIMEO2_MD5)
  110. def test_soundcloud(self):
  111. with open(DownloadTest.PARAMETERS_FILE) as f:
  112. fd = FileDownloader(json.load(f))
  113. fd.add_info_extractor(SoundcloudIE())
  114. fd.download([DownloadTest.SOUNDCLOUD_URL])
  115. self.assertTrue(os.path.exists(DownloadTest.SOUNDCLOUD_FILE))
  116. md5_down_file = md5_for_file(DownloadTest.SOUNDCLOUD_FILE)
  117. self.assertEqual(md5_down_file, DownloadTest.SOUNDCLOUD_MD5)
  118. def test_standford(self):
  119. with open(DownloadTest.PARAMETERS_FILE) as f:
  120. fd = FileDownloader(json.load(f))
  121. fd.add_info_extractor(StanfordOpenClassroomIE())
  122. fd.download([DownloadTest.STANDFORD_URL])
  123. self.assertTrue(os.path.exists(DownloadTest.STANDFORD_FILE))
  124. md5_down_file = md5_for_file(DownloadTest.STANDFORD_FILE)
  125. self.assertEqual(md5_down_file, DownloadTest.STANDFORD_MD5)
  126. def test_collegehumor(self):
  127. with open(DownloadTest.PARAMETERS_FILE) as f:
  128. fd = FileDownloader(json.load(f))
  129. fd.add_info_extractor(CollegeHumorIE())
  130. fd.download([DownloadTest.COLLEGEHUMOR_URL])
  131. self.assertTrue(os.path.exists(DownloadTest.COLLEGEHUMOR_FILE))
  132. md5_down_file = md5_for_file(DownloadTest.COLLEGEHUMOR_FILE)
  133. self.assertEqual(md5_down_file, DownloadTest.COLLEGEHUMOR_MD5)
  134. def test_xnxx(self):
  135. with open(DownloadTest.PARAMETERS_FILE) as f:
  136. fd = FileDownloader(json.load(f))
  137. fd.add_info_extractor(XNXXIE())
  138. fd.download([DownloadTest.XNXX_URL])
  139. self.assertTrue(os.path.exists(DownloadTest.XNXX_FILE))
  140. md5_down_file = md5_for_file(DownloadTest.XNXX_FILE)
  141. self.assertEqual(md5_down_file, DownloadTest.XNXX_MD5)
  142. def tearDown(self):
  143. if os.path.exists(DownloadTest.YOUTUBE_FILE):
  144. os.remove(DownloadTest.YOUTUBE_FILE)
  145. if os.path.exists(DownloadTest.DAILYMOTION_FILE):
  146. os.remove(DownloadTest.DAILYMOTION_FILE)
  147. if os.path.exists(DownloadTest.METACAFE_FILE):
  148. os.remove(DownloadTest.METACAFE_FILE)
  149. if os.path.exists(DownloadTest.BLIP_FILE):
  150. os.remove(DownloadTest.BLIP_FILE)
  151. if os.path.exists(DownloadTest.XVIDEO_FILE):
  152. os.remove(DownloadTest.XVIDEO_FILE)
  153. if os.path.exists(DownloadTest.VIMEO_FILE):
  154. os.remove(DownloadTest.VIMEO_FILE)
  155. if os.path.exists(DownloadTest.SOUNDCLOUD_FILE):
  156. os.remove(DownloadTest.SOUNDCLOUD_FILE)
  157. if os.path.exists(DownloadTest.STANDFORD_FILE):
  158. os.remove(DownloadTest.STANDFORD_FILE)
  159. if os.path.exists(DownloadTest.COLLEGEHUMOR_FILE):
  160. os.remove(DownloadTest.COLLEGEHUMOR_FILE)
  161. if os.path.exists(DownloadTest.XNXX_FILE):
  162. os.remove(DownloadTest.XNXX_FILE)
  163. def md5_for_file(filename, block_size=2**20):
  164. with open(filename) as f:
  165. md5 = hashlib.md5()
  166. while True:
  167. data = f.read(block_size)
  168. if not data:
  169. break
  170. md5.update(data)
  171. return md5.hexdigest()