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.

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