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