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.

349 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
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
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. )
  18. class BaseTestSubtitles(unittest.TestCase):
  19. url = None
  20. IE = None
  21. def setUp(self):
  22. self.DL = FakeYDL()
  23. self.ie = self.IE(self.DL)
  24. def getInfoDict(self):
  25. info_dict = self.ie.extract(self.url)
  26. return info_dict
  27. def getSubtitles(self):
  28. info_dict = self.getInfoDict()
  29. return info_dict['subtitles']
  30. class TestYoutubeSubtitles(BaseTestSubtitles):
  31. url = 'QRS8MkLhQmM'
  32. IE = YoutubeIE
  33. def test_youtube_no_writesubtitles(self):
  34. self.DL.params['writesubtitles'] = False
  35. subtitles = self.getSubtitles()
  36. self.assertEqual(subtitles, None)
  37. def test_youtube_subtitles(self):
  38. self.DL.params['writesubtitles'] = True
  39. subtitles = self.getSubtitles()
  40. self.assertEqual(md5(subtitles['en']), '4cd9278a35ba2305f47354ee13472260')
  41. def test_youtube_subtitles_lang(self):
  42. self.DL.params['writesubtitles'] = True
  43. self.DL.params['subtitleslangs'] = ['it']
  44. subtitles = self.getSubtitles()
  45. self.assertEqual(md5(subtitles['it']), '164a51f16f260476a05b50fe4c2f161d')
  46. def test_youtube_allsubtitles(self):
  47. self.DL.params['writesubtitles'] = True
  48. self.DL.params['allsubtitles'] = True
  49. subtitles = self.getSubtitles()
  50. self.assertEqual(len(subtitles.keys()), 13)
  51. def test_youtube_subtitles_sbv_format(self):
  52. self.DL.params['writesubtitles'] = True
  53. self.DL.params['subtitlesformat'] = 'sbv'
  54. subtitles = self.getSubtitles()
  55. self.assertEqual(md5(subtitles['en']), '13aeaa0c245a8bed9a451cb643e3ad8b')
  56. def test_youtube_subtitles_vtt_format(self):
  57. self.DL.params['writesubtitles'] = True
  58. self.DL.params['subtitlesformat'] = 'vtt'
  59. subtitles = self.getSubtitles()
  60. self.assertEqual(md5(subtitles['en']), '3cb210999d3e021bd6c7f0ea751eab06')
  61. def test_youtube_list_subtitles(self):
  62. self.DL.expect_warning('Video doesn\'t have automatic captions')
  63. self.DL.params['listsubtitles'] = True
  64. info_dict = self.getInfoDict()
  65. self.assertEqual(info_dict, None)
  66. def test_youtube_automatic_captions(self):
  67. self.url = '8YoUxe5ncPo'
  68. self.DL.params['writeautomaticsub'] = True
  69. self.DL.params['subtitleslangs'] = ['it']
  70. subtitles = self.getSubtitles()
  71. self.assertTrue(subtitles['it'] is not None)
  72. def test_youtube_translated_subtitles(self):
  73. # This video has a subtitles track, which can be translated
  74. self.url = 'Ky9eprVWzlI'
  75. self.DL.params['writeautomaticsub'] = True
  76. self.DL.params['subtitleslangs'] = ['it']
  77. subtitles = self.getSubtitles()
  78. self.assertTrue(subtitles['it'] is not None)
  79. def test_youtube_nosubtitles(self):
  80. self.DL.expect_warning('video doesn\'t have subtitles')
  81. self.url = 'n5BB19UTcdA'
  82. self.DL.params['writesubtitles'] = True
  83. self.DL.params['allsubtitles'] = True
  84. subtitles = self.getSubtitles()
  85. self.assertEqual(len(subtitles), 0)
  86. def test_youtube_multiple_langs(self):
  87. self.url = 'QRS8MkLhQmM'
  88. self.DL.params['writesubtitles'] = True
  89. langs = ['it', 'fr', 'de']
  90. self.DL.params['subtitleslangs'] = langs
  91. subtitles = self.getSubtitles()
  92. for lang in langs:
  93. self.assertTrue(subtitles.get(lang) is not None, 'Subtitles for \'%s\' not extracted' % lang)
  94. class TestDailymotionSubtitles(BaseTestSubtitles):
  95. url = 'http://www.dailymotion.com/video/xczg00'
  96. IE = DailymotionIE
  97. def test_no_writesubtitles(self):
  98. subtitles = self.getSubtitles()
  99. self.assertEqual(subtitles, None)
  100. def test_subtitles(self):
  101. self.DL.params['writesubtitles'] = True
  102. subtitles = self.getSubtitles()
  103. self.assertEqual(md5(subtitles['en']), '976553874490cba125086bbfea3ff76f')
  104. def test_subtitles_lang(self):
  105. self.DL.params['writesubtitles'] = True
  106. self.DL.params['subtitleslangs'] = ['fr']
  107. subtitles = self.getSubtitles()
  108. self.assertEqual(md5(subtitles['fr']), '594564ec7d588942e384e920e5341792')
  109. def test_allsubtitles(self):
  110. self.DL.params['writesubtitles'] = True
  111. self.DL.params['allsubtitles'] = True
  112. subtitles = self.getSubtitles()
  113. self.assertTrue(len(subtitles.keys()) >= 6)
  114. def test_list_subtitles(self):
  115. self.DL.expect_warning('Automatic Captions not supported by this server')
  116. self.DL.params['listsubtitles'] = True
  117. info_dict = self.getInfoDict()
  118. self.assertEqual(info_dict, None)
  119. def test_automatic_captions(self):
  120. self.DL.expect_warning('Automatic Captions not supported by this server')
  121. self.DL.params['writeautomaticsub'] = True
  122. self.DL.params['subtitleslang'] = ['en']
  123. subtitles = self.getSubtitles()
  124. self.assertTrue(len(subtitles.keys()) == 0)
  125. def test_nosubtitles(self):
  126. self.DL.expect_warning('video doesn\'t have subtitles')
  127. self.url = 'http://www.dailymotion.com/video/x12u166_le-zapping-tele-star-du-08-aout-2013_tv'
  128. self.DL.params['writesubtitles'] = True
  129. self.DL.params['allsubtitles'] = True
  130. subtitles = self.getSubtitles()
  131. self.assertEqual(len(subtitles), 0)
  132. def test_multiple_langs(self):
  133. self.DL.params['writesubtitles'] = True
  134. langs = ['es', 'fr', 'de']
  135. self.DL.params['subtitleslangs'] = langs
  136. subtitles = self.getSubtitles()
  137. for lang in langs:
  138. self.assertTrue(subtitles.get(lang) is not None, 'Subtitles for \'%s\' not extracted' % lang)
  139. class TestTedSubtitles(BaseTestSubtitles):
  140. url = 'http://www.ted.com/talks/dan_dennett_on_our_consciousness.html'
  141. IE = TEDIE
  142. def test_no_writesubtitles(self):
  143. subtitles = self.getSubtitles()
  144. self.assertEqual(subtitles, None)
  145. def test_subtitles(self):
  146. self.DL.params['writesubtitles'] = True
  147. subtitles = self.getSubtitles()
  148. self.assertEqual(md5(subtitles['en']), '4262c1665ff928a2dada178f62cb8d14')
  149. def test_subtitles_lang(self):
  150. self.DL.params['writesubtitles'] = True
  151. self.DL.params['subtitleslangs'] = ['fr']
  152. subtitles = self.getSubtitles()
  153. self.assertEqual(md5(subtitles['fr']), '66a63f7f42c97a50f8c0e90bc7797bb5')
  154. def test_allsubtitles(self):
  155. self.DL.params['writesubtitles'] = True
  156. self.DL.params['allsubtitles'] = True
  157. subtitles = self.getSubtitles()
  158. self.assertTrue(len(subtitles.keys()) >= 28)
  159. def test_list_subtitles(self):
  160. self.DL.expect_warning('Automatic Captions not supported by this server')
  161. self.DL.params['listsubtitles'] = True
  162. info_dict = self.getInfoDict()
  163. self.assertEqual(info_dict, None)
  164. def test_automatic_captions(self):
  165. self.DL.expect_warning('Automatic Captions not supported by this server')
  166. self.DL.params['writeautomaticsub'] = True
  167. self.DL.params['subtitleslang'] = ['en']
  168. subtitles = self.getSubtitles()
  169. self.assertTrue(len(subtitles.keys()) == 0)
  170. def test_multiple_langs(self):
  171. self.DL.params['writesubtitles'] = True
  172. langs = ['es', 'fr', 'de']
  173. self.DL.params['subtitleslangs'] = langs
  174. subtitles = self.getSubtitles()
  175. for lang in langs:
  176. self.assertTrue(subtitles.get(lang) is not None, 'Subtitles for \'%s\' not extracted' % lang)
  177. class TestBlipTVSubtitles(BaseTestSubtitles):
  178. url = 'http://blip.tv/a/a-6603250'
  179. IE = BlipTVIE
  180. def test_list_subtitles(self):
  181. self.DL.expect_warning('Automatic Captions not supported by this server')
  182. self.DL.params['listsubtitles'] = True
  183. info_dict = self.getInfoDict()
  184. self.assertEqual(info_dict, None)
  185. def test_allsubtitles(self):
  186. self.DL.expect_warning('Automatic Captions not supported by this server')
  187. self.DL.params['writesubtitles'] = True
  188. self.DL.params['allsubtitles'] = True
  189. subtitles = self.getSubtitles()
  190. self.assertEqual(set(subtitles.keys()), set(['en']))
  191. self.assertEqual(md5(subtitles['en']), '5b75c300af65fe4476dff79478bb93e4')
  192. class TestVimeoSubtitles(BaseTestSubtitles):
  193. url = 'http://vimeo.com/76979871'
  194. IE = VimeoIE
  195. def test_no_writesubtitles(self):
  196. subtitles = self.getSubtitles()
  197. self.assertEqual(subtitles, None)
  198. def test_subtitles(self):
  199. self.DL.params['writesubtitles'] = True
  200. subtitles = self.getSubtitles()
  201. self.assertEqual(md5(subtitles['en']), '8062383cf4dec168fc40a088aa6d5888')
  202. def test_subtitles_lang(self):
  203. self.DL.params['writesubtitles'] = True
  204. self.DL.params['subtitleslangs'] = ['fr']
  205. subtitles = self.getSubtitles()
  206. self.assertEqual(md5(subtitles['fr']), 'b6191146a6c5d3a452244d853fde6dc8')
  207. def test_allsubtitles(self):
  208. self.DL.params['writesubtitles'] = True
  209. self.DL.params['allsubtitles'] = True
  210. subtitles = self.getSubtitles()
  211. self.assertEqual(set(subtitles.keys()), set(['de', 'en', 'es', 'fr']))
  212. def test_list_subtitles(self):
  213. self.DL.expect_warning('Automatic Captions not supported by this server')
  214. self.DL.params['listsubtitles'] = True
  215. info_dict = self.getInfoDict()
  216. self.assertEqual(info_dict, None)
  217. def test_automatic_captions(self):
  218. self.DL.expect_warning('Automatic Captions not supported by this server')
  219. self.DL.params['writeautomaticsub'] = True
  220. self.DL.params['subtitleslang'] = ['en']
  221. subtitles = self.getSubtitles()
  222. self.assertTrue(len(subtitles.keys()) == 0)
  223. def test_nosubtitles(self):
  224. self.DL.expect_warning('video doesn\'t have subtitles')
  225. self.url = 'http://vimeo.com/56015672'
  226. self.DL.params['writesubtitles'] = True
  227. self.DL.params['allsubtitles'] = True
  228. subtitles = self.getSubtitles()
  229. self.assertEqual(len(subtitles), 0)
  230. def test_multiple_langs(self):
  231. self.DL.params['writesubtitles'] = True
  232. langs = ['es', 'fr', 'de']
  233. self.DL.params['subtitleslangs'] = langs
  234. subtitles = self.getSubtitles()
  235. for lang in langs:
  236. self.assertTrue(subtitles.get(lang) is not None, 'Subtitles for \'%s\' not extracted' % lang)
  237. class TestWallaSubtitles(BaseTestSubtitles):
  238. url = 'http://vod.walla.co.il/movie/2705958/the-yes-men'
  239. IE = WallaIE
  240. def test_list_subtitles(self):
  241. self.DL.expect_warning('Automatic Captions not supported by this server')
  242. self.DL.params['listsubtitles'] = True
  243. info_dict = self.getInfoDict()
  244. self.assertEqual(info_dict, None)
  245. def test_allsubtitles(self):
  246. self.DL.expect_warning('Automatic Captions not supported by this server')
  247. self.DL.params['writesubtitles'] = True
  248. self.DL.params['allsubtitles'] = True
  249. subtitles = self.getSubtitles()
  250. self.assertEqual(set(subtitles.keys()), set(['heb']))
  251. self.assertEqual(md5(subtitles['heb']), 'e758c5d7cb982f6bef14f377ec7a3920')
  252. def test_nosubtitles(self):
  253. self.DL.expect_warning('video doesn\'t have subtitles')
  254. self.url = 'http://vod.walla.co.il/movie/2642630/one-direction-all-for-one'
  255. self.DL.params['writesubtitles'] = True
  256. self.DL.params['allsubtitles'] = True
  257. subtitles = self.getSubtitles()
  258. self.assertEqual(len(subtitles), 0)
  259. class TestCeskaTelevizeSubtitles(BaseTestSubtitles):
  260. url = 'http://www.ceskatelevize.cz/ivysilani/10600540290-u6-uzasny-svet-techniky'
  261. IE = CeskaTelevizeIE
  262. def test_list_subtitles(self):
  263. self.DL.expect_warning('Automatic Captions not supported by this server')
  264. self.DL.params['listsubtitles'] = True
  265. info_dict = self.getInfoDict()
  266. self.assertEqual(info_dict, None)
  267. def test_allsubtitles(self):
  268. self.DL.expect_warning('Automatic Captions not supported by this server')
  269. self.DL.params['writesubtitles'] = True
  270. self.DL.params['allsubtitles'] = True
  271. subtitles = self.getSubtitles()
  272. self.assertEqual(set(subtitles.keys()), set(['cs']))
  273. self.assertTrue(len(subtitles['cs']) > 20000)
  274. def test_nosubtitles(self):
  275. self.DL.expect_warning('video doesn\'t have subtitles')
  276. self.url = 'http://www.ceskatelevize.cz/ivysilani/ivysilani/10441294653-hyde-park-civilizace/214411058091220'
  277. self.DL.params['writesubtitles'] = True
  278. self.DL.params['allsubtitles'] = True
  279. subtitles = self.getSubtitles()
  280. self.assertEqual(len(subtitles), 0)
  281. if __name__ == '__main__':
  282. unittest.main()