]>
Raphaƫl G. Git Repositories - youtubedl/blob - test/test_youtube_subtitles.py
9 # Allow direct execution
11 sys
.path
.append(os
.path
.dirname(os
.path
.dirname(os
.path
.abspath(__file__
))))
13 from youtube_dl
.extractor
import YoutubeIE
14 from youtube_dl
.utils
import *
15 from helper
import FakeYDL
17 md5
= lambda s
: hashlib
.md5(s
.encode('utf-8')).hexdigest()
19 class TestYoutubeSubtitles(unittest
.TestCase
):
22 DL
.params
['allsubtitles'] = False
23 DL
.params
['writesubtitles'] = False
24 DL
.params
['subtitlesformat'] = 'srt'
25 DL
.params
['listsubtitles'] = False
26 def test_youtube_no_subtitles(self
):
28 DL
.params
['writesubtitles'] = False
30 info_dict
= IE
.extract('QRS8MkLhQmM')
31 subtitles
= info_dict
[0]['subtitles']
32 self
.assertEqual(subtitles
, None)
33 def test_youtube_subtitles(self
):
35 DL
.params
['writesubtitles'] = True
37 info_dict
= IE
.extract('QRS8MkLhQmM')
38 sub
= info_dict
[0]['subtitles']['en']
39 self
.assertEqual(md5(sub
), '4cd9278a35ba2305f47354ee13472260')
40 def test_youtube_subtitles_it(self
):
42 DL
.params
['writesubtitles'] = True
43 DL
.params
['subtitleslangs'] = ['it']
45 info_dict
= IE
.extract('QRS8MkLhQmM')
46 sub
= info_dict
[0]['subtitles']['it']
47 self
.assertEqual(md5(sub
), '164a51f16f260476a05b50fe4c2f161d')
48 def test_youtube_onlysubtitles(self
):
50 DL
.params
['writesubtitles'] = True
51 DL
.params
['onlysubtitles'] = True
53 info_dict
= IE
.extract('QRS8MkLhQmM')
54 sub
= info_dict
[0]['subtitles']['en']
55 self
.assertEqual(md5(sub
), '4cd9278a35ba2305f47354ee13472260')
56 def test_youtube_allsubtitles(self
):
58 DL
.params
['allsubtitles'] = True
60 info_dict
= IE
.extract('QRS8MkLhQmM')
61 subtitles
= info_dict
[0]['subtitles']
62 self
.assertEqual(len(subtitles
.keys()), 13)
63 def test_youtube_subtitles_sbv_format(self
):
65 DL
.params
['writesubtitles'] = True
66 DL
.params
['subtitlesformat'] = 'sbv'
68 info_dict
= IE
.extract('QRS8MkLhQmM')
69 sub
= info_dict
[0]['subtitles']['en']
70 self
.assertEqual(md5(sub
), '13aeaa0c245a8bed9a451cb643e3ad8b')
71 def test_youtube_subtitles_vtt_format(self
):
73 DL
.params
['writesubtitles'] = True
74 DL
.params
['subtitlesformat'] = 'vtt'
76 info_dict
= IE
.extract('QRS8MkLhQmM')
77 sub
= info_dict
[0]['subtitles']['en']
78 self
.assertEqual(md5(sub
), '356cdc577fde0c6783b9b822e7206ff7')
79 def test_youtube_list_subtitles(self
):
81 DL
.params
['listsubtitles'] = True
83 info_dict
= IE
.extract('QRS8MkLhQmM')
84 self
.assertEqual(info_dict
, None)
85 def test_youtube_automatic_captions(self
):
87 DL
.params
['writeautomaticsub'] = True
88 DL
.params
['subtitleslangs'] = ['it']
90 info_dict
= IE
.extract('8YoUxe5ncPo')
91 sub
= info_dict
[0]['subtitles']['it']
92 self
.assertTrue(sub
is not None)
93 def test_youtube_multiple_langs(self
):
95 DL
.params
['writesubtitles'] = True
96 langs
= ['it', 'fr', 'de']
97 DL
.params
['subtitleslangs'] = langs
99 subtitles
= IE
.extract('QRS8MkLhQmM')[0]['subtitles']
101 self
.assertTrue(subtitles
.get(lang
) is not None, u
'Subtitles for \'%s\' not extracted' % lang
)
103 if __name__
== '__main__':