]>
Commit | Line | Data |
---|---|---|
14719565 JMF |
1 | #!/usr/bin/env python |
2 | ||
3 | from __future__ import unicode_literals | |
4 | ||
5 | # Allow direct execution | |
cb252080 | 6 | import io |
14719565 JMF |
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 | ||
95e42d73 | 12 | from test.helper import FakeYDL, expect_dict, expect_value, http_server_port |
7a5c1cfe P |
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 | |
95e42d73 XDG |
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 | |
14719565 JMF |
36 | |
37 | ||
38 | class TestIE(InfoExtractor): | |
39 | pass | |
40 | ||
41 | ||
42 | class TestInfoExtractor(unittest.TestCase): | |
43 | def setUp(self): | |
44 | self.ie = TestIE(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&key2=val2'/> | |
1c29e81e | 60 | <meta content='application/x-shockwave-flash' property='og:video:type'> |
db0a8ad9 | 61 | <meta content='Foo' property=og:foobar> |
448ef1f3 S |
62 | <meta name="og:test1" content='foo > < bar'/> |
63 | <meta name="og:test2" content="foo >//< bar"/> | |
22f5f5c6 | 64 | <meta property=og-test3 content='Ill-formatted opengraph'/> |
14719565 JMF |
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') | |
1c29e81e | 69 | self.assertEqual(ie._og_search_video_url(html, default=None), None) |
db0a8ad9 | 70 | self.assertEqual(ie._og_search_property('foobar', html), 'Foo') |
448ef1f3 S |
71 | self.assertEqual(ie._og_search_property('test1', html), 'foo > < bar') |
72 | self.assertEqual(ie._og_search_property('test2', html), 'foo >//< bar') | |
22f5f5c6 | 73 | self.assertEqual(ie._og_search_property('test3', html), 'Ill-formatted opengraph') |
b070564e S |
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) | |
14719565 | 77 | |
bec22481 PH |
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') | |
88d9f6c0 S |
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) | |
bec22481 | 100 | |
29f7c58a | 101 | def test_search_json_ld_realworld(self): |
102 | # https://github.com/ytdl-org/youtube-dl/issues/23306 | |
103 | expect_dict( | |
104 | self, | |
105 | self.ie._search_json_ld(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>''', None), | |
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 | ||
6a801f44 JMF |
150 | def test_download_json(self): |
151 | uri = encode_data_uri(b'{"foo": "blah"}', 'application/json') | |
152 | self.assertEqual(self.ie._download_json(uri, None), {'foo': 'blah'}) | |
153 | uri = encode_data_uri(b'callback({"foo": "blah"})', 'application/javascript') | |
154 | self.assertEqual(self.ie._download_json(uri, None, transform_source=strip_jsonp), {'foo': 'blah'}) | |
155 | uri = encode_data_uri(b'{"foo": invalid}', 'application/json') | |
156 | self.assertRaises(ExtractorError, self.ie._download_json, uri, None) | |
157 | self.assertEqual(self.ie._download_json(uri, None, fatal=False), None) | |
158 | ||
d493f15c | 159 | def test_parse_html5_media_entries(self): |
29f7c58a | 160 | # inline video tag |
161 | expect_dict( | |
162 | self, | |
163 | self.ie._parse_html5_media_entries( | |
164 | 'https://127.0.0.1/video.html', | |
165 | r'<html><video src="/vid.mp4" /></html>', None)[0], | |
166 | { | |
167 | 'formats': [{ | |
168 | 'url': 'https://127.0.0.1/vid.mp4', | |
169 | }], | |
170 | }) | |
171 | ||
d493f15c S |
172 | # from https://www.r18.com/ |
173 | # with kpbs in label | |
174 | expect_dict( | |
175 | self, | |
176 | self.ie._parse_html5_media_entries( | |
177 | 'https://www.r18.com/', | |
178 | r''' | |
179 | <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"> | |
180 | <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"> | |
181 | <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"> | |
182 | <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"> | |
183 | <p>Your browser does not support the video tag.</p> | |
184 | </video> | |
185 | ''', None)[0], | |
186 | { | |
187 | 'formats': [{ | |
188 | 'url': 'https://awscc3001.r18.com/litevideo/freepv/m/mgm/mgmr105/mgmr105_sm_w.mp4', | |
189 | 'ext': 'mp4', | |
190 | 'format_id': '300kbps', | |
191 | 'height': 240, | |
192 | 'tbr': 300, | |
193 | }, { | |
194 | 'url': 'https://awscc3001.r18.com/litevideo/freepv/m/mgm/mgmr105/mgmr105_dm_w.mp4', | |
195 | 'ext': 'mp4', | |
196 | 'format_id': '1000kbps', | |
197 | 'height': 480, | |
198 | 'tbr': 1000, | |
199 | }, { | |
200 | 'url': 'https://awscc3001.r18.com/litevideo/freepv/m/mgm/mgmr105/mgmr105_dmb_w.mp4', | |
201 | 'ext': 'mp4', | |
202 | 'format_id': '1500kbps', | |
203 | 'height': 740, | |
204 | 'tbr': 1500, | |
205 | }], | |
206 | 'thumbnail': '//pics.r18.com/digital/amateur/mgmr105/mgmr105jp.jpg' | |
207 | }) | |
208 | ||
209 | # from https://www.csfd.cz/ | |
210 | # with width and height | |
211 | expect_dict( | |
212 | self, | |
213 | self.ie._parse_html5_media_entries( | |
214 | 'https://www.csfd.cz/', | |
215 | r''' | |
216 | <video width="770" height="328" preload="none" controls poster="https://img.csfd.cz/files/images/film/video/preview/163/344/163344118_748d20.png?h360" > | |
217 | <source src="https://video.csfd.cz/files/videos/157/750/157750813/163327358_eac647.mp4" type="video/mp4" width="640" height="360"> | |
218 | <source src="https://video.csfd.cz/files/videos/157/750/157750813/163327360_3d2646.mp4" type="video/mp4" width="1280" height="720"> | |
219 | <source src="https://video.csfd.cz/files/videos/157/750/157750813/163327356_91f258.mp4" type="video/mp4" width="1920" height="1080"> | |
220 | <source src="https://video.csfd.cz/files/videos/157/750/157750813/163327359_962b4a.webm" type="video/webm" width="640" height="360"> | |
221 | <source src="https://video.csfd.cz/files/videos/157/750/157750813/163327361_6feee0.webm" type="video/webm" width="1280" height="720"> | |
222 | <source src="https://video.csfd.cz/files/videos/157/750/157750813/163327357_8ab472.webm" type="video/webm" width="1920" height="1080"> | |
223 | <track src="https://video.csfd.cz/files/subtitles/163/344/163344115_4c388b.srt" type="text/x-srt" kind="subtitles" srclang="cs" label="cs"> | |
224 | </video> | |
225 | ''', None)[0], | |
226 | { | |
227 | 'formats': [{ | |
228 | 'url': 'https://video.csfd.cz/files/videos/157/750/157750813/163327358_eac647.mp4', | |
229 | 'ext': 'mp4', | |
230 | 'width': 640, | |
231 | 'height': 360, | |
232 | }, { | |
233 | 'url': 'https://video.csfd.cz/files/videos/157/750/157750813/163327360_3d2646.mp4', | |
234 | 'ext': 'mp4', | |
235 | 'width': 1280, | |
236 | 'height': 720, | |
237 | }, { | |
238 | 'url': 'https://video.csfd.cz/files/videos/157/750/157750813/163327356_91f258.mp4', | |
239 | 'ext': 'mp4', | |
240 | 'width': 1920, | |
241 | 'height': 1080, | |
242 | }, { | |
243 | 'url': 'https://video.csfd.cz/files/videos/157/750/157750813/163327359_962b4a.webm', | |
244 | 'ext': 'webm', | |
245 | 'width': 640, | |
246 | 'height': 360, | |
247 | }, { | |
248 | 'url': 'https://video.csfd.cz/files/videos/157/750/157750813/163327361_6feee0.webm', | |
249 | 'ext': 'webm', | |
250 | 'width': 1280, | |
251 | 'height': 720, | |
252 | }, { | |
253 | 'url': 'https://video.csfd.cz/files/videos/157/750/157750813/163327357_8ab472.webm', | |
254 | 'ext': 'webm', | |
255 | 'width': 1920, | |
256 | 'height': 1080, | |
257 | }], | |
258 | 'subtitles': { | |
259 | 'cs': [{'url': 'https://video.csfd.cz/files/subtitles/163/344/163344115_4c388b.srt'}] | |
260 | }, | |
261 | 'thumbnail': 'https://img.csfd.cz/files/images/film/video/preview/163/344/163344118_748d20.png?h360' | |
262 | }) | |
263 | ||
264 | # from https://tamasha.com/v/Kkdjw | |
265 | # with height in label | |
266 | expect_dict( | |
267 | self, | |
268 | self.ie._parse_html5_media_entries( | |
269 | 'https://tamasha.com/v/Kkdjw', | |
270 | r''' | |
271 | <video crossorigin="anonymous"> | |
272 | <source src="https://s-v2.tamasha.com/statics/videos_file/19/8f/Kkdjw_198feff8577d0057536e905cce1fb61438dd64e0_n_240.mp4" type="video/mp4" label="AUTO" res="0"/> | |
273 | <source src="https://s-v2.tamasha.com/statics/videos_file/19/8f/Kkdjw_198feff8577d0057536e905cce1fb61438dd64e0_n_240.mp4" type="video/mp4" | |
274 | label="240p" res="240"/> | |
275 | <source src="https://s-v2.tamasha.com/statics/videos_file/20/00/Kkdjw_200041c66f657fc967db464d156eafbc1ed9fe6f_n_144.mp4" type="video/mp4" | |
276 | label="144p" res="144"/> | |
277 | </video> | |
278 | ''', None)[0], | |
279 | { | |
280 | 'formats': [{ | |
281 | 'url': 'https://s-v2.tamasha.com/statics/videos_file/19/8f/Kkdjw_198feff8577d0057536e905cce1fb61438dd64e0_n_240.mp4', | |
282 | }, { | |
283 | 'url': 'https://s-v2.tamasha.com/statics/videos_file/19/8f/Kkdjw_198feff8577d0057536e905cce1fb61438dd64e0_n_240.mp4', | |
284 | 'ext': 'mp4', | |
285 | 'format_id': '240p', | |
286 | 'height': 240, | |
287 | }, { | |
288 | 'url': 'https://s-v2.tamasha.com/statics/videos_file/20/00/Kkdjw_200041c66f657fc967db464d156eafbc1ed9fe6f_n_144.mp4', | |
289 | 'ext': 'mp4', | |
290 | 'format_id': '144p', | |
291 | 'height': 144, | |
292 | }] | |
293 | }) | |
294 | ||
295 | # from https://www.directvnow.com | |
296 | # with data-src | |
297 | expect_dict( | |
298 | self, | |
299 | self.ie._parse_html5_media_entries( | |
300 | 'https://www.directvnow.com', | |
301 | r''' | |
302 | <video id="vid1" class="header--video-masked active" muted playsinline> | |
303 | <source data-src="https://cdn.directv.com/content/dam/dtv/prod/website_directvnow-international/videos/DTVN_hdr_HBO_v3.mp4" type="video/mp4" /> | |
304 | </video> | |
305 | ''', None)[0], | |
306 | { | |
307 | 'formats': [{ | |
308 | 'ext': 'mp4', | |
309 | 'url': 'https://cdn.directv.com/content/dam/dtv/prod/website_directvnow-international/videos/DTVN_hdr_HBO_v3.mp4', | |
310 | }] | |
311 | }) | |
312 | ||
313 | # from https://www.directvnow.com | |
314 | # with data-src | |
315 | expect_dict( | |
316 | self, | |
317 | self.ie._parse_html5_media_entries( | |
318 | 'https://www.directvnow.com', | |
319 | r''' | |
320 | <video id="vid1" class="header--video-masked active" muted playsinline> | |
321 | <source data-src="https://cdn.directv.com/content/dam/dtv/prod/website_directvnow-international/videos/DTVN_hdr_HBO_v3.mp4" type="video/mp4" /> | |
322 | </video> | |
323 | ''', None)[0], | |
324 | { | |
325 | 'formats': [{ | |
326 | 'url': 'https://cdn.directv.com/content/dam/dtv/prod/website_directvnow-international/videos/DTVN_hdr_HBO_v3.mp4', | |
327 | 'ext': 'mp4', | |
328 | }] | |
329 | }) | |
330 | ||
331 | # from https://www.klarna.com/uk/ | |
332 | # with data-video-src | |
333 | expect_dict( | |
334 | self, | |
335 | self.ie._parse_html5_media_entries( | |
336 | 'https://www.directvnow.com', | |
337 | r''' | |
338 | <video loop autoplay muted class="responsive-video block-kl__video video-on-medium"> | |
339 | <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" /> | |
340 | </video> | |
341 | ''', None)[0], | |
342 | { | |
343 | 'formats': [{ | |
344 | 'url': 'https://www.klarna.com/uk/wp-content/uploads/sites/11/2019/01/KL062_Smooth3_0_DogWalking_5s_920x080_.mp4', | |
345 | 'ext': 'mp4', | |
346 | }], | |
347 | }) | |
348 | ||
7f3590c4 S |
349 | def test_extract_jwplayer_data_realworld(self): |
350 | # from http://www.suffolk.edu/sjc/ | |
351 | expect_dict( | |
352 | self, | |
353 | self.ie._extract_jwplayer_data(r''' | |
354 | <script type='text/javascript'> | |
355 | jwplayer('my-video').setup({ | |
356 | file: 'rtmp://192.138.214.154/live/sjclive', | |
357 | fallback: 'true', | |
358 | width: '95%', | |
359 | aspectratio: '16:9', | |
360 | primary: 'flash', | |
361 | mediaid:'XEgvuql4' | |
362 | }); | |
363 | </script> | |
364 | ''', None, require_title=False), | |
365 | { | |
366 | 'id': 'XEgvuql4', | |
367 | 'formats': [{ | |
368 | 'url': 'rtmp://192.138.214.154/live/sjclive', | |
369 | 'ext': 'flv' | |
370 | }] | |
371 | }) | |
372 | ||
373 | # from https://www.pornoxo.com/videos/7564/striptease-from-sexy-secretary/ | |
374 | expect_dict( | |
375 | self, | |
376 | self.ie._extract_jwplayer_data(r''' | |
377 | <script type="text/javascript"> | |
378 | jwplayer("mediaplayer").setup({ | |
379 | 'videoid': "7564", | |
380 | 'width': "100%", | |
381 | 'aspectratio': "16:9", | |
382 | 'stretching': "exactfit", | |
383 | 'autostart': 'false', | |
384 | 'flashplayer': "https://t04.vipstreamservice.com/jwplayer/v5.10/player.swf", | |
385 | '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", | |
386 | 'image': "https://t03.vipstreamservice.com/thumbs/pxo-full/2009-12/14/a4b2157147afe5efa93ce1978e0265289c193874e02597.flv-full-13.jpg", | |
387 | '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", | |
388 | 'logo.hide': true, | |
389 | 'skin': "https://t04.vipstreamservice.com/jwplayer/skin/modieus-blk.zip", | |
390 | 'plugins': "https://t04.vipstreamservice.com/jwplayer/dock/dockableskinnableplugin.swf", | |
391 | 'dockableskinnableplugin.piclink': "/index.php?key=ajax-videothumbsn&vid=7564&data=2009-12--14--4b2157147afe5efa93ce1978e0265289c193874e02597.flv--17370", | |
392 | 'controlbar': 'bottom', | |
393 | 'modes': [ | |
394 | {type: 'flash', src: 'https://t04.vipstreamservice.com/jwplayer/v5.10/player.swf'} | |
395 | ], | |
396 | 'provider': 'http' | |
397 | }); | |
398 | //noinspection JSAnnotator | |
399 | invideo.setup({ | |
400 | adsUrl: "/banner-iframe/?zoneId=32", | |
401 | adsUrl2: "", | |
402 | autostart: false | |
403 | }); | |
404 | </script> | |
405 | ''', 'dummy', require_title=False), | |
406 | { | |
407 | 'thumbnail': 'https://t03.vipstreamservice.com/thumbs/pxo-full/2009-12/14/a4b2157147afe5efa93ce1978e0265289c193874e02597.flv-full-13.jpg', | |
408 | 'formats': [{ | |
409 | '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', | |
410 | 'ext': 'flv' | |
411 | }] | |
412 | }) | |
413 | ||
414 | # from http://www.indiedb.com/games/king-machine/videos | |
415 | expect_dict( | |
416 | self, | |
417 | self.ie._extract_jwplayer_data(r''' | |
418 | <script> | |
419 | 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) { | |
420 | videoAnalytics("play"); | |
421 | }).once("complete", function(event) { | |
422 | videoAnalytics("completed"); | |
423 | }); | |
424 | </script> | |
425 | ''', 'dummy'), | |
426 | { | |
427 | 'title': 'king machine trailer 1', | |
428 | 'thumbnail': 'http://media.indiedb.com/cache/images/games/1/50/49678/thumb_620x2000/king-machine-trailer.mp4.jpg', | |
429 | 'formats': [{ | |
430 | 'url': 'http://cdn.dbolical.com/cache/videos/games/1/50/49678/encode_mp4/king-machine-trailer.mp4', | |
431 | 'height': 360, | |
432 | 'ext': 'mp4' | |
433 | }, { | |
434 | 'url': 'http://cdn.dbolical.com/cache/videos/games/1/50/49678/encode720p_mp4/king-machine-trailer.mp4', | |
435 | 'height': 720, | |
436 | 'ext': 'mp4' | |
437 | }] | |
438 | }) | |
439 | ||
cb252080 S |
440 | def test_parse_m3u8_formats(self): |
441 | _TEST_CASES = [ | |
442 | ( | |
310c2ed2 | 443 | # https://github.com/ytdl-org/youtube-dl/issues/11995 |
444 | # http://teamcoco.com/video/clueless-gamer-super-bowl-for-honor | |
445 | 'img_bipbop_adv_example_fmp4', | |
446 | 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/master.m3u8', | |
cb252080 | 447 | [{ |
310c2ed2 | 448 | 'format_id': 'aud1-English', |
449 | 'url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/a1/prog_index.m3u8', | |
450 | 'manifest_url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/master.m3u8', | |
451 | 'language': 'en', | |
cb252080 | 452 | 'ext': 'mp4', |
cb252080 | 453 | 'protocol': 'm3u8', |
310c2ed2 | 454 | 'audio_ext': 'mp4', |
cb252080 | 455 | }, { |
310c2ed2 | 456 | 'format_id': 'aud2-English', |
457 | 'url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/a2/prog_index.m3u8', | |
458 | 'manifest_url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/master.m3u8', | |
459 | 'language': 'en', | |
cb252080 | 460 | 'ext': 'mp4', |
cb252080 | 461 | 'protocol': 'm3u8', |
310c2ed2 | 462 | 'audio_ext': 'mp4', |
cb252080 | 463 | }, { |
310c2ed2 | 464 | 'format_id': 'aud3-English', |
465 | 'url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/a3/prog_index.m3u8', | |
466 | 'manifest_url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/master.m3u8', | |
467 | 'language': 'en', | |
cb252080 | 468 | 'ext': 'mp4', |
cb252080 | 469 | 'protocol': 'm3u8', |
310c2ed2 | 470 | 'audio_ext': 'mp4', |
cb252080 | 471 | }, { |
310c2ed2 | 472 | 'format_id': '530', |
473 | 'url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/v2/prog_index.m3u8', | |
474 | 'manifest_url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/master.m3u8', | |
cb252080 | 475 | 'ext': 'mp4', |
cb252080 | 476 | 'protocol': 'm3u8', |
310c2ed2 | 477 | 'width': 480, |
478 | 'height': 270, | |
479 | 'vcodec': 'avc1.640015', | |
cb252080 | 480 | }, { |
310c2ed2 | 481 | 'format_id': '561', |
482 | 'url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/v2/prog_index.m3u8', | |
483 | 'manifest_url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/master.m3u8', | |
cb252080 S |
484 | 'ext': 'mp4', |
485 | 'protocol': 'm3u8', | |
310c2ed2 | 486 | 'width': 480, |
487 | 'height': 270, | |
488 | 'vcodec': 'avc1.640015', | |
489 | }, { | |
490 | 'format_id': '753', | |
491 | 'url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/v2/prog_index.m3u8', | |
492 | 'manifest_url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/master.m3u8', | |
cb252080 | 493 | 'ext': 'mp4', |
cb252080 | 494 | 'protocol': 'm3u8', |
310c2ed2 | 495 | 'width': 480, |
496 | 'height': 270, | |
497 | 'vcodec': 'avc1.640015', | |
cb252080 | 498 | }, { |
310c2ed2 | 499 | 'format_id': '895', |
500 | 'url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/v3/prog_index.m3u8', | |
501 | 'manifest_url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/master.m3u8', | |
cb252080 | 502 | 'ext': 'mp4', |
cb252080 | 503 | 'protocol': 'm3u8', |
310c2ed2 | 504 | 'width': 640, |
505 | 'height': 360, | |
506 | 'vcodec': 'avc1.64001e', | |
cb252080 | 507 | }, { |
310c2ed2 | 508 | 'format_id': '926', |
509 | 'url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/v3/prog_index.m3u8', | |
510 | 'manifest_url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/master.m3u8', | |
cb252080 | 511 | 'ext': 'mp4', |
cb252080 | 512 | 'protocol': 'm3u8', |
310c2ed2 | 513 | 'width': 640, |
514 | 'height': 360, | |
515 | 'vcodec': 'avc1.64001e', | |
cb252080 | 516 | }, { |
310c2ed2 | 517 | 'format_id': '1118', |
518 | 'url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/v3/prog_index.m3u8', | |
519 | 'manifest_url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/master.m3u8', | |
cb252080 | 520 | 'ext': 'mp4', |
cb252080 | 521 | 'protocol': 'm3u8', |
310c2ed2 | 522 | 'width': 640, |
523 | 'height': 360, | |
524 | 'vcodec': 'avc1.64001e', | |
cb252080 | 525 | }, { |
310c2ed2 | 526 | 'format_id': '1265', |
527 | 'url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/v4/prog_index.m3u8', | |
528 | 'manifest_url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/master.m3u8', | |
cb252080 | 529 | 'ext': 'mp4', |
cb252080 | 530 | 'protocol': 'm3u8', |
310c2ed2 | 531 | 'width': 768, |
532 | 'height': 432, | |
533 | 'vcodec': 'avc1.64001e', | |
cb252080 | 534 | }, { |
310c2ed2 | 535 | 'format_id': '1295', |
536 | 'url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/v4/prog_index.m3u8', | |
537 | 'manifest_url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/master.m3u8', | |
cb252080 | 538 | 'ext': 'mp4', |
cb252080 | 539 | 'protocol': 'm3u8', |
310c2ed2 | 540 | 'width': 768, |
541 | 'height': 432, | |
542 | 'vcodec': 'avc1.64001e', | |
cb252080 | 543 | }, { |
310c2ed2 | 544 | 'format_id': '1487', |
545 | 'url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/v4/prog_index.m3u8', | |
546 | 'manifest_url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/master.m3u8', | |
cb252080 | 547 | 'ext': 'mp4', |
cb252080 | 548 | 'protocol': 'm3u8', |
310c2ed2 | 549 | 'width': 768, |
550 | 'height': 432, | |
551 | 'vcodec': 'avc1.64001e', | |
552 | }, { | |
553 | 'format_id': '2168', | |
554 | 'url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/v5/prog_index.m3u8', | |
555 | 'manifest_url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/master.m3u8', | |
cb252080 | 556 | 'ext': 'mp4', |
cb252080 | 557 | 'protocol': 'm3u8', |
310c2ed2 | 558 | 'width': 960, |
559 | 'height': 540, | |
560 | 'vcodec': 'avc1.640020', | |
cb252080 | 561 | }, { |
310c2ed2 | 562 | 'format_id': '2198', |
563 | 'url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/v5/prog_index.m3u8', | |
564 | 'manifest_url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/master.m3u8', | |
cb252080 | 565 | 'ext': 'mp4', |
cb252080 | 566 | 'protocol': 'm3u8', |
310c2ed2 | 567 | 'width': 960, |
568 | 'height': 540, | |
569 | 'vcodec': 'avc1.640020', | |
cb252080 | 570 | }, { |
310c2ed2 | 571 | 'format_id': '2390', |
572 | 'url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/v5/prog_index.m3u8', | |
573 | 'manifest_url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/master.m3u8', | |
cb252080 | 574 | 'ext': 'mp4', |
cb252080 | 575 | 'protocol': 'm3u8', |
310c2ed2 | 576 | 'width': 960, |
577 | 'height': 540, | |
578 | 'vcodec': 'avc1.640020', | |
cb252080 | 579 | }, { |
310c2ed2 | 580 | 'format_id': '3168', |
581 | 'url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/v6/prog_index.m3u8', | |
582 | 'manifest_url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/master.m3u8', | |
cb252080 | 583 | 'ext': 'mp4', |
cb252080 | 584 | 'protocol': 'm3u8', |
310c2ed2 | 585 | 'width': 1280, |
586 | 'height': 720, | |
587 | 'vcodec': 'avc1.640020', | |
cb252080 | 588 | }, { |
310c2ed2 | 589 | 'format_id': '3199', |
590 | 'url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/v6/prog_index.m3u8', | |
591 | 'manifest_url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/master.m3u8', | |
cb252080 | 592 | 'ext': 'mp4', |
cb252080 | 593 | 'protocol': 'm3u8', |
310c2ed2 | 594 | 'width': 1280, |
595 | 'height': 720, | |
596 | 'vcodec': 'avc1.640020', | |
cb252080 | 597 | }, { |
310c2ed2 | 598 | 'format_id': '3391', |
599 | 'url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/v6/prog_index.m3u8', | |
600 | 'manifest_url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/master.m3u8', | |
cb252080 | 601 | 'ext': 'mp4', |
cb252080 | 602 | 'protocol': 'm3u8', |
310c2ed2 | 603 | 'width': 1280, |
604 | 'height': 720, | |
605 | 'vcodec': 'avc1.640020', | |
606 | }, { | |
607 | 'format_id': '4670', | |
608 | 'url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/v7/prog_index.m3u8', | |
609 | 'manifest_url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/master.m3u8', | |
cb252080 | 610 | 'ext': 'mp4', |
cb252080 | 611 | 'protocol': 'm3u8', |
310c2ed2 | 612 | 'width': 1920, |
613 | 'height': 1080, | |
614 | 'vcodec': 'avc1.64002a', | |
cb252080 | 615 | }, { |
310c2ed2 | 616 | 'format_id': '4701', |
617 | 'url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/v7/prog_index.m3u8', | |
618 | 'manifest_url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/master.m3u8', | |
cb252080 | 619 | 'ext': 'mp4', |
cb252080 | 620 | 'protocol': 'm3u8', |
310c2ed2 | 621 | 'width': 1920, |
622 | 'height': 1080, | |
623 | 'vcodec': 'avc1.64002a', | |
cb252080 | 624 | }, { |
310c2ed2 | 625 | 'format_id': '4893', |
626 | 'url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/v7/prog_index.m3u8', | |
627 | 'manifest_url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/master.m3u8', | |
cb252080 | 628 | 'ext': 'mp4', |
cb252080 | 629 | 'protocol': 'm3u8', |
310c2ed2 | 630 | 'width': 1920, |
631 | 'height': 1080, | |
632 | 'vcodec': 'avc1.64002a', | |
cb252080 | 633 | }, { |
310c2ed2 | 634 | 'format_id': '6170', |
635 | 'url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/v8/prog_index.m3u8', | |
636 | 'manifest_url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/master.m3u8', | |
cb252080 | 637 | 'ext': 'mp4', |
cb252080 | 638 | 'protocol': 'm3u8', |
310c2ed2 | 639 | 'width': 1920, |
640 | 'height': 1080, | |
641 | 'vcodec': 'avc1.64002a', | |
cb252080 | 642 | }, { |
310c2ed2 | 643 | 'format_id': '6200', |
644 | 'url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/v8/prog_index.m3u8', | |
645 | 'manifest_url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/master.m3u8', | |
cb252080 | 646 | 'ext': 'mp4', |
cb252080 | 647 | 'protocol': 'm3u8', |
310c2ed2 | 648 | 'width': 1920, |
649 | 'height': 1080, | |
650 | 'vcodec': 'avc1.64002a', | |
cb252080 | 651 | }, { |
310c2ed2 | 652 | 'format_id': '6392', |
653 | 'url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/v8/prog_index.m3u8', | |
654 | 'manifest_url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/master.m3u8', | |
cb252080 | 655 | 'ext': 'mp4', |
cb252080 | 656 | 'protocol': 'm3u8', |
310c2ed2 | 657 | 'width': 1920, |
658 | 'height': 1080, | |
659 | 'vcodec': 'avc1.64002a', | |
660 | }, { | |
661 | 'format_id': '7968', | |
662 | 'url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/v9/prog_index.m3u8', | |
663 | 'manifest_url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/master.m3u8', | |
ddd258f9 | 664 | 'ext': 'mp4', |
ddd258f9 | 665 | 'protocol': 'm3u8', |
310c2ed2 | 666 | 'width': 1920, |
667 | 'height': 1080, | |
668 | 'vcodec': 'avc1.64002a', | |
ddd258f9 | 669 | }, { |
310c2ed2 | 670 | 'format_id': '7998', |
671 | 'url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/v9/prog_index.m3u8', | |
672 | 'manifest_url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/master.m3u8', | |
ddd258f9 | 673 | 'ext': 'mp4', |
ddd258f9 | 674 | 'protocol': 'm3u8', |
310c2ed2 | 675 | 'width': 1920, |
676 | 'height': 1080, | |
677 | 'vcodec': 'avc1.64002a', | |
ddd258f9 | 678 | }, { |
310c2ed2 | 679 | 'format_id': '8190', |
680 | 'url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/v9/prog_index.m3u8', | |
681 | 'manifest_url': 'https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/master.m3u8', | |
ddd258f9 | 682 | 'ext': 'mp4', |
ddd258f9 | 683 | 'protocol': 'm3u8', |
310c2ed2 | 684 | 'width': 1920, |
685 | 'height': 1080, | |
686 | 'vcodec': 'avc1.64002a', | |
a0c3b2d5 F |
687 | }], |
688 | {} | |
fc746c3f | 689 | ), |
cb252080 S |
690 | ] |
691 | ||
a0c3b2d5 | 692 | for m3u8_file, m3u8_url, expected_formats, expected_subs in _TEST_CASES: |
cb252080 S |
693 | with io.open('./test/testdata/m3u8/%s.m3u8' % m3u8_file, |
694 | mode='r', encoding='utf-8') as f: | |
a0c3b2d5 | 695 | formats, subs = self.ie._parse_m3u8_formats_and_subtitles( |
cb252080 S |
696 | f.read(), m3u8_url, ext='mp4') |
697 | self.ie._sort_formats(formats) | |
698 | expect_value(self, formats, expected_formats, None) | |
a0c3b2d5 | 699 | expect_value(self, subs, expected_subs, None) |
cb252080 | 700 | |
48504785 S |
701 | def test_parse_mpd_formats(self): |
702 | _TEST_CASES = [ | |
703 | ( | |
067aa17e | 704 | # https://github.com/ytdl-org/youtube-dl/issues/13919 |
9d6ac71c | 705 | # Also tests duplicate representation ids, see |
067aa17e | 706 | # https://github.com/ytdl-org/youtube-dl/issues/15111 |
48504785 | 707 | 'float_duration', |
2e27421c S |
708 | 'http://unknown/manifest.mpd', # mpd_url |
709 | None, # mpd_base_url | |
48504785 | 710 | [{ |
9d6ac71c S |
711 | 'manifest_url': 'http://unknown/manifest.mpd', |
712 | 'ext': 'm4a', | |
713 | 'format_id': '318597', | |
714 | 'format_note': 'DASH audio', | |
715 | 'protocol': 'http_dash_segments', | |
716 | 'acodec': 'mp4a.40.2', | |
717 | 'vcodec': 'none', | |
718 | 'tbr': 61.587, | |
719 | }, { | |
48504785 S |
720 | 'manifest_url': 'http://unknown/manifest.mpd', |
721 | 'ext': 'mp4', | |
722 | 'format_id': '318597', | |
723 | 'format_note': 'DASH video', | |
724 | 'protocol': 'http_dash_segments', | |
725 | 'acodec': 'none', | |
726 | 'vcodec': 'avc1.42001f', | |
727 | 'tbr': 318.597, | |
728 | 'width': 340, | |
729 | 'height': 192, | |
730 | }, { | |
731 | 'manifest_url': 'http://unknown/manifest.mpd', | |
732 | 'ext': 'mp4', | |
733 | 'format_id': '638590', | |
734 | 'format_note': 'DASH video', | |
735 | 'protocol': 'http_dash_segments', | |
736 | 'acodec': 'none', | |
737 | 'vcodec': 'avc1.42001f', | |
738 | 'tbr': 638.59, | |
739 | 'width': 512, | |
740 | 'height': 288, | |
741 | }, { | |
742 | 'manifest_url': 'http://unknown/manifest.mpd', | |
743 | 'ext': 'mp4', | |
744 | 'format_id': '1022565', | |
745 | 'format_note': 'DASH video', | |
746 | 'protocol': 'http_dash_segments', | |
747 | 'acodec': 'none', | |
748 | 'vcodec': 'avc1.4d001f', | |
749 | 'tbr': 1022.565, | |
750 | 'width': 688, | |
751 | 'height': 384, | |
752 | }, { | |
753 | 'manifest_url': 'http://unknown/manifest.mpd', | |
754 | 'ext': 'mp4', | |
755 | 'format_id': '2046506', | |
756 | 'format_note': 'DASH video', | |
757 | 'protocol': 'http_dash_segments', | |
758 | 'acodec': 'none', | |
759 | 'vcodec': 'avc1.4d001f', | |
760 | 'tbr': 2046.506, | |
761 | 'width': 1024, | |
762 | 'height': 576, | |
763 | }, { | |
764 | 'manifest_url': 'http://unknown/manifest.mpd', | |
765 | 'ext': 'mp4', | |
766 | 'format_id': '3998017', | |
767 | 'format_note': 'DASH video', | |
768 | 'protocol': 'http_dash_segments', | |
769 | 'acodec': 'none', | |
770 | 'vcodec': 'avc1.640029', | |
771 | 'tbr': 3998.017, | |
772 | 'width': 1280, | |
773 | 'height': 720, | |
774 | }, { | |
775 | 'manifest_url': 'http://unknown/manifest.mpd', | |
776 | 'ext': 'mp4', | |
777 | 'format_id': '5997485', | |
778 | 'format_note': 'DASH video', | |
779 | 'protocol': 'http_dash_segments', | |
780 | 'acodec': 'none', | |
781 | 'vcodec': 'avc1.640032', | |
782 | 'tbr': 5997.485, | |
783 | 'width': 1920, | |
784 | 'height': 1080, | |
785 | }] | |
41bf647e | 786 | ), ( |
067aa17e | 787 | # https://github.com/ytdl-org/youtube-dl/pull/14844 |
41bf647e | 788 | 'urls_only', |
2e27421c S |
789 | 'http://unknown/manifest.mpd', # mpd_url |
790 | None, # mpd_base_url | |
41bf647e PN |
791 | [{ |
792 | 'manifest_url': 'http://unknown/manifest.mpd', | |
793 | 'ext': 'mp4', | |
794 | 'format_id': 'h264_aac_144p_m4s', | |
795 | 'format_note': 'DASH video', | |
796 | 'protocol': 'http_dash_segments', | |
797 | 'acodec': 'mp4a.40.2', | |
798 | 'vcodec': 'avc3.42c01e', | |
799 | 'tbr': 200, | |
800 | 'width': 256, | |
801 | 'height': 144, | |
802 | }, { | |
803 | 'manifest_url': 'http://unknown/manifest.mpd', | |
804 | 'ext': 'mp4', | |
805 | 'format_id': 'h264_aac_240p_m4s', | |
806 | 'format_note': 'DASH video', | |
807 | 'protocol': 'http_dash_segments', | |
808 | 'acodec': 'mp4a.40.2', | |
809 | 'vcodec': 'avc3.42c01e', | |
810 | 'tbr': 400, | |
811 | 'width': 424, | |
812 | 'height': 240, | |
813 | }, { | |
814 | 'manifest_url': 'http://unknown/manifest.mpd', | |
815 | 'ext': 'mp4', | |
816 | 'format_id': 'h264_aac_360p_m4s', | |
817 | 'format_note': 'DASH video', | |
818 | 'protocol': 'http_dash_segments', | |
819 | 'acodec': 'mp4a.40.2', | |
820 | 'vcodec': 'avc3.42c01e', | |
821 | 'tbr': 800, | |
822 | 'width': 640, | |
823 | 'height': 360, | |
824 | }, { | |
825 | 'manifest_url': 'http://unknown/manifest.mpd', | |
826 | 'ext': 'mp4', | |
827 | 'format_id': 'h264_aac_480p_m4s', | |
828 | 'format_note': 'DASH video', | |
829 | 'protocol': 'http_dash_segments', | |
830 | 'acodec': 'mp4a.40.2', | |
831 | 'vcodec': 'avc3.42c01e', | |
832 | 'tbr': 1200, | |
833 | 'width': 856, | |
834 | 'height': 480, | |
835 | }, { | |
836 | 'manifest_url': 'http://unknown/manifest.mpd', | |
837 | 'ext': 'mp4', | |
838 | 'format_id': 'h264_aac_576p_m4s', | |
839 | 'format_note': 'DASH video', | |
840 | 'protocol': 'http_dash_segments', | |
841 | 'acodec': 'mp4a.40.2', | |
842 | 'vcodec': 'avc3.42c01e', | |
843 | 'tbr': 1600, | |
844 | 'width': 1024, | |
845 | 'height': 576, | |
846 | }, { | |
847 | 'manifest_url': 'http://unknown/manifest.mpd', | |
848 | 'ext': 'mp4', | |
849 | 'format_id': 'h264_aac_720p_m4s', | |
850 | 'format_note': 'DASH video', | |
851 | 'protocol': 'http_dash_segments', | |
852 | 'acodec': 'mp4a.40.2', | |
853 | 'vcodec': 'avc3.42c01e', | |
854 | 'tbr': 2400, | |
855 | 'width': 1280, | |
856 | 'height': 720, | |
857 | }, { | |
858 | 'manifest_url': 'http://unknown/manifest.mpd', | |
859 | 'ext': 'mp4', | |
860 | 'format_id': 'h264_aac_1080p_m4s', | |
861 | 'format_note': 'DASH video', | |
862 | 'protocol': 'http_dash_segments', | |
863 | 'acodec': 'mp4a.40.2', | |
864 | 'vcodec': 'avc3.42c01e', | |
865 | 'tbr': 4400, | |
866 | 'width': 1920, | |
867 | 'height': 1080, | |
868 | }] | |
2e27421c S |
869 | ), ( |
870 | # https://github.com/ytdl-org/youtube-dl/issues/20346 | |
871 | # Media considered unfragmented even though it contains | |
872 | # Initialization tag | |
873 | 'unfragmented', | |
874 | 'https://v.redd.it/hw1x7rcg7zl21/DASHPlaylist.mpd', # mpd_url | |
875 | 'https://v.redd.it/hw1x7rcg7zl21', # mpd_base_url | |
876 | [{ | |
877 | 'url': 'https://v.redd.it/hw1x7rcg7zl21/audio', | |
878 | 'manifest_url': 'https://v.redd.it/hw1x7rcg7zl21/DASHPlaylist.mpd', | |
879 | 'ext': 'm4a', | |
880 | 'format_id': 'AUDIO-1', | |
881 | 'format_note': 'DASH audio', | |
882 | 'container': 'm4a_dash', | |
883 | 'acodec': 'mp4a.40.2', | |
884 | 'vcodec': 'none', | |
885 | 'tbr': 129.87, | |
886 | 'asr': 48000, | |
887 | ||
888 | }, { | |
889 | 'url': 'https://v.redd.it/hw1x7rcg7zl21/DASH_240', | |
890 | 'manifest_url': 'https://v.redd.it/hw1x7rcg7zl21/DASHPlaylist.mpd', | |
891 | 'ext': 'mp4', | |
892 | 'format_id': 'VIDEO-2', | |
893 | 'format_note': 'DASH video', | |
894 | 'container': 'mp4_dash', | |
895 | 'acodec': 'none', | |
896 | 'vcodec': 'avc1.4d401e', | |
897 | 'tbr': 608.0, | |
898 | 'width': 240, | |
899 | 'height': 240, | |
900 | 'fps': 30, | |
901 | }, { | |
902 | 'url': 'https://v.redd.it/hw1x7rcg7zl21/DASH_360', | |
903 | 'manifest_url': 'https://v.redd.it/hw1x7rcg7zl21/DASHPlaylist.mpd', | |
904 | 'ext': 'mp4', | |
905 | 'format_id': 'VIDEO-1', | |
906 | 'format_note': 'DASH video', | |
907 | 'container': 'mp4_dash', | |
908 | 'acodec': 'none', | |
909 | 'vcodec': 'avc1.4d401e', | |
910 | 'tbr': 804.261, | |
911 | 'width': 360, | |
912 | 'height': 360, | |
913 | 'fps': 30, | |
914 | }] | |
41bf647e | 915 | ) |
48504785 S |
916 | ] |
917 | ||
2e27421c | 918 | for mpd_file, mpd_url, mpd_base_url, expected_formats in _TEST_CASES: |
48504785 S |
919 | with io.open('./test/testdata/mpd/%s.mpd' % mpd_file, |
920 | mode='r', encoding='utf-8') as f: | |
921 | formats = self.ie._parse_mpd_formats( | |
922 | compat_etree_fromstring(f.read().encode('utf-8')), | |
2e27421c | 923 | mpd_base_url=mpd_base_url, mpd_url=mpd_url) |
48504785 S |
924 | self.ie._sort_formats(formats) |
925 | expect_value(self, formats, expected_formats, None) | |
926 | ||
181e381f S |
927 | def test_parse_f4m_formats(self): |
928 | _TEST_CASES = [ | |
929 | ( | |
067aa17e | 930 | # https://github.com/ytdl-org/youtube-dl/issues/14660 |
181e381f S |
931 | 'custom_base_url', |
932 | 'http://api.new.livestream.com/accounts/6115179/events/6764928/videos/144884262.f4m', | |
933 | [{ | |
934 | 'manifest_url': 'http://api.new.livestream.com/accounts/6115179/events/6764928/videos/144884262.f4m', | |
935 | 'ext': 'flv', | |
936 | 'format_id': '2148', | |
937 | 'protocol': 'f4m', | |
938 | 'tbr': 2148, | |
939 | 'width': 1280, | |
940 | 'height': 720, | |
941 | }] | |
942 | ), | |
943 | ] | |
944 | ||
945 | for f4m_file, f4m_url, expected_formats in _TEST_CASES: | |
946 | with io.open('./test/testdata/f4m/%s.f4m' % f4m_file, | |
947 | mode='r', encoding='utf-8') as f: | |
948 | formats = self.ie._parse_f4m_formats( | |
949 | compat_etree_fromstring(f.read().encode('utf-8')), | |
950 | f4m_url, None) | |
951 | self.ie._sort_formats(formats) | |
952 | expect_value(self, formats, expected_formats, None) | |
582be358 | 953 | |
96b8b9ab RC |
954 | def test_parse_xspf(self): |
955 | _TEST_CASES = [ | |
956 | ( | |
957 | 'foo_xspf', | |
47a5cb77 | 958 | 'https://example.org/src/foo_xspf.xspf', |
96b8b9ab | 959 | [{ |
47a5cb77 S |
960 | 'id': 'foo_xspf', |
961 | 'title': 'Pandemonium', | |
96b8b9ab RC |
962 | 'description': 'Visit http://bigbrother404.bandcamp.com', |
963 | 'duration': 202.416, | |
47a5cb77 S |
964 | 'formats': [{ |
965 | 'manifest_url': 'https://example.org/src/foo_xspf.xspf', | |
966 | 'url': 'https://example.org/src/cd1/track%201.mp3', | |
967 | }], | |
968 | }, { | |
96b8b9ab | 969 | 'id': 'foo_xspf', |
47a5cb77 | 970 | 'title': 'Final Cartridge (Nichico Twelve Remix)', |
96b8b9ab RC |
971 | 'description': 'Visit http://bigbrother404.bandcamp.com', |
972 | 'duration': 255.857, | |
47a5cb77 S |
973 | 'formats': [{ |
974 | 'manifest_url': 'https://example.org/src/foo_xspf.xspf', | |
975 | 'url': 'https://example.org/%E3%83%88%E3%83%A9%E3%83%83%E3%82%AF%E3%80%80%EF%BC%92.mp3', | |
976 | }], | |
977 | }, { | |
96b8b9ab | 978 | 'id': 'foo_xspf', |
47a5cb77 | 979 | 'title': 'Rebuilding Nightingale', |
96b8b9ab RC |
980 | 'description': 'Visit http://bigbrother404.bandcamp.com', |
981 | 'duration': 287.915, | |
47a5cb77 S |
982 | 'formats': [{ |
983 | 'manifest_url': 'https://example.org/src/foo_xspf.xspf', | |
984 | 'url': 'https://example.org/src/track3.mp3', | |
985 | }, { | |
986 | 'manifest_url': 'https://example.org/src/foo_xspf.xspf', | |
987 | 'url': 'https://example.com/track3.mp3', | |
988 | }] | |
96b8b9ab RC |
989 | }] |
990 | ), | |
991 | ] | |
992 | ||
47a5cb77 | 993 | for xspf_file, xspf_url, expected_entries in _TEST_CASES: |
96b8b9ab RC |
994 | with io.open('./test/testdata/xspf/%s.xspf' % xspf_file, |
995 | mode='r', encoding='utf-8') as f: | |
996 | entries = self.ie._parse_xspf( | |
997 | compat_etree_fromstring(f.read().encode('utf-8')), | |
47a5cb77 | 998 | xspf_file, xspf_url=xspf_url, xspf_base_url=xspf_url) |
96b8b9ab RC |
999 | expect_value(self, entries, expected_entries, None) |
1000 | for i in range(len(entries)): | |
1001 | expect_dict(self, entries[i], expected_entries[i]) | |
1002 | ||
95e42d73 XDG |
1003 | def test_response_with_expected_status_returns_content(self): |
1004 | # Checks for mitigations against the effects of | |
1005 | # <https://bugs.python.org/issue15002> that affect Python 3.4.1+, which | |
1006 | # manifest as `_download_webpage`, `_download_xml`, `_download_json`, | |
1007 | # or the underlying `_download_webpage_handle` returning no content | |
1008 | # when a response matches `expected_status`. | |
1009 | ||
1010 | httpd = compat_http_server.HTTPServer( | |
1011 | ('127.0.0.1', 0), InfoExtractorTestRequestHandler) | |
1012 | port = http_server_port(httpd) | |
1013 | server_thread = threading.Thread(target=httpd.serve_forever) | |
1014 | server_thread.daemon = True | |
1015 | server_thread.start() | |
1016 | ||
1017 | (content, urlh) = self.ie._download_webpage_handle( | |
1018 | 'http://127.0.0.1:%d/teapot' % port, None, | |
1019 | expected_status=TEAPOT_RESPONSE_STATUS) | |
1020 | self.assertEqual(content, TEAPOT_RESPONSE_BODY) | |
1021 | ||
f58a5060 | 1022 | |
14719565 JMF |
1023 | if __name__ == '__main__': |
1024 | unittest.main() |