]> jfr.im git - yt-dlp.git/blame - test/test_InfoExtractor.py
[toggo] Improve `_VALID_URL` (#3689)
[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
7f3590c4
S
505 def test_extract_jwplayer_data_realworld(self):
506 # from http://www.suffolk.edu/sjc/
507 expect_dict(
508 self,
509 self.ie._extract_jwplayer_data(r'''
510 <script type='text/javascript'>
511 jwplayer('my-video').setup({
512 file: 'rtmp://192.138.214.154/live/sjclive',
513 fallback: 'true',
514 width: '95%',
515 aspectratio: '16:9',
516 primary: 'flash',
517 mediaid:'XEgvuql4'
518 });
519 </script>
520 ''', None, require_title=False),
521 {
522 'id': 'XEgvuql4',
523 'formats': [{
524 'url': 'rtmp://192.138.214.154/live/sjclive',
525 'ext': 'flv'
526 }]
527 })
528
529 # from https://www.pornoxo.com/videos/7564/striptease-from-sexy-secretary/
530 expect_dict(
531 self,
532 self.ie._extract_jwplayer_data(r'''
533<script type="text/javascript">
534 jwplayer("mediaplayer").setup({
535 'videoid': "7564",
536 'width': "100%",
537 'aspectratio': "16:9",
538 'stretching': "exactfit",
539 'autostart': 'false',
540 'flashplayer': "https://t04.vipstreamservice.com/jwplayer/v5.10/player.swf",
541 '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",
542 'image': "https://t03.vipstreamservice.com/thumbs/pxo-full/2009-12/14/a4b2157147afe5efa93ce1978e0265289c193874e02597.flv-full-13.jpg",
543 '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",
544 'logo.hide': true,
545 'skin': "https://t04.vipstreamservice.com/jwplayer/skin/modieus-blk.zip",
546 'plugins': "https://t04.vipstreamservice.com/jwplayer/dock/dockableskinnableplugin.swf",
547 'dockableskinnableplugin.piclink': "/index.php?key=ajax-videothumbsn&vid=7564&data=2009-12--14--4b2157147afe5efa93ce1978e0265289c193874e02597.flv--17370",
548 'controlbar': 'bottom',
549 'modes': [
550 {type: 'flash', src: 'https://t04.vipstreamservice.com/jwplayer/v5.10/player.swf'}
551 ],
552 'provider': 'http'
553 });
554 //noinspection JSAnnotator
555 invideo.setup({
556 adsUrl: "/banner-iframe/?zoneId=32",
557 adsUrl2: "",
558 autostart: false
559 });
560</script>
561 ''', 'dummy', require_title=False),
562 {
563 'thumbnail': 'https://t03.vipstreamservice.com/thumbs/pxo-full/2009-12/14/a4b2157147afe5efa93ce1978e0265289c193874e02597.flv-full-13.jpg',
564 'formats': [{
565 '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',
566 'ext': 'flv'
567 }]
568 })
569
570 # from http://www.indiedb.com/games/king-machine/videos
571 expect_dict(
572 self,
573 self.ie._extract_jwplayer_data(r'''
574<script>
575jwplayer("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) {
576 videoAnalytics("play");
577}).once("complete", function(event) {
578 videoAnalytics("completed");
579});
580</script>
581 ''', 'dummy'),
582 {
583 'title': 'king machine trailer 1',
584 'thumbnail': 'http://media.indiedb.com/cache/images/games/1/50/49678/thumb_620x2000/king-machine-trailer.mp4.jpg',
585 'formats': [{
586 'url': 'http://cdn.dbolical.com/cache/videos/games/1/50/49678/encode_mp4/king-machine-trailer.mp4',
587 'height': 360,
588 'ext': 'mp4'
589 }, {
590 'url': 'http://cdn.dbolical.com/cache/videos/games/1/50/49678/encode720p_mp4/king-machine-trailer.mp4',
591 'height': 720,
592 'ext': 'mp4'
593 }]
594 })
595
cb252080
S
596 def test_parse_m3u8_formats(self):
597 _TEST_CASES = [
598 (
310c2ed2 599 # https://github.com/ytdl-org/youtube-dl/issues/11995
600 # http://teamcoco.com/video/clueless-gamer-super-bowl-for-honor
601 'img_bipbop_adv_example_fmp4',
602 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/master.m3u8',
cb252080 603 [{
310c2ed2 604 'format_id': 'aud1-English',
605 'url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/a1/prog_index.m3u8',
606 'manifest_url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/master.m3u8',
607 'language': 'en',
cb252080 608 'ext': 'mp4',
177877c5 609 'protocol': 'm3u8_native',
310c2ed2 610 'audio_ext': 'mp4',
cb252080 611 }, {
310c2ed2 612 'format_id': 'aud2-English',
613 'url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/a2/prog_index.m3u8',
614 'manifest_url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/master.m3u8',
615 'language': 'en',
cb252080 616 'ext': 'mp4',
177877c5 617 'protocol': 'm3u8_native',
310c2ed2 618 'audio_ext': 'mp4',
cb252080 619 }, {
310c2ed2 620 'format_id': 'aud3-English',
621 'url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/a3/prog_index.m3u8',
622 'manifest_url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/master.m3u8',
623 'language': 'en',
cb252080 624 'ext': 'mp4',
177877c5 625 'protocol': 'm3u8_native',
310c2ed2 626 'audio_ext': 'mp4',
cb252080 627 }, {
310c2ed2 628 'format_id': '530',
629 'url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/v2/prog_index.m3u8',
630 'manifest_url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/master.m3u8',
cb252080 631 'ext': 'mp4',
177877c5 632 'protocol': 'm3u8_native',
310c2ed2 633 'width': 480,
634 'height': 270,
635 'vcodec': 'avc1.640015',
cb252080 636 }, {
310c2ed2 637 'format_id': '561',
638 'url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/v2/prog_index.m3u8',
639 'manifest_url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/master.m3u8',
cb252080 640 'ext': 'mp4',
177877c5 641 'protocol': 'm3u8_native',
310c2ed2 642 'width': 480,
643 'height': 270,
644 'vcodec': 'avc1.640015',
645 }, {
646 'format_id': '753',
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': '895',
656 'url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/v3/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': 640,
661 'height': 360,
662 'vcodec': 'avc1.64001e',
cb252080 663 }, {
310c2ed2 664 'format_id': '926',
665 'url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/v3/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': 640,
670 'height': 360,
671 'vcodec': 'avc1.64001e',
cb252080 672 }, {
310c2ed2 673 'format_id': '1118',
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': '1265',
683 'url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/v4/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': 768,
688 'height': 432,
689 'vcodec': 'avc1.64001e',
cb252080 690 }, {
310c2ed2 691 'format_id': '1295',
692 'url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/v4/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': 768,
697 'height': 432,
698 'vcodec': 'avc1.64001e',
cb252080 699 }, {
310c2ed2 700 'format_id': '1487',
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',
708 }, {
709 'format_id': '2168',
710 'url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/v5/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': 960,
715 'height': 540,
716 'vcodec': 'avc1.640020',
cb252080 717 }, {
310c2ed2 718 'format_id': '2198',
719 'url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/v5/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': 960,
724 'height': 540,
725 'vcodec': 'avc1.640020',
cb252080 726 }, {
310c2ed2 727 'format_id': '2390',
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': '3168',
737 'url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/v6/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': 1280,
742 'height': 720,
743 'vcodec': 'avc1.640020',
cb252080 744 }, {
310c2ed2 745 'format_id': '3199',
746 'url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/v6/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': 1280,
751 'height': 720,
752 'vcodec': 'avc1.640020',
cb252080 753 }, {
310c2ed2 754 'format_id': '3391',
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',
762 }, {
763 'format_id': '4670',
764 'url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/v7/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': 1920,
769 'height': 1080,
770 'vcodec': 'avc1.64002a',
cb252080 771 }, {
310c2ed2 772 'format_id': '4701',
773 'url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/v7/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': 1920,
778 'height': 1080,
779 'vcodec': 'avc1.64002a',
cb252080 780 }, {
310c2ed2 781 'format_id': '4893',
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': '6170',
791 'url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/v8/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': '6200',
800 'url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/v8/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': '6392',
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',
816 }, {
817 'format_id': '7968',
818 'url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/v9/prog_index.m3u8',
819 'manifest_url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/master.m3u8',
ddd258f9 820 'ext': 'mp4',
177877c5 821 'protocol': 'm3u8_native',
310c2ed2 822 'width': 1920,
823 'height': 1080,
824 'vcodec': 'avc1.64002a',
ddd258f9 825 }, {
310c2ed2 826 'format_id': '7998',
827 'url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/v9/prog_index.m3u8',
828 'manifest_url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/master.m3u8',
ddd258f9 829 'ext': 'mp4',
177877c5 830 'protocol': 'm3u8_native',
310c2ed2 831 'width': 1920,
832 'height': 1080,
833 'vcodec': 'avc1.64002a',
ddd258f9 834 }, {
310c2ed2 835 'format_id': '8190',
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',
a0c3b2d5
F
843 }],
844 {}
fc746c3f 845 ),
73b9088a
F
846 (
847 'bipbop_16x9',
848 'https://devstreaming-cdn.apple.com/videos/streaming/examples/bipbop_16x9/bipbop_16x9_variant.m3u8',
849 [{
177877c5 850 'format_id': 'bipbop_audio-BipBop Audio 2',
851 'format_index': None,
852 'url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/bipbop_16x9/alternate_audio_aac/prog_index.m3u8',
853 'manifest_url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/bipbop_16x9/bipbop_16x9_variant.m3u8',
854 'language': 'eng',
855 'ext': 'mp4',
856 'protocol': 'm3u8_native',
857 'preference': None,
858 'quality': None,
859 'vcodec': 'none',
860 'audio_ext': 'mp4',
861 'video_ext': 'none',
862 }, {
863 'format_id': '41',
864 'format_index': None,
865 'url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/bipbop_16x9/gear0/prog_index.m3u8',
866 'manifest_url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/bipbop_16x9/bipbop_16x9_variant.m3u8',
867 'tbr': 41.457,
868 'ext': 'mp4',
869 'fps': None,
870 'protocol': 'm3u8_native',
871 'preference': None,
872 'quality': None,
873 'vcodec': 'none',
874 'acodec': 'mp4a.40.2',
875 'audio_ext': 'mp4',
876 'video_ext': 'none',
877 'abr': 41.457,
878 }, {
879 'format_id': '263',
880 'format_index': None,
881 'url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/bipbop_16x9/gear1/prog_index.m3u8',
882 'manifest_url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/bipbop_16x9/bipbop_16x9_variant.m3u8',
883 'tbr': 263.851,
884 'ext': 'mp4',
885 'fps': None,
886 'protocol': 'm3u8_native',
887 'preference': None,
888 'quality': None,
889 'width': 416,
890 'height': 234,
891 'vcodec': 'avc1.4d400d',
892 'acodec': 'mp4a.40.2',
893 'video_ext': 'mp4',
894 'audio_ext': 'none',
895 'vbr': 263.851,
896 'abr': 0,
897 }, {
898 'format_id': '577',
899 'format_index': None,
900 'url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/bipbop_16x9/gear2/prog_index.m3u8',
901 'manifest_url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/bipbop_16x9/bipbop_16x9_variant.m3u8',
902 'tbr': 577.61,
903 'ext': 'mp4',
904 'fps': None,
905 'protocol': 'm3u8_native',
906 'preference': None,
907 'quality': None,
908 'width': 640,
909 'height': 360,
910 'vcodec': 'avc1.4d401e',
911 'acodec': 'mp4a.40.2',
912 'video_ext': 'mp4',
913 'audio_ext': 'none',
914 'vbr': 577.61,
915 'abr': 0,
916 }, {
917 'format_id': '915',
918 'format_index': None,
919 'url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/bipbop_16x9/gear3/prog_index.m3u8',
920 'manifest_url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/bipbop_16x9/bipbop_16x9_variant.m3u8',
921 'tbr': 915.905,
922 'ext': 'mp4',
923 'fps': None,
924 'protocol': 'm3u8_native',
925 'preference': None,
926 'quality': None,
927 'width': 960,
928 'height': 540,
929 'vcodec': 'avc1.4d401f',
930 'acodec': 'mp4a.40.2',
931 'video_ext': 'mp4',
932 'audio_ext': 'none',
933 'vbr': 915.905,
934 'abr': 0,
935 }, {
936 'format_id': '1030',
937 'format_index': None,
938 'url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/bipbop_16x9/gear4/prog_index.m3u8',
939 'manifest_url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/bipbop_16x9/bipbop_16x9_variant.m3u8',
940 'tbr': 1030.138,
941 'ext': 'mp4',
942 'fps': None,
943 'protocol': 'm3u8_native',
944 'preference': None,
945 'quality': None,
946 'width': 1280,
947 'height': 720,
948 'vcodec': 'avc1.4d401f',
949 'acodec': 'mp4a.40.2',
950 'video_ext': 'mp4',
951 'audio_ext': 'none',
952 'vbr': 1030.138,
953 'abr': 0,
954 }, {
955 'format_id': '1924',
956 'format_index': None,
957 'url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/bipbop_16x9/gear5/prog_index.m3u8',
958 'manifest_url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/bipbop_16x9/bipbop_16x9_variant.m3u8',
959 'tbr': 1924.009,
960 'ext': 'mp4',
961 'fps': None,
962 'protocol': 'm3u8_native',
963 'preference': None,
964 'quality': None,
965 'width': 1920,
966 'height': 1080,
967 'vcodec': 'avc1.4d401f',
968 'acodec': 'mp4a.40.2',
969 'video_ext': 'mp4',
970 'audio_ext': 'none',
971 'vbr': 1924.009,
972 'abr': 0,
73b9088a
F
973 }],
974 {
177877c5 975 'en': [{
976 'url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/bipbop_16x9/subtitles/eng/prog_index.m3u8',
977 'ext': 'vtt',
978 'protocol': 'm3u8_native'
73b9088a 979 }, {
177877c5 980 'url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/bipbop_16x9/subtitles/eng_forced/prog_index.m3u8',
981 'ext': 'vtt',
982 'protocol': 'm3u8_native'
73b9088a 983 }],
177877c5 984 'fr': [{
985 'url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/bipbop_16x9/subtitles/fra/prog_index.m3u8',
986 'ext': 'vtt',
987 'protocol': 'm3u8_native'
73b9088a 988 }, {
177877c5 989 'url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/bipbop_16x9/subtitles/fra_forced/prog_index.m3u8',
990 'ext': 'vtt',
991 'protocol': 'm3u8_native'
73b9088a 992 }],
177877c5 993 'es': [{
994 'url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/bipbop_16x9/subtitles/spa/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/spa_forced/prog_index.m3u8',
999 'ext': 'vtt',
1000 'protocol': 'm3u8_native'
73b9088a 1001 }],
177877c5 1002 'ja': [{
1003 'url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/bipbop_16x9/subtitles/jpn/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/jpn_forced/prog_index.m3u8',
1008 'ext': 'vtt',
1009 'protocol': 'm3u8_native'
73b9088a
F
1010 }],
1011 }
1012 ),
cb252080
S
1013 ]
1014
a0c3b2d5 1015 for m3u8_file, m3u8_url, expected_formats, expected_subs in _TEST_CASES:
86e5f3ed 1016 with open('./test/testdata/m3u8/%s.m3u8' % m3u8_file, encoding='utf-8') as f:
a0c3b2d5 1017 formats, subs = self.ie._parse_m3u8_formats_and_subtitles(
cb252080
S
1018 f.read(), m3u8_url, ext='mp4')
1019 self.ie._sort_formats(formats)
1020 expect_value(self, formats, expected_formats, None)
a0c3b2d5 1021 expect_value(self, subs, expected_subs, None)
cb252080 1022
48504785
S
1023 def test_parse_mpd_formats(self):
1024 _TEST_CASES = [
1025 (
067aa17e 1026 # https://github.com/ytdl-org/youtube-dl/issues/13919
9d6ac71c 1027 # Also tests duplicate representation ids, see
067aa17e 1028 # https://github.com/ytdl-org/youtube-dl/issues/15111
48504785 1029 'float_duration',
2e27421c
S
1030 'http://unknown/manifest.mpd', # mpd_url
1031 None, # mpd_base_url
48504785 1032 [{
9d6ac71c
S
1033 'manifest_url': 'http://unknown/manifest.mpd',
1034 'ext': 'm4a',
1035 'format_id': '318597',
1036 'format_note': 'DASH audio',
1037 'protocol': 'http_dash_segments',
1038 'acodec': 'mp4a.40.2',
1039 'vcodec': 'none',
1040 'tbr': 61.587,
1041 }, {
48504785
S
1042 'manifest_url': 'http://unknown/manifest.mpd',
1043 'ext': 'mp4',
1044 'format_id': '318597',
1045 'format_note': 'DASH video',
1046 'protocol': 'http_dash_segments',
1047 'acodec': 'none',
1048 'vcodec': 'avc1.42001f',
1049 'tbr': 318.597,
1050 'width': 340,
1051 'height': 192,
1052 }, {
1053 'manifest_url': 'http://unknown/manifest.mpd',
1054 'ext': 'mp4',
1055 'format_id': '638590',
1056 'format_note': 'DASH video',
1057 'protocol': 'http_dash_segments',
1058 'acodec': 'none',
1059 'vcodec': 'avc1.42001f',
1060 'tbr': 638.59,
1061 'width': 512,
1062 'height': 288,
1063 }, {
1064 'manifest_url': 'http://unknown/manifest.mpd',
1065 'ext': 'mp4',
1066 'format_id': '1022565',
1067 'format_note': 'DASH video',
1068 'protocol': 'http_dash_segments',
1069 'acodec': 'none',
1070 'vcodec': 'avc1.4d001f',
1071 'tbr': 1022.565,
1072 'width': 688,
1073 'height': 384,
1074 }, {
1075 'manifest_url': 'http://unknown/manifest.mpd',
1076 'ext': 'mp4',
1077 'format_id': '2046506',
1078 'format_note': 'DASH video',
1079 'protocol': 'http_dash_segments',
1080 'acodec': 'none',
1081 'vcodec': 'avc1.4d001f',
1082 'tbr': 2046.506,
1083 'width': 1024,
1084 'height': 576,
1085 }, {
1086 'manifest_url': 'http://unknown/manifest.mpd',
1087 'ext': 'mp4',
1088 'format_id': '3998017',
1089 'format_note': 'DASH video',
1090 'protocol': 'http_dash_segments',
1091 'acodec': 'none',
1092 'vcodec': 'avc1.640029',
1093 'tbr': 3998.017,
1094 'width': 1280,
1095 'height': 720,
1096 }, {
1097 'manifest_url': 'http://unknown/manifest.mpd',
1098 'ext': 'mp4',
1099 'format_id': '5997485',
1100 'format_note': 'DASH video',
1101 'protocol': 'http_dash_segments',
1102 'acodec': 'none',
1103 'vcodec': 'avc1.640032',
1104 'tbr': 5997.485,
1105 'width': 1920,
1106 'height': 1080,
becdc7f8
F
1107 }],
1108 {},
41bf647e 1109 ), (
067aa17e 1110 # https://github.com/ytdl-org/youtube-dl/pull/14844
41bf647e 1111 'urls_only',
2e27421c
S
1112 'http://unknown/manifest.mpd', # mpd_url
1113 None, # mpd_base_url
41bf647e
PN
1114 [{
1115 'manifest_url': 'http://unknown/manifest.mpd',
1116 'ext': 'mp4',
1117 'format_id': 'h264_aac_144p_m4s',
1118 'format_note': 'DASH video',
1119 'protocol': 'http_dash_segments',
1120 'acodec': 'mp4a.40.2',
1121 'vcodec': 'avc3.42c01e',
1122 'tbr': 200,
1123 'width': 256,
1124 'height': 144,
1125 }, {
1126 'manifest_url': 'http://unknown/manifest.mpd',
1127 'ext': 'mp4',
1128 'format_id': 'h264_aac_240p_m4s',
1129 'format_note': 'DASH video',
1130 'protocol': 'http_dash_segments',
1131 'acodec': 'mp4a.40.2',
1132 'vcodec': 'avc3.42c01e',
1133 'tbr': 400,
1134 'width': 424,
1135 'height': 240,
1136 }, {
1137 'manifest_url': 'http://unknown/manifest.mpd',
1138 'ext': 'mp4',
1139 'format_id': 'h264_aac_360p_m4s',
1140 'format_note': 'DASH video',
1141 'protocol': 'http_dash_segments',
1142 'acodec': 'mp4a.40.2',
1143 'vcodec': 'avc3.42c01e',
1144 'tbr': 800,
1145 'width': 640,
1146 'height': 360,
1147 }, {
1148 'manifest_url': 'http://unknown/manifest.mpd',
1149 'ext': 'mp4',
1150 'format_id': 'h264_aac_480p_m4s',
1151 'format_note': 'DASH video',
1152 'protocol': 'http_dash_segments',
1153 'acodec': 'mp4a.40.2',
1154 'vcodec': 'avc3.42c01e',
1155 'tbr': 1200,
1156 'width': 856,
1157 'height': 480,
1158 }, {
1159 'manifest_url': 'http://unknown/manifest.mpd',
1160 'ext': 'mp4',
1161 'format_id': 'h264_aac_576p_m4s',
1162 'format_note': 'DASH video',
1163 'protocol': 'http_dash_segments',
1164 'acodec': 'mp4a.40.2',
1165 'vcodec': 'avc3.42c01e',
1166 'tbr': 1600,
1167 'width': 1024,
1168 'height': 576,
1169 }, {
1170 'manifest_url': 'http://unknown/manifest.mpd',
1171 'ext': 'mp4',
1172 'format_id': 'h264_aac_720p_m4s',
1173 'format_note': 'DASH video',
1174 'protocol': 'http_dash_segments',
1175 'acodec': 'mp4a.40.2',
1176 'vcodec': 'avc3.42c01e',
1177 'tbr': 2400,
1178 'width': 1280,
1179 'height': 720,
1180 }, {
1181 'manifest_url': 'http://unknown/manifest.mpd',
1182 'ext': 'mp4',
1183 'format_id': 'h264_aac_1080p_m4s',
1184 'format_note': 'DASH video',
1185 'protocol': 'http_dash_segments',
1186 'acodec': 'mp4a.40.2',
1187 'vcodec': 'avc3.42c01e',
1188 'tbr': 4400,
1189 'width': 1920,
1190 'height': 1080,
becdc7f8
F
1191 }],
1192 {},
2e27421c
S
1193 ), (
1194 # https://github.com/ytdl-org/youtube-dl/issues/20346
1195 # Media considered unfragmented even though it contains
1196 # Initialization tag
1197 'unfragmented',
1198 'https://v.redd.it/hw1x7rcg7zl21/DASHPlaylist.mpd', # mpd_url
1199 'https://v.redd.it/hw1x7rcg7zl21', # mpd_base_url
1200 [{
1201 'url': 'https://v.redd.it/hw1x7rcg7zl21/audio',
1202 'manifest_url': 'https://v.redd.it/hw1x7rcg7zl21/DASHPlaylist.mpd',
1203 'ext': 'm4a',
1204 'format_id': 'AUDIO-1',
1205 'format_note': 'DASH audio',
1206 'container': 'm4a_dash',
1207 'acodec': 'mp4a.40.2',
1208 'vcodec': 'none',
1209 'tbr': 129.87,
1210 'asr': 48000,
1211
1212 }, {
1213 'url': 'https://v.redd.it/hw1x7rcg7zl21/DASH_240',
1214 'manifest_url': 'https://v.redd.it/hw1x7rcg7zl21/DASHPlaylist.mpd',
1215 'ext': 'mp4',
1216 'format_id': 'VIDEO-2',
1217 'format_note': 'DASH video',
1218 'container': 'mp4_dash',
1219 'acodec': 'none',
1220 'vcodec': 'avc1.4d401e',
1221 'tbr': 608.0,
1222 'width': 240,
1223 'height': 240,
1224 'fps': 30,
1225 }, {
1226 'url': 'https://v.redd.it/hw1x7rcg7zl21/DASH_360',
1227 'manifest_url': 'https://v.redd.it/hw1x7rcg7zl21/DASHPlaylist.mpd',
1228 'ext': 'mp4',
1229 'format_id': 'VIDEO-1',
1230 'format_note': 'DASH video',
1231 'container': 'mp4_dash',
1232 'acodec': 'none',
1233 'vcodec': 'avc1.4d401e',
1234 'tbr': 804.261,
1235 'width': 360,
1236 'height': 360,
1237 'fps': 30,
becdc7f8
F
1238 }],
1239 {},
1240 ), (
1241 'subtitles',
1242 'https://sdn-global-streaming-cache-3qsdn.akamaized.net/stream/3144/files/17/07/672975/3144-kZT4LWMQw6Rh7Kpd.ism/manifest.mpd',
1243 'https://sdn-global-streaming-cache-3qsdn.akamaized.net/stream/3144/files/17/07/672975/3144-kZT4LWMQw6Rh7Kpd.ism/',
1244 [{
177877c5 1245 'format_id': 'audio=128001',
1246 'manifest_url': 'https://sdn-global-streaming-cache-3qsdn.akamaized.net/stream/3144/files/17/07/672975/3144-kZT4LWMQw6Rh7Kpd.ism/manifest.mpd',
1247 'ext': 'm4a',
1248 'tbr': 128.001,
1249 'asr': 48000,
1250 'format_note': 'DASH audio',
1251 'container': 'm4a_dash',
1252 'vcodec': 'none',
1253 'acodec': 'mp4a.40.2',
1254 'url': 'https://sdn-global-streaming-cache-3qsdn.akamaized.net/stream/3144/files/17/07/672975/3144-kZT4LWMQw6Rh7Kpd.ism/manifest.mpd',
1255 'fragment_base_url': 'https://sdn-global-streaming-cache-3qsdn.akamaized.net/stream/3144/files/17/07/672975/3144-kZT4LWMQw6Rh7Kpd.ism/dash/',
1256 'protocol': 'http_dash_segments',
1257 'audio_ext': 'm4a',
1258 'video_ext': 'none',
1259 'abr': 128.001,
1260 }, {
1261 'format_id': 'video=100000',
1262 'manifest_url': 'https://sdn-global-streaming-cache-3qsdn.akamaized.net/stream/3144/files/17/07/672975/3144-kZT4LWMQw6Rh7Kpd.ism/manifest.mpd',
1263 'ext': 'mp4',
1264 'width': 336,
1265 'height': 144,
1266 'tbr': 100,
1267 'format_note': 'DASH video',
1268 'container': 'mp4_dash',
1269 'vcodec': 'avc1.4D401F',
1270 'acodec': 'none',
1271 'url': 'https://sdn-global-streaming-cache-3qsdn.akamaized.net/stream/3144/files/17/07/672975/3144-kZT4LWMQw6Rh7Kpd.ism/manifest.mpd',
1272 'fragment_base_url': 'https://sdn-global-streaming-cache-3qsdn.akamaized.net/stream/3144/files/17/07/672975/3144-kZT4LWMQw6Rh7Kpd.ism/dash/',
1273 'protocol': 'http_dash_segments',
1274 'video_ext': 'mp4',
1275 'audio_ext': 'none',
1276 'vbr': 100,
1277 }, {
1278 'format_id': 'video=326000',
1279 'manifest_url': 'https://sdn-global-streaming-cache-3qsdn.akamaized.net/stream/3144/files/17/07/672975/3144-kZT4LWMQw6Rh7Kpd.ism/manifest.mpd',
1280 'ext': 'mp4',
1281 'width': 562,
1282 'height': 240,
1283 'tbr': 326,
1284 'format_note': 'DASH video',
1285 'container': 'mp4_dash',
1286 'vcodec': 'avc1.4D401F',
1287 'acodec': 'none',
1288 'url': 'https://sdn-global-streaming-cache-3qsdn.akamaized.net/stream/3144/files/17/07/672975/3144-kZT4LWMQw6Rh7Kpd.ism/manifest.mpd',
1289 'fragment_base_url': 'https://sdn-global-streaming-cache-3qsdn.akamaized.net/stream/3144/files/17/07/672975/3144-kZT4LWMQw6Rh7Kpd.ism/dash/',
1290 'protocol': 'http_dash_segments',
1291 'video_ext': 'mp4',
1292 'audio_ext': 'none',
1293 'vbr': 326,
1294 }, {
1295 'format_id': 'video=698000',
1296 'manifest_url': 'https://sdn-global-streaming-cache-3qsdn.akamaized.net/stream/3144/files/17/07/672975/3144-kZT4LWMQw6Rh7Kpd.ism/manifest.mpd',
1297 'ext': 'mp4',
1298 'width': 844,
1299 'height': 360,
1300 'tbr': 698,
1301 'format_note': 'DASH video',
1302 'container': 'mp4_dash',
1303 'vcodec': 'avc1.4D401F',
1304 'acodec': 'none',
1305 'url': 'https://sdn-global-streaming-cache-3qsdn.akamaized.net/stream/3144/files/17/07/672975/3144-kZT4LWMQw6Rh7Kpd.ism/manifest.mpd',
1306 'fragment_base_url': 'https://sdn-global-streaming-cache-3qsdn.akamaized.net/stream/3144/files/17/07/672975/3144-kZT4LWMQw6Rh7Kpd.ism/dash/',
1307 'protocol': 'http_dash_segments',
1308 'video_ext': 'mp4',
1309 'audio_ext': 'none',
1310 'vbr': 698,
1311 }, {
1312 'format_id': 'video=1493000',
1313 'manifest_url': 'https://sdn-global-streaming-cache-3qsdn.akamaized.net/stream/3144/files/17/07/672975/3144-kZT4LWMQw6Rh7Kpd.ism/manifest.mpd',
1314 'ext': 'mp4',
1315 'width': 1126,
1316 'height': 480,
1317 'tbr': 1493,
1318 'format_note': 'DASH video',
1319 'container': 'mp4_dash',
1320 'vcodec': 'avc1.4D401F',
1321 'acodec': 'none',
1322 'url': 'https://sdn-global-streaming-cache-3qsdn.akamaized.net/stream/3144/files/17/07/672975/3144-kZT4LWMQw6Rh7Kpd.ism/manifest.mpd',
1323 'fragment_base_url': 'https://sdn-global-streaming-cache-3qsdn.akamaized.net/stream/3144/files/17/07/672975/3144-kZT4LWMQw6Rh7Kpd.ism/dash/',
1324 'protocol': 'http_dash_segments',
1325 'video_ext': 'mp4',
1326 'audio_ext': 'none',
1327 'vbr': 1493,
1328 }, {
1329 'format_id': 'video=4482000',
1330 'manifest_url': 'https://sdn-global-streaming-cache-3qsdn.akamaized.net/stream/3144/files/17/07/672975/3144-kZT4LWMQw6Rh7Kpd.ism/manifest.mpd',
1331 'ext': 'mp4',
1332 'width': 1688,
1333 'height': 720,
1334 'tbr': 4482,
1335 'format_note': 'DASH video',
1336 'container': 'mp4_dash',
1337 'vcodec': 'avc1.4D401F',
1338 'acodec': 'none',
1339 'url': 'https://sdn-global-streaming-cache-3qsdn.akamaized.net/stream/3144/files/17/07/672975/3144-kZT4LWMQw6Rh7Kpd.ism/manifest.mpd',
1340 'fragment_base_url': 'https://sdn-global-streaming-cache-3qsdn.akamaized.net/stream/3144/files/17/07/672975/3144-kZT4LWMQw6Rh7Kpd.ism/dash/',
1341 'protocol': 'http_dash_segments',
1342 'video_ext': 'mp4',
1343 'audio_ext': 'none',
1344 'vbr': 4482,
becdc7f8
F
1345 }],
1346 {
177877c5 1347 'en': [
becdc7f8 1348 {
177877c5 1349 'ext': 'mp4',
1350 'manifest_url': 'https://sdn-global-streaming-cache-3qsdn.akamaized.net/stream/3144/files/17/07/672975/3144-kZT4LWMQw6Rh7Kpd.ism/manifest.mpd',
1351 'url': 'https://sdn-global-streaming-cache-3qsdn.akamaized.net/stream/3144/files/17/07/672975/3144-kZT4LWMQw6Rh7Kpd.ism/manifest.mpd',
1352 'fragment_base_url': 'https://sdn-global-streaming-cache-3qsdn.akamaized.net/stream/3144/files/17/07/672975/3144-kZT4LWMQw6Rh7Kpd.ism/dash/',
1353 'protocol': 'http_dash_segments',
becdc7f8
F
1354 }
1355 ]
1356 },
41bf647e 1357 )
48504785
S
1358 ]
1359
becdc7f8 1360 for mpd_file, mpd_url, mpd_base_url, expected_formats, expected_subtitles in _TEST_CASES:
86e5f3ed 1361 with open('./test/testdata/mpd/%s.mpd' % mpd_file, encoding='utf-8') as f:
becdc7f8 1362 formats, subtitles = self.ie._parse_mpd_formats_and_subtitles(
48504785 1363 compat_etree_fromstring(f.read().encode('utf-8')),
2e27421c 1364 mpd_base_url=mpd_base_url, mpd_url=mpd_url)
48504785
S
1365 self.ie._sort_formats(formats)
1366 expect_value(self, formats, expected_formats, None)
becdc7f8 1367 expect_value(self, subtitles, expected_subtitles, None)
48504785 1368
5fbcebed
F
1369 def test_parse_ism_formats(self):
1370 _TEST_CASES = [
1371 (
1372 'sintel',
1373 'https://sdn-global-streaming-cache-3qsdn.akamaized.net/stream/3144/files/17/07/672975/3144-kZT4LWMQw6Rh7Kpd.ism/Manifest',
1374 [{
177877c5 1375 'format_id': 'audio-128',
1376 'url': 'https://sdn-global-streaming-cache-3qsdn.akamaized.net/stream/3144/files/17/07/672975/3144-kZT4LWMQw6Rh7Kpd.ism/Manifest',
1377 'manifest_url': 'https://sdn-global-streaming-cache-3qsdn.akamaized.net/stream/3144/files/17/07/672975/3144-kZT4LWMQw6Rh7Kpd.ism/Manifest',
1378 'ext': 'isma',
1379 'tbr': 128,
1380 'asr': 48000,
1381 'vcodec': 'none',
1382 'acodec': 'AACL',
1383 'protocol': 'ism',
1384 '_download_params': {
1385 'stream_type': 'audio',
1386 'duration': 8880746666,
1387 'timescale': 10000000,
1388 'width': 0,
1389 'height': 0,
1390 'fourcc': 'AACL',
1391 'codec_private_data': '1190',
1392 'sampling_rate': 48000,
1393 'channels': 2,
1394 'bits_per_sample': 16,
1395 'nal_unit_length_field': 4
5fbcebed 1396 },
177877c5 1397 'audio_ext': 'isma',
1398 'video_ext': 'none',
1399 'abr': 128,
1400 }, {
1401 'format_id': 'video-100',
1402 'url': 'https://sdn-global-streaming-cache-3qsdn.akamaized.net/stream/3144/files/17/07/672975/3144-kZT4LWMQw6Rh7Kpd.ism/Manifest',
1403 'manifest_url': 'https://sdn-global-streaming-cache-3qsdn.akamaized.net/stream/3144/files/17/07/672975/3144-kZT4LWMQw6Rh7Kpd.ism/Manifest',
1404 'ext': 'ismv',
1405 'width': 336,
1406 'height': 144,
1407 'tbr': 100,
1408 'vcodec': 'AVC1',
1409 'acodec': 'none',
1410 'protocol': 'ism',
1411 '_download_params': {
1412 'stream_type': 'video',
1413 'duration': 8880746666,
1414 'timescale': 10000000,
1415 'width': 336,
1416 'height': 144,
1417 'fourcc': 'AVC1',
1418 'codec_private_data': '00000001674D401FDA0544EFFC2D002CBC40000003004000000C03C60CA80000000168EF32C8',
1419 'channels': 2,
1420 'bits_per_sample': 16,
1421 'nal_unit_length_field': 4
5fbcebed 1422 },
177877c5 1423 'video_ext': 'ismv',
1424 'audio_ext': 'none',
1425 'vbr': 100,
1426 }, {
1427 'format_id': 'video-326',
1428 'url': 'https://sdn-global-streaming-cache-3qsdn.akamaized.net/stream/3144/files/17/07/672975/3144-kZT4LWMQw6Rh7Kpd.ism/Manifest',
1429 'manifest_url': 'https://sdn-global-streaming-cache-3qsdn.akamaized.net/stream/3144/files/17/07/672975/3144-kZT4LWMQw6Rh7Kpd.ism/Manifest',
1430 'ext': 'ismv',
1431 'width': 562,
1432 'height': 240,
1433 'tbr': 326,
1434 'vcodec': 'AVC1',
1435 'acodec': 'none',
1436 'protocol': 'ism',
1437 '_download_params': {
1438 'stream_type': 'video',
1439 'duration': 8880746666,
1440 'timescale': 10000000,
1441 'width': 562,
1442 'height': 240,
1443 'fourcc': 'AVC1',
1444 'codec_private_data': '00000001674D401FDA0241FE23FFC3BC83BA44000003000400000300C03C60CA800000000168EF32C8',
1445 'channels': 2,
1446 'bits_per_sample': 16,
1447 'nal_unit_length_field': 4
5fbcebed 1448 },
177877c5 1449 'video_ext': 'ismv',
1450 'audio_ext': 'none',
1451 'vbr': 326,
1452 }, {
1453 'format_id': 'video-698',
1454 'url': 'https://sdn-global-streaming-cache-3qsdn.akamaized.net/stream/3144/files/17/07/672975/3144-kZT4LWMQw6Rh7Kpd.ism/Manifest',
1455 'manifest_url': 'https://sdn-global-streaming-cache-3qsdn.akamaized.net/stream/3144/files/17/07/672975/3144-kZT4LWMQw6Rh7Kpd.ism/Manifest',
1456 'ext': 'ismv',
1457 'width': 844,
1458 'height': 360,
1459 'tbr': 698,
1460 'vcodec': 'AVC1',
1461 'acodec': 'none',
1462 'protocol': 'ism',
1463 '_download_params': {
1464 'stream_type': 'video',
1465 'duration': 8880746666,
1466 'timescale': 10000000,
1467 'width': 844,
1468 'height': 360,
1469 'fourcc': 'AVC1',
1470 'codec_private_data': '00000001674D401FDA0350BFB97FF06AF06AD1000003000100000300300F1832A00000000168EF32C8',
1471 'channels': 2,
1472 'bits_per_sample': 16,
1473 'nal_unit_length_field': 4
5fbcebed 1474 },
177877c5 1475 'video_ext': 'ismv',
1476 'audio_ext': 'none',
1477 'vbr': 698,
1478 }, {
1479 'format_id': 'video-1493',
1480 'url': 'https://sdn-global-streaming-cache-3qsdn.akamaized.net/stream/3144/files/17/07/672975/3144-kZT4LWMQw6Rh7Kpd.ism/Manifest',
1481 'manifest_url': 'https://sdn-global-streaming-cache-3qsdn.akamaized.net/stream/3144/files/17/07/672975/3144-kZT4LWMQw6Rh7Kpd.ism/Manifest',
1482 'ext': 'ismv',
1483 'width': 1126,
1484 'height': 480,
1485 'tbr': 1493,
1486 'vcodec': 'AVC1',
1487 'acodec': 'none',
1488 'protocol': 'ism',
1489 '_download_params': {
1490 'stream_type': 'video',
1491 'duration': 8880746666,
1492 'timescale': 10000000,
1493 'width': 1126,
1494 'height': 480,
1495 'fourcc': 'AVC1',
1496 'codec_private_data': '00000001674D401FDA011C3DE6FFF0D890D871000003000100000300300F1832A00000000168EF32C8',
1497 'channels': 2,
1498 'bits_per_sample': 16,
1499 'nal_unit_length_field': 4
5fbcebed 1500 },
177877c5 1501 'video_ext': 'ismv',
1502 'audio_ext': 'none',
1503 'vbr': 1493,
1504 }, {
1505 'format_id': 'video-4482',
1506 'url': 'https://sdn-global-streaming-cache-3qsdn.akamaized.net/stream/3144/files/17/07/672975/3144-kZT4LWMQw6Rh7Kpd.ism/Manifest',
1507 'manifest_url': 'https://sdn-global-streaming-cache-3qsdn.akamaized.net/stream/3144/files/17/07/672975/3144-kZT4LWMQw6Rh7Kpd.ism/Manifest',
1508 'ext': 'ismv',
1509 'width': 1688,
1510 'height': 720,
1511 'tbr': 4482,
1512 'vcodec': 'AVC1',
1513 'acodec': 'none',
1514 'protocol': 'ism',
1515 '_download_params': {
1516 'stream_type': 'video',
1517 'duration': 8880746666,
1518 'timescale': 10000000,
1519 'width': 1688,
1520 'height': 720,
1521 'fourcc': 'AVC1',
1522 'codec_private_data': '00000001674D401FDA01A816F97FFC1ABC1AB440000003004000000C03C60CA80000000168EF32C8',
1523 'channels': 2,
1524 'bits_per_sample': 16,
1525 'nal_unit_length_field': 4
5fbcebed 1526 },
177877c5 1527 'video_ext': 'ismv',
1528 'audio_ext': 'none',
1529 'vbr': 4482,
5fbcebed
F
1530 }],
1531 {
177877c5 1532 'eng': [
5fbcebed 1533 {
177877c5 1534 'ext': 'ismt',
1535 'protocol': 'ism',
1536 'url': 'https://sdn-global-streaming-cache-3qsdn.akamaized.net/stream/3144/files/17/07/672975/3144-kZT4LWMQw6Rh7Kpd.ism/Manifest',
1537 'manifest_url': 'https://sdn-global-streaming-cache-3qsdn.akamaized.net/stream/3144/files/17/07/672975/3144-kZT4LWMQw6Rh7Kpd.ism/Manifest',
1538 '_download_params': {
1539 'stream_type': 'text',
1540 'duration': 8880746666,
1541 'timescale': 10000000,
1542 'fourcc': 'TTML',
1543 'codec_private_data': ''
5fbcebed
F
1544 }
1545 }
1546 ]
1547 },
1548 ),
1549 ]
1550
1551 for ism_file, ism_url, expected_formats, expected_subtitles in _TEST_CASES:
86e5f3ed 1552 with open('./test/testdata/ism/%s.Manifest' % ism_file, encoding='utf-8') as f:
5fbcebed
F
1553 formats, subtitles = self.ie._parse_ism_formats_and_subtitles(
1554 compat_etree_fromstring(f.read().encode('utf-8')), ism_url=ism_url)
1555 self.ie._sort_formats(formats)
1556 expect_value(self, formats, expected_formats, None)
1557 expect_value(self, subtitles, expected_subtitles, None)
1558
181e381f
S
1559 def test_parse_f4m_formats(self):
1560 _TEST_CASES = [
1561 (
067aa17e 1562 # https://github.com/ytdl-org/youtube-dl/issues/14660
181e381f
S
1563 'custom_base_url',
1564 'http://api.new.livestream.com/accounts/6115179/events/6764928/videos/144884262.f4m',
1565 [{
1566 'manifest_url': 'http://api.new.livestream.com/accounts/6115179/events/6764928/videos/144884262.f4m',
1567 'ext': 'flv',
1568 'format_id': '2148',
1569 'protocol': 'f4m',
1570 'tbr': 2148,
1571 'width': 1280,
1572 'height': 720,
1573 }]
1574 ),
1575 ]
1576
1577 for f4m_file, f4m_url, expected_formats in _TEST_CASES:
86e5f3ed 1578 with open('./test/testdata/f4m/%s.f4m' % f4m_file, encoding='utf-8') as f:
181e381f
S
1579 formats = self.ie._parse_f4m_formats(
1580 compat_etree_fromstring(f.read().encode('utf-8')),
1581 f4m_url, None)
1582 self.ie._sort_formats(formats)
1583 expect_value(self, formats, expected_formats, None)
582be358 1584
96b8b9ab
RC
1585 def test_parse_xspf(self):
1586 _TEST_CASES = [
1587 (
1588 'foo_xspf',
47a5cb77 1589 'https://example.org/src/foo_xspf.xspf',
96b8b9ab 1590 [{
47a5cb77
S
1591 'id': 'foo_xspf',
1592 'title': 'Pandemonium',
96b8b9ab
RC
1593 'description': 'Visit http://bigbrother404.bandcamp.com',
1594 'duration': 202.416,
47a5cb77
S
1595 'formats': [{
1596 'manifest_url': 'https://example.org/src/foo_xspf.xspf',
1597 'url': 'https://example.org/src/cd1/track%201.mp3',
1598 }],
1599 }, {
96b8b9ab 1600 'id': 'foo_xspf',
47a5cb77 1601 'title': 'Final Cartridge (Nichico Twelve Remix)',
96b8b9ab
RC
1602 'description': 'Visit http://bigbrother404.bandcamp.com',
1603 'duration': 255.857,
47a5cb77
S
1604 'formats': [{
1605 'manifest_url': 'https://example.org/src/foo_xspf.xspf',
1606 'url': 'https://example.org/%E3%83%88%E3%83%A9%E3%83%83%E3%82%AF%E3%80%80%EF%BC%92.mp3',
1607 }],
1608 }, {
96b8b9ab 1609 'id': 'foo_xspf',
47a5cb77 1610 'title': 'Rebuilding Nightingale',
96b8b9ab
RC
1611 'description': 'Visit http://bigbrother404.bandcamp.com',
1612 'duration': 287.915,
47a5cb77
S
1613 'formats': [{
1614 'manifest_url': 'https://example.org/src/foo_xspf.xspf',
1615 'url': 'https://example.org/src/track3.mp3',
1616 }, {
1617 'manifest_url': 'https://example.org/src/foo_xspf.xspf',
1618 'url': 'https://example.com/track3.mp3',
1619 }]
96b8b9ab
RC
1620 }]
1621 ),
1622 ]
1623
47a5cb77 1624 for xspf_file, xspf_url, expected_entries in _TEST_CASES:
86e5f3ed 1625 with open('./test/testdata/xspf/%s.xspf' % xspf_file, encoding='utf-8') as f:
96b8b9ab
RC
1626 entries = self.ie._parse_xspf(
1627 compat_etree_fromstring(f.read().encode('utf-8')),
47a5cb77 1628 xspf_file, xspf_url=xspf_url, xspf_base_url=xspf_url)
96b8b9ab
RC
1629 expect_value(self, entries, expected_entries, None)
1630 for i in range(len(entries)):
1631 expect_dict(self, entries[i], expected_entries[i])
1632
95e42d73
XDG
1633 def test_response_with_expected_status_returns_content(self):
1634 # Checks for mitigations against the effects of
1635 # <https://bugs.python.org/issue15002> that affect Python 3.4.1+, which
1636 # manifest as `_download_webpage`, `_download_xml`, `_download_json`,
1637 # or the underlying `_download_webpage_handle` returning no content
1638 # when a response matches `expected_status`.
1639
1640 httpd = compat_http_server.HTTPServer(
1641 ('127.0.0.1', 0), InfoExtractorTestRequestHandler)
1642 port = http_server_port(httpd)
1643 server_thread = threading.Thread(target=httpd.serve_forever)
1644 server_thread.daemon = True
1645 server_thread.start()
1646
1647 (content, urlh) = self.ie._download_webpage_handle(
1648 'http://127.0.0.1:%d/teapot' % port, None,
1649 expected_status=TEAPOT_RESPONSE_STATUS)
1650 self.assertEqual(content, TEAPOT_RESPONSE_BODY)
1651
f58a5060 1652
14719565
JMF
1653if __name__ == '__main__':
1654 unittest.main()