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