Release 2024.11.18
[yt-dlp3.git] / test / test_InfoExtractor.py
blob54f35ef552219cbfe54e2a472693bb95d3fd68cf
1 #!/usr/bin/env python3
3 # Allow direct execution
4 import os
5 import sys
6 import unittest
8 sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
11 import http.server
12 import threading
14 from test.helper import FakeYDL, expect_dict, expect_value, http_server_port
15 from yt_dlp.compat import compat_etree_fromstring
16 from yt_dlp.extractor import YoutubeIE, get_info_extractor
17 from yt_dlp.extractor.common import InfoExtractor
18 from yt_dlp.utils import (
19 ExtractorError,
20 RegexNotFoundError,
21 encode_data_uri,
22 strip_jsonp,
25 TEAPOT_RESPONSE_STATUS = 418
26 TEAPOT_RESPONSE_BODY = "<h1>418 I'm a teapot</h1>"
29 class InfoExtractorTestRequestHandler(http.server.BaseHTTPRequestHandler):
30 def log_message(self, format, *args):
31 pass
33 def do_GET(self):
34 if self.path == '/teapot':
35 self.send_response(TEAPOT_RESPONSE_STATUS)
36 self.send_header('Content-Type', 'text/html; charset=utf-8')
37 self.end_headers()
38 self.wfile.write(TEAPOT_RESPONSE_BODY.encode())
39 else:
40 assert False
43 class DummyIE(InfoExtractor):
44 def _sort_formats(self, formats, field_preference=[]):
45 self._downloader.sort_formats(
46 {'formats': formats, '_format_sort_fields': field_preference})
49 class TestInfoExtractor(unittest.TestCase):
50 def setUp(self):
51 self.ie = DummyIE(FakeYDL())
53 def test_ie_key(self):
54 self.assertEqual(get_info_extractor(YoutubeIE.ie_key()), YoutubeIE)
56 def test_get_netrc_login_info(self):
57 for params in [
58 {'usenetrc': True, 'netrc_location': './test/testdata/netrc/netrc'},
59 {'netrc_cmd': f'{sys.executable} ./test/testdata/netrc/print_netrc.py'},
61 ie = DummyIE(FakeYDL(params))
62 self.assertEqual(ie._get_netrc_login_info(netrc_machine='normal_use'), ('user', 'pass'))
63 self.assertEqual(ie._get_netrc_login_info(netrc_machine='empty_user'), ('', 'pass'))
64 self.assertEqual(ie._get_netrc_login_info(netrc_machine='empty_pass'), ('user', ''))
65 self.assertEqual(ie._get_netrc_login_info(netrc_machine='both_empty'), ('', ''))
66 self.assertEqual(ie._get_netrc_login_info(netrc_machine='nonexistent'), (None, None))
68 def test_html_search_regex(self):
69 html = '<p id="foo">Watch this <a href="http://www.youtube.com/watch?v=BaW_jenozKc">video</a></p>'
70 search = lambda re, *args: self.ie._html_search_regex(re, html, *args)
71 self.assertEqual(search(r'<p id="foo">(.+?)</p>', 'foo'), 'Watch this video')
73 def test_opengraph(self):
74 ie = self.ie
75 html = '''
76 <meta name="og:title" content='Foo'/>
77 <meta content="Some video's description " name="og:description"/>
78 <meta property='og:image' content='http://domain.com/pic.jpg?key1=val1&amp;key2=val2'/>
79 <meta content='application/x-shockwave-flash' property='og:video:type'>
80 <meta content='Foo' property=og:foobar>
81 <meta name="og:test1" content='foo > < bar'/>
82 <meta name="og:test2" content="foo >//< bar"/>
83 <meta property=og-test3 content='Ill-formatted opengraph'/>
84 <meta property=og:test4 content=unquoted-value/>
85 '''
86 self.assertEqual(ie._og_search_title(html), 'Foo')
87 self.assertEqual(ie._og_search_description(html), 'Some video\'s description ')
88 self.assertEqual(ie._og_search_thumbnail(html), 'http://domain.com/pic.jpg?key1=val1&key2=val2')
89 self.assertEqual(ie._og_search_video_url(html, default=None), None)
90 self.assertEqual(ie._og_search_property('foobar', html), 'Foo')
91 self.assertEqual(ie._og_search_property('test1', html), 'foo > < bar')
92 self.assertEqual(ie._og_search_property('test2', html), 'foo >//< bar')
93 self.assertEqual(ie._og_search_property('test3', html), 'Ill-formatted opengraph')
94 self.assertEqual(ie._og_search_property(('test0', 'test1'), html), 'foo > < bar')
95 self.assertRaises(RegexNotFoundError, ie._og_search_property, 'test0', html, None, fatal=True)
96 self.assertRaises(RegexNotFoundError, ie._og_search_property, ('test0', 'test00'), html, None, fatal=True)
97 self.assertEqual(ie._og_search_property('test4', html), 'unquoted-value')
99 def test_html_search_meta(self):
100 ie = self.ie
101 html = '''
102 <meta name="a" content="1" />
103 <meta name='b' content='2'>
104 <meta name="c" content='3'>
105 <meta name=d content='4'>
106 <meta property="e" content='5' >
107 <meta content="6" name="f">
110 self.assertEqual(ie._html_search_meta('a', html), '1')
111 self.assertEqual(ie._html_search_meta('b', html), '2')
112 self.assertEqual(ie._html_search_meta('c', html), '3')
113 self.assertEqual(ie._html_search_meta('d', html), '4')
114 self.assertEqual(ie._html_search_meta('e', html), '5')
115 self.assertEqual(ie._html_search_meta('f', html), '6')
116 self.assertEqual(ie._html_search_meta(('a', 'b', 'c'), html), '1')
117 self.assertEqual(ie._html_search_meta(('c', 'b', 'a'), html), '3')
118 self.assertEqual(ie._html_search_meta(('z', 'x', 'c'), html), '3')
119 self.assertRaises(RegexNotFoundError, ie._html_search_meta, 'z', html, None, fatal=True)
120 self.assertRaises(RegexNotFoundError, ie._html_search_meta, ('z', 'x'), html, None, fatal=True)
122 def test_search_json_ld_realworld(self):
123 _TESTS = [
124 # https://github.com/ytdl-org/youtube-dl/issues/23306
126 r'''<script type="application/ld+json">
128 "@context": "http://schema.org/",
129 "@type": "VideoObject",
130 "name": "1 On 1 With Kleio",
131 "url": "https://www.eporner.com/hd-porn/xN49A1cT3eB/1-On-1-With-Kleio/",
132 "duration": "PT0H12M23S",
133 "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"],
134 "contentUrl": "https://gvideo.eporner.com/xN49A1cT3eB/xN49A1cT3eB.mp4",
135 "embedUrl": "https://www.eporner.com/embed/xN49A1cT3eB/1-On-1-With-Kleio/",
136 "image": "https://static-eu-cdn.eporner.com/thumbs/static4/7/78/780/780814/9_360.jpg",
137 "width": "1920",
138 "height": "1080",
139 "encodingFormat": "mp4",
140 "bitrate": "6617kbps",
141 "isFamilyFriendly": "False",
142 "description": "Kleio Valentien",
143 "uploadDate": "2015-12-05T21:24:35+01:00",
144 "interactionStatistic": {
145 "@type": "InteractionCounter",
146 "interactionType": { "@type": "http://schema.org/WatchAction" },
147 "userInteractionCount": 1120958
148 }, "aggregateRating": {
149 "@type": "AggregateRating",
150 "ratingValue": "88",
151 "ratingCount": "630",
152 "bestRating": "100",
153 "worstRating": "0"
154 }, "actor": [{
155 "@type": "Person",
156 "name": "Kleio Valentien",
157 "url": "https://www.eporner.com/pornstar/kleio-valentien/"
159 </script>''',
161 'title': '1 On 1 With Kleio',
162 'description': 'Kleio Valentien',
163 'url': 'https://gvideo.eporner.com/xN49A1cT3eB/xN49A1cT3eB.mp4',
164 'timestamp': 1449347075,
165 'duration': 743.0,
166 'view_count': 1120958,
167 'width': 1920,
168 'height': 1080,
173 r'''<script type="application/ld+json">
175 "@context": "https://schema.org",
176 "@graph": [
178 "@type": "NewsArticle",
179 "mainEntityOfPage": {
180 "@type": "WebPage",
181 "@id": "https://www.ant1news.gr/Society/article/620286/symmoria-anilikon-dikigoros-thymaton-ithelan-na-toys-apoteleiosoyn"
183 "headline": "Συμμορία ανηλίκων – δικηγόρος θυμάτων: ήθελαν να τους αποτελειώσουν",
184 "name": "Συμμορία ανηλίκων – δικηγόρος θυμάτων: ήθελαν να τους αποτελειώσουν",
185 "description": "Τα παιδιά δέχθηκαν την επίθεση επειδή αρνήθηκαν να γίνουν μέλη της συμμορίας, ανέφερε ο Γ. Ζαχαρόπουλος.",
186 "image": {
187 "@type": "ImageObject",
188 "url": "https://ant1media.azureedge.net/imgHandler/1100/a635c968-be71-447c-bf9c-80d843ece21e.jpg",
189 "width": 1100,
190 "height": 756 },
191 "datePublished": "2021-11-10T08:50:00+03:00",
192 "dateModified": "2021-11-10T08:52:53+03:00",
193 "author": {
194 "@type": "Person",
195 "@id": "https://www.ant1news.gr/",
196 "name": "Ant1news",
197 "image": "https://www.ant1news.gr/images/logo-e5d7e4b3e714c88e8d2eca96130142f6.png",
198 "url": "https://www.ant1news.gr/"
200 "publisher": {
201 "@type": "Organization",
202 "@id": "https://www.ant1news.gr#publisher",
203 "name": "Ant1news",
204 "url": "https://www.ant1news.gr",
205 "logo": {
206 "@type": "ImageObject",
207 "url": "https://www.ant1news.gr/images/logo-e5d7e4b3e714c88e8d2eca96130142f6.png",
208 "width": 400,
209 "height": 400 },
210 "sameAs": [
211 "https://www.facebook.com/Ant1news.gr",
212 "https://twitter.com/antennanews",
213 "https://www.youtube.com/channel/UC0smvAbfczoN75dP0Hw4Pzw",
214 "https://www.instagram.com/ant1news/"
218 "keywords": "μαχαίρωμα,συμμορία ανηλίκων,ΕΙΔΗΣΕΙΣ,ΕΙΔΗΣΕΙΣ ΣΗΜΕΡΑ,ΝΕΑ,Κοινωνία - Ant1news",
221 "articleSection": "Κοινωνία"
225 </script>''',
227 'timestamp': 1636523400,
228 'title': 'md5:91fe569e952e4d146485740ae927662b',
230 {'expected_type': 'NewsArticle'},
233 r'''<script type="application/ld+json">
234 {"url":"/vrtnu/a-z/het-journaal/2021/het-journaal-het-journaal-19u-20211231/",
235 "name":"Het journaal 19u",
236 "description":"Het journaal 19u van vrijdag 31 december 2021.",
237 "potentialAction":{"url":"https://vrtnu.page.link/pfVy6ihgCAJKgHqe8","@type":"ShareAction"},
238 "mainEntityOfPage":{"@id":"1640092242445","@type":"WebPage"},
239 "publication":[{
240 "startDate":"2021-12-31T19:00:00.000+01:00",
241 "endDate":"2022-01-30T23:55:00.000+01:00",
242 "publishedBy":{"name":"een","@type":"Organization"},
243 "publishedOn":{"url":"https://www.vrt.be/vrtnu/","name":"VRT NU","@type":"BroadcastService"},
244 "@id":"pbs-pub-3a7ec233-da95-4c1e-9b2b-cf5fdfebcbe8",
245 "@type":"BroadcastEvent"
247 "video":{
248 "name":"Het journaal - Aflevering 365 (Seizoen 2021)",
249 "description":"Het journaal 19u van vrijdag 31 december 2021. Bekijk aflevering 365 van seizoen 2021 met VRT NU via de site of app.",
250 "thumbnailUrl":"//images.vrt.be/width1280/2021/12/31/80d5ed00-6a64-11ec-b07d-02b7b76bf47f.jpg",
251 "expires":"2022-01-30T23:55:00.000+01:00",
252 "hasPart":[
253 {"name":"Explosie Turnhout","startOffset":70,"@type":"Clip"},
254 {"name":"Jaarwisseling","startOffset":440,"@type":"Clip"},
255 {"name":"Natuurbranden Colorado","startOffset":1179,"@type":"Clip"},
256 {"name":"Klimaatverandering","startOffset":1263,"@type":"Clip"},
257 {"name":"Zacht weer","startOffset":1367,"@type":"Clip"},
258 {"name":"Financiële balans","startOffset":1383,"@type":"Clip"},
259 {"name":"Club Brugge","startOffset":1484,"@type":"Clip"},
260 {"name":"Mentale gezondheid bij topsporters","startOffset":1575,"@type":"Clip"},
261 {"name":"Olympische Winterspelen","startOffset":1728,"@type":"Clip"},
262 {"name":"Sober oudjaar in Nederland","startOffset":1873,"@type":"Clip"}
264 "duration":"PT34M39.23S",
265 "uploadDate":"2021-12-31T19:00:00.000+01:00",
266 "@id":"vid-9457d0c6-b8ac-4aba-b5e1-15aa3a3295b5",
267 "@type":"VideoObject"
269 "genre":["Nieuws en actua"],
270 "episodeNumber":365,
271 "partOfSeries":{"name":"Het journaal","@id":"222831405527","@type":"TVSeries"},
272 "partOfSeason":{"name":"Seizoen 2021","@id":"961809365527","@type":"TVSeason"},
273 "@context":"https://schema.org","@id":"961685295527","@type":"TVEpisode"}</script>
274 ''',
276 'chapters': [
277 {'title': 'Explosie Turnhout', 'start_time': 70, 'end_time': 440},
278 {'title': 'Jaarwisseling', 'start_time': 440, 'end_time': 1179},
279 {'title': 'Natuurbranden Colorado', 'start_time': 1179, 'end_time': 1263},
280 {'title': 'Klimaatverandering', 'start_time': 1263, 'end_time': 1367},
281 {'title': 'Zacht weer', 'start_time': 1367, 'end_time': 1383},
282 {'title': 'Financiële balans', 'start_time': 1383, 'end_time': 1484},
283 {'title': 'Club Brugge', 'start_time': 1484, 'end_time': 1575},
284 {'title': 'Mentale gezondheid bij topsporters', 'start_time': 1575, 'end_time': 1728},
285 {'title': 'Olympische Winterspelen', 'start_time': 1728, 'end_time': 1873},
286 {'title': 'Sober oudjaar in Nederland', 'start_time': 1873, 'end_time': 2079.23},
288 'title': 'Het journaal - Aflevering 365 (Seizoen 2021)',
289 }, {},
292 # test multiple thumbnails in a list
293 r'''
294 <script type="application/ld+json">
295 {"@context":"https://schema.org",
296 "@type":"VideoObject",
297 "thumbnailUrl":["https://www.rainews.it/cropgd/640x360/dl/img/2021/12/30/1640886376927_GettyImages.jpg"]}
298 </script>''',
300 'thumbnails': [{'url': 'https://www.rainews.it/cropgd/640x360/dl/img/2021/12/30/1640886376927_GettyImages.jpg'}],
305 # test single thumbnail
306 r'''
307 <script type="application/ld+json">
308 {"@context":"https://schema.org",
309 "@type":"VideoObject",
310 "thumbnailUrl":"https://www.rainews.it/cropgd/640x360/dl/img/2021/12/30/1640886376927_GettyImages.jpg"}
311 </script>''',
313 'thumbnails': [{'url': 'https://www.rainews.it/cropgd/640x360/dl/img/2021/12/30/1640886376927_GettyImages.jpg'}],
318 for html, expected_dict, search_json_ld_kwargs in _TESTS:
319 expect_dict(
320 self,
321 self.ie._search_json_ld(html, None, **search_json_ld_kwargs),
322 expected_dict,
325 def test_download_json(self):
326 uri = encode_data_uri(b'{"foo": "blah"}', 'application/json')
327 self.assertEqual(self.ie._download_json(uri, None), {'foo': 'blah'})
328 uri = encode_data_uri(b'callback({"foo": "blah"})', 'application/javascript')
329 self.assertEqual(self.ie._download_json(uri, None, transform_source=strip_jsonp), {'foo': 'blah'})
330 uri = encode_data_uri(b'{"foo": invalid}', 'application/json')
331 self.assertRaises(ExtractorError, self.ie._download_json, uri, None)
332 self.assertEqual(self.ie._download_json(uri, None, fatal=False), None)
334 def test_parse_html5_media_entries(self):
335 # inline video tag
336 expect_dict(
337 self,
338 self.ie._parse_html5_media_entries(
339 'https://127.0.0.1/video.html',
340 r'<html><video src="/vid.mp4" /></html>', None)[0],
342 'formats': [{
343 'url': 'https://127.0.0.1/vid.mp4',
347 # from https://www.r18.com/
348 # with kpbs in label
349 expect_dict(
350 self,
351 self.ie._parse_html5_media_entries(
352 'https://www.r18.com/',
353 r'''
354 <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">
355 <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">
356 <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">
357 <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">
358 <p>Your browser does not support the video tag.</p>
359 </video>
360 ''', None)[0],
362 'formats': [{
363 'url': 'https://awscc3001.r18.com/litevideo/freepv/m/mgm/mgmr105/mgmr105_sm_w.mp4',
364 'ext': 'mp4',
365 'format_id': '300kbps',
366 'height': 240,
367 'tbr': 300,
368 }, {
369 'url': 'https://awscc3001.r18.com/litevideo/freepv/m/mgm/mgmr105/mgmr105_dm_w.mp4',
370 'ext': 'mp4',
371 'format_id': '1000kbps',
372 'height': 480,
373 'tbr': 1000,
374 }, {
375 'url': 'https://awscc3001.r18.com/litevideo/freepv/m/mgm/mgmr105/mgmr105_dmb_w.mp4',
376 'ext': 'mp4',
377 'format_id': '1500kbps',
378 'height': 740,
379 'tbr': 1500,
381 'thumbnail': '//pics.r18.com/digital/amateur/mgmr105/mgmr105jp.jpg',
384 # from https://www.csfd.cz/
385 # with width and height
386 expect_dict(
387 self,
388 self.ie._parse_html5_media_entries(
389 'https://www.csfd.cz/',
390 r'''
391 <video width="770" height="328" preload="none" controls poster="https://img.csfd.cz/files/images/film/video/preview/163/344/163344118_748d20.png?h360" >
392 <source src="https://video.csfd.cz/files/videos/157/750/157750813/163327358_eac647.mp4" type="video/mp4" width="640" height="360">
393 <source src="https://video.csfd.cz/files/videos/157/750/157750813/163327360_3d2646.mp4" type="video/mp4" width="1280" height="720">
394 <source src="https://video.csfd.cz/files/videos/157/750/157750813/163327356_91f258.mp4" type="video/mp4" width="1920" height="1080">
395 <source src="https://video.csfd.cz/files/videos/157/750/157750813/163327359_962b4a.webm" type="video/webm" width="640" height="360">
396 <source src="https://video.csfd.cz/files/videos/157/750/157750813/163327361_6feee0.webm" type="video/webm" width="1280" height="720">
397 <source src="https://video.csfd.cz/files/videos/157/750/157750813/163327357_8ab472.webm" type="video/webm" width="1920" height="1080">
398 <track src="https://video.csfd.cz/files/subtitles/163/344/163344115_4c388b.srt" type="text/x-srt" kind="subtitles" srclang="cs" label="cs">
399 </video>
400 ''', None)[0],
402 'formats': [{
403 'url': 'https://video.csfd.cz/files/videos/157/750/157750813/163327358_eac647.mp4',
404 'ext': 'mp4',
405 'width': 640,
406 'height': 360,
407 }, {
408 'url': 'https://video.csfd.cz/files/videos/157/750/157750813/163327360_3d2646.mp4',
409 'ext': 'mp4',
410 'width': 1280,
411 'height': 720,
412 }, {
413 'url': 'https://video.csfd.cz/files/videos/157/750/157750813/163327356_91f258.mp4',
414 'ext': 'mp4',
415 'width': 1920,
416 'height': 1080,
417 }, {
418 'url': 'https://video.csfd.cz/files/videos/157/750/157750813/163327359_962b4a.webm',
419 'ext': 'webm',
420 'width': 640,
421 'height': 360,
422 }, {
423 'url': 'https://video.csfd.cz/files/videos/157/750/157750813/163327361_6feee0.webm',
424 'ext': 'webm',
425 'width': 1280,
426 'height': 720,
427 }, {
428 'url': 'https://video.csfd.cz/files/videos/157/750/157750813/163327357_8ab472.webm',
429 'ext': 'webm',
430 'width': 1920,
431 'height': 1080,
433 'subtitles': {
434 'cs': [{'url': 'https://video.csfd.cz/files/subtitles/163/344/163344115_4c388b.srt'}],
436 'thumbnail': 'https://img.csfd.cz/files/images/film/video/preview/163/344/163344118_748d20.png?h360',
439 # from https://tamasha.com/v/Kkdjw
440 # with height in label
441 expect_dict(
442 self,
443 self.ie._parse_html5_media_entries(
444 'https://tamasha.com/v/Kkdjw',
445 r'''
446 <video crossorigin="anonymous">
447 <source src="https://s-v2.tamasha.com/statics/videos_file/19/8f/Kkdjw_198feff8577d0057536e905cce1fb61438dd64e0_n_240.mp4" type="video/mp4" label="AUTO" res="0"/>
448 <source src="https://s-v2.tamasha.com/statics/videos_file/19/8f/Kkdjw_198feff8577d0057536e905cce1fb61438dd64e0_n_240.mp4" type="video/mp4"
449 label="240p" res="240"/>
450 <source src="https://s-v2.tamasha.com/statics/videos_file/20/00/Kkdjw_200041c66f657fc967db464d156eafbc1ed9fe6f_n_144.mp4" type="video/mp4"
451 label="144p" res="144"/>
452 </video>
453 ''', None)[0],
455 'formats': [{
456 'url': 'https://s-v2.tamasha.com/statics/videos_file/19/8f/Kkdjw_198feff8577d0057536e905cce1fb61438dd64e0_n_240.mp4',
457 }, {
458 'url': 'https://s-v2.tamasha.com/statics/videos_file/19/8f/Kkdjw_198feff8577d0057536e905cce1fb61438dd64e0_n_240.mp4',
459 'ext': 'mp4',
460 'format_id': '240p',
461 'height': 240,
462 }, {
463 'url': 'https://s-v2.tamasha.com/statics/videos_file/20/00/Kkdjw_200041c66f657fc967db464d156eafbc1ed9fe6f_n_144.mp4',
464 'ext': 'mp4',
465 'format_id': '144p',
466 'height': 144,
470 # from https://www.directvnow.com
471 # with data-src
472 expect_dict(
473 self,
474 self.ie._parse_html5_media_entries(
475 'https://www.directvnow.com',
476 r'''
477 <video id="vid1" class="header--video-masked active" muted playsinline>
478 <source data-src="https://cdn.directv.com/content/dam/dtv/prod/website_directvnow-international/videos/DTVN_hdr_HBO_v3.mp4" type="video/mp4" />
479 </video>
480 ''', None)[0],
482 'formats': [{
483 'ext': 'mp4',
484 'url': 'https://cdn.directv.com/content/dam/dtv/prod/website_directvnow-international/videos/DTVN_hdr_HBO_v3.mp4',
488 # from https://www.directvnow.com
489 # with data-src
490 expect_dict(
491 self,
492 self.ie._parse_html5_media_entries(
493 'https://www.directvnow.com',
494 r'''
495 <video id="vid1" class="header--video-masked active" muted playsinline>
496 <source data-src="https://cdn.directv.com/content/dam/dtv/prod/website_directvnow-international/videos/DTVN_hdr_HBO_v3.mp4" type="video/mp4" />
497 </video>
498 ''', None)[0],
500 'formats': [{
501 'url': 'https://cdn.directv.com/content/dam/dtv/prod/website_directvnow-international/videos/DTVN_hdr_HBO_v3.mp4',
502 'ext': 'mp4',
506 # from https://www.klarna.com/uk/
507 # with data-video-src
508 expect_dict(
509 self,
510 self.ie._parse_html5_media_entries(
511 'https://www.directvnow.com',
512 r'''
513 <video loop autoplay muted class="responsive-video block-kl__video video-on-medium">
514 <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" />
515 </video>
516 ''', None)[0],
518 'formats': [{
519 'url': 'https://www.klarna.com/uk/wp-content/uploads/sites/11/2019/01/KL062_Smooth3_0_DogWalking_5s_920x080_.mp4',
520 'ext': 'mp4',
524 # from https://0000.studio/
525 # with type attribute but without extension in URL
526 expect_dict(
527 self,
528 self.ie._parse_html5_media_entries(
529 'https://0000.studio',
530 r'''
531 <video src="https://d1ggyt9m8pwf3g.cloudfront.net/protected/ap-northeast-1:1864af40-28d5-492b-b739-b32314b1a527/archive/clip/838db6a7-8973-4cd6-840d-8517e4093c92"
532 controls="controls" type="video/mp4" preload="metadata" autoplay="autoplay" playsinline class="object-contain">
533 </video>
534 ''', None)[0],
536 'formats': [{
537 'url': 'https://d1ggyt9m8pwf3g.cloudfront.net/protected/ap-northeast-1:1864af40-28d5-492b-b739-b32314b1a527/archive/clip/838db6a7-8973-4cd6-840d-8517e4093c92',
538 'ext': 'mp4',
542 def test_extract_jwplayer_data_realworld(self):
543 # from http://www.suffolk.edu/sjc/
544 expect_dict(
545 self,
546 self.ie._extract_jwplayer_data(r'''
547 <script type='text/javascript'>
548 jwplayer('my-video').setup({
549 file: 'rtmp://192.138.214.154/live/sjclive',
550 fallback: 'true',
551 width: '95%',
552 aspectratio: '16:9',
553 primary: 'flash',
554 mediaid:'XEgvuql4'
556 </script>
557 ''', None, require_title=False),
559 'id': 'XEgvuql4',
560 'formats': [{
561 'url': 'rtmp://192.138.214.154/live/sjclive',
562 'ext': 'flv',
566 # from https://www.pornoxo.com/videos/7564/striptease-from-sexy-secretary/
567 expect_dict(
568 self,
569 self.ie._extract_jwplayer_data(r'''
570 <script type="text/javascript">
571 jwplayer("mediaplayer").setup({
572 'videoid': "7564",
573 'width': "100%",
574 'aspectratio': "16:9",
575 'stretching': "exactfit",
576 'autostart': 'false',
577 'flashplayer': "https://t04.vipstreamservice.com/jwplayer/v5.10/player.swf",
578 '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",
579 'image': "https://t03.vipstreamservice.com/thumbs/pxo-full/2009-12/14/a4b2157147afe5efa93ce1978e0265289c193874e02597.flv-full-13.jpg",
580 '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",
581 'logo.hide': true,
582 'skin': "https://t04.vipstreamservice.com/jwplayer/skin/modieus-blk.zip",
583 'plugins': "https://t04.vipstreamservice.com/jwplayer/dock/dockableskinnableplugin.swf",
584 'dockableskinnableplugin.piclink': "/index.php?key=ajax-videothumbsn&vid=7564&data=2009-12--14--4b2157147afe5efa93ce1978e0265289c193874e02597.flv--17370",
585 'controlbar': 'bottom',
586 'modes': [
587 {type: 'flash', src: 'https://t04.vipstreamservice.com/jwplayer/v5.10/player.swf'}
589 'provider': 'http'
591 //noinspection JSAnnotator
592 invideo.setup({
593 adsUrl: "/banner-iframe/?zoneId=32",
594 adsUrl2: "",
595 autostart: false
597 </script>
598 ''', 'dummy', require_title=False),
600 'thumbnail': 'https://t03.vipstreamservice.com/thumbs/pxo-full/2009-12/14/a4b2157147afe5efa93ce1978e0265289c193874e02597.flv-full-13.jpg',
601 'formats': [{
602 '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',
603 'ext': 'flv',
607 # from http://www.indiedb.com/games/king-machine/videos
608 expect_dict(
609 self,
610 self.ie._extract_jwplayer_data(r'''
611 <script>
612 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) {
613 videoAnalytics("play");
614 }).once("complete", function(event) {
615 videoAnalytics("completed");
617 </script>
618 ''', 'dummy'),
620 'title': 'king machine trailer 1',
621 'thumbnail': 'http://media.indiedb.com/cache/images/games/1/50/49678/thumb_620x2000/king-machine-trailer.mp4.jpg',
622 'formats': [{
623 'url': 'http://cdn.dbolical.com/cache/videos/games/1/50/49678/encode_mp4/king-machine-trailer.mp4',
624 'height': 360,
625 'ext': 'mp4',
626 }, {
627 'url': 'http://cdn.dbolical.com/cache/videos/games/1/50/49678/encode720p_mp4/king-machine-trailer.mp4',
628 'height': 720,
629 'ext': 'mp4',
633 def test_parse_m3u8_formats(self):
634 _TEST_CASES = [
636 # https://github.com/ytdl-org/youtube-dl/issues/11995
637 # http://teamcoco.com/video/clueless-gamer-super-bowl-for-honor
638 'img_bipbop_adv_example_fmp4',
639 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/master.m3u8',
641 'format_id': 'aud1-English',
642 'url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/a1/prog_index.m3u8',
643 'manifest_url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/master.m3u8',
644 'language': 'en',
645 'ext': 'mp4',
646 'protocol': 'm3u8_native',
647 'audio_ext': 'mp4',
648 }, {
649 'format_id': 'aud2-English',
650 'url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/a2/prog_index.m3u8',
651 'manifest_url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/master.m3u8',
652 'language': 'en',
653 'ext': 'mp4',
654 'protocol': 'm3u8_native',
655 'audio_ext': 'mp4',
656 }, {
657 'format_id': 'aud3-English',
658 'url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/a3/prog_index.m3u8',
659 'manifest_url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/master.m3u8',
660 'language': 'en',
661 'ext': 'mp4',
662 'protocol': 'm3u8_native',
663 'audio_ext': 'mp4',
664 }, {
665 'format_id': '530',
666 'url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/v2/prog_index.m3u8',
667 'manifest_url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/master.m3u8',
668 'ext': 'mp4',
669 'protocol': 'm3u8_native',
670 'width': 480,
671 'height': 270,
672 'vcodec': 'avc1.640015',
673 }, {
674 'format_id': '561',
675 'url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/v2/prog_index.m3u8',
676 'manifest_url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/master.m3u8',
677 'ext': 'mp4',
678 'protocol': 'm3u8_native',
679 'width': 480,
680 'height': 270,
681 'vcodec': 'avc1.640015',
682 }, {
683 'format_id': '753',
684 'url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/v2/prog_index.m3u8',
685 'manifest_url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/master.m3u8',
686 'ext': 'mp4',
687 'protocol': 'm3u8_native',
688 'width': 480,
689 'height': 270,
690 'vcodec': 'avc1.640015',
691 }, {
692 'format_id': '895',
693 'url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/v3/prog_index.m3u8',
694 'manifest_url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/master.m3u8',
695 'ext': 'mp4',
696 'protocol': 'm3u8_native',
697 'width': 640,
698 'height': 360,
699 'vcodec': 'avc1.64001e',
700 }, {
701 'format_id': '926',
702 'url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/v3/prog_index.m3u8',
703 'manifest_url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/master.m3u8',
704 'ext': 'mp4',
705 'protocol': 'm3u8_native',
706 'width': 640,
707 'height': 360,
708 'vcodec': 'avc1.64001e',
709 }, {
710 'format_id': '1118',
711 'url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/v3/prog_index.m3u8',
712 'manifest_url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/master.m3u8',
713 'ext': 'mp4',
714 'protocol': 'm3u8_native',
715 'width': 640,
716 'height': 360,
717 'vcodec': 'avc1.64001e',
718 }, {
719 'format_id': '1265',
720 'url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/v4/prog_index.m3u8',
721 'manifest_url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/master.m3u8',
722 'ext': 'mp4',
723 'protocol': 'm3u8_native',
724 'width': 768,
725 'height': 432,
726 'vcodec': 'avc1.64001e',
727 }, {
728 'format_id': '1295',
729 'url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/v4/prog_index.m3u8',
730 'manifest_url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/master.m3u8',
731 'ext': 'mp4',
732 'protocol': 'm3u8_native',
733 'width': 768,
734 'height': 432,
735 'vcodec': 'avc1.64001e',
736 }, {
737 'format_id': '1487',
738 'url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/v4/prog_index.m3u8',
739 'manifest_url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/master.m3u8',
740 'ext': 'mp4',
741 'protocol': 'm3u8_native',
742 'width': 768,
743 'height': 432,
744 'vcodec': 'avc1.64001e',
745 }, {
746 'format_id': '2168',
747 'url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/v5/prog_index.m3u8',
748 'manifest_url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/master.m3u8',
749 'ext': 'mp4',
750 'protocol': 'm3u8_native',
751 'width': 960,
752 'height': 540,
753 'vcodec': 'avc1.640020',
754 }, {
755 'format_id': '2198',
756 'url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/v5/prog_index.m3u8',
757 'manifest_url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/master.m3u8',
758 'ext': 'mp4',
759 'protocol': 'm3u8_native',
760 'width': 960,
761 'height': 540,
762 'vcodec': 'avc1.640020',
763 }, {
764 'format_id': '2390',
765 'url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/v5/prog_index.m3u8',
766 'manifest_url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/master.m3u8',
767 'ext': 'mp4',
768 'protocol': 'm3u8_native',
769 'width': 960,
770 'height': 540,
771 'vcodec': 'avc1.640020',
772 }, {
773 'format_id': '3168',
774 'url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/v6/prog_index.m3u8',
775 'manifest_url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/master.m3u8',
776 'ext': 'mp4',
777 'protocol': 'm3u8_native',
778 'width': 1280,
779 'height': 720,
780 'vcodec': 'avc1.640020',
781 }, {
782 'format_id': '3199',
783 'url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/v6/prog_index.m3u8',
784 'manifest_url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/master.m3u8',
785 'ext': 'mp4',
786 'protocol': 'm3u8_native',
787 'width': 1280,
788 'height': 720,
789 'vcodec': 'avc1.640020',
790 }, {
791 'format_id': '3391',
792 'url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/v6/prog_index.m3u8',
793 'manifest_url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/master.m3u8',
794 'ext': 'mp4',
795 'protocol': 'm3u8_native',
796 'width': 1280,
797 'height': 720,
798 'vcodec': 'avc1.640020',
799 }, {
800 'format_id': '4670',
801 'url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/v7/prog_index.m3u8',
802 'manifest_url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/master.m3u8',
803 'ext': 'mp4',
804 'protocol': 'm3u8_native',
805 'width': 1920,
806 'height': 1080,
807 'vcodec': 'avc1.64002a',
808 }, {
809 'format_id': '4701',
810 'url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/v7/prog_index.m3u8',
811 'manifest_url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/master.m3u8',
812 'ext': 'mp4',
813 'protocol': 'm3u8_native',
814 'width': 1920,
815 'height': 1080,
816 'vcodec': 'avc1.64002a',
817 }, {
818 'format_id': '4893',
819 'url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/v7/prog_index.m3u8',
820 'manifest_url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/master.m3u8',
821 'ext': 'mp4',
822 'protocol': 'm3u8_native',
823 'width': 1920,
824 'height': 1080,
825 'vcodec': 'avc1.64002a',
826 }, {
827 'format_id': '6170',
828 'url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/v8/prog_index.m3u8',
829 'manifest_url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/master.m3u8',
830 'ext': 'mp4',
831 'protocol': 'm3u8_native',
832 'width': 1920,
833 'height': 1080,
834 'vcodec': 'avc1.64002a',
835 }, {
836 'format_id': '6200',
837 'url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/v8/prog_index.m3u8',
838 'manifest_url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/master.m3u8',
839 'ext': 'mp4',
840 'protocol': 'm3u8_native',
841 'width': 1920,
842 'height': 1080,
843 'vcodec': 'avc1.64002a',
844 }, {
845 'format_id': '6392',
846 'url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/v8/prog_index.m3u8',
847 'manifest_url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/master.m3u8',
848 'ext': 'mp4',
849 'protocol': 'm3u8_native',
850 'width': 1920,
851 'height': 1080,
852 'vcodec': 'avc1.64002a',
853 }, {
854 'format_id': '7968',
855 'url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/v9/prog_index.m3u8',
856 'manifest_url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/master.m3u8',
857 'ext': 'mp4',
858 'protocol': 'm3u8_native',
859 'width': 1920,
860 'height': 1080,
861 'vcodec': 'avc1.64002a',
862 }, {
863 'format_id': '7998',
864 'url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/v9/prog_index.m3u8',
865 'manifest_url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/master.m3u8',
866 'ext': 'mp4',
867 'protocol': 'm3u8_native',
868 'width': 1920,
869 'height': 1080,
870 'vcodec': 'avc1.64002a',
871 }, {
872 'format_id': '8190',
873 'url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/v9/prog_index.m3u8',
874 'manifest_url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/master.m3u8',
875 'ext': 'mp4',
876 'protocol': 'm3u8_native',
877 'width': 1920,
878 'height': 1080,
879 'vcodec': 'avc1.64002a',
884 'bipbop_16x9',
885 'https://devstreaming-cdn.apple.com/videos/streaming/examples/bipbop_16x9/bipbop_16x9_variant.m3u8',
887 'format_id': 'bipbop_audio-BipBop Audio 2',
888 'format_index': None,
889 'url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/bipbop_16x9/alternate_audio_aac/prog_index.m3u8',
890 'manifest_url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/bipbop_16x9/bipbop_16x9_variant.m3u8',
891 'language': 'eng',
892 'ext': 'mp4',
893 'protocol': 'm3u8_native',
894 'preference': None,
895 'quality': None,
896 'vcodec': 'none',
897 'audio_ext': 'mp4',
898 'video_ext': 'none',
899 }, {
900 'format_id': '41',
901 'format_index': None,
902 'url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/bipbop_16x9/gear0/prog_index.m3u8',
903 'manifest_url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/bipbop_16x9/bipbop_16x9_variant.m3u8',
904 'tbr': 41.457,
905 'ext': 'mp4',
906 'fps': None,
907 'protocol': 'm3u8_native',
908 'preference': None,
909 'quality': None,
910 'vcodec': 'none',
911 'acodec': 'mp4a.40.2',
912 'audio_ext': 'mp4',
913 'video_ext': 'none',
914 'abr': 41.457,
915 }, {
916 'format_id': '263',
917 'format_index': None,
918 'url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/bipbop_16x9/gear1/prog_index.m3u8',
919 'manifest_url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/bipbop_16x9/bipbop_16x9_variant.m3u8',
920 'tbr': 263.851,
921 'ext': 'mp4',
922 'fps': None,
923 'protocol': 'm3u8_native',
924 'preference': None,
925 'quality': None,
926 'width': 416,
927 'height': 234,
928 'vcodec': 'avc1.4d400d',
929 'acodec': 'mp4a.40.2',
930 'video_ext': 'mp4',
931 'audio_ext': 'none',
932 }, {
933 'format_id': '577',
934 'format_index': None,
935 'url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/bipbop_16x9/gear2/prog_index.m3u8',
936 'manifest_url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/bipbop_16x9/bipbop_16x9_variant.m3u8',
937 'tbr': 577.61,
938 'ext': 'mp4',
939 'fps': None,
940 'protocol': 'm3u8_native',
941 'preference': None,
942 'quality': None,
943 'width': 640,
944 'height': 360,
945 'vcodec': 'avc1.4d401e',
946 'acodec': 'mp4a.40.2',
947 'video_ext': 'mp4',
948 'audio_ext': 'none',
949 }, {
950 'format_id': '915',
951 'format_index': None,
952 'url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/bipbop_16x9/gear3/prog_index.m3u8',
953 'manifest_url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/bipbop_16x9/bipbop_16x9_variant.m3u8',
954 'tbr': 915.905,
955 'ext': 'mp4',
956 'fps': None,
957 'protocol': 'm3u8_native',
958 'preference': None,
959 'quality': None,
960 'width': 960,
961 'height': 540,
962 'vcodec': 'avc1.4d401f',
963 'acodec': 'mp4a.40.2',
964 'video_ext': 'mp4',
965 'audio_ext': 'none',
966 }, {
967 'format_id': '1030',
968 'format_index': None,
969 'url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/bipbop_16x9/gear4/prog_index.m3u8',
970 'manifest_url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/bipbop_16x9/bipbop_16x9_variant.m3u8',
971 'tbr': 1030.138,
972 'ext': 'mp4',
973 'fps': None,
974 'protocol': 'm3u8_native',
975 'preference': None,
976 'quality': None,
977 'width': 1280,
978 'height': 720,
979 'vcodec': 'avc1.4d401f',
980 'acodec': 'mp4a.40.2',
981 'video_ext': 'mp4',
982 'audio_ext': 'none',
983 }, {
984 'format_id': '1924',
985 'format_index': None,
986 'url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/bipbop_16x9/gear5/prog_index.m3u8',
987 'manifest_url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/bipbop_16x9/bipbop_16x9_variant.m3u8',
988 'tbr': 1924.009,
989 'ext': 'mp4',
990 'fps': None,
991 'protocol': 'm3u8_native',
992 'preference': None,
993 'quality': None,
994 'width': 1920,
995 'height': 1080,
996 'vcodec': 'avc1.4d401f',
997 'acodec': 'mp4a.40.2',
998 'video_ext': 'mp4',
999 'audio_ext': 'none',
1002 'en': [{
1003 'url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/bipbop_16x9/subtitles/eng/prog_index.m3u8',
1004 'ext': 'vtt',
1005 'protocol': 'm3u8_native',
1006 }, {
1007 'url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/bipbop_16x9/subtitles/eng_forced/prog_index.m3u8',
1008 'ext': 'vtt',
1009 'protocol': 'm3u8_native',
1011 'fr': [{
1012 'url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/bipbop_16x9/subtitles/fra/prog_index.m3u8',
1013 'ext': 'vtt',
1014 'protocol': 'm3u8_native',
1015 }, {
1016 'url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/bipbop_16x9/subtitles/fra_forced/prog_index.m3u8',
1017 'ext': 'vtt',
1018 'protocol': 'm3u8_native',
1020 'es': [{
1021 'url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/bipbop_16x9/subtitles/spa/prog_index.m3u8',
1022 'ext': 'vtt',
1023 'protocol': 'm3u8_native',
1024 }, {
1025 'url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/bipbop_16x9/subtitles/spa_forced/prog_index.m3u8',
1026 'ext': 'vtt',
1027 'protocol': 'm3u8_native',
1029 'ja': [{
1030 'url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/bipbop_16x9/subtitles/jpn/prog_index.m3u8',
1031 'ext': 'vtt',
1032 'protocol': 'm3u8_native',
1033 }, {
1034 'url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/bipbop_16x9/subtitles/jpn_forced/prog_index.m3u8',
1035 'ext': 'vtt',
1036 'protocol': 'm3u8_native',
1042 for m3u8_file, m3u8_url, expected_formats, expected_subs in _TEST_CASES:
1043 with open(f'./test/testdata/m3u8/{m3u8_file}.m3u8', encoding='utf-8') as f:
1044 formats, subs = self.ie._parse_m3u8_formats_and_subtitles(
1045 f.read(), m3u8_url, ext='mp4')
1046 self.ie._sort_formats(formats)
1047 expect_value(self, formats, expected_formats, None)
1048 expect_value(self, subs, expected_subs, None)
1050 def test_parse_mpd_formats(self):
1051 _TEST_CASES = [
1053 # https://github.com/ytdl-org/youtube-dl/issues/13919
1054 # Also tests duplicate representation ids, see
1055 # https://github.com/ytdl-org/youtube-dl/issues/15111
1056 'float_duration',
1057 'http://unknown/manifest.mpd', # mpd_url
1058 None, # mpd_base_url
1060 'manifest_url': 'http://unknown/manifest.mpd',
1061 'ext': 'm4a',
1062 'format_id': '318597',
1063 'format_note': 'DASH audio',
1064 'protocol': 'http_dash_segments',
1065 'acodec': 'mp4a.40.2',
1066 'vcodec': 'none',
1067 'tbr': 61.587,
1068 }, {
1069 'manifest_url': 'http://unknown/manifest.mpd',
1070 'ext': 'mp4',
1071 'format_id': '318597',
1072 'format_note': 'DASH video',
1073 'protocol': 'http_dash_segments',
1074 'acodec': 'none',
1075 'vcodec': 'avc1.42001f',
1076 'tbr': 318.597,
1077 'width': 340,
1078 'height': 192,
1079 }, {
1080 'manifest_url': 'http://unknown/manifest.mpd',
1081 'ext': 'mp4',
1082 'format_id': '638590',
1083 'format_note': 'DASH video',
1084 'protocol': 'http_dash_segments',
1085 'acodec': 'none',
1086 'vcodec': 'avc1.42001f',
1087 'tbr': 638.59,
1088 'width': 512,
1089 'height': 288,
1090 }, {
1091 'manifest_url': 'http://unknown/manifest.mpd',
1092 'ext': 'mp4',
1093 'format_id': '1022565',
1094 'format_note': 'DASH video',
1095 'protocol': 'http_dash_segments',
1096 'acodec': 'none',
1097 'vcodec': 'avc1.4d001f',
1098 'tbr': 1022.565,
1099 'width': 688,
1100 'height': 384,
1101 }, {
1102 'manifest_url': 'http://unknown/manifest.mpd',
1103 'ext': 'mp4',
1104 'format_id': '2046506',
1105 'format_note': 'DASH video',
1106 'protocol': 'http_dash_segments',
1107 'acodec': 'none',
1108 'vcodec': 'avc1.4d001f',
1109 'tbr': 2046.506,
1110 'width': 1024,
1111 'height': 576,
1112 }, {
1113 'manifest_url': 'http://unknown/manifest.mpd',
1114 'ext': 'mp4',
1115 'format_id': '3998017',
1116 'format_note': 'DASH video',
1117 'protocol': 'http_dash_segments',
1118 'acodec': 'none',
1119 'vcodec': 'avc1.640029',
1120 'tbr': 3998.017,
1121 'width': 1280,
1122 'height': 720,
1123 }, {
1124 'manifest_url': 'http://unknown/manifest.mpd',
1125 'ext': 'mp4',
1126 'format_id': '5997485',
1127 'format_note': 'DASH video',
1128 'protocol': 'http_dash_segments',
1129 'acodec': 'none',
1130 'vcodec': 'avc1.640032',
1131 'tbr': 5997.485,
1132 'width': 1920,
1133 'height': 1080,
1136 ), (
1137 # https://github.com/ytdl-org/youtube-dl/pull/14844
1138 'urls_only',
1139 'http://unknown/manifest.mpd', # mpd_url
1140 None, # mpd_base_url
1142 'manifest_url': 'http://unknown/manifest.mpd',
1143 'ext': 'mp4',
1144 'format_id': 'h264_aac_144p_m4s',
1145 'format_note': 'DASH video',
1146 'protocol': 'http_dash_segments',
1147 'acodec': 'mp4a.40.2',
1148 'vcodec': 'avc3.42c01e',
1149 'tbr': 200,
1150 'width': 256,
1151 'height': 144,
1152 }, {
1153 'manifest_url': 'http://unknown/manifest.mpd',
1154 'ext': 'mp4',
1155 'format_id': 'h264_aac_240p_m4s',
1156 'format_note': 'DASH video',
1157 'protocol': 'http_dash_segments',
1158 'acodec': 'mp4a.40.2',
1159 'vcodec': 'avc3.42c01e',
1160 'tbr': 400,
1161 'width': 424,
1162 'height': 240,
1163 }, {
1164 'manifest_url': 'http://unknown/manifest.mpd',
1165 'ext': 'mp4',
1166 'format_id': 'h264_aac_360p_m4s',
1167 'format_note': 'DASH video',
1168 'protocol': 'http_dash_segments',
1169 'acodec': 'mp4a.40.2',
1170 'vcodec': 'avc3.42c01e',
1171 'tbr': 800,
1172 'width': 640,
1173 'height': 360,
1174 }, {
1175 'manifest_url': 'http://unknown/manifest.mpd',
1176 'ext': 'mp4',
1177 'format_id': 'h264_aac_480p_m4s',
1178 'format_note': 'DASH video',
1179 'protocol': 'http_dash_segments',
1180 'acodec': 'mp4a.40.2',
1181 'vcodec': 'avc3.42c01e',
1182 'tbr': 1200,
1183 'width': 856,
1184 'height': 480,
1185 }, {
1186 'manifest_url': 'http://unknown/manifest.mpd',
1187 'ext': 'mp4',
1188 'format_id': 'h264_aac_576p_m4s',
1189 'format_note': 'DASH video',
1190 'protocol': 'http_dash_segments',
1191 'acodec': 'mp4a.40.2',
1192 'vcodec': 'avc3.42c01e',
1193 'tbr': 1600,
1194 'width': 1024,
1195 'height': 576,
1196 }, {
1197 'manifest_url': 'http://unknown/manifest.mpd',
1198 'ext': 'mp4',
1199 'format_id': 'h264_aac_720p_m4s',
1200 'format_note': 'DASH video',
1201 'protocol': 'http_dash_segments',
1202 'acodec': 'mp4a.40.2',
1203 'vcodec': 'avc3.42c01e',
1204 'tbr': 2400,
1205 'width': 1280,
1206 'height': 720,
1207 }, {
1208 'manifest_url': 'http://unknown/manifest.mpd',
1209 'ext': 'mp4',
1210 'format_id': 'h264_aac_1080p_m4s',
1211 'format_note': 'DASH video',
1212 'protocol': 'http_dash_segments',
1213 'acodec': 'mp4a.40.2',
1214 'vcodec': 'avc3.42c01e',
1215 'tbr': 4400,
1216 'width': 1920,
1217 'height': 1080,
1220 ), (
1221 # https://github.com/ytdl-org/youtube-dl/issues/20346
1222 # Media considered unfragmented even though it contains
1223 # Initialization tag
1224 'unfragmented',
1225 'https://v.redd.it/hw1x7rcg7zl21/DASHPlaylist.mpd', # mpd_url
1226 'https://v.redd.it/hw1x7rcg7zl21', # mpd_base_url
1228 'url': 'https://v.redd.it/hw1x7rcg7zl21/audio',
1229 'manifest_url': 'https://v.redd.it/hw1x7rcg7zl21/DASHPlaylist.mpd',
1230 'ext': 'm4a',
1231 'format_id': 'AUDIO-1',
1232 'format_note': 'DASH audio',
1233 'container': 'm4a_dash',
1234 'acodec': 'mp4a.40.2',
1235 'vcodec': 'none',
1236 'tbr': 129.87,
1237 'asr': 48000,
1239 }, {
1240 'url': 'https://v.redd.it/hw1x7rcg7zl21/DASH_240',
1241 'manifest_url': 'https://v.redd.it/hw1x7rcg7zl21/DASHPlaylist.mpd',
1242 'ext': 'mp4',
1243 'format_id': 'VIDEO-2',
1244 'format_note': 'DASH video',
1245 'container': 'mp4_dash',
1246 'acodec': 'none',
1247 'vcodec': 'avc1.4d401e',
1248 'tbr': 608.0,
1249 'width': 240,
1250 'height': 240,
1251 'fps': 30,
1252 }, {
1253 'url': 'https://v.redd.it/hw1x7rcg7zl21/DASH_360',
1254 'manifest_url': 'https://v.redd.it/hw1x7rcg7zl21/DASHPlaylist.mpd',
1255 'ext': 'mp4',
1256 'format_id': 'VIDEO-1',
1257 'format_note': 'DASH video',
1258 'container': 'mp4_dash',
1259 'acodec': 'none',
1260 'vcodec': 'avc1.4d401e',
1261 'tbr': 804.261,
1262 'width': 360,
1263 'height': 360,
1264 'fps': 30,
1267 ), (
1268 'subtitles',
1269 'https://sdn-global-streaming-cache-3qsdn.akamaized.net/stream/3144/files/17/07/672975/3144-kZT4LWMQw6Rh7Kpd.ism/manifest.mpd',
1270 'https://sdn-global-streaming-cache-3qsdn.akamaized.net/stream/3144/files/17/07/672975/3144-kZT4LWMQw6Rh7Kpd.ism/',
1272 'format_id': 'audio=128001',
1273 'manifest_url': 'https://sdn-global-streaming-cache-3qsdn.akamaized.net/stream/3144/files/17/07/672975/3144-kZT4LWMQw6Rh7Kpd.ism/manifest.mpd',
1274 'ext': 'm4a',
1275 'tbr': 128.001,
1276 'asr': 48000,
1277 'format_note': 'DASH audio',
1278 'container': 'm4a_dash',
1279 'vcodec': 'none',
1280 'acodec': 'mp4a.40.2',
1281 'url': 'https://sdn-global-streaming-cache-3qsdn.akamaized.net/stream/3144/files/17/07/672975/3144-kZT4LWMQw6Rh7Kpd.ism/manifest.mpd',
1282 'fragment_base_url': 'https://sdn-global-streaming-cache-3qsdn.akamaized.net/stream/3144/files/17/07/672975/3144-kZT4LWMQw6Rh7Kpd.ism/dash/',
1283 'protocol': 'http_dash_segments',
1284 'audio_ext': 'm4a',
1285 'video_ext': 'none',
1286 'abr': 128.001,
1287 }, {
1288 'format_id': 'video=100000',
1289 'manifest_url': 'https://sdn-global-streaming-cache-3qsdn.akamaized.net/stream/3144/files/17/07/672975/3144-kZT4LWMQw6Rh7Kpd.ism/manifest.mpd',
1290 'ext': 'mp4',
1291 'width': 336,
1292 'height': 144,
1293 'tbr': 100,
1294 'format_note': 'DASH video',
1295 'container': 'mp4_dash',
1296 'vcodec': 'avc1.4D401F',
1297 'acodec': 'none',
1298 'url': 'https://sdn-global-streaming-cache-3qsdn.akamaized.net/stream/3144/files/17/07/672975/3144-kZT4LWMQw6Rh7Kpd.ism/manifest.mpd',
1299 'fragment_base_url': 'https://sdn-global-streaming-cache-3qsdn.akamaized.net/stream/3144/files/17/07/672975/3144-kZT4LWMQw6Rh7Kpd.ism/dash/',
1300 'protocol': 'http_dash_segments',
1301 'video_ext': 'mp4',
1302 'audio_ext': 'none',
1303 'vbr': 100,
1304 }, {
1305 'format_id': 'video=326000',
1306 'manifest_url': 'https://sdn-global-streaming-cache-3qsdn.akamaized.net/stream/3144/files/17/07/672975/3144-kZT4LWMQw6Rh7Kpd.ism/manifest.mpd',
1307 'ext': 'mp4',
1308 'width': 562,
1309 'height': 240,
1310 'tbr': 326,
1311 'format_note': 'DASH video',
1312 'container': 'mp4_dash',
1313 'vcodec': 'avc1.4D401F',
1314 'acodec': 'none',
1315 'url': 'https://sdn-global-streaming-cache-3qsdn.akamaized.net/stream/3144/files/17/07/672975/3144-kZT4LWMQw6Rh7Kpd.ism/manifest.mpd',
1316 'fragment_base_url': 'https://sdn-global-streaming-cache-3qsdn.akamaized.net/stream/3144/files/17/07/672975/3144-kZT4LWMQw6Rh7Kpd.ism/dash/',
1317 'protocol': 'http_dash_segments',
1318 'video_ext': 'mp4',
1319 'audio_ext': 'none',
1320 'vbr': 326,
1321 }, {
1322 'format_id': 'video=698000',
1323 'manifest_url': 'https://sdn-global-streaming-cache-3qsdn.akamaized.net/stream/3144/files/17/07/672975/3144-kZT4LWMQw6Rh7Kpd.ism/manifest.mpd',
1324 'ext': 'mp4',
1325 'width': 844,
1326 'height': 360,
1327 'tbr': 698,
1328 'format_note': 'DASH video',
1329 'container': 'mp4_dash',
1330 'vcodec': 'avc1.4D401F',
1331 'acodec': 'none',
1332 'url': 'https://sdn-global-streaming-cache-3qsdn.akamaized.net/stream/3144/files/17/07/672975/3144-kZT4LWMQw6Rh7Kpd.ism/manifest.mpd',
1333 'fragment_base_url': 'https://sdn-global-streaming-cache-3qsdn.akamaized.net/stream/3144/files/17/07/672975/3144-kZT4LWMQw6Rh7Kpd.ism/dash/',
1334 'protocol': 'http_dash_segments',
1335 'video_ext': 'mp4',
1336 'audio_ext': 'none',
1337 'vbr': 698,
1338 }, {
1339 'format_id': 'video=1493000',
1340 'manifest_url': 'https://sdn-global-streaming-cache-3qsdn.akamaized.net/stream/3144/files/17/07/672975/3144-kZT4LWMQw6Rh7Kpd.ism/manifest.mpd',
1341 'ext': 'mp4',
1342 'width': 1126,
1343 'height': 480,
1344 'tbr': 1493,
1345 'format_note': 'DASH video',
1346 'container': 'mp4_dash',
1347 'vcodec': 'avc1.4D401F',
1348 'acodec': 'none',
1349 'url': 'https://sdn-global-streaming-cache-3qsdn.akamaized.net/stream/3144/files/17/07/672975/3144-kZT4LWMQw6Rh7Kpd.ism/manifest.mpd',
1350 'fragment_base_url': 'https://sdn-global-streaming-cache-3qsdn.akamaized.net/stream/3144/files/17/07/672975/3144-kZT4LWMQw6Rh7Kpd.ism/dash/',
1351 'protocol': 'http_dash_segments',
1352 'video_ext': 'mp4',
1353 'audio_ext': 'none',
1354 'vbr': 1493,
1355 }, {
1356 'format_id': 'video=4482000',
1357 'manifest_url': 'https://sdn-global-streaming-cache-3qsdn.akamaized.net/stream/3144/files/17/07/672975/3144-kZT4LWMQw6Rh7Kpd.ism/manifest.mpd',
1358 'ext': 'mp4',
1359 'width': 1688,
1360 'height': 720,
1361 'tbr': 4482,
1362 'format_note': 'DASH video',
1363 'container': 'mp4_dash',
1364 'vcodec': 'avc1.4D401F',
1365 'acodec': 'none',
1366 'url': 'https://sdn-global-streaming-cache-3qsdn.akamaized.net/stream/3144/files/17/07/672975/3144-kZT4LWMQw6Rh7Kpd.ism/manifest.mpd',
1367 'fragment_base_url': 'https://sdn-global-streaming-cache-3qsdn.akamaized.net/stream/3144/files/17/07/672975/3144-kZT4LWMQw6Rh7Kpd.ism/dash/',
1368 'protocol': 'http_dash_segments',
1369 'video_ext': 'mp4',
1370 'audio_ext': 'none',
1371 'vbr': 4482,
1374 'en': [
1376 'ext': 'mp4',
1377 'manifest_url': 'https://sdn-global-streaming-cache-3qsdn.akamaized.net/stream/3144/files/17/07/672975/3144-kZT4LWMQw6Rh7Kpd.ism/manifest.mpd',
1378 'url': 'https://sdn-global-streaming-cache-3qsdn.akamaized.net/stream/3144/files/17/07/672975/3144-kZT4LWMQw6Rh7Kpd.ism/manifest.mpd',
1379 'fragment_base_url': 'https://sdn-global-streaming-cache-3qsdn.akamaized.net/stream/3144/files/17/07/672975/3144-kZT4LWMQw6Rh7Kpd.ism/dash/',
1380 'protocol': 'http_dash_segments',
1387 for mpd_file, mpd_url, mpd_base_url, expected_formats, expected_subtitles in _TEST_CASES:
1388 with open(f'./test/testdata/mpd/{mpd_file}.mpd', encoding='utf-8') as f:
1389 formats, subtitles = self.ie._parse_mpd_formats_and_subtitles(
1390 compat_etree_fromstring(f.read().encode()),
1391 mpd_base_url=mpd_base_url, mpd_url=mpd_url)
1392 self.ie._sort_formats(formats)
1393 expect_value(self, formats, expected_formats, None)
1394 expect_value(self, subtitles, expected_subtitles, None)
1396 def test_parse_ism_formats(self):
1397 _TEST_CASES = [
1399 'sintel',
1400 'https://sdn-global-streaming-cache-3qsdn.akamaized.net/stream/3144/files/17/07/672975/3144-kZT4LWMQw6Rh7Kpd.ism/Manifest',
1402 'format_id': 'audio-128',
1403 'url': 'https://sdn-global-streaming-cache-3qsdn.akamaized.net/stream/3144/files/17/07/672975/3144-kZT4LWMQw6Rh7Kpd.ism/Manifest',
1404 'manifest_url': 'https://sdn-global-streaming-cache-3qsdn.akamaized.net/stream/3144/files/17/07/672975/3144-kZT4LWMQw6Rh7Kpd.ism/Manifest',
1405 'ext': 'isma',
1406 'tbr': 128,
1407 'asr': 48000,
1408 'vcodec': 'none',
1409 'acodec': 'AACL',
1410 'protocol': 'ism',
1411 'audio_channels': 2,
1412 '_download_params': {
1413 'stream_type': 'audio',
1414 'duration': 8880746666,
1415 'timescale': 10000000,
1416 'width': 0,
1417 'height': 0,
1418 'fourcc': 'AACL',
1419 'codec_private_data': '1190',
1420 'sampling_rate': 48000,
1421 'channels': 2,
1422 'bits_per_sample': 16,
1423 'nal_unit_length_field': 4,
1425 }, {
1426 'format_id': 'video-100',
1427 'url': 'https://sdn-global-streaming-cache-3qsdn.akamaized.net/stream/3144/files/17/07/672975/3144-kZT4LWMQw6Rh7Kpd.ism/Manifest',
1428 'manifest_url': 'https://sdn-global-streaming-cache-3qsdn.akamaized.net/stream/3144/files/17/07/672975/3144-kZT4LWMQw6Rh7Kpd.ism/Manifest',
1429 'ext': 'ismv',
1430 'width': 336,
1431 'height': 144,
1432 'tbr': 100,
1433 'vcodec': 'AVC1',
1434 'acodec': 'none',
1435 'protocol': 'ism',
1436 '_download_params': {
1437 'stream_type': 'video',
1438 'duration': 8880746666,
1439 'timescale': 10000000,
1440 'width': 336,
1441 'height': 144,
1442 'fourcc': 'AVC1',
1443 'codec_private_data': '00000001674D401FDA0544EFFC2D002CBC40000003004000000C03C60CA80000000168EF32C8',
1444 'channels': 2,
1445 'bits_per_sample': 16,
1446 'nal_unit_length_field': 4,
1448 }, {
1449 'format_id': 'video-326',
1450 'url': 'https://sdn-global-streaming-cache-3qsdn.akamaized.net/stream/3144/files/17/07/672975/3144-kZT4LWMQw6Rh7Kpd.ism/Manifest',
1451 'manifest_url': 'https://sdn-global-streaming-cache-3qsdn.akamaized.net/stream/3144/files/17/07/672975/3144-kZT4LWMQw6Rh7Kpd.ism/Manifest',
1452 'ext': 'ismv',
1453 'width': 562,
1454 'height': 240,
1455 'tbr': 326,
1456 'vcodec': 'AVC1',
1457 'acodec': 'none',
1458 'protocol': 'ism',
1459 '_download_params': {
1460 'stream_type': 'video',
1461 'duration': 8880746666,
1462 'timescale': 10000000,
1463 'width': 562,
1464 'height': 240,
1465 'fourcc': 'AVC1',
1466 'codec_private_data': '00000001674D401FDA0241FE23FFC3BC83BA44000003000400000300C03C60CA800000000168EF32C8',
1467 'channels': 2,
1468 'bits_per_sample': 16,
1469 'nal_unit_length_field': 4,
1471 }, {
1472 'format_id': 'video-698',
1473 'url': 'https://sdn-global-streaming-cache-3qsdn.akamaized.net/stream/3144/files/17/07/672975/3144-kZT4LWMQw6Rh7Kpd.ism/Manifest',
1474 'manifest_url': 'https://sdn-global-streaming-cache-3qsdn.akamaized.net/stream/3144/files/17/07/672975/3144-kZT4LWMQw6Rh7Kpd.ism/Manifest',
1475 'ext': 'ismv',
1476 'width': 844,
1477 'height': 360,
1478 'tbr': 698,
1479 'vcodec': 'AVC1',
1480 'acodec': 'none',
1481 'protocol': 'ism',
1482 '_download_params': {
1483 'stream_type': 'video',
1484 'duration': 8880746666,
1485 'timescale': 10000000,
1486 'width': 844,
1487 'height': 360,
1488 'fourcc': 'AVC1',
1489 'codec_private_data': '00000001674D401FDA0350BFB97FF06AF06AD1000003000100000300300F1832A00000000168EF32C8',
1490 'channels': 2,
1491 'bits_per_sample': 16,
1492 'nal_unit_length_field': 4,
1494 }, {
1495 'format_id': 'video-1493',
1496 'url': 'https://sdn-global-streaming-cache-3qsdn.akamaized.net/stream/3144/files/17/07/672975/3144-kZT4LWMQw6Rh7Kpd.ism/Manifest',
1497 'manifest_url': 'https://sdn-global-streaming-cache-3qsdn.akamaized.net/stream/3144/files/17/07/672975/3144-kZT4LWMQw6Rh7Kpd.ism/Manifest',
1498 'ext': 'ismv',
1499 'width': 1126,
1500 'height': 480,
1501 'tbr': 1493,
1502 'vcodec': 'AVC1',
1503 'acodec': 'none',
1504 'protocol': 'ism',
1505 '_download_params': {
1506 'stream_type': 'video',
1507 'duration': 8880746666,
1508 'timescale': 10000000,
1509 'width': 1126,
1510 'height': 480,
1511 'fourcc': 'AVC1',
1512 'codec_private_data': '00000001674D401FDA011C3DE6FFF0D890D871000003000100000300300F1832A00000000168EF32C8',
1513 'channels': 2,
1514 'bits_per_sample': 16,
1515 'nal_unit_length_field': 4,
1517 }, {
1518 'format_id': 'video-4482',
1519 'url': 'https://sdn-global-streaming-cache-3qsdn.akamaized.net/stream/3144/files/17/07/672975/3144-kZT4LWMQw6Rh7Kpd.ism/Manifest',
1520 'manifest_url': 'https://sdn-global-streaming-cache-3qsdn.akamaized.net/stream/3144/files/17/07/672975/3144-kZT4LWMQw6Rh7Kpd.ism/Manifest',
1521 'ext': 'ismv',
1522 'width': 1688,
1523 'height': 720,
1524 'tbr': 4482,
1525 'vcodec': 'AVC1',
1526 'acodec': 'none',
1527 'protocol': 'ism',
1528 '_download_params': {
1529 'stream_type': 'video',
1530 'duration': 8880746666,
1531 'timescale': 10000000,
1532 'width': 1688,
1533 'height': 720,
1534 'fourcc': 'AVC1',
1535 'codec_private_data': '00000001674D401FDA01A816F97FFC1ABC1AB440000003004000000C03C60CA80000000168EF32C8',
1536 'channels': 2,
1537 'bits_per_sample': 16,
1538 'nal_unit_length_field': 4,
1542 'eng': [
1544 'ext': 'ismt',
1545 'protocol': 'ism',
1546 'url': 'https://sdn-global-streaming-cache-3qsdn.akamaized.net/stream/3144/files/17/07/672975/3144-kZT4LWMQw6Rh7Kpd.ism/Manifest',
1547 'manifest_url': 'https://sdn-global-streaming-cache-3qsdn.akamaized.net/stream/3144/files/17/07/672975/3144-kZT4LWMQw6Rh7Kpd.ism/Manifest',
1548 '_download_params': {
1549 'stream_type': 'text',
1550 'duration': 8880746666,
1551 'timescale': 10000000,
1552 'fourcc': 'TTML',
1553 'codec_private_data': '',
1560 'ec-3_test',
1561 'https://smstr01.dmm.t-online.de/smooth24/smoothstream_m1/streaming/sony/9221438342941275747/636887760842957027/25_km_h-Trailer-9221571562372022953_deu_20_1300k_HD_H_264_ISMV.ism/Manifest',
1563 'format_id': 'audio_deu-127',
1564 'url': 'https://smstr01.dmm.t-online.de/smooth24/smoothstream_m1/streaming/sony/9221438342941275747/636887760842957027/25_km_h-Trailer-9221571562372022953_deu_20_1300k_HD_H_264_ISMV.ism/Manifest',
1565 'manifest_url': 'https://smstr01.dmm.t-online.de/smooth24/smoothstream_m1/streaming/sony/9221438342941275747/636887760842957027/25_km_h-Trailer-9221571562372022953_deu_20_1300k_HD_H_264_ISMV.ism/Manifest',
1566 'ext': 'isma',
1567 'tbr': 127,
1568 'asr': 48000,
1569 'vcodec': 'none',
1570 'acodec': 'AACL',
1571 'protocol': 'ism',
1572 'language': 'deu',
1573 'audio_channels': 2,
1574 '_download_params': {
1575 'stream_type': 'audio',
1576 'duration': 370000000,
1577 'timescale': 10000000,
1578 'width': 0,
1579 'height': 0,
1580 'fourcc': 'AACL',
1581 'language': 'deu',
1582 'codec_private_data': '1190',
1583 'sampling_rate': 48000,
1584 'channels': 2,
1585 'bits_per_sample': 16,
1586 'nal_unit_length_field': 4,
1588 }, {
1589 'format_id': 'audio_deu_1-224',
1590 'url': 'https://smstr01.dmm.t-online.de/smooth24/smoothstream_m1/streaming/sony/9221438342941275747/636887760842957027/25_km_h-Trailer-9221571562372022953_deu_20_1300k_HD_H_264_ISMV.ism/Manifest',
1591 'manifest_url': 'https://smstr01.dmm.t-online.de/smooth24/smoothstream_m1/streaming/sony/9221438342941275747/636887760842957027/25_km_h-Trailer-9221571562372022953_deu_20_1300k_HD_H_264_ISMV.ism/Manifest',
1592 'ext': 'isma',
1593 'tbr': 224,
1594 'asr': 48000,
1595 'vcodec': 'none',
1596 'acodec': 'EC-3',
1597 'protocol': 'ism',
1598 'language': 'deu',
1599 'audio_channels': 6,
1600 '_download_params': {
1601 'stream_type': 'audio',
1602 'duration': 370000000,
1603 'timescale': 10000000,
1604 'width': 0,
1605 'height': 0,
1606 'fourcc': 'EC-3',
1607 'language': 'deu',
1608 'codec_private_data': '00063F000000AF87FBA7022DFB42A4D405CD93843BDD0700200F00',
1609 'sampling_rate': 48000,
1610 'channels': 6,
1611 'bits_per_sample': 16,
1612 'nal_unit_length_field': 4,
1614 }, {
1615 'format_id': 'video_deu-23',
1616 'url': 'https://smstr01.dmm.t-online.de/smooth24/smoothstream_m1/streaming/sony/9221438342941275747/636887760842957027/25_km_h-Trailer-9221571562372022953_deu_20_1300k_HD_H_264_ISMV.ism/Manifest',
1617 'manifest_url': 'https://smstr01.dmm.t-online.de/smooth24/smoothstream_m1/streaming/sony/9221438342941275747/636887760842957027/25_km_h-Trailer-9221571562372022953_deu_20_1300k_HD_H_264_ISMV.ism/Manifest',
1618 'ext': 'ismv',
1619 'width': 384,
1620 'height': 216,
1621 'tbr': 23,
1622 'vcodec': 'AVC1',
1623 'acodec': 'none',
1624 'protocol': 'ism',
1625 'language': 'deu',
1626 '_download_params': {
1627 'stream_type': 'video',
1628 'duration': 370000000,
1629 'timescale': 10000000,
1630 'width': 384,
1631 'height': 216,
1632 'fourcc': 'AVC1',
1633 'language': 'deu',
1634 'codec_private_data': '000000016742C00CDB06077E5C05A808080A00000300020000030009C0C02EE0177CC6300F142AE00000000168CA8DC8',
1635 'channels': 2,
1636 'bits_per_sample': 16,
1637 'nal_unit_length_field': 4,
1639 }, {
1640 'format_id': 'video_deu-403',
1641 'url': 'https://smstr01.dmm.t-online.de/smooth24/smoothstream_m1/streaming/sony/9221438342941275747/636887760842957027/25_km_h-Trailer-9221571562372022953_deu_20_1300k_HD_H_264_ISMV.ism/Manifest',
1642 'manifest_url': 'https://smstr01.dmm.t-online.de/smooth24/smoothstream_m1/streaming/sony/9221438342941275747/636887760842957027/25_km_h-Trailer-9221571562372022953_deu_20_1300k_HD_H_264_ISMV.ism/Manifest',
1643 'ext': 'ismv',
1644 'width': 400,
1645 'height': 224,
1646 'tbr': 403,
1647 'vcodec': 'AVC1',
1648 'acodec': 'none',
1649 'protocol': 'ism',
1650 'language': 'deu',
1651 '_download_params': {
1652 'stream_type': 'video',
1653 'duration': 370000000,
1654 'timescale': 10000000,
1655 'width': 400,
1656 'height': 224,
1657 'fourcc': 'AVC1',
1658 'language': 'deu',
1659 'codec_private_data': '00000001674D4014E98323B602D4040405000003000100000300320F1429380000000168EAECF2',
1660 'channels': 2,
1661 'bits_per_sample': 16,
1662 'nal_unit_length_field': 4,
1664 }, {
1665 'format_id': 'video_deu-680',
1666 'url': 'https://smstr01.dmm.t-online.de/smooth24/smoothstream_m1/streaming/sony/9221438342941275747/636887760842957027/25_km_h-Trailer-9221571562372022953_deu_20_1300k_HD_H_264_ISMV.ism/Manifest',
1667 'manifest_url': 'https://smstr01.dmm.t-online.de/smooth24/smoothstream_m1/streaming/sony/9221438342941275747/636887760842957027/25_km_h-Trailer-9221571562372022953_deu_20_1300k_HD_H_264_ISMV.ism/Manifest',
1668 'ext': 'ismv',
1669 'width': 640,
1670 'height': 360,
1671 'tbr': 680,
1672 'vcodec': 'AVC1',
1673 'acodec': 'none',
1674 'protocol': 'ism',
1675 'language': 'deu',
1676 '_download_params': {
1677 'stream_type': 'video',
1678 'duration': 370000000,
1679 'timescale': 10000000,
1680 'width': 640,
1681 'height': 360,
1682 'fourcc': 'AVC1',
1683 'language': 'deu',
1684 'codec_private_data': '00000001674D401EE981405FF2E02D4040405000000300100000030320F162D3800000000168EAECF2',
1685 'channels': 2,
1686 'bits_per_sample': 16,
1687 'nal_unit_length_field': 4,
1689 }, {
1690 'format_id': 'video_deu-1253',
1691 'url': 'https://smstr01.dmm.t-online.de/smooth24/smoothstream_m1/streaming/sony/9221438342941275747/636887760842957027/25_km_h-Trailer-9221571562372022953_deu_20_1300k_HD_H_264_ISMV.ism/Manifest',
1692 'manifest_url': 'https://smstr01.dmm.t-online.de/smooth24/smoothstream_m1/streaming/sony/9221438342941275747/636887760842957027/25_km_h-Trailer-9221571562372022953_deu_20_1300k_HD_H_264_ISMV.ism/Manifest',
1693 'ext': 'ismv',
1694 'width': 640,
1695 'height': 360,
1696 'tbr': 1253,
1697 'vcodec': 'AVC1',
1698 'acodec': 'none',
1699 'protocol': 'ism',
1700 'vbr': 1253,
1701 'language': 'deu',
1702 '_download_params': {
1703 'stream_type': 'video',
1704 'duration': 370000000,
1705 'timescale': 10000000,
1706 'width': 640,
1707 'height': 360,
1708 'fourcc': 'AVC1',
1709 'language': 'deu',
1710 'codec_private_data': '00000001674D401EE981405FF2E02D4040405000000300100000030320F162D3800000000168EAECF2',
1711 'channels': 2,
1712 'bits_per_sample': 16,
1713 'nal_unit_length_field': 4,
1715 }, {
1716 'format_id': 'video_deu-2121',
1717 'url': 'https://smstr01.dmm.t-online.de/smooth24/smoothstream_m1/streaming/sony/9221438342941275747/636887760842957027/25_km_h-Trailer-9221571562372022953_deu_20_1300k_HD_H_264_ISMV.ism/Manifest',
1718 'manifest_url': 'https://smstr01.dmm.t-online.de/smooth24/smoothstream_m1/streaming/sony/9221438342941275747/636887760842957027/25_km_h-Trailer-9221571562372022953_deu_20_1300k_HD_H_264_ISMV.ism/Manifest',
1719 'ext': 'ismv',
1720 'width': 768,
1721 'height': 432,
1722 'tbr': 2121,
1723 'vcodec': 'AVC1',
1724 'acodec': 'none',
1725 'protocol': 'ism',
1726 'language': 'deu',
1727 '_download_params': {
1728 'stream_type': 'video',
1729 'duration': 370000000,
1730 'timescale': 10000000,
1731 'width': 768,
1732 'height': 432,
1733 'fourcc': 'AVC1',
1734 'language': 'deu',
1735 'codec_private_data': '00000001674D401EECA0601BD80B50101014000003000400000300C83C58B6580000000168E93B3C80',
1736 'channels': 2,
1737 'bits_per_sample': 16,
1738 'nal_unit_length_field': 4,
1740 }, {
1741 'format_id': 'video_deu-3275',
1742 'url': 'https://smstr01.dmm.t-online.de/smooth24/smoothstream_m1/streaming/sony/9221438342941275747/636887760842957027/25_km_h-Trailer-9221571562372022953_deu_20_1300k_HD_H_264_ISMV.ism/Manifest',
1743 'manifest_url': 'https://smstr01.dmm.t-online.de/smooth24/smoothstream_m1/streaming/sony/9221438342941275747/636887760842957027/25_km_h-Trailer-9221571562372022953_deu_20_1300k_HD_H_264_ISMV.ism/Manifest',
1744 'ext': 'ismv',
1745 'width': 1280,
1746 'height': 720,
1747 'tbr': 3275,
1748 'vcodec': 'AVC1',
1749 'acodec': 'none',
1750 'protocol': 'ism',
1751 'language': 'deu',
1752 '_download_params': {
1753 'stream_type': 'video',
1754 'duration': 370000000,
1755 'timescale': 10000000,
1756 'width': 1280,
1757 'height': 720,
1758 'fourcc': 'AVC1',
1759 'language': 'deu',
1760 'codec_private_data': '00000001674D4020ECA02802DD80B501010140000003004000000C83C60C65800000000168E93B3C80',
1761 'channels': 2,
1762 'bits_per_sample': 16,
1763 'nal_unit_length_field': 4,
1765 }, {
1766 'format_id': 'video_deu-5300',
1767 'url': 'https://smstr01.dmm.t-online.de/smooth24/smoothstream_m1/streaming/sony/9221438342941275747/636887760842957027/25_km_h-Trailer-9221571562372022953_deu_20_1300k_HD_H_264_ISMV.ism/Manifest',
1768 'manifest_url': 'https://smstr01.dmm.t-online.de/smooth24/smoothstream_m1/streaming/sony/9221438342941275747/636887760842957027/25_km_h-Trailer-9221571562372022953_deu_20_1300k_HD_H_264_ISMV.ism/Manifest',
1769 'ext': 'ismv',
1770 'width': 1920,
1771 'height': 1080,
1772 'tbr': 5300,
1773 'vcodec': 'AVC1',
1774 'acodec': 'none',
1775 'protocol': 'ism',
1776 'language': 'deu',
1777 '_download_params': {
1778 'stream_type': 'video',
1779 'duration': 370000000,
1780 'timescale': 10000000,
1781 'width': 1920,
1782 'height': 1080,
1783 'fourcc': 'AVC1',
1784 'language': 'deu',
1785 'codec_private_data': '00000001674D4028ECA03C0113F2E02D4040405000000300100000030320F18319600000000168E93B3C80',
1786 'channels': 2,
1787 'bits_per_sample': 16,
1788 'nal_unit_length_field': 4,
1790 }, {
1791 'format_id': 'video_deu-8079',
1792 'url': 'https://smstr01.dmm.t-online.de/smooth24/smoothstream_m1/streaming/sony/9221438342941275747/636887760842957027/25_km_h-Trailer-9221571562372022953_deu_20_1300k_HD_H_264_ISMV.ism/Manifest',
1793 'manifest_url': 'https://smstr01.dmm.t-online.de/smooth24/smoothstream_m1/streaming/sony/9221438342941275747/636887760842957027/25_km_h-Trailer-9221571562372022953_deu_20_1300k_HD_H_264_ISMV.ism/Manifest',
1794 'ext': 'ismv',
1795 'width': 1920,
1796 'height': 1080,
1797 'tbr': 8079,
1798 'vcodec': 'AVC1',
1799 'acodec': 'none',
1800 'protocol': 'ism',
1801 'language': 'deu',
1802 '_download_params': {
1803 'stream_type': 'video',
1804 'duration': 370000000,
1805 'timescale': 10000000,
1806 'width': 1920,
1807 'height': 1080,
1808 'fourcc': 'AVC1',
1809 'language': 'deu',
1810 'codec_private_data': '00000001674D4028ECA03C0113F2E02D4040405000000300100000030320F18319600000000168E93B3C80',
1811 'channels': 2,
1812 'bits_per_sample': 16,
1813 'nal_unit_length_field': 4,
1820 for ism_file, ism_url, expected_formats, expected_subtitles in _TEST_CASES:
1821 with open(f'./test/testdata/ism/{ism_file}.Manifest', encoding='utf-8') as f:
1822 formats, subtitles = self.ie._parse_ism_formats_and_subtitles(
1823 compat_etree_fromstring(f.read().encode()), ism_url=ism_url)
1824 self.ie._sort_formats(formats)
1825 expect_value(self, formats, expected_formats, None)
1826 expect_value(self, subtitles, expected_subtitles, None)
1828 def test_parse_f4m_formats(self):
1829 _TEST_CASES = [
1831 # https://github.com/ytdl-org/youtube-dl/issues/14660
1832 'custom_base_url',
1833 'http://api.new.livestream.com/accounts/6115179/events/6764928/videos/144884262.f4m',
1835 'manifest_url': 'http://api.new.livestream.com/accounts/6115179/events/6764928/videos/144884262.f4m',
1836 'ext': 'flv',
1837 'format_id': '2148',
1838 'protocol': 'f4m',
1839 'tbr': 2148,
1840 'width': 1280,
1841 'height': 720,
1846 for f4m_file, f4m_url, expected_formats in _TEST_CASES:
1847 with open(f'./test/testdata/f4m/{f4m_file}.f4m', encoding='utf-8') as f:
1848 formats = self.ie._parse_f4m_formats(
1849 compat_etree_fromstring(f.read().encode()),
1850 f4m_url, None)
1851 self.ie._sort_formats(formats)
1852 expect_value(self, formats, expected_formats, None)
1854 def test_parse_xspf(self):
1855 _TEST_CASES = [
1857 'foo_xspf',
1858 'https://example.org/src/foo_xspf.xspf',
1860 'id': 'foo_xspf',
1861 'title': 'Pandemonium',
1862 'description': 'Visit http://bigbrother404.bandcamp.com',
1863 'duration': 202.416,
1864 'formats': [{
1865 'manifest_url': 'https://example.org/src/foo_xspf.xspf',
1866 'url': 'https://example.org/src/cd1/track%201.mp3',
1868 }, {
1869 'id': 'foo_xspf',
1870 'title': 'Final Cartridge (Nichico Twelve Remix)',
1871 'description': 'Visit http://bigbrother404.bandcamp.com',
1872 'duration': 255.857,
1873 'formats': [{
1874 'manifest_url': 'https://example.org/src/foo_xspf.xspf',
1875 'url': 'https://example.org/%E3%83%88%E3%83%A9%E3%83%83%E3%82%AF%E3%80%80%EF%BC%92.mp3',
1877 }, {
1878 'id': 'foo_xspf',
1879 'title': 'Rebuilding Nightingale',
1880 'description': 'Visit http://bigbrother404.bandcamp.com',
1881 'duration': 287.915,
1882 'formats': [{
1883 'manifest_url': 'https://example.org/src/foo_xspf.xspf',
1884 'url': 'https://example.org/src/track3.mp3',
1885 }, {
1886 'manifest_url': 'https://example.org/src/foo_xspf.xspf',
1887 'url': 'https://example.com/track3.mp3',
1893 for xspf_file, xspf_url, expected_entries in _TEST_CASES:
1894 with open(f'./test/testdata/xspf/{xspf_file}.xspf', encoding='utf-8') as f:
1895 entries = self.ie._parse_xspf(
1896 compat_etree_fromstring(f.read().encode()),
1897 xspf_file, xspf_url=xspf_url, xspf_base_url=xspf_url)
1898 expect_value(self, entries, expected_entries, None)
1899 for i in range(len(entries)):
1900 expect_dict(self, entries[i], expected_entries[i])
1902 def test_response_with_expected_status_returns_content(self):
1903 # Checks for mitigations against the effects of
1904 # <https://bugs.python.org/issue15002> that affect Python 3.4.1+, which
1905 # manifest as `_download_webpage`, `_download_xml`, `_download_json`,
1906 # or the underlying `_download_webpage_handle` returning no content
1907 # when a response matches `expected_status`.
1909 httpd = http.server.HTTPServer(
1910 ('127.0.0.1', 0), InfoExtractorTestRequestHandler)
1911 port = http_server_port(httpd)
1912 server_thread = threading.Thread(target=httpd.serve_forever)
1913 server_thread.daemon = True
1914 server_thread.start()
1916 (content, urlh) = self.ie._download_webpage_handle(
1917 f'http://127.0.0.1:{port}/teapot', None,
1918 expected_status=TEAPOT_RESPONSE_STATUS)
1919 self.assertEqual(content, TEAPOT_RESPONSE_BODY)
1921 def test_search_nextjs_data(self):
1922 data = '<script id="__NEXT_DATA__" type="application/json">{"props":{}}</script>'
1923 self.assertEqual(self.ie._search_nextjs_data(data, None), {'props': {}})
1924 self.assertEqual(self.ie._search_nextjs_data('', None, fatal=False), {})
1925 self.assertEqual(self.ie._search_nextjs_data('', None, default=None), None)
1926 self.assertEqual(self.ie._search_nextjs_data('', None, default={}), {})
1927 with self.assertWarns(DeprecationWarning):
1928 self.assertEqual(self.ie._search_nextjs_data('', None, default='{}'), {})
1931 if __name__ == '__main__':
1932 unittest.main()