test_download.py 6.6 KB

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