]> jfr.im git - yt-dlp.git/blob - test/test_InfoExtractor.py
[test] Test SSTR manifest parsing
[yt-dlp.git] / 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 yt_dlp.compat import compat_etree_fromstring, compat_http_server
14 from yt_dlp.extractor.common import InfoExtractor
15 from yt_dlp.extractor import YoutubeIE, get_info_extractor
16 from yt_dlp.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_search_json_ld_realworld(self):
102 # https://github.com/ytdl-org/youtube-dl/issues/23306
103 expect_dict(
104 self,
105 self.ie._search_json_ld(r'''<script type="application/ld+json">
106 {
107 "@context": "http://schema.org/",
108 "@type": "VideoObject",
109 "name": "1 On 1 With Kleio",
110 "url": "https://www.eporner.com/hd-porn/xN49A1cT3eB/1-On-1-With-Kleio/",
111 "duration": "PT0H12M23S",
112 "thumbnailUrl": ["https://static-eu-cdn.eporner.com/thumbs/static4/7/78/780/780814/9_360.jpg", "https://imggen.eporner.com/780814/1920/1080/9.jpg"],
113 "contentUrl": "https://gvideo.eporner.com/xN49A1cT3eB/xN49A1cT3eB.mp4",
114 "embedUrl": "https://www.eporner.com/embed/xN49A1cT3eB/1-On-1-With-Kleio/",
115 "image": "https://static-eu-cdn.eporner.com/thumbs/static4/7/78/780/780814/9_360.jpg",
116 "width": "1920",
117 "height": "1080",
118 "encodingFormat": "mp4",
119 "bitrate": "6617kbps",
120 "isFamilyFriendly": "False",
121 "description": "Kleio Valentien",
122 "uploadDate": "2015-12-05T21:24:35+01:00",
123 "interactionStatistic": {
124 "@type": "InteractionCounter",
125 "interactionType": { "@type": "http://schema.org/WatchAction" },
126 "userInteractionCount": 1120958
127 }, "aggregateRating": {
128 "@type": "AggregateRating",
129 "ratingValue": "88",
130 "ratingCount": "630",
131 "bestRating": "100",
132 "worstRating": "0"
133 }, "actor": [{
134 "@type": "Person",
135 "name": "Kleio Valentien",
136 "url": "https://www.eporner.com/pornstar/kleio-valentien/"
137 }]}
138 </script>''', None),
139 {
140 'title': '1 On 1 With Kleio',
141 'description': 'Kleio Valentien',
142 'url': 'https://gvideo.eporner.com/xN49A1cT3eB/xN49A1cT3eB.mp4',
143 'timestamp': 1449347075,
144 'duration': 743.0,
145 'view_count': 1120958,
146 'width': 1920,
147 'height': 1080,
148 })
149
150 def test_download_json(self):
151 uri = encode_data_uri(b'{"foo": "blah"}', 'application/json')
152 self.assertEqual(self.ie._download_json(uri, None), {'foo': 'blah'})
153 uri = encode_data_uri(b'callback({"foo": "blah"})', 'application/javascript')
154 self.assertEqual(self.ie._download_json(uri, None, transform_source=strip_jsonp), {'foo': 'blah'})
155 uri = encode_data_uri(b'{"foo": invalid}', 'application/json')
156 self.assertRaises(ExtractorError, self.ie._download_json, uri, None)
157 self.assertEqual(self.ie._download_json(uri, None, fatal=False), None)
158
159 def test_parse_html5_media_entries(self):
160 # inline video tag
161 expect_dict(
162 self,
163 self.ie._parse_html5_media_entries(
164 'https://127.0.0.1/video.html',
165 r'<html><video src="/vid.mp4" /></html>', None)[0],
166 {
167 'formats': [{
168 'url': 'https://127.0.0.1/vid.mp4',
169 }],
170 })
171
172 # from https://www.r18.com/
173 # with kpbs in label
174 expect_dict(
175 self,
176 self.ie._parse_html5_media_entries(
177 'https://www.r18.com/',
178 r'''
179 <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">
180 <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">
181 <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">
182 <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">
183 <p>Your browser does not support the video tag.</p>
184 </video>
185 ''', None)[0],
186 {
187 'formats': [{
188 'url': 'https://awscc3001.r18.com/litevideo/freepv/m/mgm/mgmr105/mgmr105_sm_w.mp4',
189 'ext': 'mp4',
190 'format_id': '300kbps',
191 'height': 240,
192 'tbr': 300,
193 }, {
194 'url': 'https://awscc3001.r18.com/litevideo/freepv/m/mgm/mgmr105/mgmr105_dm_w.mp4',
195 'ext': 'mp4',
196 'format_id': '1000kbps',
197 'height': 480,
198 'tbr': 1000,
199 }, {
200 'url': 'https://awscc3001.r18.com/litevideo/freepv/m/mgm/mgmr105/mgmr105_dmb_w.mp4',
201 'ext': 'mp4',
202 'format_id': '1500kbps',
203 'height': 740,
204 'tbr': 1500,
205 }],
206 'thumbnail': '//pics.r18.com/digital/amateur/mgmr105/mgmr105jp.jpg'
207 })
208
209 # from https://www.csfd.cz/
210 # with width and height
211 expect_dict(
212 self,
213 self.ie._parse_html5_media_entries(
214 'https://www.csfd.cz/',
215 r'''
216 <video width="770" height="328" preload="none" controls poster="https://img.csfd.cz/files/images/film/video/preview/163/344/163344118_748d20.png?h360" >
217 <source src="https://video.csfd.cz/files/videos/157/750/157750813/163327358_eac647.mp4" type="video/mp4" width="640" height="360">
218 <source src="https://video.csfd.cz/files/videos/157/750/157750813/163327360_3d2646.mp4" type="video/mp4" width="1280" height="720">
219 <source src="https://video.csfd.cz/files/videos/157/750/157750813/163327356_91f258.mp4" type="video/mp4" width="1920" height="1080">
220 <source src="https://video.csfd.cz/files/videos/157/750/157750813/163327359_962b4a.webm" type="video/webm" width="640" height="360">
221 <source src="https://video.csfd.cz/files/videos/157/750/157750813/163327361_6feee0.webm" type="video/webm" width="1280" height="720">
222 <source src="https://video.csfd.cz/files/videos/157/750/157750813/163327357_8ab472.webm" type="video/webm" width="1920" height="1080">
223 <track src="https://video.csfd.cz/files/subtitles/163/344/163344115_4c388b.srt" type="text/x-srt" kind="subtitles" srclang="cs" label="cs">
224 </video>
225 ''', None)[0],
226 {
227 'formats': [{
228 'url': 'https://video.csfd.cz/files/videos/157/750/157750813/163327358_eac647.mp4',
229 'ext': 'mp4',
230 'width': 640,
231 'height': 360,
232 }, {
233 'url': 'https://video.csfd.cz/files/videos/157/750/157750813/163327360_3d2646.mp4',
234 'ext': 'mp4',
235 'width': 1280,
236 'height': 720,
237 }, {
238 'url': 'https://video.csfd.cz/files/videos/157/750/157750813/163327356_91f258.mp4',
239 'ext': 'mp4',
240 'width': 1920,
241 'height': 1080,
242 }, {
243 'url': 'https://video.csfd.cz/files/videos/157/750/157750813/163327359_962b4a.webm',
244 'ext': 'webm',
245 'width': 640,
246 'height': 360,
247 }, {
248 'url': 'https://video.csfd.cz/files/videos/157/750/157750813/163327361_6feee0.webm',
249 'ext': 'webm',
250 'width': 1280,
251 'height': 720,
252 }, {
253 'url': 'https://video.csfd.cz/files/videos/157/750/157750813/163327357_8ab472.webm',
254 'ext': 'webm',
255 'width': 1920,
256 'height': 1080,
257 }],
258 'subtitles': {
259 'cs': [{'url': 'https://video.csfd.cz/files/subtitles/163/344/163344115_4c388b.srt'}]
260 },
261 'thumbnail': 'https://img.csfd.cz/files/images/film/video/preview/163/344/163344118_748d20.png?h360'
262 })
263
264 # from https://tamasha.com/v/Kkdjw
265 # with height in label
266 expect_dict(
267 self,
268 self.ie._parse_html5_media_entries(
269 'https://tamasha.com/v/Kkdjw',
270 r'''
271 <video crossorigin="anonymous">
272 <source src="https://s-v2.tamasha.com/statics/videos_file/19/8f/Kkdjw_198feff8577d0057536e905cce1fb61438dd64e0_n_240.mp4" type="video/mp4" label="AUTO" res="0"/>
273 <source src="https://s-v2.tamasha.com/statics/videos_file/19/8f/Kkdjw_198feff8577d0057536e905cce1fb61438dd64e0_n_240.mp4" type="video/mp4"
274 label="240p" res="240"/>
275 <source src="https://s-v2.tamasha.com/statics/videos_file/20/00/Kkdjw_200041c66f657fc967db464d156eafbc1ed9fe6f_n_144.mp4" type="video/mp4"
276 label="144p" res="144"/>
277 </video>
278 ''', None)[0],
279 {
280 'formats': [{
281 'url': 'https://s-v2.tamasha.com/statics/videos_file/19/8f/Kkdjw_198feff8577d0057536e905cce1fb61438dd64e0_n_240.mp4',
282 }, {
283 'url': 'https://s-v2.tamasha.com/statics/videos_file/19/8f/Kkdjw_198feff8577d0057536e905cce1fb61438dd64e0_n_240.mp4',
284 'ext': 'mp4',
285 'format_id': '240p',
286 'height': 240,
287 }, {
288 'url': 'https://s-v2.tamasha.com/statics/videos_file/20/00/Kkdjw_200041c66f657fc967db464d156eafbc1ed9fe6f_n_144.mp4',
289 'ext': 'mp4',
290 'format_id': '144p',
291 'height': 144,
292 }]
293 })
294
295 # from https://www.directvnow.com
296 # with data-src
297 expect_dict(
298 self,
299 self.ie._parse_html5_media_entries(
300 'https://www.directvnow.com',
301 r'''
302 <video id="vid1" class="header--video-masked active" muted playsinline>
303 <source data-src="https://cdn.directv.com/content/dam/dtv/prod/website_directvnow-international/videos/DTVN_hdr_HBO_v3.mp4" type="video/mp4" />
304 </video>
305 ''', None)[0],
306 {
307 'formats': [{
308 'ext': 'mp4',
309 'url': 'https://cdn.directv.com/content/dam/dtv/prod/website_directvnow-international/videos/DTVN_hdr_HBO_v3.mp4',
310 }]
311 })
312
313 # from https://www.directvnow.com
314 # with data-src
315 expect_dict(
316 self,
317 self.ie._parse_html5_media_entries(
318 'https://www.directvnow.com',
319 r'''
320 <video id="vid1" class="header--video-masked active" muted playsinline>
321 <source data-src="https://cdn.directv.com/content/dam/dtv/prod/website_directvnow-international/videos/DTVN_hdr_HBO_v3.mp4" type="video/mp4" />
322 </video>
323 ''', None)[0],
324 {
325 'formats': [{
326 'url': 'https://cdn.directv.com/content/dam/dtv/prod/website_directvnow-international/videos/DTVN_hdr_HBO_v3.mp4',
327 'ext': 'mp4',
328 }]
329 })
330
331 # from https://www.klarna.com/uk/
332 # with data-video-src
333 expect_dict(
334 self,
335 self.ie._parse_html5_media_entries(
336 'https://www.directvnow.com',
337 r'''
338 <video loop autoplay muted class="responsive-video block-kl__video video-on-medium">
339 <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" />
340 </video>
341 ''', None)[0],
342 {
343 'formats': [{
344 'url': 'https://www.klarna.com/uk/wp-content/uploads/sites/11/2019/01/KL062_Smooth3_0_DogWalking_5s_920x080_.mp4',
345 'ext': 'mp4',
346 }],
347 })
348
349 def test_extract_jwplayer_data_realworld(self):
350 # from http://www.suffolk.edu/sjc/
351 expect_dict(
352 self,
353 self.ie._extract_jwplayer_data(r'''
354 <script type='text/javascript'>
355 jwplayer('my-video').setup({
356 file: 'rtmp://192.138.214.154/live/sjclive',
357 fallback: 'true',
358 width: '95%',
359 aspectratio: '16:9',
360 primary: 'flash',
361 mediaid:'XEgvuql4'
362 });
363 </script>
364 ''', None, require_title=False),
365 {
366 'id': 'XEgvuql4',
367 'formats': [{
368 'url': 'rtmp://192.138.214.154/live/sjclive',
369 'ext': 'flv'
370 }]
371 })
372
373 # from https://www.pornoxo.com/videos/7564/striptease-from-sexy-secretary/
374 expect_dict(
375 self,
376 self.ie._extract_jwplayer_data(r'''
377 <script type="text/javascript">
378 jwplayer("mediaplayer").setup({
379 'videoid': "7564",
380 'width': "100%",
381 'aspectratio': "16:9",
382 'stretching': "exactfit",
383 'autostart': 'false',
384 'flashplayer': "https://t04.vipstreamservice.com/jwplayer/v5.10/player.swf",
385 '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",
386 'image': "https://t03.vipstreamservice.com/thumbs/pxo-full/2009-12/14/a4b2157147afe5efa93ce1978e0265289c193874e02597.flv-full-13.jpg",
387 '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",
388 'logo.hide': true,
389 'skin': "https://t04.vipstreamservice.com/jwplayer/skin/modieus-blk.zip",
390 'plugins': "https://t04.vipstreamservice.com/jwplayer/dock/dockableskinnableplugin.swf",
391 'dockableskinnableplugin.piclink': "/index.php?key=ajax-videothumbsn&vid=7564&data=2009-12--14--4b2157147afe5efa93ce1978e0265289c193874e02597.flv--17370",
392 'controlbar': 'bottom',
393 'modes': [
394 {type: 'flash', src: 'https://t04.vipstreamservice.com/jwplayer/v5.10/player.swf'}
395 ],
396 'provider': 'http'
397 });
398 //noinspection JSAnnotator
399 invideo.setup({
400 adsUrl: "/banner-iframe/?zoneId=32",
401 adsUrl2: "",
402 autostart: false
403 });
404 </script>
405 ''', 'dummy', require_title=False),
406 {
407 'thumbnail': 'https://t03.vipstreamservice.com/thumbs/pxo-full/2009-12/14/a4b2157147afe5efa93ce1978e0265289c193874e02597.flv-full-13.jpg',
408 'formats': [{
409 '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',
410 'ext': 'flv'
411 }]
412 })
413
414 # from http://www.indiedb.com/games/king-machine/videos
415 expect_dict(
416 self,
417 self.ie._extract_jwplayer_data(r'''
418 <script>
419 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) {
420 videoAnalytics("play");
421 }).once("complete", function(event) {
422 videoAnalytics("completed");
423 });
424 </script>
425 ''', 'dummy'),
426 {
427 'title': 'king machine trailer 1',
428 'thumbnail': 'http://media.indiedb.com/cache/images/games/1/50/49678/thumb_620x2000/king-machine-trailer.mp4.jpg',
429 'formats': [{
430 'url': 'http://cdn.dbolical.com/cache/videos/games/1/50/49678/encode_mp4/king-machine-trailer.mp4',
431 'height': 360,
432 'ext': 'mp4'
433 }, {
434 'url': 'http://cdn.dbolical.com/cache/videos/games/1/50/49678/encode720p_mp4/king-machine-trailer.mp4',
435 'height': 720,
436 'ext': 'mp4'
437 }]
438 })
439
440 def test_parse_m3u8_formats(self):
441 _TEST_CASES = [
442 (
443 # https://github.com/ytdl-org/youtube-dl/issues/11995
444 # http://teamcoco.com/video/clueless-gamer-super-bowl-for-honor
445 'img_bipbop_adv_example_fmp4',
446 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/master.m3u8',
447 [{
448 'format_id': 'aud1-English',
449 'url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/a1/prog_index.m3u8',
450 'manifest_url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/master.m3u8',
451 'language': 'en',
452 'ext': 'mp4',
453 'protocol': 'm3u8',
454 'audio_ext': 'mp4',
455 }, {
456 'format_id': 'aud2-English',
457 'url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/a2/prog_index.m3u8',
458 'manifest_url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/master.m3u8',
459 'language': 'en',
460 'ext': 'mp4',
461 'protocol': 'm3u8',
462 'audio_ext': 'mp4',
463 }, {
464 'format_id': 'aud3-English',
465 'url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/a3/prog_index.m3u8',
466 'manifest_url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/master.m3u8',
467 'language': 'en',
468 'ext': 'mp4',
469 'protocol': 'm3u8',
470 'audio_ext': 'mp4',
471 }, {
472 'format_id': '530',
473 'url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/v2/prog_index.m3u8',
474 'manifest_url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/master.m3u8',
475 'ext': 'mp4',
476 'protocol': 'm3u8',
477 'width': 480,
478 'height': 270,
479 'vcodec': 'avc1.640015',
480 }, {
481 'format_id': '561',
482 'url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/v2/prog_index.m3u8',
483 'manifest_url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/master.m3u8',
484 'ext': 'mp4',
485 'protocol': 'm3u8',
486 'width': 480,
487 'height': 270,
488 'vcodec': 'avc1.640015',
489 }, {
490 'format_id': '753',
491 'url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/v2/prog_index.m3u8',
492 'manifest_url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/master.m3u8',
493 'ext': 'mp4',
494 'protocol': 'm3u8',
495 'width': 480,
496 'height': 270,
497 'vcodec': 'avc1.640015',
498 }, {
499 'format_id': '895',
500 'url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/v3/prog_index.m3u8',
501 'manifest_url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/master.m3u8',
502 'ext': 'mp4',
503 'protocol': 'm3u8',
504 'width': 640,
505 'height': 360,
506 'vcodec': 'avc1.64001e',
507 }, {
508 'format_id': '926',
509 'url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/v3/prog_index.m3u8',
510 'manifest_url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/master.m3u8',
511 'ext': 'mp4',
512 'protocol': 'm3u8',
513 'width': 640,
514 'height': 360,
515 'vcodec': 'avc1.64001e',
516 }, {
517 'format_id': '1118',
518 'url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/v3/prog_index.m3u8',
519 'manifest_url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/master.m3u8',
520 'ext': 'mp4',
521 'protocol': 'm3u8',
522 'width': 640,
523 'height': 360,
524 'vcodec': 'avc1.64001e',
525 }, {
526 'format_id': '1265',
527 'url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/v4/prog_index.m3u8',
528 'manifest_url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/master.m3u8',
529 'ext': 'mp4',
530 'protocol': 'm3u8',
531 'width': 768,
532 'height': 432,
533 'vcodec': 'avc1.64001e',
534 }, {
535 'format_id': '1295',
536 'url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/v4/prog_index.m3u8',
537 'manifest_url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/master.m3u8',
538 'ext': 'mp4',
539 'protocol': 'm3u8',
540 'width': 768,
541 'height': 432,
542 'vcodec': 'avc1.64001e',
543 }, {
544 'format_id': '1487',
545 'url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/v4/prog_index.m3u8',
546 'manifest_url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/master.m3u8',
547 'ext': 'mp4',
548 'protocol': 'm3u8',
549 'width': 768,
550 'height': 432,
551 'vcodec': 'avc1.64001e',
552 }, {
553 'format_id': '2168',
554 'url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/v5/prog_index.m3u8',
555 'manifest_url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/master.m3u8',
556 'ext': 'mp4',
557 'protocol': 'm3u8',
558 'width': 960,
559 'height': 540,
560 'vcodec': 'avc1.640020',
561 }, {
562 'format_id': '2198',
563 'url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/v5/prog_index.m3u8',
564 'manifest_url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/master.m3u8',
565 'ext': 'mp4',
566 'protocol': 'm3u8',
567 'width': 960,
568 'height': 540,
569 'vcodec': 'avc1.640020',
570 }, {
571 'format_id': '2390',
572 'url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/v5/prog_index.m3u8',
573 'manifest_url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/master.m3u8',
574 'ext': 'mp4',
575 'protocol': 'm3u8',
576 'width': 960,
577 'height': 540,
578 'vcodec': 'avc1.640020',
579 }, {
580 'format_id': '3168',
581 'url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/v6/prog_index.m3u8',
582 'manifest_url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/master.m3u8',
583 'ext': 'mp4',
584 'protocol': 'm3u8',
585 'width': 1280,
586 'height': 720,
587 'vcodec': 'avc1.640020',
588 }, {
589 'format_id': '3199',
590 'url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/v6/prog_index.m3u8',
591 'manifest_url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/master.m3u8',
592 'ext': 'mp4',
593 'protocol': 'm3u8',
594 'width': 1280,
595 'height': 720,
596 'vcodec': 'avc1.640020',
597 }, {
598 'format_id': '3391',
599 'url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/v6/prog_index.m3u8',
600 'manifest_url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/master.m3u8',
601 'ext': 'mp4',
602 'protocol': 'm3u8',
603 'width': 1280,
604 'height': 720,
605 'vcodec': 'avc1.640020',
606 }, {
607 'format_id': '4670',
608 'url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/v7/prog_index.m3u8',
609 'manifest_url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/master.m3u8',
610 'ext': 'mp4',
611 'protocol': 'm3u8',
612 'width': 1920,
613 'height': 1080,
614 'vcodec': 'avc1.64002a',
615 }, {
616 'format_id': '4701',
617 'url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/v7/prog_index.m3u8',
618 'manifest_url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/master.m3u8',
619 'ext': 'mp4',
620 'protocol': 'm3u8',
621 'width': 1920,
622 'height': 1080,
623 'vcodec': 'avc1.64002a',
624 }, {
625 'format_id': '4893',
626 'url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/v7/prog_index.m3u8',
627 'manifest_url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/master.m3u8',
628 'ext': 'mp4',
629 'protocol': 'm3u8',
630 'width': 1920,
631 'height': 1080,
632 'vcodec': 'avc1.64002a',
633 }, {
634 'format_id': '6170',
635 'url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/v8/prog_index.m3u8',
636 'manifest_url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/master.m3u8',
637 'ext': 'mp4',
638 'protocol': 'm3u8',
639 'width': 1920,
640 'height': 1080,
641 'vcodec': 'avc1.64002a',
642 }, {
643 'format_id': '6200',
644 'url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/v8/prog_index.m3u8',
645 'manifest_url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/master.m3u8',
646 'ext': 'mp4',
647 'protocol': 'm3u8',
648 'width': 1920,
649 'height': 1080,
650 'vcodec': 'avc1.64002a',
651 }, {
652 'format_id': '6392',
653 'url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/v8/prog_index.m3u8',
654 'manifest_url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/master.m3u8',
655 'ext': 'mp4',
656 'protocol': 'm3u8',
657 'width': 1920,
658 'height': 1080,
659 'vcodec': 'avc1.64002a',
660 }, {
661 'format_id': '7968',
662 'url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/v9/prog_index.m3u8',
663 'manifest_url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/master.m3u8',
664 'ext': 'mp4',
665 'protocol': 'm3u8',
666 'width': 1920,
667 'height': 1080,
668 'vcodec': 'avc1.64002a',
669 }, {
670 'format_id': '7998',
671 'url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/v9/prog_index.m3u8',
672 'manifest_url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/master.m3u8',
673 'ext': 'mp4',
674 'protocol': 'm3u8',
675 'width': 1920,
676 'height': 1080,
677 'vcodec': 'avc1.64002a',
678 }, {
679 'format_id': '8190',
680 'url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/v9/prog_index.m3u8',
681 'manifest_url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/master.m3u8',
682 'ext': 'mp4',
683 'protocol': 'm3u8',
684 'width': 1920,
685 'height': 1080,
686 'vcodec': 'avc1.64002a',
687 }],
688 {}
689 ),
690 (
691 'bipbop_16x9',
692 'https://devstreaming-cdn.apple.com/videos/streaming/examples/bipbop_16x9/bipbop_16x9_variant.m3u8',
693 [{
694 "format_id": "bipbop_audio-BipBop Audio 2",
695 "format_index": None,
696 "url": "https://devstreaming-cdn.apple.com/videos/streaming/examples/bipbop_16x9/alternate_audio_aac/prog_index.m3u8",
697 "manifest_url": "https://devstreaming-cdn.apple.com/videos/streaming/examples/bipbop_16x9/bipbop_16x9_variant.m3u8",
698 "language": "eng",
699 "ext": "mp4",
700 "protocol": "m3u8",
701 "preference": None,
702 "quality": None,
703 "vcodec": "none",
704 "audio_ext": "mp4",
705 "video_ext": "none",
706 }, {
707 "format_id": "41",
708 "format_index": None,
709 "url": "https://devstreaming-cdn.apple.com/videos/streaming/examples/bipbop_16x9/gear0/prog_index.m3u8",
710 "manifest_url": "https://devstreaming-cdn.apple.com/videos/streaming/examples/bipbop_16x9/bipbop_16x9_variant.m3u8",
711 "tbr": 41.457,
712 "ext": "mp4",
713 "fps": None,
714 "protocol": "m3u8",
715 "preference": None,
716 "quality": None,
717 "vcodec": "none",
718 "acodec": "mp4a.40.2",
719 "audio_ext": "mp4",
720 "video_ext": "none",
721 "abr": 41.457,
722 }, {
723 "format_id": "263",
724 "format_index": None,
725 "url": "https://devstreaming-cdn.apple.com/videos/streaming/examples/bipbop_16x9/gear1/prog_index.m3u8",
726 "manifest_url": "https://devstreaming-cdn.apple.com/videos/streaming/examples/bipbop_16x9/bipbop_16x9_variant.m3u8",
727 "tbr": 263.851,
728 "ext": "mp4",
729 "fps": None,
730 "protocol": "m3u8",
731 "preference": None,
732 "quality": None,
733 "width": 416,
734 "height": 234,
735 "vcodec": "avc1.4d400d",
736 "acodec": "mp4a.40.2",
737 "video_ext": "mp4",
738 "audio_ext": "none",
739 "vbr": 263.851,
740 "abr": 0,
741 }, {
742 "format_id": "577",
743 "format_index": None,
744 "url": "https://devstreaming-cdn.apple.com/videos/streaming/examples/bipbop_16x9/gear2/prog_index.m3u8",
745 "manifest_url": "https://devstreaming-cdn.apple.com/videos/streaming/examples/bipbop_16x9/bipbop_16x9_variant.m3u8",
746 "tbr": 577.61,
747 "ext": "mp4",
748 "fps": None,
749 "protocol": "m3u8",
750 "preference": None,
751 "quality": None,
752 "width": 640,
753 "height": 360,
754 "vcodec": "avc1.4d401e",
755 "acodec": "mp4a.40.2",
756 "video_ext": "mp4",
757 "audio_ext": "none",
758 "vbr": 577.61,
759 "abr": 0,
760 }, {
761 "format_id": "915",
762 "format_index": None,
763 "url": "https://devstreaming-cdn.apple.com/videos/streaming/examples/bipbop_16x9/gear3/prog_index.m3u8",
764 "manifest_url": "https://devstreaming-cdn.apple.com/videos/streaming/examples/bipbop_16x9/bipbop_16x9_variant.m3u8",
765 "tbr": 915.905,
766 "ext": "mp4",
767 "fps": None,
768 "protocol": "m3u8",
769 "preference": None,
770 "quality": None,
771 "width": 960,
772 "height": 540,
773 "vcodec": "avc1.4d401f",
774 "acodec": "mp4a.40.2",
775 "video_ext": "mp4",
776 "audio_ext": "none",
777 "vbr": 915.905,
778 "abr": 0,
779 }, {
780 "format_id": "1030",
781 "format_index": None,
782 "url": "https://devstreaming-cdn.apple.com/videos/streaming/examples/bipbop_16x9/gear4/prog_index.m3u8",
783 "manifest_url": "https://devstreaming-cdn.apple.com/videos/streaming/examples/bipbop_16x9/bipbop_16x9_variant.m3u8",
784 "tbr": 1030.138,
785 "ext": "mp4",
786 "fps": None,
787 "protocol": "m3u8",
788 "preference": None,
789 "quality": None,
790 "width": 1280,
791 "height": 720,
792 "vcodec": "avc1.4d401f",
793 "acodec": "mp4a.40.2",
794 "video_ext": "mp4",
795 "audio_ext": "none",
796 "vbr": 1030.138,
797 "abr": 0,
798 }, {
799 "format_id": "1924",
800 "format_index": None,
801 "url": "https://devstreaming-cdn.apple.com/videos/streaming/examples/bipbop_16x9/gear5/prog_index.m3u8",
802 "manifest_url": "https://devstreaming-cdn.apple.com/videos/streaming/examples/bipbop_16x9/bipbop_16x9_variant.m3u8",
803 "tbr": 1924.009,
804 "ext": "mp4",
805 "fps": None,
806 "protocol": "m3u8",
807 "preference": None,
808 "quality": None,
809 "width": 1920,
810 "height": 1080,
811 "vcodec": "avc1.4d401f",
812 "acodec": "mp4a.40.2",
813 "video_ext": "mp4",
814 "audio_ext": "none",
815 "vbr": 1924.009,
816 "abr": 0,
817 }],
818 {
819 "en": [{
820 "url": "https://devstreaming-cdn.apple.com/videos/streaming/examples/bipbop_16x9/subtitles/eng/prog_index.m3u8",
821 "ext": "vtt",
822 "protocol": "m3u8_native"
823 }, {
824 "url": "https://devstreaming-cdn.apple.com/videos/streaming/examples/bipbop_16x9/subtitles/eng_forced/prog_index.m3u8",
825 "ext": "vtt",
826 "protocol": "m3u8_native"
827 }],
828 "fr": [{
829 "url": "https://devstreaming-cdn.apple.com/videos/streaming/examples/bipbop_16x9/subtitles/fra/prog_index.m3u8",
830 "ext": "vtt",
831 "protocol": "m3u8_native"
832 }, {
833 "url": "https://devstreaming-cdn.apple.com/videos/streaming/examples/bipbop_16x9/subtitles/fra_forced/prog_index.m3u8",
834 "ext": "vtt",
835 "protocol": "m3u8_native"
836 }],
837 "es": [{
838 "url": "https://devstreaming-cdn.apple.com/videos/streaming/examples/bipbop_16x9/subtitles/spa/prog_index.m3u8",
839 "ext": "vtt",
840 "protocol": "m3u8_native"
841 }, {
842 "url": "https://devstreaming-cdn.apple.com/videos/streaming/examples/bipbop_16x9/subtitles/spa_forced/prog_index.m3u8",
843 "ext": "vtt",
844 "protocol": "m3u8_native"
845 }],
846 "ja": [{
847 "url": "https://devstreaming-cdn.apple.com/videos/streaming/examples/bipbop_16x9/subtitles/jpn/prog_index.m3u8",
848 "ext": "vtt",
849 "protocol": "m3u8_native"
850 }, {
851 "url": "https://devstreaming-cdn.apple.com/videos/streaming/examples/bipbop_16x9/subtitles/jpn_forced/prog_index.m3u8",
852 "ext": "vtt",
853 "protocol": "m3u8_native"
854 }],
855 }
856 ),
857 ]
858
859 for m3u8_file, m3u8_url, expected_formats, expected_subs in _TEST_CASES:
860 with io.open('./test/testdata/m3u8/%s.m3u8' % m3u8_file,
861 mode='r', encoding='utf-8') as f:
862 formats, subs = self.ie._parse_m3u8_formats_and_subtitles(
863 f.read(), m3u8_url, ext='mp4')
864 self.ie._sort_formats(formats)
865 expect_value(self, formats, expected_formats, None)
866 expect_value(self, subs, expected_subs, None)
867
868 def test_parse_mpd_formats(self):
869 _TEST_CASES = [
870 (
871 # https://github.com/ytdl-org/youtube-dl/issues/13919
872 # Also tests duplicate representation ids, see
873 # https://github.com/ytdl-org/youtube-dl/issues/15111
874 'float_duration',
875 'http://unknown/manifest.mpd', # mpd_url
876 None, # mpd_base_url
877 [{
878 'manifest_url': 'http://unknown/manifest.mpd',
879 'ext': 'm4a',
880 'format_id': '318597',
881 'format_note': 'DASH audio',
882 'protocol': 'http_dash_segments',
883 'acodec': 'mp4a.40.2',
884 'vcodec': 'none',
885 'tbr': 61.587,
886 }, {
887 'manifest_url': 'http://unknown/manifest.mpd',
888 'ext': 'mp4',
889 'format_id': '318597',
890 'format_note': 'DASH video',
891 'protocol': 'http_dash_segments',
892 'acodec': 'none',
893 'vcodec': 'avc1.42001f',
894 'tbr': 318.597,
895 'width': 340,
896 'height': 192,
897 }, {
898 'manifest_url': 'http://unknown/manifest.mpd',
899 'ext': 'mp4',
900 'format_id': '638590',
901 'format_note': 'DASH video',
902 'protocol': 'http_dash_segments',
903 'acodec': 'none',
904 'vcodec': 'avc1.42001f',
905 'tbr': 638.59,
906 'width': 512,
907 'height': 288,
908 }, {
909 'manifest_url': 'http://unknown/manifest.mpd',
910 'ext': 'mp4',
911 'format_id': '1022565',
912 'format_note': 'DASH video',
913 'protocol': 'http_dash_segments',
914 'acodec': 'none',
915 'vcodec': 'avc1.4d001f',
916 'tbr': 1022.565,
917 'width': 688,
918 'height': 384,
919 }, {
920 'manifest_url': 'http://unknown/manifest.mpd',
921 'ext': 'mp4',
922 'format_id': '2046506',
923 'format_note': 'DASH video',
924 'protocol': 'http_dash_segments',
925 'acodec': 'none',
926 'vcodec': 'avc1.4d001f',
927 'tbr': 2046.506,
928 'width': 1024,
929 'height': 576,
930 }, {
931 'manifest_url': 'http://unknown/manifest.mpd',
932 'ext': 'mp4',
933 'format_id': '3998017',
934 'format_note': 'DASH video',
935 'protocol': 'http_dash_segments',
936 'acodec': 'none',
937 'vcodec': 'avc1.640029',
938 'tbr': 3998.017,
939 'width': 1280,
940 'height': 720,
941 }, {
942 'manifest_url': 'http://unknown/manifest.mpd',
943 'ext': 'mp4',
944 'format_id': '5997485',
945 'format_note': 'DASH video',
946 'protocol': 'http_dash_segments',
947 'acodec': 'none',
948 'vcodec': 'avc1.640032',
949 'tbr': 5997.485,
950 'width': 1920,
951 'height': 1080,
952 }],
953 {},
954 ), (
955 # https://github.com/ytdl-org/youtube-dl/pull/14844
956 'urls_only',
957 'http://unknown/manifest.mpd', # mpd_url
958 None, # mpd_base_url
959 [{
960 'manifest_url': 'http://unknown/manifest.mpd',
961 'ext': 'mp4',
962 'format_id': 'h264_aac_144p_m4s',
963 'format_note': 'DASH video',
964 'protocol': 'http_dash_segments',
965 'acodec': 'mp4a.40.2',
966 'vcodec': 'avc3.42c01e',
967 'tbr': 200,
968 'width': 256,
969 'height': 144,
970 }, {
971 'manifest_url': 'http://unknown/manifest.mpd',
972 'ext': 'mp4',
973 'format_id': 'h264_aac_240p_m4s',
974 'format_note': 'DASH video',
975 'protocol': 'http_dash_segments',
976 'acodec': 'mp4a.40.2',
977 'vcodec': 'avc3.42c01e',
978 'tbr': 400,
979 'width': 424,
980 'height': 240,
981 }, {
982 'manifest_url': 'http://unknown/manifest.mpd',
983 'ext': 'mp4',
984 'format_id': 'h264_aac_360p_m4s',
985 'format_note': 'DASH video',
986 'protocol': 'http_dash_segments',
987 'acodec': 'mp4a.40.2',
988 'vcodec': 'avc3.42c01e',
989 'tbr': 800,
990 'width': 640,
991 'height': 360,
992 }, {
993 'manifest_url': 'http://unknown/manifest.mpd',
994 'ext': 'mp4',
995 'format_id': 'h264_aac_480p_m4s',
996 'format_note': 'DASH video',
997 'protocol': 'http_dash_segments',
998 'acodec': 'mp4a.40.2',
999 'vcodec': 'avc3.42c01e',
1000 'tbr': 1200,
1001 'width': 856,
1002 'height': 480,
1003 }, {
1004 'manifest_url': 'http://unknown/manifest.mpd',
1005 'ext': 'mp4',
1006 'format_id': 'h264_aac_576p_m4s',
1007 'format_note': 'DASH video',
1008 'protocol': 'http_dash_segments',
1009 'acodec': 'mp4a.40.2',
1010 'vcodec': 'avc3.42c01e',
1011 'tbr': 1600,
1012 'width': 1024,
1013 'height': 576,
1014 }, {
1015 'manifest_url': 'http://unknown/manifest.mpd',
1016 'ext': 'mp4',
1017 'format_id': 'h264_aac_720p_m4s',
1018 'format_note': 'DASH video',
1019 'protocol': 'http_dash_segments',
1020 'acodec': 'mp4a.40.2',
1021 'vcodec': 'avc3.42c01e',
1022 'tbr': 2400,
1023 'width': 1280,
1024 'height': 720,
1025 }, {
1026 'manifest_url': 'http://unknown/manifest.mpd',
1027 'ext': 'mp4',
1028 'format_id': 'h264_aac_1080p_m4s',
1029 'format_note': 'DASH video',
1030 'protocol': 'http_dash_segments',
1031 'acodec': 'mp4a.40.2',
1032 'vcodec': 'avc3.42c01e',
1033 'tbr': 4400,
1034 'width': 1920,
1035 'height': 1080,
1036 }],
1037 {},
1038 ), (
1039 # https://github.com/ytdl-org/youtube-dl/issues/20346
1040 # Media considered unfragmented even though it contains
1041 # Initialization tag
1042 'unfragmented',
1043 'https://v.redd.it/hw1x7rcg7zl21/DASHPlaylist.mpd', # mpd_url
1044 'https://v.redd.it/hw1x7rcg7zl21', # mpd_base_url
1045 [{
1046 'url': 'https://v.redd.it/hw1x7rcg7zl21/audio',
1047 'manifest_url': 'https://v.redd.it/hw1x7rcg7zl21/DASHPlaylist.mpd',
1048 'ext': 'm4a',
1049 'format_id': 'AUDIO-1',
1050 'format_note': 'DASH audio',
1051 'container': 'm4a_dash',
1052 'acodec': 'mp4a.40.2',
1053 'vcodec': 'none',
1054 'tbr': 129.87,
1055 'asr': 48000,
1056
1057 }, {
1058 'url': 'https://v.redd.it/hw1x7rcg7zl21/DASH_240',
1059 'manifest_url': 'https://v.redd.it/hw1x7rcg7zl21/DASHPlaylist.mpd',
1060 'ext': 'mp4',
1061 'format_id': 'VIDEO-2',
1062 'format_note': 'DASH video',
1063 'container': 'mp4_dash',
1064 'acodec': 'none',
1065 'vcodec': 'avc1.4d401e',
1066 'tbr': 608.0,
1067 'width': 240,
1068 'height': 240,
1069 'fps': 30,
1070 }, {
1071 'url': 'https://v.redd.it/hw1x7rcg7zl21/DASH_360',
1072 'manifest_url': 'https://v.redd.it/hw1x7rcg7zl21/DASHPlaylist.mpd',
1073 'ext': 'mp4',
1074 'format_id': 'VIDEO-1',
1075 'format_note': 'DASH video',
1076 'container': 'mp4_dash',
1077 'acodec': 'none',
1078 'vcodec': 'avc1.4d401e',
1079 'tbr': 804.261,
1080 'width': 360,
1081 'height': 360,
1082 'fps': 30,
1083 }],
1084 {},
1085 ), (
1086 'subtitles',
1087 'https://sdn-global-streaming-cache-3qsdn.akamaized.net/stream/3144/files/17/07/672975/3144-kZT4LWMQw6Rh7Kpd.ism/manifest.mpd',
1088 'https://sdn-global-streaming-cache-3qsdn.akamaized.net/stream/3144/files/17/07/672975/3144-kZT4LWMQw6Rh7Kpd.ism/',
1089 [{
1090 "format_id": "audio=128001",
1091 "manifest_url": "https://sdn-global-streaming-cache-3qsdn.akamaized.net/stream/3144/files/17/07/672975/3144-kZT4LWMQw6Rh7Kpd.ism/manifest.mpd",
1092 "ext": "m4a",
1093 "tbr": 128.001,
1094 "asr": 48000,
1095 "format_note": "DASH audio",
1096 "container": "m4a_dash",
1097 "vcodec": "none",
1098 "acodec": "mp4a.40.2",
1099 "url": "https://sdn-global-streaming-cache-3qsdn.akamaized.net/stream/3144/files/17/07/672975/3144-kZT4LWMQw6Rh7Kpd.ism/manifest.mpd",
1100 "fragment_base_url": "https://sdn-global-streaming-cache-3qsdn.akamaized.net/stream/3144/files/17/07/672975/3144-kZT4LWMQw6Rh7Kpd.ism/dash/",
1101 "protocol": "http_dash_segments",
1102 "audio_ext": "m4a",
1103 "video_ext": "none",
1104 "abr": 128.001,
1105 }, {
1106 "format_id": "video=100000",
1107 "manifest_url": "https://sdn-global-streaming-cache-3qsdn.akamaized.net/stream/3144/files/17/07/672975/3144-kZT4LWMQw6Rh7Kpd.ism/manifest.mpd",
1108 "ext": "mp4",
1109 "width": 336,
1110 "height": 144,
1111 "tbr": 100,
1112 "format_note": "DASH video",
1113 "container": "mp4_dash",
1114 "vcodec": "avc1.4D401F",
1115 "acodec": "none",
1116 "url": "https://sdn-global-streaming-cache-3qsdn.akamaized.net/stream/3144/files/17/07/672975/3144-kZT4LWMQw6Rh7Kpd.ism/manifest.mpd",
1117 "fragment_base_url": "https://sdn-global-streaming-cache-3qsdn.akamaized.net/stream/3144/files/17/07/672975/3144-kZT4LWMQw6Rh7Kpd.ism/dash/",
1118 "protocol": "http_dash_segments",
1119 "video_ext": "mp4",
1120 "audio_ext": "none",
1121 "vbr": 100,
1122 }, {
1123 "format_id": "video=326000",
1124 "manifest_url": "https://sdn-global-streaming-cache-3qsdn.akamaized.net/stream/3144/files/17/07/672975/3144-kZT4LWMQw6Rh7Kpd.ism/manifest.mpd",
1125 "ext": "mp4",
1126 "width": 562,
1127 "height": 240,
1128 "tbr": 326,
1129 "format_note": "DASH video",
1130 "container": "mp4_dash",
1131 "vcodec": "avc1.4D401F",
1132 "acodec": "none",
1133 "url": "https://sdn-global-streaming-cache-3qsdn.akamaized.net/stream/3144/files/17/07/672975/3144-kZT4LWMQw6Rh7Kpd.ism/manifest.mpd",
1134 "fragment_base_url": "https://sdn-global-streaming-cache-3qsdn.akamaized.net/stream/3144/files/17/07/672975/3144-kZT4LWMQw6Rh7Kpd.ism/dash/",
1135 "protocol": "http_dash_segments",
1136 "video_ext": "mp4",
1137 "audio_ext": "none",
1138 "vbr": 326,
1139 }, {
1140 "format_id": "video=698000",
1141 "manifest_url": "https://sdn-global-streaming-cache-3qsdn.akamaized.net/stream/3144/files/17/07/672975/3144-kZT4LWMQw6Rh7Kpd.ism/manifest.mpd",
1142 "ext": "mp4",
1143 "width": 844,
1144 "height": 360,
1145 "tbr": 698,
1146 "format_note": "DASH video",
1147 "container": "mp4_dash",
1148 "vcodec": "avc1.4D401F",
1149 "acodec": "none",
1150 "url": "https://sdn-global-streaming-cache-3qsdn.akamaized.net/stream/3144/files/17/07/672975/3144-kZT4LWMQw6Rh7Kpd.ism/manifest.mpd",
1151 "fragment_base_url": "https://sdn-global-streaming-cache-3qsdn.akamaized.net/stream/3144/files/17/07/672975/3144-kZT4LWMQw6Rh7Kpd.ism/dash/",
1152 "protocol": "http_dash_segments",
1153 "video_ext": "mp4",
1154 "audio_ext": "none",
1155 "vbr": 698,
1156 }, {
1157 "format_id": "video=1493000",
1158 "manifest_url": "https://sdn-global-streaming-cache-3qsdn.akamaized.net/stream/3144/files/17/07/672975/3144-kZT4LWMQw6Rh7Kpd.ism/manifest.mpd",
1159 "ext": "mp4",
1160 "width": 1126,
1161 "height": 480,
1162 "tbr": 1493,
1163 "format_note": "DASH video",
1164 "container": "mp4_dash",
1165 "vcodec": "avc1.4D401F",
1166 "acodec": "none",
1167 "url": "https://sdn-global-streaming-cache-3qsdn.akamaized.net/stream/3144/files/17/07/672975/3144-kZT4LWMQw6Rh7Kpd.ism/manifest.mpd",
1168 "fragment_base_url": "https://sdn-global-streaming-cache-3qsdn.akamaized.net/stream/3144/files/17/07/672975/3144-kZT4LWMQw6Rh7Kpd.ism/dash/",
1169 "protocol": "http_dash_segments",
1170 "video_ext": "mp4",
1171 "audio_ext": "none",
1172 "vbr": 1493,
1173 }, {
1174 "format_id": "video=4482000",
1175 "manifest_url": "https://sdn-global-streaming-cache-3qsdn.akamaized.net/stream/3144/files/17/07/672975/3144-kZT4LWMQw6Rh7Kpd.ism/manifest.mpd",
1176 "ext": "mp4",
1177 "width": 1688,
1178 "height": 720,
1179 "tbr": 4482,
1180 "format_note": "DASH video",
1181 "container": "mp4_dash",
1182 "vcodec": "avc1.4D401F",
1183 "acodec": "none",
1184 "url": "https://sdn-global-streaming-cache-3qsdn.akamaized.net/stream/3144/files/17/07/672975/3144-kZT4LWMQw6Rh7Kpd.ism/manifest.mpd",
1185 "fragment_base_url": "https://sdn-global-streaming-cache-3qsdn.akamaized.net/stream/3144/files/17/07/672975/3144-kZT4LWMQw6Rh7Kpd.ism/dash/",
1186 "protocol": "http_dash_segments",
1187 "video_ext": "mp4",
1188 "audio_ext": "none",
1189 "vbr": 4482,
1190 }],
1191 {
1192 "en": [
1193 {
1194 "ext": "mp4",
1195 "manifest_url": "https://sdn-global-streaming-cache-3qsdn.akamaized.net/stream/3144/files/17/07/672975/3144-kZT4LWMQw6Rh7Kpd.ism/manifest.mpd",
1196 "url": "https://sdn-global-streaming-cache-3qsdn.akamaized.net/stream/3144/files/17/07/672975/3144-kZT4LWMQw6Rh7Kpd.ism/manifest.mpd",
1197 "fragment_base_url": "https://sdn-global-streaming-cache-3qsdn.akamaized.net/stream/3144/files/17/07/672975/3144-kZT4LWMQw6Rh7Kpd.ism/dash/",
1198 "protocol": "http_dash_segments",
1199 }
1200 ]
1201 },
1202 )
1203 ]
1204
1205 for mpd_file, mpd_url, mpd_base_url, expected_formats, expected_subtitles in _TEST_CASES:
1206 with io.open('./test/testdata/mpd/%s.mpd' % mpd_file,
1207 mode='r', encoding='utf-8') as f:
1208 formats, subtitles = self.ie._parse_mpd_formats_and_subtitles(
1209 compat_etree_fromstring(f.read().encode('utf-8')),
1210 mpd_base_url=mpd_base_url, mpd_url=mpd_url)
1211 self.ie._sort_formats(formats)
1212 expect_value(self, formats, expected_formats, None)
1213 expect_value(self, subtitles, expected_subtitles, None)
1214
1215 def test_parse_ism_formats(self):
1216 _TEST_CASES = [
1217 (
1218 'sintel',
1219 'https://sdn-global-streaming-cache-3qsdn.akamaized.net/stream/3144/files/17/07/672975/3144-kZT4LWMQw6Rh7Kpd.ism/Manifest',
1220 [{
1221 "format_id": "audio-128",
1222 "url": "https://sdn-global-streaming-cache-3qsdn.akamaized.net/stream/3144/files/17/07/672975/3144-kZT4LWMQw6Rh7Kpd.ism/Manifest",
1223 "manifest_url": "https://sdn-global-streaming-cache-3qsdn.akamaized.net/stream/3144/files/17/07/672975/3144-kZT4LWMQw6Rh7Kpd.ism/Manifest",
1224 "ext": "isma",
1225 "tbr": 128,
1226 "asr": 48000,
1227 "vcodec": "none",
1228 "acodec": "AACL",
1229 "protocol": "ism",
1230 "_download_params": {
1231 "stream_type": "audio",
1232 "duration": 8880746666,
1233 "timescale": 10000000,
1234 "width": 0,
1235 "height": 0,
1236 "fourcc": "AACL",
1237 "codec_private_data": "1190",
1238 "sampling_rate": 48000,
1239 "channels": 2,
1240 "bits_per_sample": 16,
1241 "nal_unit_length_field": 4
1242 },
1243 "audio_ext": "isma",
1244 "video_ext": "none",
1245 "abr": 128,
1246 }, {
1247 "format_id": "video-100",
1248 "url": "https://sdn-global-streaming-cache-3qsdn.akamaized.net/stream/3144/files/17/07/672975/3144-kZT4LWMQw6Rh7Kpd.ism/Manifest",
1249 "manifest_url": "https://sdn-global-streaming-cache-3qsdn.akamaized.net/stream/3144/files/17/07/672975/3144-kZT4LWMQw6Rh7Kpd.ism/Manifest",
1250 "ext": "ismv",
1251 "width": 336,
1252 "height": 144,
1253 "tbr": 100,
1254 "vcodec": "AVC1",
1255 "acodec": "none",
1256 "protocol": "ism",
1257 "_download_params": {
1258 "stream_type": "video",
1259 "duration": 8880746666,
1260 "timescale": 10000000,
1261 "width": 336,
1262 "height": 144,
1263 "fourcc": "AVC1",
1264 "codec_private_data": "00000001674D401FDA0544EFFC2D002CBC40000003004000000C03C60CA80000000168EF32C8",
1265 "channels": 2,
1266 "bits_per_sample": 16,
1267 "nal_unit_length_field": 4
1268 },
1269 "video_ext": "ismv",
1270 "audio_ext": "none",
1271 "vbr": 100,
1272 }, {
1273 "format_id": "video-326",
1274 "url": "https://sdn-global-streaming-cache-3qsdn.akamaized.net/stream/3144/files/17/07/672975/3144-kZT4LWMQw6Rh7Kpd.ism/Manifest",
1275 "manifest_url": "https://sdn-global-streaming-cache-3qsdn.akamaized.net/stream/3144/files/17/07/672975/3144-kZT4LWMQw6Rh7Kpd.ism/Manifest",
1276 "ext": "ismv",
1277 "width": 562,
1278 "height": 240,
1279 "tbr": 326,
1280 "vcodec": "AVC1",
1281 "acodec": "none",
1282 "protocol": "ism",
1283 "_download_params": {
1284 "stream_type": "video",
1285 "duration": 8880746666,
1286 "timescale": 10000000,
1287 "width": 562,
1288 "height": 240,
1289 "fourcc": "AVC1",
1290 "codec_private_data": "00000001674D401FDA0241FE23FFC3BC83BA44000003000400000300C03C60CA800000000168EF32C8",
1291 "channels": 2,
1292 "bits_per_sample": 16,
1293 "nal_unit_length_field": 4
1294 },
1295 "video_ext": "ismv",
1296 "audio_ext": "none",
1297 "vbr": 326,
1298 }, {
1299 "format_id": "video-698",
1300 "url": "https://sdn-global-streaming-cache-3qsdn.akamaized.net/stream/3144/files/17/07/672975/3144-kZT4LWMQw6Rh7Kpd.ism/Manifest",
1301 "manifest_url": "https://sdn-global-streaming-cache-3qsdn.akamaized.net/stream/3144/files/17/07/672975/3144-kZT4LWMQw6Rh7Kpd.ism/Manifest",
1302 "ext": "ismv",
1303 "width": 844,
1304 "height": 360,
1305 "tbr": 698,
1306 "vcodec": "AVC1",
1307 "acodec": "none",
1308 "protocol": "ism",
1309 "_download_params": {
1310 "stream_type": "video",
1311 "duration": 8880746666,
1312 "timescale": 10000000,
1313 "width": 844,
1314 "height": 360,
1315 "fourcc": "AVC1",
1316 "codec_private_data": "00000001674D401FDA0350BFB97FF06AF06AD1000003000100000300300F1832A00000000168EF32C8",
1317 "channels": 2,
1318 "bits_per_sample": 16,
1319 "nal_unit_length_field": 4
1320 },
1321 "video_ext": "ismv",
1322 "audio_ext": "none",
1323 "vbr": 698,
1324 }, {
1325 "format_id": "video-1493",
1326 "url": "https://sdn-global-streaming-cache-3qsdn.akamaized.net/stream/3144/files/17/07/672975/3144-kZT4LWMQw6Rh7Kpd.ism/Manifest",
1327 "manifest_url": "https://sdn-global-streaming-cache-3qsdn.akamaized.net/stream/3144/files/17/07/672975/3144-kZT4LWMQw6Rh7Kpd.ism/Manifest",
1328 "ext": "ismv",
1329 "width": 1126,
1330 "height": 480,
1331 "tbr": 1493,
1332 "vcodec": "AVC1",
1333 "acodec": "none",
1334 "protocol": "ism",
1335 "_download_params": {
1336 "stream_type": "video",
1337 "duration": 8880746666,
1338 "timescale": 10000000,
1339 "width": 1126,
1340 "height": 480,
1341 "fourcc": "AVC1",
1342 "codec_private_data": "00000001674D401FDA011C3DE6FFF0D890D871000003000100000300300F1832A00000000168EF32C8",
1343 "channels": 2,
1344 "bits_per_sample": 16,
1345 "nal_unit_length_field": 4
1346 },
1347 "video_ext": "ismv",
1348 "audio_ext": "none",
1349 "vbr": 1493,
1350 }, {
1351 "format_id": "video-4482",
1352 "url": "https://sdn-global-streaming-cache-3qsdn.akamaized.net/stream/3144/files/17/07/672975/3144-kZT4LWMQw6Rh7Kpd.ism/Manifest",
1353 "manifest_url": "https://sdn-global-streaming-cache-3qsdn.akamaized.net/stream/3144/files/17/07/672975/3144-kZT4LWMQw6Rh7Kpd.ism/Manifest",
1354 "ext": "ismv",
1355 "width": 1688,
1356 "height": 720,
1357 "tbr": 4482,
1358 "vcodec": "AVC1",
1359 "acodec": "none",
1360 "protocol": "ism",
1361 "_download_params": {
1362 "stream_type": "video",
1363 "duration": 8880746666,
1364 "timescale": 10000000,
1365 "width": 1688,
1366 "height": 720,
1367 "fourcc": "AVC1",
1368 "codec_private_data": "00000001674D401FDA01A816F97FFC1ABC1AB440000003004000000C03C60CA80000000168EF32C8",
1369 "channels": 2,
1370 "bits_per_sample": 16,
1371 "nal_unit_length_field": 4
1372 },
1373 "video_ext": "ismv",
1374 "audio_ext": "none",
1375 "vbr": 4482,
1376 }],
1377 {
1378 "eng": [
1379 {
1380 "ext": "ismt",
1381 "protocol": "ism",
1382 "url": "https://sdn-global-streaming-cache-3qsdn.akamaized.net/stream/3144/files/17/07/672975/3144-kZT4LWMQw6Rh7Kpd.ism/Manifest",
1383 "manifest_url": "https://sdn-global-streaming-cache-3qsdn.akamaized.net/stream/3144/files/17/07/672975/3144-kZT4LWMQw6Rh7Kpd.ism/Manifest",
1384 "_download_params": {
1385 "stream_type": "text",
1386 "duration": 8880746666,
1387 "timescale": 10000000,
1388 "fourcc": "TTML",
1389 "codec_private_data": ""
1390 }
1391 }
1392 ]
1393 },
1394 ),
1395 ]
1396
1397 for ism_file, ism_url, expected_formats, expected_subtitles in _TEST_CASES:
1398 with io.open('./test/testdata/ism/%s.Manifest' % ism_file,
1399 mode='r', encoding='utf-8') as f:
1400 formats, subtitles = self.ie._parse_ism_formats_and_subtitles(
1401 compat_etree_fromstring(f.read().encode('utf-8')), ism_url=ism_url)
1402 self.ie._sort_formats(formats)
1403 expect_value(self, formats, expected_formats, None)
1404 expect_value(self, subtitles, expected_subtitles, None)
1405
1406 def test_parse_f4m_formats(self):
1407 _TEST_CASES = [
1408 (
1409 # https://github.com/ytdl-org/youtube-dl/issues/14660
1410 'custom_base_url',
1411 'http://api.new.livestream.com/accounts/6115179/events/6764928/videos/144884262.f4m',
1412 [{
1413 'manifest_url': 'http://api.new.livestream.com/accounts/6115179/events/6764928/videos/144884262.f4m',
1414 'ext': 'flv',
1415 'format_id': '2148',
1416 'protocol': 'f4m',
1417 'tbr': 2148,
1418 'width': 1280,
1419 'height': 720,
1420 }]
1421 ),
1422 ]
1423
1424 for f4m_file, f4m_url, expected_formats in _TEST_CASES:
1425 with io.open('./test/testdata/f4m/%s.f4m' % f4m_file,
1426 mode='r', encoding='utf-8') as f:
1427 formats = self.ie._parse_f4m_formats(
1428 compat_etree_fromstring(f.read().encode('utf-8')),
1429 f4m_url, None)
1430 self.ie._sort_formats(formats)
1431 expect_value(self, formats, expected_formats, None)
1432
1433 def test_parse_xspf(self):
1434 _TEST_CASES = [
1435 (
1436 'foo_xspf',
1437 'https://example.org/src/foo_xspf.xspf',
1438 [{
1439 'id': 'foo_xspf',
1440 'title': 'Pandemonium',
1441 'description': 'Visit http://bigbrother404.bandcamp.com',
1442 'duration': 202.416,
1443 'formats': [{
1444 'manifest_url': 'https://example.org/src/foo_xspf.xspf',
1445 'url': 'https://example.org/src/cd1/track%201.mp3',
1446 }],
1447 }, {
1448 'id': 'foo_xspf',
1449 'title': 'Final Cartridge (Nichico Twelve Remix)',
1450 'description': 'Visit http://bigbrother404.bandcamp.com',
1451 'duration': 255.857,
1452 'formats': [{
1453 'manifest_url': 'https://example.org/src/foo_xspf.xspf',
1454 'url': 'https://example.org/%E3%83%88%E3%83%A9%E3%83%83%E3%82%AF%E3%80%80%EF%BC%92.mp3',
1455 }],
1456 }, {
1457 'id': 'foo_xspf',
1458 'title': 'Rebuilding Nightingale',
1459 'description': 'Visit http://bigbrother404.bandcamp.com',
1460 'duration': 287.915,
1461 'formats': [{
1462 'manifest_url': 'https://example.org/src/foo_xspf.xspf',
1463 'url': 'https://example.org/src/track3.mp3',
1464 }, {
1465 'manifest_url': 'https://example.org/src/foo_xspf.xspf',
1466 'url': 'https://example.com/track3.mp3',
1467 }]
1468 }]
1469 ),
1470 ]
1471
1472 for xspf_file, xspf_url, expected_entries in _TEST_CASES:
1473 with io.open('./test/testdata/xspf/%s.xspf' % xspf_file,
1474 mode='r', encoding='utf-8') as f:
1475 entries = self.ie._parse_xspf(
1476 compat_etree_fromstring(f.read().encode('utf-8')),
1477 xspf_file, xspf_url=xspf_url, xspf_base_url=xspf_url)
1478 expect_value(self, entries, expected_entries, None)
1479 for i in range(len(entries)):
1480 expect_dict(self, entries[i], expected_entries[i])
1481
1482 def test_response_with_expected_status_returns_content(self):
1483 # Checks for mitigations against the effects of
1484 # <https://bugs.python.org/issue15002> that affect Python 3.4.1+, which
1485 # manifest as `_download_webpage`, `_download_xml`, `_download_json`,
1486 # or the underlying `_download_webpage_handle` returning no content
1487 # when a response matches `expected_status`.
1488
1489 httpd = compat_http_server.HTTPServer(
1490 ('127.0.0.1', 0), InfoExtractorTestRequestHandler)
1491 port = http_server_port(httpd)
1492 server_thread = threading.Thread(target=httpd.serve_forever)
1493 server_thread.daemon = True
1494 server_thread.start()
1495
1496 (content, urlh) = self.ie._download_webpage_handle(
1497 'http://127.0.0.1:%d/teapot' % port, None,
1498 expected_status=TEAPOT_RESPONSE_STATUS)
1499 self.assertEqual(content, TEAPOT_RESPONSE_BODY)
1500
1501
1502 if __name__ == '__main__':
1503 unittest.main()