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.

350 lines
13 KiB

10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
  1. #!/usr/bin/env python
  2. from __future__ import unicode_literals
  3. # Allow direct execution
  4. import os
  5. import sys
  6. import unittest
  7. sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
  8. from test.helper import FakeYDL, md5
  9. from youtube_dl.extractor import (
  10. BlipTVIE,
  11. YoutubeIE,
  12. DailymotionIE,
  13. TEDIE,
  14. VimeoIE,
  15. WallaIE,
  16. CeskaTelevizeIE,
  17. LyndaIE,
  18. NPOIE,
  19. ComedyCentralIE,
  20. NRKTVIE,
  21. RaiIE,
  22. VikiIE,
  23. ThePlatformIE,
  24. ThePlatformFeedIE,
  25. RTVEALaCartaIE,
  26. FunnyOrDieIE,
  27. )
  28. class BaseTestSubtitles(unittest.TestCase):
  29. url = None
  30. IE = None
  31. def setUp(self):
  32. self.DL = FakeYDL()
  33. self.ie = self.IE()
  34. self.DL.add_info_extractor(self.ie)
  35. def getInfoDict(self):
  36. info_dict = self.DL.extract_info(self.url, download=False)
  37. return info_dict
  38. def getSubtitles(self):
  39. info_dict = self.getInfoDict()
  40. subtitles = info_dict['requested_subtitles']
  41. if not subtitles:
  42. return subtitles
  43. for sub_info in subtitles.values():
  44. if sub_info.get('data') is None:
  45. uf = self.DL.urlopen(sub_info['url'])
  46. sub_info['data'] = uf.read().decode('utf-8')
  47. return dict((l, sub_info['data']) for l, sub_info in subtitles.items())
  48. class TestYoutubeSubtitles(BaseTestSubtitles):
  49. url = 'QRS8MkLhQmM'
  50. IE = YoutubeIE
  51. def test_youtube_allsubtitles(self):
  52. self.DL.params['writesubtitles'] = True
  53. self.DL.params['allsubtitles'] = True
  54. subtitles = self.getSubtitles()
  55. self.assertEqual(len(subtitles.keys()), 13)
  56. self.assertEqual(md5(subtitles['en']), '4cd9278a35ba2305f47354ee13472260')
  57. self.assertEqual(md5(subtitles['it']), '164a51f16f260476a05b50fe4c2f161d')
  58. for lang in ['it', 'fr', 'de']:
  59. self.assertTrue(subtitles.get(lang) is not None, 'Subtitles for \'%s\' not extracted' % lang)
  60. def test_youtube_subtitles_sbv_format(self):
  61. self.DL.params['writesubtitles'] = True
  62. self.DL.params['subtitlesformat'] = 'sbv'
  63. subtitles = self.getSubtitles()
  64. self.assertEqual(md5(subtitles['en']), '13aeaa0c245a8bed9a451cb643e3ad8b')
  65. def test_youtube_subtitles_vtt_format(self):
  66. self.DL.params['writesubtitles'] = True
  67. self.DL.params['subtitlesformat'] = 'vtt'
  68. subtitles = self.getSubtitles()
  69. self.assertEqual(md5(subtitles['en']), '3cb210999d3e021bd6c7f0ea751eab06')
  70. def test_youtube_automatic_captions(self):
  71. self.url = '8YoUxe5ncPo'
  72. self.DL.params['writeautomaticsub'] = True
  73. self.DL.params['subtitleslangs'] = ['it']
  74. subtitles = self.getSubtitles()
  75. self.assertTrue(subtitles['it'] is not None)
  76. def test_youtube_translated_subtitles(self):
  77. # This video has a subtitles track, which can be translated
  78. self.url = 'Ky9eprVWzlI'
  79. self.DL.params['writeautomaticsub'] = True
  80. self.DL.params['subtitleslangs'] = ['it']
  81. subtitles = self.getSubtitles()
  82. self.assertTrue(subtitles['it'] is not None)
  83. def test_youtube_nosubtitles(self):
  84. self.DL.expect_warning('video doesn\'t have subtitles')
  85. self.url = 'n5BB19UTcdA'
  86. self.DL.params['writesubtitles'] = True
  87. self.DL.params['allsubtitles'] = True
  88. subtitles = self.getSubtitles()
  89. self.assertFalse(subtitles)
  90. class TestDailymotionSubtitles(BaseTestSubtitles):
  91. url = 'http://www.dailymotion.com/video/xczg00'
  92. IE = DailymotionIE
  93. def test_allsubtitles(self):
  94. self.DL.params['writesubtitles'] = True
  95. self.DL.params['allsubtitles'] = True
  96. subtitles = self.getSubtitles()
  97. self.assertTrue(len(subtitles.keys()) >= 6)
  98. self.assertEqual(md5(subtitles['en']), '976553874490cba125086bbfea3ff76f')
  99. self.assertEqual(md5(subtitles['fr']), '594564ec7d588942e384e920e5341792')
  100. for lang in ['es', 'fr', 'de']:
  101. self.assertTrue(subtitles.get(lang) is not None, 'Subtitles for \'%s\' not extracted' % lang)
  102. def test_nosubtitles(self):
  103. self.DL.expect_warning('video doesn\'t have subtitles')
  104. self.url = 'http://www.dailymotion.com/video/x12u166_le-zapping-tele-star-du-08-aout-2013_tv'
  105. self.DL.params['writesubtitles'] = True
  106. self.DL.params['allsubtitles'] = True
  107. subtitles = self.getSubtitles()
  108. self.assertFalse(subtitles)
  109. class TestTedSubtitles(BaseTestSubtitles):
  110. url = 'http://www.ted.com/talks/dan_dennett_on_our_consciousness.html'
  111. IE = TEDIE
  112. def test_allsubtitles(self):
  113. self.DL.params['writesubtitles'] = True
  114. self.DL.params['allsubtitles'] = True
  115. subtitles = self.getSubtitles()
  116. self.assertTrue(len(subtitles.keys()) >= 28)
  117. self.assertEqual(md5(subtitles['en']), '4262c1665ff928a2dada178f62cb8d14')
  118. self.assertEqual(md5(subtitles['fr']), '66a63f7f42c97a50f8c0e90bc7797bb5')
  119. for lang in ['es', 'fr', 'de']:
  120. self.assertTrue(subtitles.get(lang) is not None, 'Subtitles for \'%s\' not extracted' % lang)
  121. class TestBlipTVSubtitles(BaseTestSubtitles):
  122. url = 'http://blip.tv/a/a-6603250'
  123. IE = BlipTVIE
  124. def test_allsubtitles(self):
  125. self.DL.params['writesubtitles'] = True
  126. self.DL.params['allsubtitles'] = True
  127. subtitles = self.getSubtitles()
  128. self.assertEqual(set(subtitles.keys()), set(['en']))
  129. self.assertEqual(md5(subtitles['en']), '5b75c300af65fe4476dff79478bb93e4')
  130. class TestVimeoSubtitles(BaseTestSubtitles):
  131. url = 'http://vimeo.com/76979871'
  132. IE = VimeoIE
  133. def test_allsubtitles(self):
  134. self.DL.params['writesubtitles'] = True
  135. self.DL.params['allsubtitles'] = True
  136. subtitles = self.getSubtitles()
  137. self.assertEqual(set(subtitles.keys()), set(['de', 'en', 'es', 'fr']))
  138. self.assertEqual(md5(subtitles['en']), '8062383cf4dec168fc40a088aa6d5888')
  139. self.assertEqual(md5(subtitles['fr']), 'b6191146a6c5d3a452244d853fde6dc8')
  140. def test_nosubtitles(self):
  141. self.DL.expect_warning('video doesn\'t have subtitles')
  142. self.url = 'http://vimeo.com/56015672'
  143. self.DL.params['writesubtitles'] = True
  144. self.DL.params['allsubtitles'] = True
  145. subtitles = self.getSubtitles()
  146. self.assertFalse(subtitles)
  147. class TestWallaSubtitles(BaseTestSubtitles):
  148. url = 'http://vod.walla.co.il/movie/2705958/the-yes-men'
  149. IE = WallaIE
  150. def test_allsubtitles(self):
  151. self.DL.expect_warning('Automatic Captions not supported by this server')
  152. self.DL.params['writesubtitles'] = True
  153. self.DL.params['allsubtitles'] = True
  154. subtitles = self.getSubtitles()
  155. self.assertEqual(set(subtitles.keys()), set(['heb']))
  156. self.assertEqual(md5(subtitles['heb']), 'e758c5d7cb982f6bef14f377ec7a3920')
  157. def test_nosubtitles(self):
  158. self.DL.expect_warning('video doesn\'t have subtitles')
  159. self.url = 'http://vod.walla.co.il/movie/2642630/one-direction-all-for-one'
  160. self.DL.params['writesubtitles'] = True
  161. self.DL.params['allsubtitles'] = True
  162. subtitles = self.getSubtitles()
  163. self.assertFalse(subtitles)
  164. class TestCeskaTelevizeSubtitles(BaseTestSubtitles):
  165. url = 'http://www.ceskatelevize.cz/ivysilani/10600540290-u6-uzasny-svet-techniky'
  166. IE = CeskaTelevizeIE
  167. def test_allsubtitles(self):
  168. self.DL.expect_warning('Automatic Captions not supported by this server')
  169. self.DL.params['writesubtitles'] = True
  170. self.DL.params['allsubtitles'] = True
  171. subtitles = self.getSubtitles()
  172. self.assertEqual(set(subtitles.keys()), set(['cs']))
  173. self.assertTrue(len(subtitles['cs']) > 20000)
  174. def test_nosubtitles(self):
  175. self.DL.expect_warning('video doesn\'t have subtitles')
  176. self.url = 'http://www.ceskatelevize.cz/ivysilani/ivysilani/10441294653-hyde-park-civilizace/214411058091220'
  177. self.DL.params['writesubtitles'] = True
  178. self.DL.params['allsubtitles'] = True
  179. subtitles = self.getSubtitles()
  180. self.assertFalse(subtitles)
  181. class TestLyndaSubtitles(BaseTestSubtitles):
  182. url = 'http://www.lynda.com/Bootstrap-tutorials/Using-exercise-files/110885/114408-4.html'
  183. IE = LyndaIE
  184. def test_allsubtitles(self):
  185. self.DL.params['writesubtitles'] = True
  186. self.DL.params['allsubtitles'] = True
  187. subtitles = self.getSubtitles()
  188. self.assertEqual(set(subtitles.keys()), set(['en']))
  189. self.assertEqual(md5(subtitles['en']), '09bbe67222259bed60deaa26997d73a7')
  190. class TestNPOSubtitles(BaseTestSubtitles):
  191. url = 'http://www.npo.nl/nos-journaal/28-08-2014/POW_00722860'
  192. IE = NPOIE
  193. def test_allsubtitles(self):
  194. self.DL.params['writesubtitles'] = True
  195. self.DL.params['allsubtitles'] = True
  196. subtitles = self.getSubtitles()
  197. self.assertEqual(set(subtitles.keys()), set(['nl']))
  198. self.assertEqual(md5(subtitles['nl']), 'fc6435027572b63fb4ab143abd5ad3f4')
  199. class TestMTVSubtitles(BaseTestSubtitles):
  200. url = 'http://www.cc.com/video-clips/kllhuv/stand-up-greg-fitzsimmons--uncensored---too-good-of-a-mother'
  201. IE = ComedyCentralIE
  202. def getInfoDict(self):
  203. return super(TestMTVSubtitles, self).getInfoDict()['entries'][0]
  204. def test_allsubtitles(self):
  205. self.DL.params['writesubtitles'] = True
  206. self.DL.params['allsubtitles'] = True
  207. subtitles = self.getSubtitles()
  208. self.assertEqual(set(subtitles.keys()), set(['en']))
  209. self.assertEqual(md5(subtitles['en']), 'b9f6ca22a6acf597ec76f61749765e65')
  210. class TestNRKSubtitles(BaseTestSubtitles):
  211. url = 'http://tv.nrk.no/serie/ikke-gjoer-dette-hjemme/DMPV73000411/sesong-2/episode-1'
  212. IE = NRKTVIE
  213. def test_allsubtitles(self):
  214. self.DL.params['writesubtitles'] = True
  215. self.DL.params['allsubtitles'] = True
  216. subtitles = self.getSubtitles()
  217. self.assertEqual(set(subtitles.keys()), set(['no']))
  218. self.assertEqual(md5(subtitles['no']), '544fa917d3197fcbee64634559221cc2')
  219. class TestRaiSubtitles(BaseTestSubtitles):
  220. url = 'http://www.rai.tv/dl/RaiTV/programmi/media/ContentItem-cb27157f-9dd0-4aee-b788-b1f67643a391.html'
  221. IE = RaiIE
  222. def test_allsubtitles(self):
  223. self.DL.params['writesubtitles'] = True
  224. self.DL.params['allsubtitles'] = True
  225. subtitles = self.getSubtitles()
  226. self.assertEqual(set(subtitles.keys()), set(['it']))
  227. self.assertEqual(md5(subtitles['it']), 'b1d90a98755126b61e667567a1f6680a')
  228. class TestVikiSubtitles(BaseTestSubtitles):
  229. url = 'http://www.viki.com/videos/1060846v-punch-episode-18'
  230. IE = VikiIE
  231. def test_allsubtitles(self):
  232. self.DL.params['writesubtitles'] = True
  233. self.DL.params['allsubtitles'] = True
  234. subtitles = self.getSubtitles()
  235. self.assertEqual(set(subtitles.keys()), set(['en']))
  236. self.assertEqual(md5(subtitles['en']), '53cb083a5914b2d84ef1ab67b880d18a')
  237. class TestThePlatformSubtitles(BaseTestSubtitles):
  238. # from http://www.3playmedia.com/services-features/tools/integrations/theplatform/
  239. # (see http://theplatform.com/about/partners/type/subtitles-closed-captioning/)
  240. url = 'theplatform:JFUjUE1_ehvq'
  241. IE = ThePlatformIE
  242. def test_allsubtitles(self):
  243. self.DL.params['writesubtitles'] = True
  244. self.DL.params['allsubtitles'] = True
  245. subtitles = self.getSubtitles()
  246. self.assertEqual(set(subtitles.keys()), set(['en']))
  247. self.assertEqual(md5(subtitles['en']), '97e7670cbae3c4d26ae8bcc7fdd78d4b')
  248. class TestThePlatformFeedSubtitles(BaseTestSubtitles):
  249. url = 'http://feed.theplatform.com/f/7wvmTC/msnbc_video-p-test?form=json&pretty=true&range=-40&byGuid=n_hardball_5biden_140207'
  250. IE = ThePlatformFeedIE
  251. def test_allsubtitles(self):
  252. self.DL.params['writesubtitles'] = True
  253. self.DL.params['allsubtitles'] = True
  254. subtitles = self.getSubtitles()
  255. self.assertEqual(set(subtitles.keys()), set(['en']))
  256. self.assertEqual(md5(subtitles['en']), '48649a22e82b2da21c9a67a395eedade')
  257. class TestRtveSubtitles(BaseTestSubtitles):
  258. url = 'http://www.rtve.es/alacarta/videos/los-misterios-de-laura/misterios-laura-capitulo-32-misterio-del-numero-17-2-parte/2428621/'
  259. IE = RTVEALaCartaIE
  260. def test_allsubtitles(self):
  261. print('Skipping, only available from Spain')
  262. return
  263. self.DL.params['writesubtitles'] = True
  264. self.DL.params['allsubtitles'] = True
  265. subtitles = self.getSubtitles()
  266. self.assertEqual(set(subtitles.keys()), set(['es']))
  267. self.assertEqual(md5(subtitles['es']), '69e70cae2d40574fb7316f31d6eb7fca')
  268. class TestFunnyOrDieSubtitles(BaseTestSubtitles):
  269. url = 'http://www.funnyordie.com/videos/224829ff6d/judd-apatow-will-direct-your-vine'
  270. IE = FunnyOrDieIE
  271. def test_allsubtitles(self):
  272. self.DL.params['writesubtitles'] = True
  273. self.DL.params['allsubtitles'] = True
  274. subtitles = self.getSubtitles()
  275. self.assertEqual(set(subtitles.keys()), set(['en']))
  276. self.assertEqual(md5(subtitles['en']), 'c5593c193eacd353596c11c2d4f9ecc4')
  277. if __name__ == '__main__':
  278. unittest.main()