]> Raphaƫl G. Git Repositories - youtubedl/blob - test/test_youtube_subtitles.py
Fix description of the modularization.
[youtubedl] / test / test_youtube_subtitles.py
1 #!/usr/bin/env python
2
3 import sys
4 import unittest
5 import json
6 import io
7 import hashlib
8
9 # Allow direct execution
10 import os
11 sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
12
13 from youtube_dl.extractor import YoutubeIE
14 from youtube_dl.utils import *
15 from helper import FakeYDL
16
17 md5 = lambda s: hashlib.md5(s.encode('utf-8')).hexdigest()
18
19 class TestYoutubeSubtitles(unittest.TestCase):
20 def setUp(self):
21 DL = FakeYDL()
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):
27 DL = FakeYDL()
28 DL.params['writesubtitles'] = False
29 IE = YoutubeIE(DL)
30 info_dict = IE.extract('QRS8MkLhQmM')
31 subtitles = info_dict[0]['subtitles']
32 self.assertEqual(subtitles, None)
33 def test_youtube_subtitles(self):
34 DL = FakeYDL()
35 DL.params['writesubtitles'] = True
36 IE = YoutubeIE(DL)
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):
41 DL = FakeYDL()
42 DL.params['writesubtitles'] = True
43 DL.params['subtitleslang'] = 'it'
44 IE = YoutubeIE(DL)
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):
49 DL = FakeYDL()
50 DL.params['writesubtitles'] = True
51 DL.params['onlysubtitles'] = True
52 IE = YoutubeIE(DL)
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):
57 DL = FakeYDL()
58 DL.params['allsubtitles'] = True
59 IE = YoutubeIE(DL)
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):
64 DL = FakeYDL()
65 DL.params['writesubtitles'] = True
66 DL.params['subtitlesformat'] = 'sbv'
67 IE = YoutubeIE(DL)
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):
72 DL = FakeYDL()
73 DL.params['writesubtitles'] = True
74 DL.params['subtitlesformat'] = 'vtt'
75 IE = YoutubeIE(DL)
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):
80 DL = FakeYDL()
81 DL.params['listsubtitles'] = True
82 IE = YoutubeIE(DL)
83 info_dict = IE.extract('QRS8MkLhQmM')
84 self.assertEqual(info_dict, None)
85 def test_youtube_automatic_captions(self):
86 DL = FakeYDL()
87 DL.params['writeautomaticsub'] = True
88 DL.params['subtitleslang'] = 'it'
89 IE = YoutubeIE(DL)
90 info_dict = IE.extract('8YoUxe5ncPo')
91 sub = info_dict[0]['subtitles'][0]
92 self.assertTrue(sub[2] is not None)
93
94 if __name__ == '__main__':
95 unittest.main()