[extractor/crunchyroll:beta] Improve handling of hardsubs (#5041)
[yt-dlp3.git] / test / test_InfoExtractor.py
blobf57a29ffc7becd1fb0cf808b258d5a94544cb49f
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 pass
47 class TestInfoExtractor(unittest.TestCase):
48 def setUp(self):
49 self.ie = DummyIE(FakeYDL())
51 def test_ie_key(self):
52 self.assertEqual(get_info_extractor(YoutubeIE.ie_key()), YoutubeIE)
54 def test_html_search_regex(self):
55 html = '<p id="foo">Watch this <a href="http://www.youtube.com/watch?v=BaW_jenozKc">video</a></p>'
56 search = lambda re, *args: self.ie._html_search_regex(re, html, *args)
57 self.assertEqual(search(r'<p id="foo">(.+?)</p>', 'foo'), 'Watch this video')
59 def test_opengraph(self):
60 ie = self.ie
61 html = '''
62 <meta name="og:title" content='Foo'/>
63 <meta content="Some video's description " name="og:description"/>
64 <meta property='og:image' content='http://domain.com/pic.jpg?key1=val1&amp;key2=val2'/>
65 <meta content='application/x-shockwave-flash' property='og:video:type'>
66 <meta content='Foo' property=og:foobar>
67 <meta name="og:test1" content='foo > < bar'/>
68 <meta name="og:test2" content="foo >//< bar"/>
69 <meta property=og-test3 content='Ill-formatted opengraph'/>
70 '''
71 self.assertEqual(ie._og_search_title(html), 'Foo')
72 self.assertEqual(ie._og_search_description(html), 'Some video\'s description ')
73 self.assertEqual(ie._og_search_thumbnail(html), 'http://domain.com/pic.jpg?key1=val1&key2=val2')
74 self.assertEqual(ie._og_search_video_url(html, default=None), None)
75 self.assertEqual(ie._og_search_property('foobar', html), 'Foo')
76 self.assertEqual(ie._og_search_property('test1', html), 'foo > < bar')
77 self.assertEqual(ie._og_search_property('test2', html), 'foo >//< bar')
78 self.assertEqual(ie._og_search_property('test3', html), 'Ill-formatted opengraph')
79 self.assertEqual(ie._og_search_property(('test0', 'test1'), html), 'foo > < bar')
80 self.assertRaises(RegexNotFoundError, ie._og_search_property, 'test0', html, None, fatal=True)
81 self.assertRaises(RegexNotFoundError, ie._og_search_property, ('test0', 'test00'), html, None, fatal=True)
83 def test_html_search_meta(self):
84 ie = self.ie
85 html = '''
86 <meta name="a" content="1" />
87 <meta name='b' content='2'>
88 <meta name="c" content='3'>
89 <meta name=d content='4'>
90 <meta property="e" content='5' >
91 <meta content="6" name="f">
92 '''
94 self.assertEqual(ie._html_search_meta('a', html), '1')
95 self.assertEqual(ie._html_search_meta('b', html), '2')
96 self.assertEqual(ie._html_search_meta('c', html), '3')
97 self.assertEqual(ie._html_search_meta('d', html), '4')
98 self.assertEqual(ie._html_search_meta('e', html), '5')
99 self.assertEqual(ie._html_search_meta('f', html), '6')
100 self.assertEqual(ie._html_search_meta(('a', 'b', 'c'), html), '1')
101 self.assertEqual(ie._html_search_meta(('c', 'b', 'a'), html), '3')
102 self.assertEqual(ie._html_search_meta(('z', 'x', 'c'), html), '3')
103 self.assertRaises(RegexNotFoundError, ie._html_search_meta, 'z', html, None, fatal=True)
104 self.assertRaises(RegexNotFoundError, ie._html_search_meta, ('z', 'x'), html, None, fatal=True)
106 def test_search_json_ld_realworld(self):
107 _TESTS = [
108 # https://github.com/ytdl-org/youtube-dl/issues/23306
110 r'''<script type="application/ld+json">
112 "@context": "http://schema.org/",
113 "@type": "VideoObject",
114 "name": "1 On 1 With Kleio",
115 "url": "https://www.eporner.com/hd-porn/xN49A1cT3eB/1-On-1-With-Kleio/",
116 "duration": "PT0H12M23S",
117 "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"],
118 "contentUrl": "https://gvideo.eporner.com/xN49A1cT3eB/xN49A1cT3eB.mp4",
119 "embedUrl": "https://www.eporner.com/embed/xN49A1cT3eB/1-On-1-With-Kleio/",
120 "image": "https://static-eu-cdn.eporner.com/thumbs/static4/7/78/780/780814/9_360.jpg",
121 "width": "1920",
122 "height": "1080",
123 "encodingFormat": "mp4",
124 "bitrate": "6617kbps",
125 "isFamilyFriendly": "False",
126 "description": "Kleio Valentien",
127 "uploadDate": "2015-12-05T21:24:35+01:00",
128 "interactionStatistic": {
129 "@type": "InteractionCounter",
130 "interactionType": { "@type": "http://schema.org/WatchAction" },
131 "userInteractionCount": 1120958
132 }, "aggregateRating": {
133 "@type": "AggregateRating",
134 "ratingValue": "88",
135 "ratingCount": "630",
136 "bestRating": "100",
137 "worstRating": "0"
138 }, "actor": [{
139 "@type": "Person",
140 "name": "Kleio Valentien",
141 "url": "https://www.eporner.com/pornstar/kleio-valentien/"
143 </script>''',
145 'title': '1 On 1 With Kleio',
146 'description': 'Kleio Valentien',
147 'url': 'https://gvideo.eporner.com/xN49A1cT3eB/xN49A1cT3eB.mp4',
148 'timestamp': 1449347075,
149 'duration': 743.0,
150 'view_count': 1120958,
151 'width': 1920,
152 'height': 1080,
157 r'''<script type="application/ld+json">
159 "@context": "https://schema.org",
160 "@graph": [
162 "@type": "NewsArticle",
163 "mainEntityOfPage": {
164 "@type": "WebPage",
165 "@id": "https://www.ant1news.gr/Society/article/620286/symmoria-anilikon-dikigoros-thymaton-ithelan-na-toys-apoteleiosoyn"
167 "headline": "Συμμορία ανηλίκων – δικηγόρος θυμάτων: ήθελαν να τους αποτελειώσουν",
168 "name": "Συμμορία ανηλίκων – δικηγόρος θυμάτων: ήθελαν να τους αποτελειώσουν",
169 "description": "Τα παιδιά δέχθηκαν την επίθεση επειδή αρνήθηκαν να γίνουν μέλη της συμμορίας, ανέφερε ο Γ. Ζαχαρόπουλος.",
170 "image": {
171 "@type": "ImageObject",
172 "url": "https://ant1media.azureedge.net/imgHandler/1100/a635c968-be71-447c-bf9c-80d843ece21e.jpg",
173 "width": 1100,
174 "height": 756 },
175 "datePublished": "2021-11-10T08:50:00+03:00",
176 "dateModified": "2021-11-10T08:52:53+03:00",
177 "author": {
178 "@type": "Person",
179 "@id": "https://www.ant1news.gr/",
180 "name": "Ant1news",
181 "image": "https://www.ant1news.gr/images/logo-e5d7e4b3e714c88e8d2eca96130142f6.png",
182 "url": "https://www.ant1news.gr/"
184 "publisher": {
185 "@type": "Organization",
186 "@id": "https://www.ant1news.gr#publisher",
187 "name": "Ant1news",
188 "url": "https://www.ant1news.gr",
189 "logo": {
190 "@type": "ImageObject",
191 "url": "https://www.ant1news.gr/images/logo-e5d7e4b3e714c88e8d2eca96130142f6.png",
192 "width": 400,
193 "height": 400 },
194 "sameAs": [
195 "https://www.facebook.com/Ant1news.gr",
196 "https://twitter.com/antennanews",
197 "https://www.youtube.com/channel/UC0smvAbfczoN75dP0Hw4Pzw",
198 "https://www.instagram.com/ant1news/"
202 "keywords": "μαχαίρωμα,συμμορία ανηλίκων,ΕΙΔΗΣΕΙΣ,ΕΙΔΗΣΕΙΣ ΣΗΜΕΡΑ,ΝΕΑ,Κοινωνία - Ant1news",
205 "articleSection": "Κοινωνία"
209 </script>''',
211 'timestamp': 1636523400,
212 'title': 'md5:91fe569e952e4d146485740ae927662b',
214 {'expected_type': 'NewsArticle'},
217 r'''<script type="application/ld+json">
218 {"url":"/vrtnu/a-z/het-journaal/2021/het-journaal-het-journaal-19u-20211231/",
219 "name":"Het journaal 19u",
220 "description":"Het journaal 19u van vrijdag 31 december 2021.",
221 "potentialAction":{"url":"https://vrtnu.page.link/pfVy6ihgCAJKgHqe8","@type":"ShareAction"},
222 "mainEntityOfPage":{"@id":"1640092242445","@type":"WebPage"},
223 "publication":[{
224 "startDate":"2021-12-31T19:00:00.000+01:00",
225 "endDate":"2022-01-30T23:55:00.000+01:00",
226 "publishedBy":{"name":"een","@type":"Organization"},
227 "publishedOn":{"url":"https://www.vrt.be/vrtnu/","name":"VRT NU","@type":"BroadcastService"},
228 "@id":"pbs-pub-3a7ec233-da95-4c1e-9b2b-cf5fdfebcbe8",
229 "@type":"BroadcastEvent"
231 "video":{
232 "name":"Het journaal - Aflevering 365 (Seizoen 2021)",
233 "description":"Het journaal 19u van vrijdag 31 december 2021. Bekijk aflevering 365 van seizoen 2021 met VRT NU via de site of app.",
234 "thumbnailUrl":"//images.vrt.be/width1280/2021/12/31/80d5ed00-6a64-11ec-b07d-02b7b76bf47f.jpg",
235 "expires":"2022-01-30T23:55:00.000+01:00",
236 "hasPart":[
237 {"name":"Explosie Turnhout","startOffset":70,"@type":"Clip"},
238 {"name":"Jaarwisseling","startOffset":440,"@type":"Clip"},
239 {"name":"Natuurbranden Colorado","startOffset":1179,"@type":"Clip"},
240 {"name":"Klimaatverandering","startOffset":1263,"@type":"Clip"},
241 {"name":"Zacht weer","startOffset":1367,"@type":"Clip"},
242 {"name":"Financiële balans","startOffset":1383,"@type":"Clip"},
243 {"name":"Club Brugge","startOffset":1484,"@type":"Clip"},
244 {"name":"Mentale gezondheid bij topsporters","startOffset":1575,"@type":"Clip"},
245 {"name":"Olympische Winterspelen","startOffset":1728,"@type":"Clip"},
246 {"name":"Sober oudjaar in Nederland","startOffset":1873,"@type":"Clip"}
248 "duration":"PT34M39.23S",
249 "uploadDate":"2021-12-31T19:00:00.000+01:00",
250 "@id":"vid-9457d0c6-b8ac-4aba-b5e1-15aa3a3295b5",
251 "@type":"VideoObject"
253 "genre":["Nieuws en actua"],
254 "episodeNumber":365,
255 "partOfSeries":{"name":"Het journaal","@id":"222831405527","@type":"TVSeries"},
256 "partOfSeason":{"name":"Seizoen 2021","@id":"961809365527","@type":"TVSeason"},
257 "@context":"https://schema.org","@id":"961685295527","@type":"TVEpisode"}</script>
258 ''',
260 'chapters': [
261 {"title": "Explosie Turnhout", "start_time": 70, "end_time": 440},
262 {"title": "Jaarwisseling", "start_time": 440, "end_time": 1179},
263 {"title": "Natuurbranden Colorado", "start_time": 1179, "end_time": 1263},
264 {"title": "Klimaatverandering", "start_time": 1263, "end_time": 1367},
265 {"title": "Zacht weer", "start_time": 1367, "end_time": 1383},
266 {"title": "Financiële balans", "start_time": 1383, "end_time": 1484},
267 {"title": "Club Brugge", "start_time": 1484, "end_time": 1575},
268 {"title": "Mentale gezondheid bij topsporters", "start_time": 1575, "end_time": 1728},
269 {"title": "Olympische Winterspelen", "start_time": 1728, "end_time": 1873},
270 {"title": "Sober oudjaar in Nederland", "start_time": 1873, "end_time": 2079.23}
272 'title': 'Het journaal - Aflevering 365 (Seizoen 2021)'
273 }, {}
276 # test multiple thumbnails in a list
277 r'''
278 <script type="application/ld+json">
279 {"@context":"https://schema.org",
280 "@type":"VideoObject",
281 "thumbnailUrl":["https://www.rainews.it/cropgd/640x360/dl/img/2021/12/30/1640886376927_GettyImages.jpg"]}
282 </script>''',
284 'thumbnails': [{'url': 'https://www.rainews.it/cropgd/640x360/dl/img/2021/12/30/1640886376927_GettyImages.jpg'}],
289 # test single thumbnail
290 r'''
291 <script type="application/ld+json">
292 {"@context":"https://schema.org",
293 "@type":"VideoObject",
294 "thumbnailUrl":"https://www.rainews.it/cropgd/640x360/dl/img/2021/12/30/1640886376927_GettyImages.jpg"}
295 </script>''',
297 'thumbnails': [{'url': 'https://www.rainews.it/cropgd/640x360/dl/img/2021/12/30/1640886376927_GettyImages.jpg'}],
302 for html, expected_dict, search_json_ld_kwargs in _TESTS:
303 expect_dict(
304 self,
305 self.ie._search_json_ld(html, None, **search_json_ld_kwargs),
306 expected_dict
309 def test_download_json(self):
310 uri = encode_data_uri(b'{"foo": "blah"}', 'application/json')
311 self.assertEqual(self.ie._download_json(uri, None), {'foo': 'blah'})
312 uri = encode_data_uri(b'callback({"foo": "blah"})', 'application/javascript')
313 self.assertEqual(self.ie._download_json(uri, None, transform_source=strip_jsonp), {'foo': 'blah'})
314 uri = encode_data_uri(b'{"foo": invalid}', 'application/json')
315 self.assertRaises(ExtractorError, self.ie._download_json, uri, None)
316 self.assertEqual(self.ie._download_json(uri, None, fatal=False), None)
318 def test_parse_html5_media_entries(self):
319 # inline video tag
320 expect_dict(
321 self,
322 self.ie._parse_html5_media_entries(
323 'https://127.0.0.1/video.html',
324 r'<html><video src="/vid.mp4" /></html>', None)[0],
326 'formats': [{
327 'url': 'https://127.0.0.1/vid.mp4',
331 # from https://www.r18.com/
332 # with kpbs in label
333 expect_dict(
334 self,
335 self.ie._parse_html5_media_entries(
336 'https://www.r18.com/',
337 r'''
338 <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">
339 <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">
340 <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">
341 <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">
342 <p>Your browser does not support the video tag.</p>
343 </video>
344 ''', None)[0],
346 'formats': [{
347 'url': 'https://awscc3001.r18.com/litevideo/freepv/m/mgm/mgmr105/mgmr105_sm_w.mp4',
348 'ext': 'mp4',
349 'format_id': '300kbps',
350 'height': 240,
351 'tbr': 300,
352 }, {
353 'url': 'https://awscc3001.r18.com/litevideo/freepv/m/mgm/mgmr105/mgmr105_dm_w.mp4',
354 'ext': 'mp4',
355 'format_id': '1000kbps',
356 'height': 480,
357 'tbr': 1000,
358 }, {
359 'url': 'https://awscc3001.r18.com/litevideo/freepv/m/mgm/mgmr105/mgmr105_dmb_w.mp4',
360 'ext': 'mp4',
361 'format_id': '1500kbps',
362 'height': 740,
363 'tbr': 1500,
365 'thumbnail': '//pics.r18.com/digital/amateur/mgmr105/mgmr105jp.jpg'
368 # from https://www.csfd.cz/
369 # with width and height
370 expect_dict(
371 self,
372 self.ie._parse_html5_media_entries(
373 'https://www.csfd.cz/',
374 r'''
375 <video width="770" height="328" preload="none" controls poster="https://img.csfd.cz/files/images/film/video/preview/163/344/163344118_748d20.png?h360" >
376 <source src="https://video.csfd.cz/files/videos/157/750/157750813/163327358_eac647.mp4" type="video/mp4" width="640" height="360">
377 <source src="https://video.csfd.cz/files/videos/157/750/157750813/163327360_3d2646.mp4" type="video/mp4" width="1280" height="720">
378 <source src="https://video.csfd.cz/files/videos/157/750/157750813/163327356_91f258.mp4" type="video/mp4" width="1920" height="1080">
379 <source src="https://video.csfd.cz/files/videos/157/750/157750813/163327359_962b4a.webm" type="video/webm" width="640" height="360">
380 <source src="https://video.csfd.cz/files/videos/157/750/157750813/163327361_6feee0.webm" type="video/webm" width="1280" height="720">
381 <source src="https://video.csfd.cz/files/videos/157/750/157750813/163327357_8ab472.webm" type="video/webm" width="1920" height="1080">
382 <track src="https://video.csfd.cz/files/subtitles/163/344/163344115_4c388b.srt" type="text/x-srt" kind="subtitles" srclang="cs" label="cs">
383 </video>
384 ''', None)[0],
386 'formats': [{
387 'url': 'https://video.csfd.cz/files/videos/157/750/157750813/163327358_eac647.mp4',
388 'ext': 'mp4',
389 'width': 640,
390 'height': 360,
391 }, {
392 'url': 'https://video.csfd.cz/files/videos/157/750/157750813/163327360_3d2646.mp4',
393 'ext': 'mp4',
394 'width': 1280,
395 'height': 720,
396 }, {
397 'url': 'https://video.csfd.cz/files/videos/157/750/157750813/163327356_91f258.mp4',
398 'ext': 'mp4',
399 'width': 1920,
400 'height': 1080,
401 }, {
402 'url': 'https://video.csfd.cz/files/videos/157/750/157750813/163327359_962b4a.webm',
403 'ext': 'webm',
404 'width': 640,
405 'height': 360,
406 }, {
407 'url': 'https://video.csfd.cz/files/videos/157/750/157750813/163327361_6feee0.webm',
408 'ext': 'webm',
409 'width': 1280,
410 'height': 720,
411 }, {
412 'url': 'https://video.csfd.cz/files/videos/157/750/157750813/163327357_8ab472.webm',
413 'ext': 'webm',
414 'width': 1920,
415 'height': 1080,
417 'subtitles': {
418 'cs': [{'url': 'https://video.csfd.cz/files/subtitles/163/344/163344115_4c388b.srt'}]
420 'thumbnail': 'https://img.csfd.cz/files/images/film/video/preview/163/344/163344118_748d20.png?h360'
423 # from https://tamasha.com/v/Kkdjw
424 # with height in label
425 expect_dict(
426 self,
427 self.ie._parse_html5_media_entries(
428 'https://tamasha.com/v/Kkdjw',
429 r'''
430 <video crossorigin="anonymous">
431 <source src="https://s-v2.tamasha.com/statics/videos_file/19/8f/Kkdjw_198feff8577d0057536e905cce1fb61438dd64e0_n_240.mp4" type="video/mp4" label="AUTO" res="0"/>
432 <source src="https://s-v2.tamasha.com/statics/videos_file/19/8f/Kkdjw_198feff8577d0057536e905cce1fb61438dd64e0_n_240.mp4" type="video/mp4"
433 label="240p" res="240"/>
434 <source src="https://s-v2.tamasha.com/statics/videos_file/20/00/Kkdjw_200041c66f657fc967db464d156eafbc1ed9fe6f_n_144.mp4" type="video/mp4"
435 label="144p" res="144"/>
436 </video>
437 ''', None)[0],
439 'formats': [{
440 'url': 'https://s-v2.tamasha.com/statics/videos_file/19/8f/Kkdjw_198feff8577d0057536e905cce1fb61438dd64e0_n_240.mp4',
441 }, {
442 'url': 'https://s-v2.tamasha.com/statics/videos_file/19/8f/Kkdjw_198feff8577d0057536e905cce1fb61438dd64e0_n_240.mp4',
443 'ext': 'mp4',
444 'format_id': '240p',
445 'height': 240,
446 }, {
447 'url': 'https://s-v2.tamasha.com/statics/videos_file/20/00/Kkdjw_200041c66f657fc967db464d156eafbc1ed9fe6f_n_144.mp4',
448 'ext': 'mp4',
449 'format_id': '144p',
450 'height': 144,
454 # from https://www.directvnow.com
455 # with data-src
456 expect_dict(
457 self,
458 self.ie._parse_html5_media_entries(
459 'https://www.directvnow.com',
460 r'''
461 <video id="vid1" class="header--video-masked active" muted playsinline>
462 <source data-src="https://cdn.directv.com/content/dam/dtv/prod/website_directvnow-international/videos/DTVN_hdr_HBO_v3.mp4" type="video/mp4" />
463 </video>
464 ''', None)[0],
466 'formats': [{
467 'ext': 'mp4',
468 'url': 'https://cdn.directv.com/content/dam/dtv/prod/website_directvnow-international/videos/DTVN_hdr_HBO_v3.mp4',
472 # from https://www.directvnow.com
473 # with data-src
474 expect_dict(
475 self,
476 self.ie._parse_html5_media_entries(
477 'https://www.directvnow.com',
478 r'''
479 <video id="vid1" class="header--video-masked active" muted playsinline>
480 <source data-src="https://cdn.directv.com/content/dam/dtv/prod/website_directvnow-international/videos/DTVN_hdr_HBO_v3.mp4" type="video/mp4" />
481 </video>
482 ''', None)[0],
484 'formats': [{
485 'url': 'https://cdn.directv.com/content/dam/dtv/prod/website_directvnow-international/videos/DTVN_hdr_HBO_v3.mp4',
486 'ext': 'mp4',
490 # from https://www.klarna.com/uk/
491 # with data-video-src
492 expect_dict(
493 self,
494 self.ie._parse_html5_media_entries(
495 'https://www.directvnow.com',
496 r'''
497 <video loop autoplay muted class="responsive-video block-kl__video video-on-medium">
498 <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" />
499 </video>
500 ''', None)[0],
502 'formats': [{
503 'url': 'https://www.klarna.com/uk/wp-content/uploads/sites/11/2019/01/KL062_Smooth3_0_DogWalking_5s_920x080_.mp4',
504 'ext': 'mp4',
508 # from https://0000.studio/
509 # with type attribute but without extension in URL
510 expect_dict(
511 self,
512 self.ie._parse_html5_media_entries(
513 'https://0000.studio',
514 r'''
515 <video src="https://d1ggyt9m8pwf3g.cloudfront.net/protected/ap-northeast-1:1864af40-28d5-492b-b739-b32314b1a527/archive/clip/838db6a7-8973-4cd6-840d-8517e4093c92"
516 controls="controls" type="video/mp4" preload="metadata" autoplay="autoplay" playsinline class="object-contain">
517 </video>
518 ''', None)[0],
520 'formats': [{
521 'url': 'https://d1ggyt9m8pwf3g.cloudfront.net/protected/ap-northeast-1:1864af40-28d5-492b-b739-b32314b1a527/archive/clip/838db6a7-8973-4cd6-840d-8517e4093c92',
522 'ext': 'mp4',
526 def test_extract_jwplayer_data_realworld(self):
527 # from http://www.suffolk.edu/sjc/
528 expect_dict(
529 self,
530 self.ie._extract_jwplayer_data(r'''
531 <script type='text/javascript'>
532 jwplayer('my-video').setup({
533 file: 'rtmp://192.138.214.154/live/sjclive',
534 fallback: 'true',
535 width: '95%',
536 aspectratio: '16:9',
537 primary: 'flash',
538 mediaid:'XEgvuql4'
540 </script>
541 ''', None, require_title=False),
543 'id': 'XEgvuql4',
544 'formats': [{
545 'url': 'rtmp://192.138.214.154/live/sjclive',
546 'ext': 'flv'
550 # from https://www.pornoxo.com/videos/7564/striptease-from-sexy-secretary/
551 expect_dict(
552 self,
553 self.ie._extract_jwplayer_data(r'''
554 <script type="text/javascript">
555 jwplayer("mediaplayer").setup({
556 'videoid': "7564",
557 'width': "100%",
558 'aspectratio': "16:9",
559 'stretching': "exactfit",
560 'autostart': 'false',
561 'flashplayer': "https://t04.vipstreamservice.com/jwplayer/v5.10/player.swf",
562 '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",
563 'image': "https://t03.vipstreamservice.com/thumbs/pxo-full/2009-12/14/a4b2157147afe5efa93ce1978e0265289c193874e02597.flv-full-13.jpg",
564 '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",
565 'logo.hide': true,
566 'skin': "https://t04.vipstreamservice.com/jwplayer/skin/modieus-blk.zip",
567 'plugins': "https://t04.vipstreamservice.com/jwplayer/dock/dockableskinnableplugin.swf",
568 'dockableskinnableplugin.piclink': "/index.php?key=ajax-videothumbsn&vid=7564&data=2009-12--14--4b2157147afe5efa93ce1978e0265289c193874e02597.flv--17370",
569 'controlbar': 'bottom',
570 'modes': [
571 {type: 'flash', src: 'https://t04.vipstreamservice.com/jwplayer/v5.10/player.swf'}
573 'provider': 'http'
575 //noinspection JSAnnotator
576 invideo.setup({
577 adsUrl: "/banner-iframe/?zoneId=32",
578 adsUrl2: "",
579 autostart: false
581 </script>
582 ''', 'dummy', require_title=False),
584 'thumbnail': 'https://t03.vipstreamservice.com/thumbs/pxo-full/2009-12/14/a4b2157147afe5efa93ce1978e0265289c193874e02597.flv-full-13.jpg',
585 'formats': [{
586 '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',
587 'ext': 'flv'
591 # from http://www.indiedb.com/games/king-machine/videos
592 expect_dict(
593 self,
594 self.ie._extract_jwplayer_data(r'''
595 <script>
596 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) {
597 videoAnalytics("play");
598 }).once("complete", function(event) {
599 videoAnalytics("completed");
601 </script>
602 ''', 'dummy'),
604 'title': 'king machine trailer 1',
605 'thumbnail': 'http://media.indiedb.com/cache/images/games/1/50/49678/thumb_620x2000/king-machine-trailer.mp4.jpg',
606 'formats': [{
607 'url': 'http://cdn.dbolical.com/cache/videos/games/1/50/49678/encode_mp4/king-machine-trailer.mp4',
608 'height': 360,
609 'ext': 'mp4'
610 }, {
611 'url': 'http://cdn.dbolical.com/cache/videos/games/1/50/49678/encode720p_mp4/king-machine-trailer.mp4',
612 'height': 720,
613 'ext': 'mp4'
617 def test_parse_m3u8_formats(self):
618 _TEST_CASES = [
620 # https://github.com/ytdl-org/youtube-dl/issues/11995
621 # http://teamcoco.com/video/clueless-gamer-super-bowl-for-honor
622 'img_bipbop_adv_example_fmp4',
623 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/master.m3u8',
625 'format_id': 'aud1-English',
626 'url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/a1/prog_index.m3u8',
627 'manifest_url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/master.m3u8',
628 'language': 'en',
629 'ext': 'mp4',
630 'protocol': 'm3u8_native',
631 'audio_ext': 'mp4',
632 }, {
633 'format_id': 'aud2-English',
634 'url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/a2/prog_index.m3u8',
635 'manifest_url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/master.m3u8',
636 'language': 'en',
637 'ext': 'mp4',
638 'protocol': 'm3u8_native',
639 'audio_ext': 'mp4',
640 }, {
641 'format_id': 'aud3-English',
642 'url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/a3/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': '530',
650 'url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/v2/prog_index.m3u8',
651 'manifest_url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/master.m3u8',
652 'ext': 'mp4',
653 'protocol': 'm3u8_native',
654 'width': 480,
655 'height': 270,
656 'vcodec': 'avc1.640015',
657 }, {
658 'format_id': '561',
659 'url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/v2/prog_index.m3u8',
660 'manifest_url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/master.m3u8',
661 'ext': 'mp4',
662 'protocol': 'm3u8_native',
663 'width': 480,
664 'height': 270,
665 'vcodec': 'avc1.640015',
666 }, {
667 'format_id': '753',
668 'url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/v2/prog_index.m3u8',
669 'manifest_url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/master.m3u8',
670 'ext': 'mp4',
671 'protocol': 'm3u8_native',
672 'width': 480,
673 'height': 270,
674 'vcodec': 'avc1.640015',
675 }, {
676 'format_id': '895',
677 'url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/v3/prog_index.m3u8',
678 'manifest_url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/master.m3u8',
679 'ext': 'mp4',
680 'protocol': 'm3u8_native',
681 'width': 640,
682 'height': 360,
683 'vcodec': 'avc1.64001e',
684 }, {
685 'format_id': '926',
686 'url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/v3/prog_index.m3u8',
687 'manifest_url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/master.m3u8',
688 'ext': 'mp4',
689 'protocol': 'm3u8_native',
690 'width': 640,
691 'height': 360,
692 'vcodec': 'avc1.64001e',
693 }, {
694 'format_id': '1118',
695 'url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/v3/prog_index.m3u8',
696 'manifest_url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/master.m3u8',
697 'ext': 'mp4',
698 'protocol': 'm3u8_native',
699 'width': 640,
700 'height': 360,
701 'vcodec': 'avc1.64001e',
702 }, {
703 'format_id': '1265',
704 'url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/v4/prog_index.m3u8',
705 'manifest_url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/master.m3u8',
706 'ext': 'mp4',
707 'protocol': 'm3u8_native',
708 'width': 768,
709 'height': 432,
710 'vcodec': 'avc1.64001e',
711 }, {
712 'format_id': '1295',
713 'url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/v4/prog_index.m3u8',
714 'manifest_url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/master.m3u8',
715 'ext': 'mp4',
716 'protocol': 'm3u8_native',
717 'width': 768,
718 'height': 432,
719 'vcodec': 'avc1.64001e',
720 }, {
721 'format_id': '1487',
722 'url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/v4/prog_index.m3u8',
723 'manifest_url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/master.m3u8',
724 'ext': 'mp4',
725 'protocol': 'm3u8_native',
726 'width': 768,
727 'height': 432,
728 'vcodec': 'avc1.64001e',
729 }, {
730 'format_id': '2168',
731 'url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/v5/prog_index.m3u8',
732 'manifest_url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/master.m3u8',
733 'ext': 'mp4',
734 'protocol': 'm3u8_native',
735 'width': 960,
736 'height': 540,
737 'vcodec': 'avc1.640020',
738 }, {
739 'format_id': '2198',
740 'url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/v5/prog_index.m3u8',
741 'manifest_url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/master.m3u8',
742 'ext': 'mp4',
743 'protocol': 'm3u8_native',
744 'width': 960,
745 'height': 540,
746 'vcodec': 'avc1.640020',
747 }, {
748 'format_id': '2390',
749 'url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/v5/prog_index.m3u8',
750 'manifest_url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/master.m3u8',
751 'ext': 'mp4',
752 'protocol': 'm3u8_native',
753 'width': 960,
754 'height': 540,
755 'vcodec': 'avc1.640020',
756 }, {
757 'format_id': '3168',
758 'url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/v6/prog_index.m3u8',
759 'manifest_url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/master.m3u8',
760 'ext': 'mp4',
761 'protocol': 'm3u8_native',
762 'width': 1280,
763 'height': 720,
764 'vcodec': 'avc1.640020',
765 }, {
766 'format_id': '3199',
767 'url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/v6/prog_index.m3u8',
768 'manifest_url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/master.m3u8',
769 'ext': 'mp4',
770 'protocol': 'm3u8_native',
771 'width': 1280,
772 'height': 720,
773 'vcodec': 'avc1.640020',
774 }, {
775 'format_id': '3391',
776 'url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/v6/prog_index.m3u8',
777 'manifest_url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/master.m3u8',
778 'ext': 'mp4',
779 'protocol': 'm3u8_native',
780 'width': 1280,
781 'height': 720,
782 'vcodec': 'avc1.640020',
783 }, {
784 'format_id': '4670',
785 'url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/v7/prog_index.m3u8',
786 'manifest_url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/master.m3u8',
787 'ext': 'mp4',
788 'protocol': 'm3u8_native',
789 'width': 1920,
790 'height': 1080,
791 'vcodec': 'avc1.64002a',
792 }, {
793 'format_id': '4701',
794 'url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/v7/prog_index.m3u8',
795 'manifest_url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/master.m3u8',
796 'ext': 'mp4',
797 'protocol': 'm3u8_native',
798 'width': 1920,
799 'height': 1080,
800 'vcodec': 'avc1.64002a',
801 }, {
802 'format_id': '4893',
803 'url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/v7/prog_index.m3u8',
804 'manifest_url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/master.m3u8',
805 'ext': 'mp4',
806 'protocol': 'm3u8_native',
807 'width': 1920,
808 'height': 1080,
809 'vcodec': 'avc1.64002a',
810 }, {
811 'format_id': '6170',
812 'url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/v8/prog_index.m3u8',
813 'manifest_url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/master.m3u8',
814 'ext': 'mp4',
815 'protocol': 'm3u8_native',
816 'width': 1920,
817 'height': 1080,
818 'vcodec': 'avc1.64002a',
819 }, {
820 'format_id': '6200',
821 'url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/v8/prog_index.m3u8',
822 'manifest_url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/master.m3u8',
823 'ext': 'mp4',
824 'protocol': 'm3u8_native',
825 'width': 1920,
826 'height': 1080,
827 'vcodec': 'avc1.64002a',
828 }, {
829 'format_id': '6392',
830 'url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/v8/prog_index.m3u8',
831 'manifest_url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/master.m3u8',
832 'ext': 'mp4',
833 'protocol': 'm3u8_native',
834 'width': 1920,
835 'height': 1080,
836 'vcodec': 'avc1.64002a',
837 }, {
838 'format_id': '7968',
839 'url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/v9/prog_index.m3u8',
840 'manifest_url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/master.m3u8',
841 'ext': 'mp4',
842 'protocol': 'm3u8_native',
843 'width': 1920,
844 'height': 1080,
845 'vcodec': 'avc1.64002a',
846 }, {
847 'format_id': '7998',
848 'url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/v9/prog_index.m3u8',
849 'manifest_url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/master.m3u8',
850 'ext': 'mp4',
851 'protocol': 'm3u8_native',
852 'width': 1920,
853 'height': 1080,
854 'vcodec': 'avc1.64002a',
855 }, {
856 'format_id': '8190',
857 'url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/v9/prog_index.m3u8',
858 'manifest_url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/master.m3u8',
859 'ext': 'mp4',
860 'protocol': 'm3u8_native',
861 'width': 1920,
862 'height': 1080,
863 'vcodec': 'avc1.64002a',
868 'bipbop_16x9',
869 'https://devstreaming-cdn.apple.com/videos/streaming/examples/bipbop_16x9/bipbop_16x9_variant.m3u8',
871 'format_id': 'bipbop_audio-BipBop Audio 2',
872 'format_index': None,
873 'url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/bipbop_16x9/alternate_audio_aac/prog_index.m3u8',
874 'manifest_url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/bipbop_16x9/bipbop_16x9_variant.m3u8',
875 'language': 'eng',
876 'ext': 'mp4',
877 'protocol': 'm3u8_native',
878 'preference': None,
879 'quality': None,
880 'vcodec': 'none',
881 'audio_ext': 'mp4',
882 'video_ext': 'none',
883 }, {
884 'format_id': '41',
885 'format_index': None,
886 'url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/bipbop_16x9/gear0/prog_index.m3u8',
887 'manifest_url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/bipbop_16x9/bipbop_16x9_variant.m3u8',
888 'tbr': 41.457,
889 'ext': 'mp4',
890 'fps': None,
891 'protocol': 'm3u8_native',
892 'preference': None,
893 'quality': None,
894 'vcodec': 'none',
895 'acodec': 'mp4a.40.2',
896 'audio_ext': 'mp4',
897 'video_ext': 'none',
898 'abr': 41.457,
899 }, {
900 'format_id': '263',
901 'format_index': None,
902 'url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/bipbop_16x9/gear1/prog_index.m3u8',
903 'manifest_url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/bipbop_16x9/bipbop_16x9_variant.m3u8',
904 'tbr': 263.851,
905 'ext': 'mp4',
906 'fps': None,
907 'protocol': 'm3u8_native',
908 'preference': None,
909 'quality': None,
910 'width': 416,
911 'height': 234,
912 'vcodec': 'avc1.4d400d',
913 'acodec': 'mp4a.40.2',
914 'video_ext': 'mp4',
915 'audio_ext': 'none',
916 'vbr': 263.851,
917 'abr': 0,
918 }, {
919 'format_id': '577',
920 'format_index': None,
921 'url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/bipbop_16x9/gear2/prog_index.m3u8',
922 'manifest_url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/bipbop_16x9/bipbop_16x9_variant.m3u8',
923 'tbr': 577.61,
924 'ext': 'mp4',
925 'fps': None,
926 'protocol': 'm3u8_native',
927 'preference': None,
928 'quality': None,
929 'width': 640,
930 'height': 360,
931 'vcodec': 'avc1.4d401e',
932 'acodec': 'mp4a.40.2',
933 'video_ext': 'mp4',
934 'audio_ext': 'none',
935 'vbr': 577.61,
936 'abr': 0,
937 }, {
938 'format_id': '915',
939 'format_index': None,
940 'url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/bipbop_16x9/gear3/prog_index.m3u8',
941 'manifest_url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/bipbop_16x9/bipbop_16x9_variant.m3u8',
942 'tbr': 915.905,
943 'ext': 'mp4',
944 'fps': None,
945 'protocol': 'm3u8_native',
946 'preference': None,
947 'quality': None,
948 'width': 960,
949 'height': 540,
950 'vcodec': 'avc1.4d401f',
951 'acodec': 'mp4a.40.2',
952 'video_ext': 'mp4',
953 'audio_ext': 'none',
954 'vbr': 915.905,
955 'abr': 0,
956 }, {
957 'format_id': '1030',
958 'format_index': None,
959 'url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/bipbop_16x9/gear4/prog_index.m3u8',
960 'manifest_url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/bipbop_16x9/bipbop_16x9_variant.m3u8',
961 'tbr': 1030.138,
962 'ext': 'mp4',
963 'fps': None,
964 'protocol': 'm3u8_native',
965 'preference': None,
966 'quality': None,
967 'width': 1280,
968 'height': 720,
969 'vcodec': 'avc1.4d401f',
970 'acodec': 'mp4a.40.2',
971 'video_ext': 'mp4',
972 'audio_ext': 'none',
973 'vbr': 1030.138,
974 'abr': 0,
975 }, {
976 'format_id': '1924',
977 'format_index': None,
978 'url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/bipbop_16x9/gear5/prog_index.m3u8',
979 'manifest_url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/bipbop_16x9/bipbop_16x9_variant.m3u8',
980 'tbr': 1924.009,
981 'ext': 'mp4',
982 'fps': None,
983 'protocol': 'm3u8_native',
984 'preference': None,
985 'quality': None,
986 'width': 1920,
987 'height': 1080,
988 'vcodec': 'avc1.4d401f',
989 'acodec': 'mp4a.40.2',
990 'video_ext': 'mp4',
991 'audio_ext': 'none',
992 'vbr': 1924.009,
993 'abr': 0,
996 'en': [{
997 'url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/bipbop_16x9/subtitles/eng/prog_index.m3u8',
998 'ext': 'vtt',
999 'protocol': 'm3u8_native'
1000 }, {
1001 'url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/bipbop_16x9/subtitles/eng_forced/prog_index.m3u8',
1002 'ext': 'vtt',
1003 'protocol': 'm3u8_native'
1005 'fr': [{
1006 'url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/bipbop_16x9/subtitles/fra/prog_index.m3u8',
1007 'ext': 'vtt',
1008 'protocol': 'm3u8_native'
1009 }, {
1010 'url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/bipbop_16x9/subtitles/fra_forced/prog_index.m3u8',
1011 'ext': 'vtt',
1012 'protocol': 'm3u8_native'
1014 'es': [{
1015 'url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/bipbop_16x9/subtitles/spa/prog_index.m3u8',
1016 'ext': 'vtt',
1017 'protocol': 'm3u8_native'
1018 }, {
1019 'url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/bipbop_16x9/subtitles/spa_forced/prog_index.m3u8',
1020 'ext': 'vtt',
1021 'protocol': 'm3u8_native'
1023 'ja': [{
1024 'url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/bipbop_16x9/subtitles/jpn/prog_index.m3u8',
1025 'ext': 'vtt',
1026 'protocol': 'm3u8_native'
1027 }, {
1028 'url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/bipbop_16x9/subtitles/jpn_forced/prog_index.m3u8',
1029 'ext': 'vtt',
1030 'protocol': 'm3u8_native'
1036 for m3u8_file, m3u8_url, expected_formats, expected_subs in _TEST_CASES:
1037 with open('./test/testdata/m3u8/%s.m3u8' % m3u8_file, encoding='utf-8') as f:
1038 formats, subs = self.ie._parse_m3u8_formats_and_subtitles(
1039 f.read(), m3u8_url, ext='mp4')
1040 self.ie._sort_formats(formats)
1041 expect_value(self, formats, expected_formats, None)
1042 expect_value(self, subs, expected_subs, None)
1044 def test_parse_mpd_formats(self):
1045 _TEST_CASES = [
1047 # https://github.com/ytdl-org/youtube-dl/issues/13919
1048 # Also tests duplicate representation ids, see
1049 # https://github.com/ytdl-org/youtube-dl/issues/15111
1050 'float_duration',
1051 'http://unknown/manifest.mpd', # mpd_url
1052 None, # mpd_base_url
1054 'manifest_url': 'http://unknown/manifest.mpd',
1055 'ext': 'm4a',
1056 'format_id': '318597',
1057 'format_note': 'DASH audio',
1058 'protocol': 'http_dash_segments',
1059 'acodec': 'mp4a.40.2',
1060 'vcodec': 'none',
1061 'tbr': 61.587,
1062 }, {
1063 'manifest_url': 'http://unknown/manifest.mpd',
1064 'ext': 'mp4',
1065 'format_id': '318597',
1066 'format_note': 'DASH video',
1067 'protocol': 'http_dash_segments',
1068 'acodec': 'none',
1069 'vcodec': 'avc1.42001f',
1070 'tbr': 318.597,
1071 'width': 340,
1072 'height': 192,
1073 }, {
1074 'manifest_url': 'http://unknown/manifest.mpd',
1075 'ext': 'mp4',
1076 'format_id': '638590',
1077 'format_note': 'DASH video',
1078 'protocol': 'http_dash_segments',
1079 'acodec': 'none',
1080 'vcodec': 'avc1.42001f',
1081 'tbr': 638.59,
1082 'width': 512,
1083 'height': 288,
1084 }, {
1085 'manifest_url': 'http://unknown/manifest.mpd',
1086 'ext': 'mp4',
1087 'format_id': '1022565',
1088 'format_note': 'DASH video',
1089 'protocol': 'http_dash_segments',
1090 'acodec': 'none',
1091 'vcodec': 'avc1.4d001f',
1092 'tbr': 1022.565,
1093 'width': 688,
1094 'height': 384,
1095 }, {
1096 'manifest_url': 'http://unknown/manifest.mpd',
1097 'ext': 'mp4',
1098 'format_id': '2046506',
1099 'format_note': 'DASH video',
1100 'protocol': 'http_dash_segments',
1101 'acodec': 'none',
1102 'vcodec': 'avc1.4d001f',
1103 'tbr': 2046.506,
1104 'width': 1024,
1105 'height': 576,
1106 }, {
1107 'manifest_url': 'http://unknown/manifest.mpd',
1108 'ext': 'mp4',
1109 'format_id': '3998017',
1110 'format_note': 'DASH video',
1111 'protocol': 'http_dash_segments',
1112 'acodec': 'none',
1113 'vcodec': 'avc1.640029',
1114 'tbr': 3998.017,
1115 'width': 1280,
1116 'height': 720,
1117 }, {
1118 'manifest_url': 'http://unknown/manifest.mpd',
1119 'ext': 'mp4',
1120 'format_id': '5997485',
1121 'format_note': 'DASH video',
1122 'protocol': 'http_dash_segments',
1123 'acodec': 'none',
1124 'vcodec': 'avc1.640032',
1125 'tbr': 5997.485,
1126 'width': 1920,
1127 'height': 1080,
1130 ), (
1131 # https://github.com/ytdl-org/youtube-dl/pull/14844
1132 'urls_only',
1133 'http://unknown/manifest.mpd', # mpd_url
1134 None, # mpd_base_url
1136 'manifest_url': 'http://unknown/manifest.mpd',
1137 'ext': 'mp4',
1138 'format_id': 'h264_aac_144p_m4s',
1139 'format_note': 'DASH video',
1140 'protocol': 'http_dash_segments',
1141 'acodec': 'mp4a.40.2',
1142 'vcodec': 'avc3.42c01e',
1143 'tbr': 200,
1144 'width': 256,
1145 'height': 144,
1146 }, {
1147 'manifest_url': 'http://unknown/manifest.mpd',
1148 'ext': 'mp4',
1149 'format_id': 'h264_aac_240p_m4s',
1150 'format_note': 'DASH video',
1151 'protocol': 'http_dash_segments',
1152 'acodec': 'mp4a.40.2',
1153 'vcodec': 'avc3.42c01e',
1154 'tbr': 400,
1155 'width': 424,
1156 'height': 240,
1157 }, {
1158 'manifest_url': 'http://unknown/manifest.mpd',
1159 'ext': 'mp4',
1160 'format_id': 'h264_aac_360p_m4s',
1161 'format_note': 'DASH video',
1162 'protocol': 'http_dash_segments',
1163 'acodec': 'mp4a.40.2',
1164 'vcodec': 'avc3.42c01e',
1165 'tbr': 800,
1166 'width': 640,
1167 'height': 360,
1168 }, {
1169 'manifest_url': 'http://unknown/manifest.mpd',
1170 'ext': 'mp4',
1171 'format_id': 'h264_aac_480p_m4s',
1172 'format_note': 'DASH video',
1173 'protocol': 'http_dash_segments',
1174 'acodec': 'mp4a.40.2',
1175 'vcodec': 'avc3.42c01e',
1176 'tbr': 1200,
1177 'width': 856,
1178 'height': 480,
1179 }, {
1180 'manifest_url': 'http://unknown/manifest.mpd',
1181 'ext': 'mp4',
1182 'format_id': 'h264_aac_576p_m4s',
1183 'format_note': 'DASH video',
1184 'protocol': 'http_dash_segments',
1185 'acodec': 'mp4a.40.2',
1186 'vcodec': 'avc3.42c01e',
1187 'tbr': 1600,
1188 'width': 1024,
1189 'height': 576,
1190 }, {
1191 'manifest_url': 'http://unknown/manifest.mpd',
1192 'ext': 'mp4',
1193 'format_id': 'h264_aac_720p_m4s',
1194 'format_note': 'DASH video',
1195 'protocol': 'http_dash_segments',
1196 'acodec': 'mp4a.40.2',
1197 'vcodec': 'avc3.42c01e',
1198 'tbr': 2400,
1199 'width': 1280,
1200 'height': 720,
1201 }, {
1202 'manifest_url': 'http://unknown/manifest.mpd',
1203 'ext': 'mp4',
1204 'format_id': 'h264_aac_1080p_m4s',
1205 'format_note': 'DASH video',
1206 'protocol': 'http_dash_segments',
1207 'acodec': 'mp4a.40.2',
1208 'vcodec': 'avc3.42c01e',
1209 'tbr': 4400,
1210 'width': 1920,
1211 'height': 1080,
1214 ), (
1215 # https://github.com/ytdl-org/youtube-dl/issues/20346
1216 # Media considered unfragmented even though it contains
1217 # Initialization tag
1218 'unfragmented',
1219 'https://v.redd.it/hw1x7rcg7zl21/DASHPlaylist.mpd', # mpd_url
1220 'https://v.redd.it/hw1x7rcg7zl21', # mpd_base_url
1222 'url': 'https://v.redd.it/hw1x7rcg7zl21/audio',
1223 'manifest_url': 'https://v.redd.it/hw1x7rcg7zl21/DASHPlaylist.mpd',
1224 'ext': 'm4a',
1225 'format_id': 'AUDIO-1',
1226 'format_note': 'DASH audio',
1227 'container': 'm4a_dash',
1228 'acodec': 'mp4a.40.2',
1229 'vcodec': 'none',
1230 'tbr': 129.87,
1231 'asr': 48000,
1233 }, {
1234 'url': 'https://v.redd.it/hw1x7rcg7zl21/DASH_240',
1235 'manifest_url': 'https://v.redd.it/hw1x7rcg7zl21/DASHPlaylist.mpd',
1236 'ext': 'mp4',
1237 'format_id': 'VIDEO-2',
1238 'format_note': 'DASH video',
1239 'container': 'mp4_dash',
1240 'acodec': 'none',
1241 'vcodec': 'avc1.4d401e',
1242 'tbr': 608.0,
1243 'width': 240,
1244 'height': 240,
1245 'fps': 30,
1246 }, {
1247 'url': 'https://v.redd.it/hw1x7rcg7zl21/DASH_360',
1248 'manifest_url': 'https://v.redd.it/hw1x7rcg7zl21/DASHPlaylist.mpd',
1249 'ext': 'mp4',
1250 'format_id': 'VIDEO-1',
1251 'format_note': 'DASH video',
1252 'container': 'mp4_dash',
1253 'acodec': 'none',
1254 'vcodec': 'avc1.4d401e',
1255 'tbr': 804.261,
1256 'width': 360,
1257 'height': 360,
1258 'fps': 30,
1261 ), (
1262 'subtitles',
1263 'https://sdn-global-streaming-cache-3qsdn.akamaized.net/stream/3144/files/17/07/672975/3144-kZT4LWMQw6Rh7Kpd.ism/manifest.mpd',
1264 'https://sdn-global-streaming-cache-3qsdn.akamaized.net/stream/3144/files/17/07/672975/3144-kZT4LWMQw6Rh7Kpd.ism/',
1266 'format_id': 'audio=128001',
1267 'manifest_url': 'https://sdn-global-streaming-cache-3qsdn.akamaized.net/stream/3144/files/17/07/672975/3144-kZT4LWMQw6Rh7Kpd.ism/manifest.mpd',
1268 'ext': 'm4a',
1269 'tbr': 128.001,
1270 'asr': 48000,
1271 'format_note': 'DASH audio',
1272 'container': 'm4a_dash',
1273 'vcodec': 'none',
1274 'acodec': 'mp4a.40.2',
1275 'url': 'https://sdn-global-streaming-cache-3qsdn.akamaized.net/stream/3144/files/17/07/672975/3144-kZT4LWMQw6Rh7Kpd.ism/manifest.mpd',
1276 'fragment_base_url': 'https://sdn-global-streaming-cache-3qsdn.akamaized.net/stream/3144/files/17/07/672975/3144-kZT4LWMQw6Rh7Kpd.ism/dash/',
1277 'protocol': 'http_dash_segments',
1278 'audio_ext': 'm4a',
1279 'video_ext': 'none',
1280 'abr': 128.001,
1281 }, {
1282 'format_id': 'video=100000',
1283 'manifest_url': 'https://sdn-global-streaming-cache-3qsdn.akamaized.net/stream/3144/files/17/07/672975/3144-kZT4LWMQw6Rh7Kpd.ism/manifest.mpd',
1284 'ext': 'mp4',
1285 'width': 336,
1286 'height': 144,
1287 'tbr': 100,
1288 'format_note': 'DASH video',
1289 'container': 'mp4_dash',
1290 'vcodec': 'avc1.4D401F',
1291 'acodec': 'none',
1292 'url': 'https://sdn-global-streaming-cache-3qsdn.akamaized.net/stream/3144/files/17/07/672975/3144-kZT4LWMQw6Rh7Kpd.ism/manifest.mpd',
1293 'fragment_base_url': 'https://sdn-global-streaming-cache-3qsdn.akamaized.net/stream/3144/files/17/07/672975/3144-kZT4LWMQw6Rh7Kpd.ism/dash/',
1294 'protocol': 'http_dash_segments',
1295 'video_ext': 'mp4',
1296 'audio_ext': 'none',
1297 'vbr': 100,
1298 }, {
1299 'format_id': 'video=326000',
1300 'manifest_url': 'https://sdn-global-streaming-cache-3qsdn.akamaized.net/stream/3144/files/17/07/672975/3144-kZT4LWMQw6Rh7Kpd.ism/manifest.mpd',
1301 'ext': 'mp4',
1302 'width': 562,
1303 'height': 240,
1304 'tbr': 326,
1305 'format_note': 'DASH video',
1306 'container': 'mp4_dash',
1307 'vcodec': 'avc1.4D401F',
1308 'acodec': 'none',
1309 'url': 'https://sdn-global-streaming-cache-3qsdn.akamaized.net/stream/3144/files/17/07/672975/3144-kZT4LWMQw6Rh7Kpd.ism/manifest.mpd',
1310 'fragment_base_url': 'https://sdn-global-streaming-cache-3qsdn.akamaized.net/stream/3144/files/17/07/672975/3144-kZT4LWMQw6Rh7Kpd.ism/dash/',
1311 'protocol': 'http_dash_segments',
1312 'video_ext': 'mp4',
1313 'audio_ext': 'none',
1314 'vbr': 326,
1315 }, {
1316 'format_id': 'video=698000',
1317 'manifest_url': 'https://sdn-global-streaming-cache-3qsdn.akamaized.net/stream/3144/files/17/07/672975/3144-kZT4LWMQw6Rh7Kpd.ism/manifest.mpd',
1318 'ext': 'mp4',
1319 'width': 844,
1320 'height': 360,
1321 'tbr': 698,
1322 'format_note': 'DASH video',
1323 'container': 'mp4_dash',
1324 'vcodec': 'avc1.4D401F',
1325 'acodec': 'none',
1326 'url': 'https://sdn-global-streaming-cache-3qsdn.akamaized.net/stream/3144/files/17/07/672975/3144-kZT4LWMQw6Rh7Kpd.ism/manifest.mpd',
1327 'fragment_base_url': 'https://sdn-global-streaming-cache-3qsdn.akamaized.net/stream/3144/files/17/07/672975/3144-kZT4LWMQw6Rh7Kpd.ism/dash/',
1328 'protocol': 'http_dash_segments',
1329 'video_ext': 'mp4',
1330 'audio_ext': 'none',
1331 'vbr': 698,
1332 }, {
1333 'format_id': 'video=1493000',
1334 'manifest_url': 'https://sdn-global-streaming-cache-3qsdn.akamaized.net/stream/3144/files/17/07/672975/3144-kZT4LWMQw6Rh7Kpd.ism/manifest.mpd',
1335 'ext': 'mp4',
1336 'width': 1126,
1337 'height': 480,
1338 'tbr': 1493,
1339 'format_note': 'DASH video',
1340 'container': 'mp4_dash',
1341 'vcodec': 'avc1.4D401F',
1342 'acodec': 'none',
1343 'url': 'https://sdn-global-streaming-cache-3qsdn.akamaized.net/stream/3144/files/17/07/672975/3144-kZT4LWMQw6Rh7Kpd.ism/manifest.mpd',
1344 'fragment_base_url': 'https://sdn-global-streaming-cache-3qsdn.akamaized.net/stream/3144/files/17/07/672975/3144-kZT4LWMQw6Rh7Kpd.ism/dash/',
1345 'protocol': 'http_dash_segments',
1346 'video_ext': 'mp4',
1347 'audio_ext': 'none',
1348 'vbr': 1493,
1349 }, {
1350 'format_id': 'video=4482000',
1351 'manifest_url': 'https://sdn-global-streaming-cache-3qsdn.akamaized.net/stream/3144/files/17/07/672975/3144-kZT4LWMQw6Rh7Kpd.ism/manifest.mpd',
1352 'ext': 'mp4',
1353 'width': 1688,
1354 'height': 720,
1355 'tbr': 4482,
1356 'format_note': 'DASH video',
1357 'container': 'mp4_dash',
1358 'vcodec': 'avc1.4D401F',
1359 'acodec': 'none',
1360 'url': 'https://sdn-global-streaming-cache-3qsdn.akamaized.net/stream/3144/files/17/07/672975/3144-kZT4LWMQw6Rh7Kpd.ism/manifest.mpd',
1361 'fragment_base_url': 'https://sdn-global-streaming-cache-3qsdn.akamaized.net/stream/3144/files/17/07/672975/3144-kZT4LWMQw6Rh7Kpd.ism/dash/',
1362 'protocol': 'http_dash_segments',
1363 'video_ext': 'mp4',
1364 'audio_ext': 'none',
1365 'vbr': 4482,
1368 'en': [
1370 'ext': 'mp4',
1371 'manifest_url': 'https://sdn-global-streaming-cache-3qsdn.akamaized.net/stream/3144/files/17/07/672975/3144-kZT4LWMQw6Rh7Kpd.ism/manifest.mpd',
1372 'url': 'https://sdn-global-streaming-cache-3qsdn.akamaized.net/stream/3144/files/17/07/672975/3144-kZT4LWMQw6Rh7Kpd.ism/manifest.mpd',
1373 'fragment_base_url': 'https://sdn-global-streaming-cache-3qsdn.akamaized.net/stream/3144/files/17/07/672975/3144-kZT4LWMQw6Rh7Kpd.ism/dash/',
1374 'protocol': 'http_dash_segments',
1381 for mpd_file, mpd_url, mpd_base_url, expected_formats, expected_subtitles in _TEST_CASES:
1382 with open('./test/testdata/mpd/%s.mpd' % mpd_file, encoding='utf-8') as f:
1383 formats, subtitles = self.ie._parse_mpd_formats_and_subtitles(
1384 compat_etree_fromstring(f.read().encode()),
1385 mpd_base_url=mpd_base_url, mpd_url=mpd_url)
1386 self.ie._sort_formats(formats)
1387 expect_value(self, formats, expected_formats, None)
1388 expect_value(self, subtitles, expected_subtitles, None)
1390 def test_parse_ism_formats(self):
1391 _TEST_CASES = [
1393 'sintel',
1394 'https://sdn-global-streaming-cache-3qsdn.akamaized.net/stream/3144/files/17/07/672975/3144-kZT4LWMQw6Rh7Kpd.ism/Manifest',
1396 'format_id': 'audio-128',
1397 'url': 'https://sdn-global-streaming-cache-3qsdn.akamaized.net/stream/3144/files/17/07/672975/3144-kZT4LWMQw6Rh7Kpd.ism/Manifest',
1398 'manifest_url': 'https://sdn-global-streaming-cache-3qsdn.akamaized.net/stream/3144/files/17/07/672975/3144-kZT4LWMQw6Rh7Kpd.ism/Manifest',
1399 'ext': 'isma',
1400 'tbr': 128,
1401 'asr': 48000,
1402 'vcodec': 'none',
1403 'acodec': 'AACL',
1404 'protocol': 'ism',
1405 '_download_params': {
1406 'stream_type': 'audio',
1407 'duration': 8880746666,
1408 'timescale': 10000000,
1409 'width': 0,
1410 'height': 0,
1411 'fourcc': 'AACL',
1412 'codec_private_data': '1190',
1413 'sampling_rate': 48000,
1414 'channels': 2,
1415 'bits_per_sample': 16,
1416 'nal_unit_length_field': 4
1418 'audio_ext': 'isma',
1419 'video_ext': 'none',
1420 'abr': 128,
1421 }, {
1422 'format_id': 'video-100',
1423 'url': 'https://sdn-global-streaming-cache-3qsdn.akamaized.net/stream/3144/files/17/07/672975/3144-kZT4LWMQw6Rh7Kpd.ism/Manifest',
1424 'manifest_url': 'https://sdn-global-streaming-cache-3qsdn.akamaized.net/stream/3144/files/17/07/672975/3144-kZT4LWMQw6Rh7Kpd.ism/Manifest',
1425 'ext': 'ismv',
1426 'width': 336,
1427 'height': 144,
1428 'tbr': 100,
1429 'vcodec': 'AVC1',
1430 'acodec': 'none',
1431 'protocol': 'ism',
1432 '_download_params': {
1433 'stream_type': 'video',
1434 'duration': 8880746666,
1435 'timescale': 10000000,
1436 'width': 336,
1437 'height': 144,
1438 'fourcc': 'AVC1',
1439 'codec_private_data': '00000001674D401FDA0544EFFC2D002CBC40000003004000000C03C60CA80000000168EF32C8',
1440 'channels': 2,
1441 'bits_per_sample': 16,
1442 'nal_unit_length_field': 4
1444 'video_ext': 'ismv',
1445 'audio_ext': 'none',
1446 'vbr': 100,
1447 }, {
1448 'format_id': 'video-326',
1449 'url': 'https://sdn-global-streaming-cache-3qsdn.akamaized.net/stream/3144/files/17/07/672975/3144-kZT4LWMQw6Rh7Kpd.ism/Manifest',
1450 'manifest_url': 'https://sdn-global-streaming-cache-3qsdn.akamaized.net/stream/3144/files/17/07/672975/3144-kZT4LWMQw6Rh7Kpd.ism/Manifest',
1451 'ext': 'ismv',
1452 'width': 562,
1453 'height': 240,
1454 'tbr': 326,
1455 'vcodec': 'AVC1',
1456 'acodec': 'none',
1457 'protocol': 'ism',
1458 '_download_params': {
1459 'stream_type': 'video',
1460 'duration': 8880746666,
1461 'timescale': 10000000,
1462 'width': 562,
1463 'height': 240,
1464 'fourcc': 'AVC1',
1465 'codec_private_data': '00000001674D401FDA0241FE23FFC3BC83BA44000003000400000300C03C60CA800000000168EF32C8',
1466 'channels': 2,
1467 'bits_per_sample': 16,
1468 'nal_unit_length_field': 4
1470 'video_ext': 'ismv',
1471 'audio_ext': 'none',
1472 'vbr': 326,
1473 }, {
1474 'format_id': 'video-698',
1475 'url': 'https://sdn-global-streaming-cache-3qsdn.akamaized.net/stream/3144/files/17/07/672975/3144-kZT4LWMQw6Rh7Kpd.ism/Manifest',
1476 'manifest_url': 'https://sdn-global-streaming-cache-3qsdn.akamaized.net/stream/3144/files/17/07/672975/3144-kZT4LWMQw6Rh7Kpd.ism/Manifest',
1477 'ext': 'ismv',
1478 'width': 844,
1479 'height': 360,
1480 'tbr': 698,
1481 'vcodec': 'AVC1',
1482 'acodec': 'none',
1483 'protocol': 'ism',
1484 '_download_params': {
1485 'stream_type': 'video',
1486 'duration': 8880746666,
1487 'timescale': 10000000,
1488 'width': 844,
1489 'height': 360,
1490 'fourcc': 'AVC1',
1491 'codec_private_data': '00000001674D401FDA0350BFB97FF06AF06AD1000003000100000300300F1832A00000000168EF32C8',
1492 'channels': 2,
1493 'bits_per_sample': 16,
1494 'nal_unit_length_field': 4
1496 'video_ext': 'ismv',
1497 'audio_ext': 'none',
1498 'vbr': 698,
1499 }, {
1500 'format_id': 'video-1493',
1501 'url': 'https://sdn-global-streaming-cache-3qsdn.akamaized.net/stream/3144/files/17/07/672975/3144-kZT4LWMQw6Rh7Kpd.ism/Manifest',
1502 'manifest_url': 'https://sdn-global-streaming-cache-3qsdn.akamaized.net/stream/3144/files/17/07/672975/3144-kZT4LWMQw6Rh7Kpd.ism/Manifest',
1503 'ext': 'ismv',
1504 'width': 1126,
1505 'height': 480,
1506 'tbr': 1493,
1507 'vcodec': 'AVC1',
1508 'acodec': 'none',
1509 'protocol': 'ism',
1510 '_download_params': {
1511 'stream_type': 'video',
1512 'duration': 8880746666,
1513 'timescale': 10000000,
1514 'width': 1126,
1515 'height': 480,
1516 'fourcc': 'AVC1',
1517 'codec_private_data': '00000001674D401FDA011C3DE6FFF0D890D871000003000100000300300F1832A00000000168EF32C8',
1518 'channels': 2,
1519 'bits_per_sample': 16,
1520 'nal_unit_length_field': 4
1522 'video_ext': 'ismv',
1523 'audio_ext': 'none',
1524 'vbr': 1493,
1525 }, {
1526 'format_id': 'video-4482',
1527 'url': 'https://sdn-global-streaming-cache-3qsdn.akamaized.net/stream/3144/files/17/07/672975/3144-kZT4LWMQw6Rh7Kpd.ism/Manifest',
1528 'manifest_url': 'https://sdn-global-streaming-cache-3qsdn.akamaized.net/stream/3144/files/17/07/672975/3144-kZT4LWMQw6Rh7Kpd.ism/Manifest',
1529 'ext': 'ismv',
1530 'width': 1688,
1531 'height': 720,
1532 'tbr': 4482,
1533 'vcodec': 'AVC1',
1534 'acodec': 'none',
1535 'protocol': 'ism',
1536 '_download_params': {
1537 'stream_type': 'video',
1538 'duration': 8880746666,
1539 'timescale': 10000000,
1540 'width': 1688,
1541 'height': 720,
1542 'fourcc': 'AVC1',
1543 'codec_private_data': '00000001674D401FDA01A816F97FFC1ABC1AB440000003004000000C03C60CA80000000168EF32C8',
1544 'channels': 2,
1545 'bits_per_sample': 16,
1546 'nal_unit_length_field': 4
1548 'video_ext': 'ismv',
1549 'audio_ext': 'none',
1550 'vbr': 4482,
1553 'eng': [
1555 'ext': 'ismt',
1556 'protocol': 'ism',
1557 'url': 'https://sdn-global-streaming-cache-3qsdn.akamaized.net/stream/3144/files/17/07/672975/3144-kZT4LWMQw6Rh7Kpd.ism/Manifest',
1558 'manifest_url': 'https://sdn-global-streaming-cache-3qsdn.akamaized.net/stream/3144/files/17/07/672975/3144-kZT4LWMQw6Rh7Kpd.ism/Manifest',
1559 '_download_params': {
1560 'stream_type': 'text',
1561 'duration': 8880746666,
1562 'timescale': 10000000,
1563 'fourcc': 'TTML',
1564 'codec_private_data': ''
1572 for ism_file, ism_url, expected_formats, expected_subtitles in _TEST_CASES:
1573 with open('./test/testdata/ism/%s.Manifest' % ism_file, encoding='utf-8') as f:
1574 formats, subtitles = self.ie._parse_ism_formats_and_subtitles(
1575 compat_etree_fromstring(f.read().encode()), ism_url=ism_url)
1576 self.ie._sort_formats(formats)
1577 expect_value(self, formats, expected_formats, None)
1578 expect_value(self, subtitles, expected_subtitles, None)
1580 def test_parse_f4m_formats(self):
1581 _TEST_CASES = [
1583 # https://github.com/ytdl-org/youtube-dl/issues/14660
1584 'custom_base_url',
1585 'http://api.new.livestream.com/accounts/6115179/events/6764928/videos/144884262.f4m',
1587 'manifest_url': 'http://api.new.livestream.com/accounts/6115179/events/6764928/videos/144884262.f4m',
1588 'ext': 'flv',
1589 'format_id': '2148',
1590 'protocol': 'f4m',
1591 'tbr': 2148,
1592 'width': 1280,
1593 'height': 720,
1598 for f4m_file, f4m_url, expected_formats in _TEST_CASES:
1599 with open('./test/testdata/f4m/%s.f4m' % f4m_file, encoding='utf-8') as f:
1600 formats = self.ie._parse_f4m_formats(
1601 compat_etree_fromstring(f.read().encode()),
1602 f4m_url, None)
1603 self.ie._sort_formats(formats)
1604 expect_value(self, formats, expected_formats, None)
1606 def test_parse_xspf(self):
1607 _TEST_CASES = [
1609 'foo_xspf',
1610 'https://example.org/src/foo_xspf.xspf',
1612 'id': 'foo_xspf',
1613 'title': 'Pandemonium',
1614 'description': 'Visit http://bigbrother404.bandcamp.com',
1615 'duration': 202.416,
1616 'formats': [{
1617 'manifest_url': 'https://example.org/src/foo_xspf.xspf',
1618 'url': 'https://example.org/src/cd1/track%201.mp3',
1620 }, {
1621 'id': 'foo_xspf',
1622 'title': 'Final Cartridge (Nichico Twelve Remix)',
1623 'description': 'Visit http://bigbrother404.bandcamp.com',
1624 'duration': 255.857,
1625 'formats': [{
1626 'manifest_url': 'https://example.org/src/foo_xspf.xspf',
1627 'url': 'https://example.org/%E3%83%88%E3%83%A9%E3%83%83%E3%82%AF%E3%80%80%EF%BC%92.mp3',
1629 }, {
1630 'id': 'foo_xspf',
1631 'title': 'Rebuilding Nightingale',
1632 'description': 'Visit http://bigbrother404.bandcamp.com',
1633 'duration': 287.915,
1634 'formats': [{
1635 'manifest_url': 'https://example.org/src/foo_xspf.xspf',
1636 'url': 'https://example.org/src/track3.mp3',
1637 }, {
1638 'manifest_url': 'https://example.org/src/foo_xspf.xspf',
1639 'url': 'https://example.com/track3.mp3',
1645 for xspf_file, xspf_url, expected_entries in _TEST_CASES:
1646 with open('./test/testdata/xspf/%s.xspf' % xspf_file, encoding='utf-8') as f:
1647 entries = self.ie._parse_xspf(
1648 compat_etree_fromstring(f.read().encode()),
1649 xspf_file, xspf_url=xspf_url, xspf_base_url=xspf_url)
1650 expect_value(self, entries, expected_entries, None)
1651 for i in range(len(entries)):
1652 expect_dict(self, entries[i], expected_entries[i])
1654 def test_response_with_expected_status_returns_content(self):
1655 # Checks for mitigations against the effects of
1656 # <https://bugs.python.org/issue15002> that affect Python 3.4.1+, which
1657 # manifest as `_download_webpage`, `_download_xml`, `_download_json`,
1658 # or the underlying `_download_webpage_handle` returning no content
1659 # when a response matches `expected_status`.
1661 httpd = http.server.HTTPServer(
1662 ('127.0.0.1', 0), InfoExtractorTestRequestHandler)
1663 port = http_server_port(httpd)
1664 server_thread = threading.Thread(target=httpd.serve_forever)
1665 server_thread.daemon = True
1666 server_thread.start()
1668 (content, urlh) = self.ie._download_webpage_handle(
1669 'http://127.0.0.1:%d/teapot' % port, None,
1670 expected_status=TEAPOT_RESPONSE_STATUS)
1671 self.assertEqual(content, TEAPOT_RESPONSE_BODY)
1674 if __name__ == '__main__':
1675 unittest.main()