]>
Raphaƫl G. Git Repositories - youtubedl/blob - test/test_youtube_subtitles.py
86e09c9b1b397187acc0f28d6d03a1191fa7846f
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'][0]
39 self
.assertEqual(md5(sub
[2]), '4cd9278a35ba2305f47354ee13472260')
40 def test_youtube_subtitles_it(self
):
42 DL
.params
['writesubtitles'] = True
43 DL
.params
['subtitleslang'] = 'it'
45 info_dict
= IE
.extract('QRS8MkLhQmM')
46 sub
= info_dict
[0]['subtitles'][0]
47 self
.assertEqual(md5(sub
[2]), '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'][0]
55 self
.assertEqual(md5(sub
[2]), '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
), 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'][0]
70 self
.assertEqual(md5(sub
[2]), '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'][0]
78 self
.assertEqual(md5(sub
[2]), '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
['subtitleslang'] = 'it'
90 info_dict
= IE
.extract('8YoUxe5ncPo')
91 sub
= info_dict
[0]['subtitles'][0]
92 self
.assertTrue(sub
[2] is not None)
94 if __name__
== '__main__':