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.

187 lines
7.7 KiB

12 years ago
12 years ago
12 years ago
  1. #!/usr/bin/env python
  2. # DO NOT EDIT THIS FILE BY HAND!
  3. # It is auto-generated from tests.json and gentests.py.
  4. import hashlib
  5. import io
  6. import os
  7. import json
  8. import unittest
  9. import sys
  10. # Allow direct execution
  11. import os
  12. sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
  13. from youtube_dl.FileDownloader import FileDownloader
  14. import youtube_dl.InfoExtractors
  15. def _file_md5(fn):
  16. with open(fn, 'rb') as f:
  17. return hashlib.md5(f.read()).hexdigest()
  18. def md5_for_file(filename, block_size=2**20):
  19. with open(filename) as f:
  20. md5 = hashlib.md5()
  21. while True:
  22. data = f.read(block_size)
  23. if not data:
  24. break
  25. md5.update(data)
  26. return md5.hexdigest()
  27. _file_md5 = md5_for_file
  28. try:
  29. _skip_unless = unittest.skipUnless
  30. except AttributeError: # Python 2.6
  31. def _skip_unless(cond, reason='No reason given'):
  32. def resfunc(f):
  33. # Start the function name with test to appease nosetests-2.6
  34. def test_wfunc(*args, **kwargs):
  35. if cond:
  36. return f(*args, **kwargs)
  37. else:
  38. print('Skipped test')
  39. return
  40. return test_wfunc
  41. return resfunc
  42. _skip = lambda *args, **kwargs: _skip_unless(False, *args, **kwargs)
  43. class DownloadTest(unittest.TestCase):
  44. PARAMETERS_FILE = os.path.join(os.path.dirname(os.path.abspath(__file__)), "parameters.json")
  45. def setUp(self):
  46. # Clear old files
  47. self.tearDown()
  48. with io.open(self.PARAMETERS_FILE, encoding='utf-8') as pf:
  49. self.parameters = json.load(pf)
  50. @_skip_unless(youtube_dl.InfoExtractors.YoutubeIE._WORKING, "IE marked as not _WORKING")
  51. def test_Youtube(self):
  52. filename = 'BaW_jenozKc.mp4'
  53. fd = FileDownloader(self.parameters)
  54. fd.add_info_extractor(youtube_dl.InfoExtractors.YoutubeIE())
  55. fd.download(['http://www.youtube.com/watch?v=BaW_jenozKc'])
  56. self.assertTrue(os.path.exists(filename))
  57. self.assertEqual(os.path.getsize(filename), 1993883)
  58. @_skip_unless(youtube_dl.InfoExtractors.DailymotionIE._WORKING, "IE marked as not _WORKING")
  59. def test_Dailymotion(self):
  60. filename = 'x33vw9.mp4'
  61. fd = FileDownloader(self.parameters)
  62. fd.add_info_extractor(youtube_dl.InfoExtractors.DailymotionIE())
  63. fd.download(['http://www.dailymotion.com/video/x33vw9_tutoriel-de-youtubeur-dl-des-video_tech'])
  64. self.assertTrue(os.path.exists(filename))
  65. md5_for_file = _file_md5(filename)
  66. self.assertEqual(md5_for_file, 'd363a50e9eb4f22ce90d08d15695bb47')
  67. @_skip_unless(youtube_dl.InfoExtractors.MetacafeIE._WORKING, "IE marked as not _WORKING")
  68. def test_Metacafe(self):
  69. filename = 'aUehQsCQtM.flv'
  70. fd = FileDownloader(self.parameters)
  71. fd.add_info_extractor(youtube_dl.InfoExtractors.MetacafeIE())
  72. fd.add_info_extractor(youtube_dl.InfoExtractors.YoutubeIE())
  73. fd.download(['http://www.metacafe.com/watch/yt-_aUehQsCQtM/the_electric_company_short_i_pbs_kids_go/'])
  74. self.assertTrue(os.path.exists(filename))
  75. self.assertEqual(os.path.getsize(filename), 5754305)
  76. @_skip_unless(youtube_dl.InfoExtractors.BlipTVIE._WORKING, "IE marked as not _WORKING")
  77. def test_BlipTV(self):
  78. filename = '5779306.m4v'
  79. fd = FileDownloader(self.parameters)
  80. fd.add_info_extractor(youtube_dl.InfoExtractors.BlipTVIE())
  81. fd.download(['http://blip.tv/cbr/cbr-exclusive-gotham-city-imposters-bats-vs-jokerz-short-3-5796352'])
  82. self.assertTrue(os.path.exists(filename))
  83. md5_for_file = _file_md5(filename)
  84. self.assertEqual(md5_for_file, '93c24d2f4e0782af13b8a7606ea97ba7')
  85. @_skip_unless(youtube_dl.InfoExtractors.XVideosIE._WORKING, "IE marked as not _WORKING")
  86. def test_XVideos(self):
  87. filename = '939581.flv'
  88. fd = FileDownloader(self.parameters)
  89. fd.add_info_extractor(youtube_dl.InfoExtractors.XVideosIE())
  90. fd.download(['http://www.xvideos.com/video939581/funny_porns_by_s_-1'])
  91. self.assertTrue(os.path.exists(filename))
  92. md5_for_file = _file_md5(filename)
  93. self.assertEqual(md5_for_file, '1ab4dedc01f771cb2a65e91caa801aaf')
  94. @_skip_unless(youtube_dl.InfoExtractors.VimeoIE._WORKING, "IE marked as not _WORKING")
  95. @_skip("No output file specified")
  96. def test_Vimeo(self):
  97. filename = ''
  98. fd = FileDownloader(self.parameters)
  99. fd.add_info_extractor(youtube_dl.InfoExtractors.VimeoIE())
  100. fd.download(['http://vimeo.com/14160053'])
  101. self.assertTrue(os.path.exists(filename))
  102. md5_for_file = _file_md5(filename)
  103. self.assertEqual(md5_for_file, '1ab4dedc01f771cb2a65e91caa801aaf')
  104. @_skip_unless(youtube_dl.InfoExtractors.SoundcloudIE._WORKING, "IE marked as not _WORKING")
  105. def test_Soundcloud(self):
  106. filename = 'n6FLbx6ZzMiu.mp3'
  107. fd = FileDownloader(self.parameters)
  108. fd.add_info_extractor(youtube_dl.InfoExtractors.SoundcloudIE())
  109. fd.download(['http://soundcloud.com/ethmusic/lostin-powers-she-so-heavy'])
  110. self.assertTrue(os.path.exists(filename))
  111. md5_for_file = _file_md5(filename)
  112. self.assertEqual(md5_for_file, 'ce3775768ebb6432fa8495d446a078ed')
  113. @_skip_unless(youtube_dl.InfoExtractors.StanfordOpenClassroomIE._WORKING, "IE marked as not _WORKING")
  114. def test_StanfordOpenClassroom(self):
  115. filename = 'PracticalUnix_intro-environment.mp4'
  116. fd = FileDownloader(self.parameters)
  117. fd.add_info_extractor(youtube_dl.InfoExtractors.StanfordOpenClassroomIE())
  118. fd.download(['http://openclassroom.stanford.edu/MainFolder/VideoPage.php?course=PracticalUnix&video=intro-environment&speed=100'])
  119. self.assertTrue(os.path.exists(filename))
  120. md5_for_file = _file_md5(filename)
  121. self.assertEqual(md5_for_file, '22c8206291368c4e2c9c1a307f0ea0f4')
  122. @_skip_unless(youtube_dl.InfoExtractors.CollegeHumorIE._WORKING, "IE marked as not _WORKING")
  123. @_skip("No output file specified")
  124. def test_CollegeHumor(self):
  125. filename = ''
  126. fd = FileDownloader(self.parameters)
  127. fd.add_info_extractor(youtube_dl.InfoExtractors.CollegeHumorIE())
  128. fd.download(['http://www.collegehumor.com/video/6830834/mitt-romney-style-gangnam-style-parody'])
  129. self.assertTrue(os.path.exists(filename))
  130. md5_for_file = _file_md5(filename)
  131. self.assertEqual(md5_for_file, '')
  132. @_skip_unless(youtube_dl.InfoExtractors.XNXXIE._WORKING, "IE marked as not _WORKING")
  133. def test_XNXX(self):
  134. filename = '1135332.flv'
  135. fd = FileDownloader(self.parameters)
  136. fd.add_info_extractor(youtube_dl.InfoExtractors.XNXXIE())
  137. fd.download(['http://video.xnxx.com/video1135332/lida_naked_funny_actress_5_'])
  138. self.assertTrue(os.path.exists(filename))
  139. md5_for_file = _file_md5(filename)
  140. self.assertEqual(md5_for_file, '5f0469c8d1dfd1bc38c8e6deb5e0a21d')
  141. def tearDown(self):
  142. if os.path.exists('BaW_jenozKc.mp4'):
  143. os.remove('BaW_jenozKc.mp4')
  144. if os.path.exists('x33vw9.mp4'):
  145. os.remove('x33vw9.mp4')
  146. if os.path.exists('aUehQsCQtM.flv'):
  147. os.remove('aUehQsCQtM.flv')
  148. if os.path.exists('5779306.m4v'):
  149. os.remove('5779306.m4v')
  150. if os.path.exists('939581.flv'):
  151. os.remove('939581.flv')
  152. # No file specified for Vimeo
  153. if os.path.exists('n6FLbx6ZzMiu.mp3'):
  154. os.remove('n6FLbx6ZzMiu.mp3')
  155. if os.path.exists('PracticalUnix_intro-environment.mp4'):
  156. os.remove('PracticalUnix_intro-environment.mp4')
  157. # No file specified for CollegeHumor
  158. if os.path.exists('1135332.flv'):
  159. os.remove('1135332.flv')
  160. if __name__ == '__main__':
  161. unittest.main()