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.

174 lines
7.4 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. try:
  19. _skip_unless = unittest.skipUnless
  20. except AttributeError: # Python 2.6
  21. def _skip_unless(cond, reason='No reason given'):
  22. def resfunc(f):
  23. # Start the function name with test to appease nosetests-2.6
  24. def test_wfunc(*args, **kwargs):
  25. if cond:
  26. return f(*args, **kwargs)
  27. else:
  28. print('Skipped test')
  29. return
  30. return test_wfunc
  31. return resfunc
  32. _skip = lambda *args, **kwargs: _skip_unless(False, *args, **kwargs)
  33. class DownloadTest(unittest.TestCase):
  34. PARAMETERS_FILE = os.path.join(os.path.dirname(os.path.abspath(__file__)), "parameters.json")
  35. def setUp(self):
  36. # Clear old files
  37. self.tearDown()
  38. with io.open(self.PARAMETERS_FILE, encoding='utf-8') as pf:
  39. self.parameters = json.load(pf)
  40. @_skip_unless(youtube_dl.InfoExtractors.YoutubeIE._WORKING, "IE marked as not _WORKING")
  41. def test_Youtube(self):
  42. filename = 'BaW_jenozKc.mp4'
  43. fd = FileDownloader(self.parameters)
  44. fd.add_info_extractor(youtube_dl.InfoExtractors.YoutubeIE())
  45. fd.download(['http://www.youtube.com/watch?v=BaW_jenozKc'])
  46. self.assertTrue(os.path.exists(filename))
  47. self.assertEqual(os.path.getsize(filename), 1993883)
  48. @_skip_unless(youtube_dl.InfoExtractors.DailymotionIE._WORKING, "IE marked as not _WORKING")
  49. def test_Dailymotion(self):
  50. filename = 'x33vw9.mp4'
  51. fd = FileDownloader(self.parameters)
  52. fd.add_info_extractor(youtube_dl.InfoExtractors.DailymotionIE())
  53. fd.download(['http://www.dailymotion.com/video/x33vw9_tutoriel-de-youtubeur-dl-des-video_tech'])
  54. self.assertTrue(os.path.exists(filename))
  55. md5_for_file = _file_md5(filename)
  56. self.assertEqual(md5_for_file, 'd363a50e9eb4f22ce90d08d15695bb47')
  57. @_skip_unless(youtube_dl.InfoExtractors.MetacafeIE._WORKING, "IE marked as not _WORKING")
  58. def test_Metacafe(self):
  59. filename = 'aUehQsCQtM.flv'
  60. fd = FileDownloader(self.parameters)
  61. fd.add_info_extractor(youtube_dl.InfoExtractors.MetacafeIE())
  62. fd.add_info_extractor(youtube_dl.InfoExtractors.YoutubeIE())
  63. fd.download(['http://www.metacafe.com/watch/yt-_aUehQsCQtM/the_electric_company_short_i_pbs_kids_go/'])
  64. self.assertTrue(os.path.exists(filename))
  65. self.assertEqual(os.path.getsize(filename), 5754305)
  66. @_skip_unless(youtube_dl.InfoExtractors.BlipTVIE._WORKING, "IE marked as not _WORKING")
  67. def test_BlipTV(self):
  68. filename = '5779306.m4v'
  69. fd = FileDownloader(self.parameters)
  70. fd.add_info_extractor(youtube_dl.InfoExtractors.BlipTVIE())
  71. fd.download(['http://blip.tv/cbr/cbr-exclusive-gotham-city-imposters-bats-vs-jokerz-short-3-5796352'])
  72. self.assertTrue(os.path.exists(filename))
  73. md5_for_file = _file_md5(filename)
  74. self.assertEqual(md5_for_file, '4962f94441605832eb1008eb820ef47a')
  75. @_skip_unless(youtube_dl.InfoExtractors.XVideosIE._WORKING, "IE marked as not _WORKING")
  76. def test_XVideos(self):
  77. filename = '939581.flv'
  78. fd = FileDownloader(self.parameters)
  79. fd.add_info_extractor(youtube_dl.InfoExtractors.XVideosIE())
  80. fd.download(['http://www.xvideos.com/video939581/funny_porns_by_s_-1'])
  81. self.assertTrue(os.path.exists(filename))
  82. md5_for_file = _file_md5(filename)
  83. self.assertEqual(md5_for_file, 'aecab2ea59b7996110a7e409f0c55da3')
  84. @_skip_unless(youtube_dl.InfoExtractors.VimeoIE._WORKING, "IE marked as not _WORKING")
  85. @_skip("No output file specified")
  86. def test_Vimeo(self):
  87. filename = ''
  88. fd = FileDownloader(self.parameters)
  89. fd.add_info_extractor(youtube_dl.InfoExtractors.VimeoIE())
  90. fd.download(['http://vimeo.com/14160053'])
  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.SoundcloudIE._WORKING, "IE marked as not _WORKING")
  95. def test_Soundcloud(self):
  96. filename = 'n6FLbx6ZzMiu.mp3'
  97. fd = FileDownloader(self.parameters)
  98. fd.add_info_extractor(youtube_dl.InfoExtractors.SoundcloudIE())
  99. fd.download(['http://soundcloud.com/ethmusic/lostin-powers-she-so-heavy'])
  100. self.assertTrue(os.path.exists(filename))
  101. md5_for_file = _file_md5(filename)
  102. self.assertEqual(md5_for_file, 'c1b9b9ea8bfd620b96b2628664576e1c')
  103. @_skip_unless(youtube_dl.InfoExtractors.StanfordOpenClassroomIE._WORKING, "IE marked as not _WORKING")
  104. def test_StanfordOpenClassroom(self):
  105. filename = 'PracticalUnix_intro-environment.mp4'
  106. fd = FileDownloader(self.parameters)
  107. fd.add_info_extractor(youtube_dl.InfoExtractors.StanfordOpenClassroomIE())
  108. fd.download(['http://openclassroom.stanford.edu/MainFolder/VideoPage.php?course=PracticalUnix&video=intro-environment&speed=100'])
  109. self.assertTrue(os.path.exists(filename))
  110. md5_for_file = _file_md5(filename)
  111. self.assertEqual(md5_for_file, '8aac7873a07dcfaed66b1559ab128514')
  112. @_skip_unless(youtube_dl.InfoExtractors.CollegeHumorIE._WORKING, "IE marked as not _WORKING")
  113. @_skip("No output file specified")
  114. def test_CollegeHumor(self):
  115. filename = ''
  116. fd = FileDownloader(self.parameters)
  117. fd.add_info_extractor(youtube_dl.InfoExtractors.CollegeHumorIE())
  118. fd.download(['http://www.collegehumor.com/video/6830834/mitt-romney-style-gangnam-style-parody'])
  119. self.assertTrue(os.path.exists(filename))
  120. md5_for_file = _file_md5(filename)
  121. self.assertEqual(md5_for_file, '')
  122. @_skip_unless(youtube_dl.InfoExtractors.XNXXIE._WORKING, "IE marked as not _WORKING")
  123. def test_XNXX(self):
  124. filename = '1135332.flv'
  125. fd = FileDownloader(self.parameters)
  126. fd.add_info_extractor(youtube_dl.InfoExtractors.XNXXIE())
  127. fd.download(['http://video.xnxx.com/video1135332/lida_naked_funny_actress_5_'])
  128. self.assertTrue(os.path.exists(filename))
  129. md5_for_file = _file_md5(filename)
  130. self.assertEqual(md5_for_file, 'c5c67df477eb0d9b058200351448ba4c')
  131. def tearDown(self):
  132. if os.path.exists('BaW_jenozKc.mp4'):
  133. os.remove('BaW_jenozKc.mp4')
  134. if os.path.exists('x33vw9.mp4'):
  135. os.remove('x33vw9.mp4')
  136. if os.path.exists('aUehQsCQtM.flv'):
  137. os.remove('aUehQsCQtM.flv')
  138. if os.path.exists('5779306.m4v'):
  139. os.remove('5779306.m4v')
  140. if os.path.exists('939581.flv'):
  141. os.remove('939581.flv')
  142. # No file specified for Vimeo
  143. if os.path.exists('n6FLbx6ZzMiu.mp3'):
  144. os.remove('n6FLbx6ZzMiu.mp3')
  145. if os.path.exists('PracticalUnix_intro-environment.mp4'):
  146. os.remove('PracticalUnix_intro-environment.mp4')
  147. # No file specified for CollegeHumor
  148. if os.path.exists('1135332.flv'):
  149. os.remove('1135332.flv')
  150. if __name__ == '__main__':
  151. unittest.main()