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