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.

199 lines
8.3 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. import socket
  11. # Allow direct execution
  12. import os
  13. sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
  14. import youtube_dl.FileDownloader
  15. import youtube_dl.InfoExtractors
  16. from youtube_dl.utils import *
  17. # General configuration (from __init__, not very elegant...)
  18. jar = compat_cookiejar.CookieJar()
  19. cookie_processor = compat_urllib_request.HTTPCookieProcessor(jar)
  20. proxy_handler = compat_urllib_request.ProxyHandler()
  21. opener = compat_urllib_request.build_opener(proxy_handler, cookie_processor, YoutubeDLHandler())
  22. compat_urllib_request.install_opener(opener)
  23. socket.setdefaulttimeout(300) # 5 minutes should be enough (famous last words)
  24. class FileDownloader(youtube_dl.FileDownloader):
  25. def __init__(self, *args, **kwargs):
  26. youtube_dl.FileDownloader.__init__(self, *args, **kwargs)
  27. self.to_stderr = self.to_screen
  28. def _file_md5(fn):
  29. with open(fn, 'rb') as f:
  30. return hashlib.md5(f.read()).hexdigest()
  31. try:
  32. _skip_unless = unittest.skipUnless
  33. except AttributeError: # Python 2.6
  34. def _skip_unless(cond, reason='No reason given'):
  35. def resfunc(f):
  36. # Start the function name with test to appease nosetests-2.6
  37. def test_wfunc(*args, **kwargs):
  38. if cond:
  39. return f(*args, **kwargs)
  40. else:
  41. print('Skipped test')
  42. return
  43. test_wfunc.__name__ = f.__name__
  44. return test_wfunc
  45. return resfunc
  46. _skip = lambda *args, **kwargs: _skip_unless(False, *args, **kwargs)
  47. class DownloadTest(unittest.TestCase):
  48. PARAMETERS_FILE = os.path.join(os.path.dirname(os.path.abspath(__file__)), "parameters.json")
  49. def setUp(self):
  50. # Clear old files
  51. self.tearDown()
  52. with io.open(self.PARAMETERS_FILE, encoding='utf-8') as pf:
  53. self.parameters = json.load(pf)
  54. @_skip_unless(youtube_dl.InfoExtractors.YoutubeIE._WORKING, "IE marked as not _WORKING")
  55. def test_Youtube(self):
  56. filename = 'BaW_jenozKc.mp4'
  57. params = self.parameters
  58. fd = FileDownloader(params)
  59. fd.add_info_extractor(youtube_dl.InfoExtractors.YoutubeIE())
  60. fd.download(['http://www.youtube.com/watch?v=BaW_jenozKc'])
  61. self.assertTrue(os.path.exists(filename))
  62. @_skip_unless(youtube_dl.InfoExtractors.DailymotionIE._WORKING, "IE marked as not _WORKING")
  63. def test_Dailymotion(self):
  64. filename = 'x33vw9.mp4'
  65. params = self.parameters
  66. fd = FileDownloader(params)
  67. fd.add_info_extractor(youtube_dl.InfoExtractors.DailymotionIE())
  68. fd.download(['http://www.dailymotion.com/video/x33vw9_tutoriel-de-youtubeur-dl-des-video_tech'])
  69. self.assertTrue(os.path.exists(filename))
  70. md5_for_file = _file_md5(filename)
  71. self.assertEqual(md5_for_file, '392c4b85a60a90dc4792da41ce3144eb')
  72. @_skip_unless(youtube_dl.InfoExtractors.MetacafeIE._WORKING, "IE marked as not _WORKING")
  73. def test_Metacafe(self):
  74. filename = '_aUehQsCQtM.flv'
  75. params = self.parameters
  76. fd = FileDownloader(params)
  77. fd.add_info_extractor(youtube_dl.InfoExtractors.MetacafeIE())
  78. fd.add_info_extractor(youtube_dl.InfoExtractors.YoutubeIE())
  79. fd.download(['http://www.metacafe.com/watch/yt-_aUehQsCQtM/the_electric_company_short_i_pbs_kids_go/'])
  80. self.assertTrue(os.path.exists(filename))
  81. @_skip_unless(youtube_dl.InfoExtractors.BlipTVIE._WORKING, "IE marked as not _WORKING")
  82. def test_BlipTV(self):
  83. filename = '5779306.m4v'
  84. params = self.parameters
  85. fd = FileDownloader(params)
  86. fd.add_info_extractor(youtube_dl.InfoExtractors.BlipTVIE())
  87. fd.download(['http://blip.tv/cbr/cbr-exclusive-gotham-city-imposters-bats-vs-jokerz-short-3-5796352'])
  88. self.assertTrue(os.path.exists(filename))
  89. md5_for_file = _file_md5(filename)
  90. self.assertEqual(md5_for_file, 'b2d849efcf7ee18917e4b4d9ff37cafe')
  91. @_skip_unless(youtube_dl.InfoExtractors.XVideosIE._WORKING, "IE marked as not _WORKING")
  92. def test_XVideos(self):
  93. filename = '939581.flv'
  94. params = self.parameters
  95. fd = FileDownloader(params)
  96. fd.add_info_extractor(youtube_dl.InfoExtractors.XVideosIE())
  97. fd.download(['http://www.xvideos.com/video939581/funny_porns_by_s_-1'])
  98. self.assertTrue(os.path.exists(filename))
  99. md5_for_file = _file_md5(filename)
  100. self.assertEqual(md5_for_file, '1d0c835822f0a71a7bf011855db929d0')
  101. @_skip_unless(youtube_dl.InfoExtractors.VimeoIE._WORKING, "IE marked as not _WORKING")
  102. def test_Vimeo(self):
  103. filename = '14160053.mp4'
  104. params = self.parameters
  105. fd = FileDownloader(params)
  106. fd.add_info_extractor(youtube_dl.InfoExtractors.VimeoIE())
  107. fd.download(['http://vimeo.com/14160053'])
  108. self.assertTrue(os.path.exists(filename))
  109. md5_for_file = _file_md5(filename)
  110. self.assertEqual(md5_for_file, '60540a4ec7cc378ec84b919c0aed5023')
  111. @_skip_unless(youtube_dl.InfoExtractors.SoundcloudIE._WORKING, "IE marked as not _WORKING")
  112. def test_Soundcloud(self):
  113. filename = '62986583.mp3'
  114. params = self.parameters
  115. fd = FileDownloader(params)
  116. fd.add_info_extractor(youtube_dl.InfoExtractors.SoundcloudIE())
  117. fd.download(['http://soundcloud.com/ethmusic/lostin-powers-she-so-heavy'])
  118. self.assertTrue(os.path.exists(filename))
  119. md5_for_file = _file_md5(filename)
  120. self.assertEqual(md5_for_file, 'ebef0a451b909710ed1d7787dddbf0d7')
  121. @_skip_unless(youtube_dl.InfoExtractors.StanfordOpenClassroomIE._WORKING, "IE marked as not _WORKING")
  122. def test_StanfordOpenClassroom(self):
  123. filename = 'PracticalUnix_intro-environment.mp4'
  124. params = self.parameters
  125. fd = FileDownloader(params)
  126. fd.add_info_extractor(youtube_dl.InfoExtractors.StanfordOpenClassroomIE())
  127. fd.download(['http://openclassroom.stanford.edu/MainFolder/VideoPage.php?course=PracticalUnix&video=intro-environment&speed=100'])
  128. self.assertTrue(os.path.exists(filename))
  129. md5_for_file = _file_md5(filename)
  130. self.assertEqual(md5_for_file, '544a9468546059d4e80d76265b0443b8')
  131. @_skip_unless(youtube_dl.InfoExtractors.XNXXIE._WORKING, "IE marked as not _WORKING")
  132. def test_XNXX(self):
  133. filename = '1135332.flv'
  134. params = self.parameters
  135. fd = FileDownloader(params)
  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, '0831677e2b4761795f68d417e0b7b445')
  141. @_skip_unless(youtube_dl.InfoExtractors.YoukuIE._WORKING, "IE marked as not _WORKING")
  142. def test_Youku(self):
  143. filename = 'XNDgyMDQ2NTQw_part00.flv'
  144. params = self.parameters
  145. params["test"] = False
  146. fd = FileDownloader(params)
  147. fd.add_info_extractor(youtube_dl.InfoExtractors.YoukuIE())
  148. fd.download(['http://v.youku.com/v_show/id_XNDgyMDQ2NTQw.html'])
  149. self.assertTrue(os.path.exists(filename))
  150. md5_for_file = _file_md5(filename)
  151. self.assertEqual(md5_for_file, 'ffe3f2e435663dc2d1eea34faeff5b5b')
  152. def tearDown(self):
  153. if os.path.exists('BaW_jenozKc.mp4'):
  154. os.remove('BaW_jenozKc.mp4')
  155. if os.path.exists('x33vw9.mp4'):
  156. os.remove('x33vw9.mp4')
  157. if os.path.exists('_aUehQsCQtM.flv'):
  158. os.remove('_aUehQsCQtM.flv')
  159. if os.path.exists('5779306.m4v'):
  160. os.remove('5779306.m4v')
  161. if os.path.exists('939581.flv'):
  162. os.remove('939581.flv')
  163. if os.path.exists('14160053.mp4'):
  164. os.remove('14160053.mp4')
  165. if os.path.exists('62986583.mp3'):
  166. os.remove('62986583.mp3')
  167. if os.path.exists('PracticalUnix_intro-environment.mp4'):
  168. os.remove('PracticalUnix_intro-environment.mp4')
  169. if os.path.exists('1135332.flv'):
  170. os.remove('1135332.flv')
  171. if os.path.exists('XNDgyMDQ2NTQw_part00.flv'):
  172. os.remove('XNDgyMDQ2NTQw_part00.flv')
  173. if __name__ == '__main__':
  174. unittest.main()