]> Raphaƫl G. Git Repositories - youtubedl/blob - test/test_InfoExtractor.py
Update README.md
[youtubedl] / test / test_InfoExtractor.py
1 #!/usr/bin/env python
2
3 from __future__ import unicode_literals
4
5 # Allow direct execution
6 import io
7 import os
8 import sys
9 import unittest
10 sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
11
12 from test.helper import FakeYDL, expect_dict, expect_value, http_server_port
13 from youtube_dl.compat import compat_etree_fromstring, compat_http_server
14 from youtube_dl.extractor.common import InfoExtractor
15 from youtube_dl.extractor import YoutubeIE, get_info_extractor
16 from youtube_dl.utils import encode_data_uri, strip_jsonp, ExtractorError, RegexNotFoundError
17 import threading
18
19
20 TEAPOT_RESPONSE_STATUS = 418
21 TEAPOT_RESPONSE_BODY = "<h1>418 I'm a teapot</h1>"
22
23
24 class InfoExtractorTestRequestHandler(compat_http_server.BaseHTTPRequestHandler):
25 def log_message(self, format, *args):
26 pass
27
28 def do_GET(self):
29 if self.path == '/teapot':
30 self.send_response(TEAPOT_RESPONSE_STATUS)
31 self.send_header('Content-Type', 'text/html; charset=utf-8')
32 self.end_headers()
33 self.wfile.write(TEAPOT_RESPONSE_BODY.encode())
34 else:
35 assert False
36
37
38 class TestIE(InfoExtractor):
39 pass
40
41
42 class TestInfoExtractor(unittest.TestCase):
43 def setUp(self):
44 self.ie = TestIE(FakeYDL())
45
46 def test_ie_key(self):
47 self.assertEqual(get_info_extractor(YoutubeIE.ie_key()), YoutubeIE)
48
49 def test_html_search_regex(self):
50 html = '<p id="foo">Watch this <a href="http://www.youtube.com/watch?v=BaW_jenozKc">video</a></p>'
51 search = lambda re, *args: self.ie._html_search_regex(re, html, *args)
52 self.assertEqual(search(r'<p id="foo">(.+?)</p>', 'foo'), 'Watch this video')
53
54 def test_opengraph(self):
55 ie = self.ie
56 html = '''
57 <meta name="og:title" content='Foo'/>
58 <meta content="Some video's description " name="og:description"/>
59 <meta property='og:image' content='http://domain.com/pic.jpg?key1=val1&amp;key2=val2'/>
60 <meta content='application/x-shockwave-flash' property='og:video:type'>
61 <meta content='Foo' property=og:foobar>
62 <meta name="og:test1" content='foo > < bar'/>
63 <meta name="og:test2" content="foo >//< bar"/>
64 <meta property=og-test3 content='Ill-formatted opengraph'/>
65 '''
66 self.assertEqual(ie._og_search_title(html), 'Foo')
67 self.assertEqual(ie._og_search_description(html), 'Some video\'s description ')
68 self.assertEqual(ie._og_search_thumbnail(html), 'http://domain.com/pic.jpg?key1=val1&key2=val2')
69 self.assertEqual(ie._og_search_video_url(html, default=None), None)
70 self.assertEqual(ie._og_search_property('foobar', html), 'Foo')
71 self.assertEqual(ie._og_search_property('test1', html), 'foo > < bar')
72 self.assertEqual(ie._og_search_property('test2', html), 'foo >//< bar')
73 self.assertEqual(ie._og_search_property('test3', html), 'Ill-formatted opengraph')
74 self.assertEqual(ie._og_search_property(('test0', 'test1'), html), 'foo > < bar')
75 self.assertRaises(RegexNotFoundError, ie._og_search_property, 'test0', html, None, fatal=True)
76 self.assertRaises(RegexNotFoundError, ie._og_search_property, ('test0', 'test00'), html, None, fatal=True)
77
78 def test_html_search_meta(self):
79 ie = self.ie
80 html = '''
81 <meta name="a" content="1" />
82 <meta name='b' content='2'>
83 <meta name="c" content='3'>
84 <meta name=d content='4'>
85 <meta property="e" content='5' >
86 <meta content="6" name="f">
87 '''
88
89 self.assertEqual(ie._html_search_meta('a', html), '1')
90 self.assertEqual(ie._html_search_meta('b', html), '2')
91 self.assertEqual(ie._html_search_meta('c', html), '3')
92 self.assertEqual(ie._html_search_meta('d', html), '4')
93 self.assertEqual(ie._html_search_meta('e', html), '5')
94 self.assertEqual(ie._html_search_meta('f', html), '6')
95 self.assertEqual(ie._html_search_meta(('a', 'b', 'c'), html), '1')
96 self.assertEqual(ie._html_search_meta(('c', 'b', 'a'), html), '3')
97 self.assertEqual(ie._html_search_meta(('z', 'x', 'c'), html), '3')
98 self.assertRaises(RegexNotFoundError, ie._html_search_meta, 'z', html, None, fatal=True)
99 self.assertRaises(RegexNotFoundError, ie._html_search_meta, ('z', 'x'), html, None, fatal=True)
100
101 def test_download_json(self):
102 uri = encode_data_uri(b'{"foo": "blah"}', 'application/json')
103 self.assertEqual(self.ie._download_json(uri, None), {'foo': 'blah'})
104 uri = encode_data_uri(b'callback({"foo": "blah"})', 'application/javascript')
105 self.assertEqual(self.ie._download_json(uri, None, transform_source=strip_jsonp), {'foo': 'blah'})
106 uri = encode_data_uri(b'{"foo": invalid}', 'application/json')
107 self.assertRaises(ExtractorError, self.ie._download_json, uri, None)
108 self.assertEqual(self.ie._download_json(uri, None, fatal=False), None)
109
110 def test_parse_html5_media_entries(self):
111 # from https://www.r18.com/
112 # with kpbs in label
113 expect_dict(
114 self,
115 self.ie._parse_html5_media_entries(
116 'https://www.r18.com/',
117 r'''
118 <video id="samplevideo_amateur" class="js-samplevideo video-js vjs-default-skin vjs-big-play-centered" controls preload="auto" width="400" height="225" poster="//pics.r18.com/digital/amateur/mgmr105/mgmr105jp.jpg">
119 <source id="video_source" src="https://awscc3001.r18.com/litevideo/freepv/m/mgm/mgmr105/mgmr105_sm_w.mp4" type="video/mp4" res="240" label="300kbps">
120 <source id="video_source" src="https://awscc3001.r18.com/litevideo/freepv/m/mgm/mgmr105/mgmr105_dm_w.mp4" type="video/mp4" res="480" label="1000kbps">
121 <source id="video_source" src="https://awscc3001.r18.com/litevideo/freepv/m/mgm/mgmr105/mgmr105_dmb_w.mp4" type="video/mp4" res="740" label="1500kbps">
122 <p>Your browser does not support the video tag.</p>
123 </video>
124 ''', None)[0],
125 {
126 'formats': [{
127 'url': 'https://awscc3001.r18.com/litevideo/freepv/m/mgm/mgmr105/mgmr105_sm_w.mp4',
128 'ext': 'mp4',
129 'format_id': '300kbps',
130 'height': 240,
131 'tbr': 300,
132 }, {
133 'url': 'https://awscc3001.r18.com/litevideo/freepv/m/mgm/mgmr105/mgmr105_dm_w.mp4',
134 'ext': 'mp4',
135 'format_id': '1000kbps',
136 'height': 480,
137 'tbr': 1000,
138 }, {
139 'url': 'https://awscc3001.r18.com/litevideo/freepv/m/mgm/mgmr105/mgmr105_dmb_w.mp4',
140 'ext': 'mp4',
141 'format_id': '1500kbps',
142 'height': 740,
143 'tbr': 1500,
144 }],
145 'thumbnail': '//pics.r18.com/digital/amateur/mgmr105/mgmr105jp.jpg'
146 })
147
148 # from https://www.csfd.cz/
149 # with width and height
150 expect_dict(
151 self,
152 self.ie._parse_html5_media_entries(
153 'https://www.csfd.cz/',
154 r'''
155 <video width="770" height="328" preload="none" controls poster="https://img.csfd.cz/files/images/film/video/preview/163/344/163344118_748d20.png?h360" >
156 <source src="https://video.csfd.cz/files/videos/157/750/157750813/163327358_eac647.mp4" type="video/mp4" width="640" height="360">
157 <source src="https://video.csfd.cz/files/videos/157/750/157750813/163327360_3d2646.mp4" type="video/mp4" width="1280" height="720">
158 <source src="https://video.csfd.cz/files/videos/157/750/157750813/163327356_91f258.mp4" type="video/mp4" width="1920" height="1080">
159 <source src="https://video.csfd.cz/files/videos/157/750/157750813/163327359_962b4a.webm" type="video/webm" width="640" height="360">
160 <source src="https://video.csfd.cz/files/videos/157/750/157750813/163327361_6feee0.webm" type="video/webm" width="1280" height="720">
161 <source src="https://video.csfd.cz/files/videos/157/750/157750813/163327357_8ab472.webm" type="video/webm" width="1920" height="1080">
162 <track src="https://video.csfd.cz/files/subtitles/163/344/163344115_4c388b.srt" type="text/x-srt" kind="subtitles" srclang="cs" label="cs">
163 </video>
164 ''', None)[0],
165 {
166 'formats': [{
167 'url': 'https://video.csfd.cz/files/videos/157/750/157750813/163327358_eac647.mp4',
168 'ext': 'mp4',
169 'width': 640,
170 'height': 360,
171 }, {
172 'url': 'https://video.csfd.cz/files/videos/157/750/157750813/163327360_3d2646.mp4',
173 'ext': 'mp4',
174 'width': 1280,
175 'height': 720,
176 }, {
177 'url': 'https://video.csfd.cz/files/videos/157/750/157750813/163327356_91f258.mp4',
178 'ext': 'mp4',
179 'width': 1920,
180 'height': 1080,
181 }, {
182 'url': 'https://video.csfd.cz/files/videos/157/750/157750813/163327359_962b4a.webm',
183 'ext': 'webm',
184 'width': 640,
185 'height': 360,
186 }, {
187 'url': 'https://video.csfd.cz/files/videos/157/750/157750813/163327361_6feee0.webm',
188 'ext': 'webm',
189 'width': 1280,
190 'height': 720,
191 }, {
192 'url': 'https://video.csfd.cz/files/videos/157/750/157750813/163327357_8ab472.webm',
193 'ext': 'webm',
194 'width': 1920,
195 'height': 1080,
196 }],
197 'subtitles': {
198 'cs': [{'url': 'https://video.csfd.cz/files/subtitles/163/344/163344115_4c388b.srt'}]
199 },
200 'thumbnail': 'https://img.csfd.cz/files/images/film/video/preview/163/344/163344118_748d20.png?h360'
201 })
202
203 # from https://tamasha.com/v/Kkdjw
204 # with height in label
205 expect_dict(
206 self,
207 self.ie._parse_html5_media_entries(
208 'https://tamasha.com/v/Kkdjw',
209 r'''
210 <video crossorigin="anonymous">
211 <source src="https://s-v2.tamasha.com/statics/videos_file/19/8f/Kkdjw_198feff8577d0057536e905cce1fb61438dd64e0_n_240.mp4" type="video/mp4" label="AUTO" res="0"/>
212 <source src="https://s-v2.tamasha.com/statics/videos_file/19/8f/Kkdjw_198feff8577d0057536e905cce1fb61438dd64e0_n_240.mp4" type="video/mp4"
213 label="240p" res="240"/>
214 <source src="https://s-v2.tamasha.com/statics/videos_file/20/00/Kkdjw_200041c66f657fc967db464d156eafbc1ed9fe6f_n_144.mp4" type="video/mp4"
215 label="144p" res="144"/>
216 </video>
217 ''', None)[0],
218 {
219 'formats': [{
220 'url': 'https://s-v2.tamasha.com/statics/videos_file/19/8f/Kkdjw_198feff8577d0057536e905cce1fb61438dd64e0_n_240.mp4',
221 }, {
222 'url': 'https://s-v2.tamasha.com/statics/videos_file/19/8f/Kkdjw_198feff8577d0057536e905cce1fb61438dd64e0_n_240.mp4',
223 'ext': 'mp4',
224 'format_id': '240p',
225 'height': 240,
226 }, {
227 'url': 'https://s-v2.tamasha.com/statics/videos_file/20/00/Kkdjw_200041c66f657fc967db464d156eafbc1ed9fe6f_n_144.mp4',
228 'ext': 'mp4',
229 'format_id': '144p',
230 'height': 144,
231 }]
232 })
233
234 # from https://www.directvnow.com
235 # with data-src
236 expect_dict(
237 self,
238 self.ie._parse_html5_media_entries(
239 'https://www.directvnow.com',
240 r'''
241 <video id="vid1" class="header--video-masked active" muted playsinline>
242 <source data-src="https://cdn.directv.com/content/dam/dtv/prod/website_directvnow-international/videos/DTVN_hdr_HBO_v3.mp4" type="video/mp4" />
243 </video>
244 ''', None)[0],
245 {
246 'formats': [{
247 'ext': 'mp4',
248 'url': 'https://cdn.directv.com/content/dam/dtv/prod/website_directvnow-international/videos/DTVN_hdr_HBO_v3.mp4',
249 }]
250 })
251
252 # from https://www.directvnow.com
253 # with data-src
254 expect_dict(
255 self,
256 self.ie._parse_html5_media_entries(
257 'https://www.directvnow.com',
258 r'''
259 <video id="vid1" class="header--video-masked active" muted playsinline>
260 <source data-src="https://cdn.directv.com/content/dam/dtv/prod/website_directvnow-international/videos/DTVN_hdr_HBO_v3.mp4" type="video/mp4" />
261 </video>
262 ''', None)[0],
263 {
264 'formats': [{
265 'url': 'https://cdn.directv.com/content/dam/dtv/prod/website_directvnow-international/videos/DTVN_hdr_HBO_v3.mp4',
266 'ext': 'mp4',
267 }]
268 })
269
270 # from https://www.klarna.com/uk/
271 # with data-video-src
272 expect_dict(
273 self,
274 self.ie._parse_html5_media_entries(
275 'https://www.directvnow.com',
276 r'''
277 <video loop autoplay muted class="responsive-video block-kl__video video-on-medium">
278 <source src="" data-video-desktop data-video-src="https://www.klarna.com/uk/wp-content/uploads/sites/11/2019/01/KL062_Smooth3_0_DogWalking_5s_920x080_.mp4" type="video/mp4" />
279 </video>
280 ''', None)[0],
281 {
282 'formats': [{
283 'url': 'https://www.klarna.com/uk/wp-content/uploads/sites/11/2019/01/KL062_Smooth3_0_DogWalking_5s_920x080_.mp4',
284 'ext': 'mp4',
285 }],
286 })
287
288 def test_extract_jwplayer_data_realworld(self):
289 # from http://www.suffolk.edu/sjc/
290 expect_dict(
291 self,
292 self.ie._extract_jwplayer_data(r'''
293 <script type='text/javascript'>
294 jwplayer('my-video').setup({
295 file: 'rtmp://192.138.214.154/live/sjclive',
296 fallback: 'true',
297 width: '95%',
298 aspectratio: '16:9',
299 primary: 'flash',
300 mediaid:'XEgvuql4'
301 });
302 </script>
303 ''', None, require_title=False),
304 {
305 'id': 'XEgvuql4',
306 'formats': [{
307 'url': 'rtmp://192.138.214.154/live/sjclive',
308 'ext': 'flv'
309 }]
310 })
311
312 # from https://www.pornoxo.com/videos/7564/striptease-from-sexy-secretary/
313 expect_dict(
314 self,
315 self.ie._extract_jwplayer_data(r'''
316 <script type="text/javascript">
317 jwplayer("mediaplayer").setup({
318 'videoid': "7564",
319 'width': "100%",
320 'aspectratio': "16:9",
321 'stretching': "exactfit",
322 'autostart': 'false',
323 'flashplayer': "https://t04.vipstreamservice.com/jwplayer/v5.10/player.swf",
324 'file': "https://cdn.pornoxo.com/key=MF+oEbaxqTKb50P-w9G3nA,end=1489689259,ip=104.199.146.27/ip=104.199.146.27/speed=6573765/buffer=3.0/2009-12/4b2157147afe5efa93ce1978e0265289c193874e02597.flv",
325 'image': "https://t03.vipstreamservice.com/thumbs/pxo-full/2009-12/14/a4b2157147afe5efa93ce1978e0265289c193874e02597.flv-full-13.jpg",
326 'filefallback': "https://cdn.pornoxo.com/key=9ZPsTR5EvPLQrBaak2MUGA,end=1489689259,ip=104.199.146.27/ip=104.199.146.27/speed=6573765/buffer=3.0/2009-12/m_4b2157147afe5efa93ce1978e0265289c193874e02597.mp4",
327 'logo.hide': true,
328 'skin': "https://t04.vipstreamservice.com/jwplayer/skin/modieus-blk.zip",
329 'plugins': "https://t04.vipstreamservice.com/jwplayer/dock/dockableskinnableplugin.swf",
330 'dockableskinnableplugin.piclink': "/index.php?key=ajax-videothumbsn&vid=7564&data=2009-12--14--4b2157147afe5efa93ce1978e0265289c193874e02597.flv--17370",
331 'controlbar': 'bottom',
332 'modes': [
333 {type: 'flash', src: 'https://t04.vipstreamservice.com/jwplayer/v5.10/player.swf'}
334 ],
335 'provider': 'http'
336 });
337 //noinspection JSAnnotator
338 invideo.setup({
339 adsUrl: "/banner-iframe/?zoneId=32",
340 adsUrl2: "",
341 autostart: false
342 });
343 </script>
344 ''', 'dummy', require_title=False),
345 {
346 'thumbnail': 'https://t03.vipstreamservice.com/thumbs/pxo-full/2009-12/14/a4b2157147afe5efa93ce1978e0265289c193874e02597.flv-full-13.jpg',
347 'formats': [{
348 'url': 'https://cdn.pornoxo.com/key=MF+oEbaxqTKb50P-w9G3nA,end=1489689259,ip=104.199.146.27/ip=104.199.146.27/speed=6573765/buffer=3.0/2009-12/4b2157147afe5efa93ce1978e0265289c193874e02597.flv',
349 'ext': 'flv'
350 }]
351 })
352
353 # from http://www.indiedb.com/games/king-machine/videos
354 expect_dict(
355 self,
356 self.ie._extract_jwplayer_data(r'''
357 <script>
358 jwplayer("mediaplayer").setup({"abouttext":"Visit Indie DB","aboutlink":"http:\/\/www.indiedb.com\/","displaytitle":false,"autostart":false,"repeat":false,"title":"king machine trailer 1","sharing":{"link":"http:\/\/www.indiedb.com\/games\/king-machine\/videos\/king-machine-trailer-1","code":"<iframe width=\"560\" height=\"315\" src=\"http:\/\/www.indiedb.com\/media\/iframe\/1522983\" frameborder=\"0\" allowfullscreen><\/iframe><br><a href=\"http:\/\/www.indiedb.com\/games\/king-machine\/videos\/king-machine-trailer-1\">king machine trailer 1 - Indie DB<\/a>"},"related":{"file":"http:\/\/rss.indiedb.com\/media\/recommended\/1522983\/feed\/rss.xml","dimensions":"160x120","onclick":"link"},"sources":[{"file":"http:\/\/cdn.dbolical.com\/cache\/videos\/games\/1\/50\/49678\/encode_mp4\/king-machine-trailer.mp4","label":"360p SD","default":"true"},{"file":"http:\/\/cdn.dbolical.com\/cache\/videos\/games\/1\/50\/49678\/encode720p_mp4\/king-machine-trailer.mp4","label":"720p HD"}],"image":"http:\/\/media.indiedb.com\/cache\/images\/games\/1\/50\/49678\/thumb_620x2000\/king-machine-trailer.mp4.jpg","advertising":{"client":"vast","tag":"http:\/\/ads.intergi.com\/adrawdata\/3.0\/5205\/4251742\/0\/1013\/ADTECH;cors=yes;width=560;height=315;referring_url=http:\/\/www.indiedb.com\/games\/king-machine\/videos\/king-machine-trailer-1;content_url=http:\/\/www.indiedb.com\/games\/king-machine\/videos\/king-machine-trailer-1;media_id=1522983;title=king+machine+trailer+1;device=__DEVICE__;model=__MODEL__;os=Windows+OS;osversion=__OSVERSION__;ua=__UA__;ip=109.171.17.81;uniqueid=1522983;tags=__TAGS__;number=58cac25928151;time=1489683033"},"width":620,"height":349}).once("play", function(event) {
359 videoAnalytics("play");
360 }).once("complete", function(event) {
361 videoAnalytics("completed");
362 });
363 </script>
364 ''', 'dummy'),
365 {
366 'title': 'king machine trailer 1',
367 'thumbnail': 'http://media.indiedb.com/cache/images/games/1/50/49678/thumb_620x2000/king-machine-trailer.mp4.jpg',
368 'formats': [{
369 'url': 'http://cdn.dbolical.com/cache/videos/games/1/50/49678/encode_mp4/king-machine-trailer.mp4',
370 'height': 360,
371 'ext': 'mp4'
372 }, {
373 'url': 'http://cdn.dbolical.com/cache/videos/games/1/50/49678/encode720p_mp4/king-machine-trailer.mp4',
374 'height': 720,
375 'ext': 'mp4'
376 }]
377 })
378
379 def test_parse_m3u8_formats(self):
380 _TEST_CASES = [
381 (
382 # https://github.com/ytdl-org/youtube-dl/issues/11507
383 # http://pluzz.francetv.fr/videos/le_ministere.html
384 'pluzz_francetv_11507',
385 'http://replayftv-vh.akamaihd.net/i/streaming-adaptatif_france-dom-tom/2017/S16/J2/156589847-58f59130c1f52-,standard1,standard2,standard3,standard4,standard5,.mp4.csmil/master.m3u8?caption=2017%2F16%2F156589847-1492488987.m3u8%3Afra%3AFrancais&audiotrack=0%3Afra%3AFrancais',
386 [{
387 'url': 'http://replayftv-vh.akamaihd.net/i/streaming-adaptatif_france-dom-tom/2017/S16/J2/156589847-58f59130c1f52-,standard1,standard2,standard3,standard4,standard5,.mp4.csmil/index_0_av.m3u8?null=0',
388 'manifest_url': 'http://replayftv-vh.akamaihd.net/i/streaming-adaptatif_france-dom-tom/2017/S16/J2/156589847-58f59130c1f52-,standard1,standard2,standard3,standard4,standard5,.mp4.csmil/master.m3u8?caption=2017%2F16%2F156589847-1492488987.m3u8%3Afra%3AFrancais&audiotrack=0%3Afra%3AFrancais',
389 'ext': 'mp4',
390 'format_id': '180',
391 'protocol': 'm3u8',
392 'acodec': 'mp4a.40.2',
393 'vcodec': 'avc1.66.30',
394 'tbr': 180,
395 'width': 256,
396 'height': 144,
397 }, {
398 'url': 'http://replayftv-vh.akamaihd.net/i/streaming-adaptatif_france-dom-tom/2017/S16/J2/156589847-58f59130c1f52-,standard1,standard2,standard3,standard4,standard5,.mp4.csmil/index_1_av.m3u8?null=0',
399 'manifest_url': 'http://replayftv-vh.akamaihd.net/i/streaming-adaptatif_france-dom-tom/2017/S16/J2/156589847-58f59130c1f52-,standard1,standard2,standard3,standard4,standard5,.mp4.csmil/master.m3u8?caption=2017%2F16%2F156589847-1492488987.m3u8%3Afra%3AFrancais&audiotrack=0%3Afra%3AFrancais',
400 'ext': 'mp4',
401 'format_id': '303',
402 'protocol': 'm3u8',
403 'acodec': 'mp4a.40.2',
404 'vcodec': 'avc1.66.30',
405 'tbr': 303,
406 'width': 320,
407 'height': 180,
408 }, {
409 'url': 'http://replayftv-vh.akamaihd.net/i/streaming-adaptatif_france-dom-tom/2017/S16/J2/156589847-58f59130c1f52-,standard1,standard2,standard3,standard4,standard5,.mp4.csmil/index_2_av.m3u8?null=0',
410 'manifest_url': 'http://replayftv-vh.akamaihd.net/i/streaming-adaptatif_france-dom-tom/2017/S16/J2/156589847-58f59130c1f52-,standard1,standard2,standard3,standard4,standard5,.mp4.csmil/master.m3u8?caption=2017%2F16%2F156589847-1492488987.m3u8%3Afra%3AFrancais&audiotrack=0%3Afra%3AFrancais',
411 'ext': 'mp4',
412 'format_id': '575',
413 'protocol': 'm3u8',
414 'acodec': 'mp4a.40.2',
415 'vcodec': 'avc1.66.30',
416 'tbr': 575,
417 'width': 512,
418 'height': 288,
419 }, {
420 'url': 'http://replayftv-vh.akamaihd.net/i/streaming-adaptatif_france-dom-tom/2017/S16/J2/156589847-58f59130c1f52-,standard1,standard2,standard3,standard4,standard5,.mp4.csmil/index_3_av.m3u8?null=0',
421 'manifest_url': 'http://replayftv-vh.akamaihd.net/i/streaming-adaptatif_france-dom-tom/2017/S16/J2/156589847-58f59130c1f52-,standard1,standard2,standard3,standard4,standard5,.mp4.csmil/master.m3u8?caption=2017%2F16%2F156589847-1492488987.m3u8%3Afra%3AFrancais&audiotrack=0%3Afra%3AFrancais',
422 'ext': 'mp4',
423 'format_id': '831',
424 'protocol': 'm3u8',
425 'acodec': 'mp4a.40.2',
426 'vcodec': 'avc1.77.30',
427 'tbr': 831,
428 'width': 704,
429 'height': 396,
430 }, {
431 'url': 'http://replayftv-vh.akamaihd.net/i/streaming-adaptatif_france-dom-tom/2017/S16/J2/156589847-58f59130c1f52-,standard1,standard2,standard3,standard4,standard5,.mp4.csmil/index_4_av.m3u8?null=0',
432 'manifest_url': 'http://replayftv-vh.akamaihd.net/i/streaming-adaptatif_france-dom-tom/2017/S16/J2/156589847-58f59130c1f52-,standard1,standard2,standard3,standard4,standard5,.mp4.csmil/master.m3u8?caption=2017%2F16%2F156589847-1492488987.m3u8%3Afra%3AFrancais&audiotrack=0%3Afra%3AFrancais',
433 'ext': 'mp4',
434 'protocol': 'm3u8',
435 'format_id': '1467',
436 'acodec': 'mp4a.40.2',
437 'vcodec': 'avc1.77.30',
438 'tbr': 1467,
439 'width': 1024,
440 'height': 576,
441 }]
442 ),
443 (
444 # https://github.com/ytdl-org/youtube-dl/issues/11995
445 # http://teamcoco.com/video/clueless-gamer-super-bowl-for-honor
446 'teamcoco_11995',
447 'http://ak.storage-w.teamcococdn.com/cdn/2017-02/98599/ed8f/main.m3u8',
448 [{
449 'url': 'http://ak.storage-w.teamcococdn.com/cdn/2017-02/98599/ed8f/hls/CONAN_020217_Highlight_show-audio-160k_v4.m3u8',
450 'manifest_url': 'http://ak.storage-w.teamcococdn.com/cdn/2017-02/98599/ed8f/main.m3u8',
451 'ext': 'mp4',
452 'format_id': 'audio-0-Default',
453 'protocol': 'm3u8',
454 'vcodec': 'none',
455 }, {
456 'url': 'http://ak.storage-w.teamcococdn.com/cdn/2017-02/98599/ed8f/hls/CONAN_020217_Highlight_show-audio-64k_v4.m3u8',
457 'manifest_url': 'http://ak.storage-w.teamcococdn.com/cdn/2017-02/98599/ed8f/main.m3u8',
458 'ext': 'mp4',
459 'format_id': 'audio-1-Default',
460 'protocol': 'm3u8',
461 'vcodec': 'none',
462 }, {
463 'url': 'http://ak.storage-w.teamcococdn.com/cdn/2017-02/98599/ed8f/hls/CONAN_020217_Highlight_show-audio-64k_v4.m3u8',
464 'manifest_url': 'http://ak.storage-w.teamcococdn.com/cdn/2017-02/98599/ed8f/main.m3u8',
465 'ext': 'mp4',
466 'format_id': '71',
467 'protocol': 'm3u8',
468 'acodec': 'mp4a.40.5',
469 'vcodec': 'none',
470 'tbr': 71,
471 }, {
472 'url': 'http://ak.storage-w.teamcococdn.com/cdn/2017-02/98599/ed8f/hls/CONAN_020217_Highlight_show-400k_v4.m3u8',
473 'manifest_url': 'http://ak.storage-w.teamcococdn.com/cdn/2017-02/98599/ed8f/main.m3u8',
474 'ext': 'mp4',
475 'format_id': '413',
476 'protocol': 'm3u8',
477 'acodec': 'none',
478 'vcodec': 'avc1.42001e',
479 'tbr': 413,
480 'width': 400,
481 'height': 224,
482 }, {
483 'url': 'http://ak.storage-w.teamcococdn.com/cdn/2017-02/98599/ed8f/hls/CONAN_020217_Highlight_show-400k_v4.m3u8',
484 'manifest_url': 'http://ak.storage-w.teamcococdn.com/cdn/2017-02/98599/ed8f/main.m3u8',
485 'ext': 'mp4',
486 'format_id': '522',
487 'protocol': 'm3u8',
488 'acodec': 'none',
489 'vcodec': 'avc1.42001e',
490 'tbr': 522,
491 'width': 400,
492 'height': 224,
493 }, {
494 'url': 'http://ak.storage-w.teamcococdn.com/cdn/2017-02/98599/ed8f/hls/CONAN_020217_Highlight_show-1m_v4.m3u8',
495 'manifest_url': 'http://ak.storage-w.teamcococdn.com/cdn/2017-02/98599/ed8f/main.m3u8',
496 'ext': 'mp4',
497 'format_id': '1205',
498 'protocol': 'm3u8',
499 'acodec': 'none',
500 'vcodec': 'avc1.4d001e',
501 'tbr': 1205,
502 'width': 640,
503 'height': 360,
504 }, {
505 'url': 'http://ak.storage-w.teamcococdn.com/cdn/2017-02/98599/ed8f/hls/CONAN_020217_Highlight_show-2m_v4.m3u8',
506 'manifest_url': 'http://ak.storage-w.teamcococdn.com/cdn/2017-02/98599/ed8f/main.m3u8',
507 'ext': 'mp4',
508 'format_id': '2374',
509 'protocol': 'm3u8',
510 'acodec': 'none',
511 'vcodec': 'avc1.4d001f',
512 'tbr': 2374,
513 'width': 1024,
514 'height': 576,
515 }]
516 ),
517 (
518 # https://github.com/ytdl-org/youtube-dl/issues/12211
519 # http://video.toggle.sg/en/series/whoopie-s-world/ep3/478601
520 'toggle_mobile_12211',
521 'http://cdnapi.kaltura.com/p/2082311/sp/208231100/playManifest/protocol/http/entryId/0_89q6e8ku/format/applehttp/tags/mobile_sd/f/a.m3u8',
522 [{
523 'url': 'http://k.toggle.sg/fhls/p/2082311/sp/208231100/serveFlavor/entryId/0_89q6e8ku/v/2/pv/1/flavorId/0_sa2ntrdg/name/a.mp4/index.m3u8',
524 'manifest_url': 'http://cdnapi.kaltura.com/p/2082311/sp/208231100/playManifest/protocol/http/entryId/0_89q6e8ku/format/applehttp/tags/mobile_sd/f/a.m3u8',
525 'ext': 'mp4',
526 'format_id': 'audio-English',
527 'protocol': 'm3u8',
528 'language': 'eng',
529 'vcodec': 'none',
530 }, {
531 'url': 'http://k.toggle.sg/fhls/p/2082311/sp/208231100/serveFlavor/entryId/0_89q6e8ku/v/2/pv/1/flavorId/0_r7y0nitg/name/a.mp4/index.m3u8',
532 'manifest_url': 'http://cdnapi.kaltura.com/p/2082311/sp/208231100/playManifest/protocol/http/entryId/0_89q6e8ku/format/applehttp/tags/mobile_sd/f/a.m3u8',
533 'ext': 'mp4',
534 'format_id': 'audio-Undefined',
535 'protocol': 'm3u8',
536 'language': 'und',
537 'vcodec': 'none',
538 }, {
539 'url': 'http://k.toggle.sg/fhls/p/2082311/sp/208231100/serveFlavor/entryId/0_89q6e8ku/v/2/pv/1/flavorId/0_qlk9hlzr/name/a.mp4/index.m3u8',
540 'manifest_url': 'http://cdnapi.kaltura.com/p/2082311/sp/208231100/playManifest/protocol/http/entryId/0_89q6e8ku/format/applehttp/tags/mobile_sd/f/a.m3u8',
541 'ext': 'mp4',
542 'format_id': '155',
543 'protocol': 'm3u8',
544 'tbr': 155.648,
545 'width': 320,
546 'height': 180,
547 }, {
548 'url': 'http://k.toggle.sg/fhls/p/2082311/sp/208231100/serveFlavor/entryId/0_89q6e8ku/v/2/pv/1/flavorId/0_oefackmi/name/a.mp4/index.m3u8',
549 'manifest_url': 'http://cdnapi.kaltura.com/p/2082311/sp/208231100/playManifest/protocol/http/entryId/0_89q6e8ku/format/applehttp/tags/mobile_sd/f/a.m3u8',
550 'ext': 'mp4',
551 'format_id': '502',
552 'protocol': 'm3u8',
553 'tbr': 502.784,
554 'width': 480,
555 'height': 270,
556 }, {
557 'url': 'http://k.toggle.sg/fhls/p/2082311/sp/208231100/serveFlavor/entryId/0_89q6e8ku/v/12/pv/1/flavorId/0_vyg9pj7k/name/a.mp4/index.m3u8',
558 'manifest_url': 'http://cdnapi.kaltura.com/p/2082311/sp/208231100/playManifest/protocol/http/entryId/0_89q6e8ku/format/applehttp/tags/mobile_sd/f/a.m3u8',
559 'ext': 'mp4',
560 'format_id': '827',
561 'protocol': 'm3u8',
562 'tbr': 827.392,
563 'width': 640,
564 'height': 360,
565 }, {
566 'url': 'http://k.toggle.sg/fhls/p/2082311/sp/208231100/serveFlavor/entryId/0_89q6e8ku/v/12/pv/1/flavorId/0_50n4psvx/name/a.mp4/index.m3u8',
567 'manifest_url': 'http://cdnapi.kaltura.com/p/2082311/sp/208231100/playManifest/protocol/http/entryId/0_89q6e8ku/format/applehttp/tags/mobile_sd/f/a.m3u8',
568 'ext': 'mp4',
569 'format_id': '1396',
570 'protocol': 'm3u8',
571 'tbr': 1396.736,
572 'width': 854,
573 'height': 480,
574 }]
575 ),
576 (
577 # http://www.twitch.tv/riotgames/v/6528877
578 'twitch_vod',
579 'https://usher.ttvnw.net/vod/6528877?allow_source=true&allow_audio_only=true&allow_spectre=true&player=twitchweb&nauth=%7B%22user_id%22%3Anull%2C%22vod_id%22%3A6528877%2C%22expires%22%3A1492887874%2C%22chansub%22%3A%7B%22restricted_bitrates%22%3A%5B%5D%7D%2C%22privileged%22%3Afalse%2C%22https_required%22%3Afalse%7D&nauthsig=3e29296a6824a0f48f9e731383f77a614fc79bee',
580 [{
581 'url': 'https://vod.edgecast.hls.ttvnw.net/e5da31ab49_riotgames_15001215120_261543898/audio_only/index-muted-HM49I092CC.m3u8',
582 'manifest_url': 'https://usher.ttvnw.net/vod/6528877?allow_source=true&allow_audio_only=true&allow_spectre=true&player=twitchweb&nauth=%7B%22user_id%22%3Anull%2C%22vod_id%22%3A6528877%2C%22expires%22%3A1492887874%2C%22chansub%22%3A%7B%22restricted_bitrates%22%3A%5B%5D%7D%2C%22privileged%22%3Afalse%2C%22https_required%22%3Afalse%7D&nauthsig=3e29296a6824a0f48f9e731383f77a614fc79bee',
583 'ext': 'mp4',
584 'format_id': 'Audio Only',
585 'protocol': 'm3u8',
586 'acodec': 'mp4a.40.2',
587 'vcodec': 'none',
588 'tbr': 182.725,
589 }, {
590 'url': 'https://vod.edgecast.hls.ttvnw.net/e5da31ab49_riotgames_15001215120_261543898/mobile/index-muted-HM49I092CC.m3u8',
591 'manifest_url': 'https://usher.ttvnw.net/vod/6528877?allow_source=true&allow_audio_only=true&allow_spectre=true&player=twitchweb&nauth=%7B%22user_id%22%3Anull%2C%22vod_id%22%3A6528877%2C%22expires%22%3A1492887874%2C%22chansub%22%3A%7B%22restricted_bitrates%22%3A%5B%5D%7D%2C%22privileged%22%3Afalse%2C%22https_required%22%3Afalse%7D&nauthsig=3e29296a6824a0f48f9e731383f77a614fc79bee',
592 'ext': 'mp4',
593 'format_id': 'Mobile',
594 'protocol': 'm3u8',
595 'acodec': 'mp4a.40.2',
596 'vcodec': 'avc1.42C00D',
597 'tbr': 280.474,
598 'width': 400,
599 'height': 226,
600 }, {
601 'url': 'https://vod.edgecast.hls.ttvnw.net/e5da31ab49_riotgames_15001215120_261543898/low/index-muted-HM49I092CC.m3u8',
602 'manifest_url': 'https://usher.ttvnw.net/vod/6528877?allow_source=true&allow_audio_only=true&allow_spectre=true&player=twitchweb&nauth=%7B%22user_id%22%3Anull%2C%22vod_id%22%3A6528877%2C%22expires%22%3A1492887874%2C%22chansub%22%3A%7B%22restricted_bitrates%22%3A%5B%5D%7D%2C%22privileged%22%3Afalse%2C%22https_required%22%3Afalse%7D&nauthsig=3e29296a6824a0f48f9e731383f77a614fc79bee',
603 'ext': 'mp4',
604 'format_id': 'Low',
605 'protocol': 'm3u8',
606 'acodec': 'mp4a.40.2',
607 'vcodec': 'avc1.42C01E',
608 'tbr': 628.347,
609 'width': 640,
610 'height': 360,
611 }, {
612 'url': 'https://vod.edgecast.hls.ttvnw.net/e5da31ab49_riotgames_15001215120_261543898/medium/index-muted-HM49I092CC.m3u8',
613 'manifest_url': 'https://usher.ttvnw.net/vod/6528877?allow_source=true&allow_audio_only=true&allow_spectre=true&player=twitchweb&nauth=%7B%22user_id%22%3Anull%2C%22vod_id%22%3A6528877%2C%22expires%22%3A1492887874%2C%22chansub%22%3A%7B%22restricted_bitrates%22%3A%5B%5D%7D%2C%22privileged%22%3Afalse%2C%22https_required%22%3Afalse%7D&nauthsig=3e29296a6824a0f48f9e731383f77a614fc79bee',
614 'ext': 'mp4',
615 'format_id': 'Medium',
616 'protocol': 'm3u8',
617 'acodec': 'mp4a.40.2',
618 'vcodec': 'avc1.42C01E',
619 'tbr': 893.387,
620 'width': 852,
621 'height': 480,
622 }, {
623 'url': 'https://vod.edgecast.hls.ttvnw.net/e5da31ab49_riotgames_15001215120_261543898/high/index-muted-HM49I092CC.m3u8',
624 'manifest_url': 'https://usher.ttvnw.net/vod/6528877?allow_source=true&allow_audio_only=true&allow_spectre=true&player=twitchweb&nauth=%7B%22user_id%22%3Anull%2C%22vod_id%22%3A6528877%2C%22expires%22%3A1492887874%2C%22chansub%22%3A%7B%22restricted_bitrates%22%3A%5B%5D%7D%2C%22privileged%22%3Afalse%2C%22https_required%22%3Afalse%7D&nauthsig=3e29296a6824a0f48f9e731383f77a614fc79bee',
625 'ext': 'mp4',
626 'format_id': 'High',
627 'protocol': 'm3u8',
628 'acodec': 'mp4a.40.2',
629 'vcodec': 'avc1.42C01F',
630 'tbr': 1603.789,
631 'width': 1280,
632 'height': 720,
633 }, {
634 'url': 'https://vod.edgecast.hls.ttvnw.net/e5da31ab49_riotgames_15001215120_261543898/chunked/index-muted-HM49I092CC.m3u8',
635 'manifest_url': 'https://usher.ttvnw.net/vod/6528877?allow_source=true&allow_audio_only=true&allow_spectre=true&player=twitchweb&nauth=%7B%22user_id%22%3Anull%2C%22vod_id%22%3A6528877%2C%22expires%22%3A1492887874%2C%22chansub%22%3A%7B%22restricted_bitrates%22%3A%5B%5D%7D%2C%22privileged%22%3Afalse%2C%22https_required%22%3Afalse%7D&nauthsig=3e29296a6824a0f48f9e731383f77a614fc79bee',
636 'ext': 'mp4',
637 'format_id': 'Source',
638 'protocol': 'm3u8',
639 'acodec': 'mp4a.40.2',
640 'vcodec': 'avc1.100.31',
641 'tbr': 3214.134,
642 'width': 1280,
643 'height': 720,
644 }]
645 ),
646 (
647 # http://www.vidio.com/watch/165683-dj_ambred-booyah-live-2015
648 # EXT-X-STREAM-INF tag with NAME attribute that is not defined
649 # in HLS specification
650 'vidio',
651 'https://www.vidio.com/videos/165683/playlist.m3u8',
652 [{
653 'url': 'https://cdn1-a.production.vidio.static6.com/uploads/165683/dj_ambred-4383-b300.mp4.m3u8',
654 'manifest_url': 'https://www.vidio.com/videos/165683/playlist.m3u8',
655 'ext': 'mp4',
656 'format_id': '270p 3G',
657 'protocol': 'm3u8',
658 'tbr': 300,
659 'width': 480,
660 'height': 270,
661 }, {
662 'url': 'https://cdn1-a.production.vidio.static6.com/uploads/165683/dj_ambred-4383-b600.mp4.m3u8',
663 'manifest_url': 'https://www.vidio.com/videos/165683/playlist.m3u8',
664 'ext': 'mp4',
665 'format_id': '360p SD',
666 'protocol': 'm3u8',
667 'tbr': 600,
668 'width': 640,
669 'height': 360,
670 }, {
671 'url': 'https://cdn1-a.production.vidio.static6.com/uploads/165683/dj_ambred-4383-b1200.mp4.m3u8',
672 'manifest_url': 'https://www.vidio.com/videos/165683/playlist.m3u8',
673 'ext': 'mp4',
674 'format_id': '720p HD',
675 'protocol': 'm3u8',
676 'tbr': 1200,
677 'width': 1280,
678 'height': 720,
679 }]
680 ),
681 (
682 # https://github.com/ytdl-org/youtube-dl/issues/18923
683 # https://www.ted.com/talks/boris_hesser_a_grassroots_healthcare_revolution_in_africa
684 'ted_18923',
685 'http://hls.ted.com/talks/31241.m3u8',
686 [{
687 'url': 'http://hls.ted.com/videos/BorisHesser_2018S/audio/600k.m3u8?nobumpers=true&uniqueId=76011e2b',
688 'format_id': '600k-Audio',
689 'vcodec': 'none',
690 }, {
691 'url': 'http://hls.ted.com/videos/BorisHesser_2018S/audio/600k.m3u8?nobumpers=true&uniqueId=76011e2b',
692 'format_id': '68',
693 'vcodec': 'none',
694 }, {
695 'url': 'http://hls.ted.com/videos/BorisHesser_2018S/video/64k.m3u8?nobumpers=true&uniqueId=76011e2b',
696 'format_id': '163',
697 'acodec': 'none',
698 'width': 320,
699 'height': 180,
700 }, {
701 'url': 'http://hls.ted.com/videos/BorisHesser_2018S/video/180k.m3u8?nobumpers=true&uniqueId=76011e2b',
702 'format_id': '481',
703 'acodec': 'none',
704 'width': 512,
705 'height': 288,
706 }, {
707 'url': 'http://hls.ted.com/videos/BorisHesser_2018S/video/320k.m3u8?nobumpers=true&uniqueId=76011e2b',
708 'format_id': '769',
709 'acodec': 'none',
710 'width': 512,
711 'height': 288,
712 }, {
713 'url': 'http://hls.ted.com/videos/BorisHesser_2018S/video/450k.m3u8?nobumpers=true&uniqueId=76011e2b',
714 'format_id': '984',
715 'acodec': 'none',
716 'width': 512,
717 'height': 288,
718 }, {
719 'url': 'http://hls.ted.com/videos/BorisHesser_2018S/video/600k.m3u8?nobumpers=true&uniqueId=76011e2b',
720 'format_id': '1255',
721 'acodec': 'none',
722 'width': 640,
723 'height': 360,
724 }, {
725 'url': 'http://hls.ted.com/videos/BorisHesser_2018S/video/950k.m3u8?nobumpers=true&uniqueId=76011e2b',
726 'format_id': '1693',
727 'acodec': 'none',
728 'width': 853,
729 'height': 480,
730 }, {
731 'url': 'http://hls.ted.com/videos/BorisHesser_2018S/video/1500k.m3u8?nobumpers=true&uniqueId=76011e2b',
732 'format_id': '2462',
733 'acodec': 'none',
734 'width': 1280,
735 'height': 720,
736 }]
737 ),
738 ]
739
740 for m3u8_file, m3u8_url, expected_formats in _TEST_CASES:
741 with io.open('./test/testdata/m3u8/%s.m3u8' % m3u8_file,
742 mode='r', encoding='utf-8') as f:
743 formats = self.ie._parse_m3u8_formats(
744 f.read(), m3u8_url, ext='mp4')
745 self.ie._sort_formats(formats)
746 expect_value(self, formats, expected_formats, None)
747
748 def test_parse_mpd_formats(self):
749 _TEST_CASES = [
750 (
751 # https://github.com/ytdl-org/youtube-dl/issues/13919
752 # Also tests duplicate representation ids, see
753 # https://github.com/ytdl-org/youtube-dl/issues/15111
754 'float_duration',
755 'http://unknown/manifest.mpd', # mpd_url
756 None, # mpd_base_url
757 [{
758 'manifest_url': 'http://unknown/manifest.mpd',
759 'ext': 'm4a',
760 'format_id': '318597',
761 'format_note': 'DASH audio',
762 'protocol': 'http_dash_segments',
763 'acodec': 'mp4a.40.2',
764 'vcodec': 'none',
765 'tbr': 61.587,
766 }, {
767 'manifest_url': 'http://unknown/manifest.mpd',
768 'ext': 'mp4',
769 'format_id': '318597',
770 'format_note': 'DASH video',
771 'protocol': 'http_dash_segments',
772 'acodec': 'none',
773 'vcodec': 'avc1.42001f',
774 'tbr': 318.597,
775 'width': 340,
776 'height': 192,
777 }, {
778 'manifest_url': 'http://unknown/manifest.mpd',
779 'ext': 'mp4',
780 'format_id': '638590',
781 'format_note': 'DASH video',
782 'protocol': 'http_dash_segments',
783 'acodec': 'none',
784 'vcodec': 'avc1.42001f',
785 'tbr': 638.59,
786 'width': 512,
787 'height': 288,
788 }, {
789 'manifest_url': 'http://unknown/manifest.mpd',
790 'ext': 'mp4',
791 'format_id': '1022565',
792 'format_note': 'DASH video',
793 'protocol': 'http_dash_segments',
794 'acodec': 'none',
795 'vcodec': 'avc1.4d001f',
796 'tbr': 1022.565,
797 'width': 688,
798 'height': 384,
799 }, {
800 'manifest_url': 'http://unknown/manifest.mpd',
801 'ext': 'mp4',
802 'format_id': '2046506',
803 'format_note': 'DASH video',
804 'protocol': 'http_dash_segments',
805 'acodec': 'none',
806 'vcodec': 'avc1.4d001f',
807 'tbr': 2046.506,
808 'width': 1024,
809 'height': 576,
810 }, {
811 'manifest_url': 'http://unknown/manifest.mpd',
812 'ext': 'mp4',
813 'format_id': '3998017',
814 'format_note': 'DASH video',
815 'protocol': 'http_dash_segments',
816 'acodec': 'none',
817 'vcodec': 'avc1.640029',
818 'tbr': 3998.017,
819 'width': 1280,
820 'height': 720,
821 }, {
822 'manifest_url': 'http://unknown/manifest.mpd',
823 'ext': 'mp4',
824 'format_id': '5997485',
825 'format_note': 'DASH video',
826 'protocol': 'http_dash_segments',
827 'acodec': 'none',
828 'vcodec': 'avc1.640032',
829 'tbr': 5997.485,
830 'width': 1920,
831 'height': 1080,
832 }]
833 ), (
834 # https://github.com/ytdl-org/youtube-dl/pull/14844
835 'urls_only',
836 'http://unknown/manifest.mpd', # mpd_url
837 None, # mpd_base_url
838 [{
839 'manifest_url': 'http://unknown/manifest.mpd',
840 'ext': 'mp4',
841 'format_id': 'h264_aac_144p_m4s',
842 'format_note': 'DASH video',
843 'protocol': 'http_dash_segments',
844 'acodec': 'mp4a.40.2',
845 'vcodec': 'avc3.42c01e',
846 'tbr': 200,
847 'width': 256,
848 'height': 144,
849 }, {
850 'manifest_url': 'http://unknown/manifest.mpd',
851 'ext': 'mp4',
852 'format_id': 'h264_aac_240p_m4s',
853 'format_note': 'DASH video',
854 'protocol': 'http_dash_segments',
855 'acodec': 'mp4a.40.2',
856 'vcodec': 'avc3.42c01e',
857 'tbr': 400,
858 'width': 424,
859 'height': 240,
860 }, {
861 'manifest_url': 'http://unknown/manifest.mpd',
862 'ext': 'mp4',
863 'format_id': 'h264_aac_360p_m4s',
864 'format_note': 'DASH video',
865 'protocol': 'http_dash_segments',
866 'acodec': 'mp4a.40.2',
867 'vcodec': 'avc3.42c01e',
868 'tbr': 800,
869 'width': 640,
870 'height': 360,
871 }, {
872 'manifest_url': 'http://unknown/manifest.mpd',
873 'ext': 'mp4',
874 'format_id': 'h264_aac_480p_m4s',
875 'format_note': 'DASH video',
876 'protocol': 'http_dash_segments',
877 'acodec': 'mp4a.40.2',
878 'vcodec': 'avc3.42c01e',
879 'tbr': 1200,
880 'width': 856,
881 'height': 480,
882 }, {
883 'manifest_url': 'http://unknown/manifest.mpd',
884 'ext': 'mp4',
885 'format_id': 'h264_aac_576p_m4s',
886 'format_note': 'DASH video',
887 'protocol': 'http_dash_segments',
888 'acodec': 'mp4a.40.2',
889 'vcodec': 'avc3.42c01e',
890 'tbr': 1600,
891 'width': 1024,
892 'height': 576,
893 }, {
894 'manifest_url': 'http://unknown/manifest.mpd',
895 'ext': 'mp4',
896 'format_id': 'h264_aac_720p_m4s',
897 'format_note': 'DASH video',
898 'protocol': 'http_dash_segments',
899 'acodec': 'mp4a.40.2',
900 'vcodec': 'avc3.42c01e',
901 'tbr': 2400,
902 'width': 1280,
903 'height': 720,
904 }, {
905 'manifest_url': 'http://unknown/manifest.mpd',
906 'ext': 'mp4',
907 'format_id': 'h264_aac_1080p_m4s',
908 'format_note': 'DASH video',
909 'protocol': 'http_dash_segments',
910 'acodec': 'mp4a.40.2',
911 'vcodec': 'avc3.42c01e',
912 'tbr': 4400,
913 'width': 1920,
914 'height': 1080,
915 }]
916 ), (
917 # https://github.com/ytdl-org/youtube-dl/issues/20346
918 # Media considered unfragmented even though it contains
919 # Initialization tag
920 'unfragmented',
921 'https://v.redd.it/hw1x7rcg7zl21/DASHPlaylist.mpd', # mpd_url
922 'https://v.redd.it/hw1x7rcg7zl21', # mpd_base_url
923 [{
924 'url': 'https://v.redd.it/hw1x7rcg7zl21/audio',
925 'manifest_url': 'https://v.redd.it/hw1x7rcg7zl21/DASHPlaylist.mpd',
926 'ext': 'm4a',
927 'format_id': 'AUDIO-1',
928 'format_note': 'DASH audio',
929 'container': 'm4a_dash',
930 'acodec': 'mp4a.40.2',
931 'vcodec': 'none',
932 'tbr': 129.87,
933 'asr': 48000,
934
935 }, {
936 'url': 'https://v.redd.it/hw1x7rcg7zl21/DASH_240',
937 'manifest_url': 'https://v.redd.it/hw1x7rcg7zl21/DASHPlaylist.mpd',
938 'ext': 'mp4',
939 'format_id': 'VIDEO-2',
940 'format_note': 'DASH video',
941 'container': 'mp4_dash',
942 'acodec': 'none',
943 'vcodec': 'avc1.4d401e',
944 'tbr': 608.0,
945 'width': 240,
946 'height': 240,
947 'fps': 30,
948 }, {
949 'url': 'https://v.redd.it/hw1x7rcg7zl21/DASH_360',
950 'manifest_url': 'https://v.redd.it/hw1x7rcg7zl21/DASHPlaylist.mpd',
951 'ext': 'mp4',
952 'format_id': 'VIDEO-1',
953 'format_note': 'DASH video',
954 'container': 'mp4_dash',
955 'acodec': 'none',
956 'vcodec': 'avc1.4d401e',
957 'tbr': 804.261,
958 'width': 360,
959 'height': 360,
960 'fps': 30,
961 }]
962 )
963 ]
964
965 for mpd_file, mpd_url, mpd_base_url, expected_formats in _TEST_CASES:
966 with io.open('./test/testdata/mpd/%s.mpd' % mpd_file,
967 mode='r', encoding='utf-8') as f:
968 formats = self.ie._parse_mpd_formats(
969 compat_etree_fromstring(f.read().encode('utf-8')),
970 mpd_base_url=mpd_base_url, mpd_url=mpd_url)
971 self.ie._sort_formats(formats)
972 expect_value(self, formats, expected_formats, None)
973
974 def test_parse_f4m_formats(self):
975 _TEST_CASES = [
976 (
977 # https://github.com/ytdl-org/youtube-dl/issues/14660
978 'custom_base_url',
979 'http://api.new.livestream.com/accounts/6115179/events/6764928/videos/144884262.f4m',
980 [{
981 'manifest_url': 'http://api.new.livestream.com/accounts/6115179/events/6764928/videos/144884262.f4m',
982 'ext': 'flv',
983 'format_id': '2148',
984 'protocol': 'f4m',
985 'tbr': 2148,
986 'width': 1280,
987 'height': 720,
988 }]
989 ),
990 ]
991
992 for f4m_file, f4m_url, expected_formats in _TEST_CASES:
993 with io.open('./test/testdata/f4m/%s.f4m' % f4m_file,
994 mode='r', encoding='utf-8') as f:
995 formats = self.ie._parse_f4m_formats(
996 compat_etree_fromstring(f.read().encode('utf-8')),
997 f4m_url, None)
998 self.ie._sort_formats(formats)
999 expect_value(self, formats, expected_formats, None)
1000
1001 def test_parse_xspf(self):
1002 _TEST_CASES = [
1003 (
1004 'foo_xspf',
1005 'https://example.org/src/foo_xspf.xspf',
1006 [{
1007 'id': 'foo_xspf',
1008 'title': 'Pandemonium',
1009 'description': 'Visit http://bigbrother404.bandcamp.com',
1010 'duration': 202.416,
1011 'formats': [{
1012 'manifest_url': 'https://example.org/src/foo_xspf.xspf',
1013 'url': 'https://example.org/src/cd1/track%201.mp3',
1014 }],
1015 }, {
1016 'id': 'foo_xspf',
1017 'title': 'Final Cartridge (Nichico Twelve Remix)',
1018 'description': 'Visit http://bigbrother404.bandcamp.com',
1019 'duration': 255.857,
1020 'formats': [{
1021 'manifest_url': 'https://example.org/src/foo_xspf.xspf',
1022 'url': 'https://example.org/%E3%83%88%E3%83%A9%E3%83%83%E3%82%AF%E3%80%80%EF%BC%92.mp3',
1023 }],
1024 }, {
1025 'id': 'foo_xspf',
1026 'title': 'Rebuilding Nightingale',
1027 'description': 'Visit http://bigbrother404.bandcamp.com',
1028 'duration': 287.915,
1029 'formats': [{
1030 'manifest_url': 'https://example.org/src/foo_xspf.xspf',
1031 'url': 'https://example.org/src/track3.mp3',
1032 }, {
1033 'manifest_url': 'https://example.org/src/foo_xspf.xspf',
1034 'url': 'https://example.com/track3.mp3',
1035 }]
1036 }]
1037 ),
1038 ]
1039
1040 for xspf_file, xspf_url, expected_entries in _TEST_CASES:
1041 with io.open('./test/testdata/xspf/%s.xspf' % xspf_file,
1042 mode='r', encoding='utf-8') as f:
1043 entries = self.ie._parse_xspf(
1044 compat_etree_fromstring(f.read().encode('utf-8')),
1045 xspf_file, xspf_url=xspf_url, xspf_base_url=xspf_url)
1046 expect_value(self, entries, expected_entries, None)
1047 for i in range(len(entries)):
1048 expect_dict(self, entries[i], expected_entries[i])
1049
1050 def test_response_with_expected_status_returns_content(self):
1051 # Checks for mitigations against the effects of
1052 # <https://bugs.python.org/issue15002> that affect Python 3.4.1+, which
1053 # manifest as `_download_webpage`, `_download_xml`, `_download_json`,
1054 # or the underlying `_download_webpage_handle` returning no content
1055 # when a response matches `expected_status`.
1056
1057 httpd = compat_http_server.HTTPServer(
1058 ('127.0.0.1', 0), InfoExtractorTestRequestHandler)
1059 port = http_server_port(httpd)
1060 server_thread = threading.Thread(target=httpd.serve_forever)
1061 server_thread.daemon = True
1062 server_thread.start()
1063
1064 (content, urlh) = self.ie._download_webpage_handle(
1065 'http://127.0.0.1:%d/teapot' % port, None,
1066 expected_status=TEAPOT_RESPONSE_STATUS)
1067 self.assertEqual(content, TEAPOT_RESPONSE_BODY)
1068
1069
1070 if __name__ == '__main__':
1071 unittest.main()