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.

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