]> jfr.im git - yt-dlp.git/blame - test/test_InfoExtractor.py
[utils] Introduce parse_bitrate
[yt-dlp.git] / test / test_InfoExtractor.py
CommitLineData
14719565
JMF
1#!/usr/bin/env python
2
3from __future__ import unicode_literals
4
5# Allow direct execution
cb252080 6import io
14719565
JMF
7import os
8import sys
9import unittest
10sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
11
95e42d73
XDG
12from test.helper import FakeYDL, expect_dict, expect_value, http_server_port
13from youtube_dl.compat import compat_etree_fromstring, compat_http_server
14719565
JMF
14from youtube_dl.extractor.common import InfoExtractor
15from youtube_dl.extractor import YoutubeIE, get_info_extractor
88d9f6c0 16from youtube_dl.utils import encode_data_uri, strip_jsonp, ExtractorError, RegexNotFoundError
95e42d73
XDG
17import threading
18
19
20TEAPOT_RESPONSE_STATUS = 418
21TEAPOT_RESPONSE_BODY = "<h1>418 I'm a teapot</h1>"
22
23
24class 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
38class TestIE(InfoExtractor):
39 pass
40
41
42class 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&amp;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
6a801f44
JMF
101 def test_download_json(self):
102 uri = encode_data_uri(b'{"foo": "blah"}', 'application/json')
103 self.assertEqual(self.ie._download_json(uri, None), {'foo': 'blah'})
104 uri = encode_data_uri(b'callback({"foo": "blah"})', 'application/javascript')
105 self.assertEqual(self.ie._download_json(uri, None, transform_source=strip_jsonp), {'foo': 'blah'})
106 uri = encode_data_uri(b'{"foo": invalid}', 'application/json')
107 self.assertRaises(ExtractorError, self.ie._download_json, uri, None)
108 self.assertEqual(self.ie._download_json(uri, None, fatal=False), None)
109
7f3590c4
S
110 def test_extract_jwplayer_data_realworld(self):
111 # from http://www.suffolk.edu/sjc/
112 expect_dict(
113 self,
114 self.ie._extract_jwplayer_data(r'''
115 <script type='text/javascript'>
116 jwplayer('my-video').setup({
117 file: 'rtmp://192.138.214.154/live/sjclive',
118 fallback: 'true',
119 width: '95%',
120 aspectratio: '16:9',
121 primary: 'flash',
122 mediaid:'XEgvuql4'
123 });
124 </script>
125 ''', None, require_title=False),
126 {
127 'id': 'XEgvuql4',
128 'formats': [{
129 'url': 'rtmp://192.138.214.154/live/sjclive',
130 'ext': 'flv'
131 }]
132 })
133
134 # from https://www.pornoxo.com/videos/7564/striptease-from-sexy-secretary/
135 expect_dict(
136 self,
137 self.ie._extract_jwplayer_data(r'''
138<script type="text/javascript">
139 jwplayer("mediaplayer").setup({
140 'videoid': "7564",
141 'width': "100%",
142 'aspectratio': "16:9",
143 'stretching': "exactfit",
144 'autostart': 'false',
145 'flashplayer': "https://t04.vipstreamservice.com/jwplayer/v5.10/player.swf",
146 '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",
147 'image': "https://t03.vipstreamservice.com/thumbs/pxo-full/2009-12/14/a4b2157147afe5efa93ce1978e0265289c193874e02597.flv-full-13.jpg",
148 '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",
149 'logo.hide': true,
150 'skin': "https://t04.vipstreamservice.com/jwplayer/skin/modieus-blk.zip",
151 'plugins': "https://t04.vipstreamservice.com/jwplayer/dock/dockableskinnableplugin.swf",
152 'dockableskinnableplugin.piclink': "/index.php?key=ajax-videothumbsn&vid=7564&data=2009-12--14--4b2157147afe5efa93ce1978e0265289c193874e02597.flv--17370",
153 'controlbar': 'bottom',
154 'modes': [
155 {type: 'flash', src: 'https://t04.vipstreamservice.com/jwplayer/v5.10/player.swf'}
156 ],
157 'provider': 'http'
158 });
159 //noinspection JSAnnotator
160 invideo.setup({
161 adsUrl: "/banner-iframe/?zoneId=32",
162 adsUrl2: "",
163 autostart: false
164 });
165</script>
166 ''', 'dummy', require_title=False),
167 {
168 'thumbnail': 'https://t03.vipstreamservice.com/thumbs/pxo-full/2009-12/14/a4b2157147afe5efa93ce1978e0265289c193874e02597.flv-full-13.jpg',
169 'formats': [{
170 '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',
171 'ext': 'flv'
172 }]
173 })
174
175 # from http://www.indiedb.com/games/king-machine/videos
176 expect_dict(
177 self,
178 self.ie._extract_jwplayer_data(r'''
179<script>
180jwplayer("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) {
181 videoAnalytics("play");
182}).once("complete", function(event) {
183 videoAnalytics("completed");
184});
185</script>
186 ''', 'dummy'),
187 {
188 'title': 'king machine trailer 1',
189 'thumbnail': 'http://media.indiedb.com/cache/images/games/1/50/49678/thumb_620x2000/king-machine-trailer.mp4.jpg',
190 'formats': [{
191 'url': 'http://cdn.dbolical.com/cache/videos/games/1/50/49678/encode_mp4/king-machine-trailer.mp4',
192 'height': 360,
193 'ext': 'mp4'
194 }, {
195 'url': 'http://cdn.dbolical.com/cache/videos/games/1/50/49678/encode720p_mp4/king-machine-trailer.mp4',
196 'height': 720,
197 'ext': 'mp4'
198 }]
199 })
200
cb252080
S
201 def test_parse_m3u8_formats(self):
202 _TEST_CASES = [
203 (
067aa17e 204 # https://github.com/ytdl-org/youtube-dl/issues/11507
cb252080
S
205 # http://pluzz.francetv.fr/videos/le_ministere.html
206 'pluzz_francetv_11507',
207 'http://replayftv-vh.akamaihd.net/i/streaming-adaptatif_france-dom-tom/2017/S16/J2/156589847-58f59130c1f52-,standard1,standard2,standard3,standard4,standard5,.mp4.csmil/master.m3u8?caption=2017%2F16%2F156589847-1492488987.m3u8%3Afra%3AFrancais&audiotrack=0%3Afra%3AFrancais',
208 [{
cb252080 209 'url': 'http://replayftv-vh.akamaihd.net/i/streaming-adaptatif_france-dom-tom/2017/S16/J2/156589847-58f59130c1f52-,standard1,standard2,standard3,standard4,standard5,.mp4.csmil/index_0_av.m3u8?null=0',
30bb6ce1 210 'manifest_url': 'http://replayftv-vh.akamaihd.net/i/streaming-adaptatif_france-dom-tom/2017/S16/J2/156589847-58f59130c1f52-,standard1,standard2,standard3,standard4,standard5,.mp4.csmil/master.m3u8?caption=2017%2F16%2F156589847-1492488987.m3u8%3Afra%3AFrancais&audiotrack=0%3Afra%3AFrancais',
cb252080
S
211 'ext': 'mp4',
212 'format_id': '180',
213 'protocol': 'm3u8',
214 'acodec': 'mp4a.40.2',
215 'vcodec': 'avc1.66.30',
216 'tbr': 180,
217 'width': 256,
218 'height': 144,
219 }, {
220 'url': 'http://replayftv-vh.akamaihd.net/i/streaming-adaptatif_france-dom-tom/2017/S16/J2/156589847-58f59130c1f52-,standard1,standard2,standard3,standard4,standard5,.mp4.csmil/index_1_av.m3u8?null=0',
30bb6ce1 221 'manifest_url': 'http://replayftv-vh.akamaihd.net/i/streaming-adaptatif_france-dom-tom/2017/S16/J2/156589847-58f59130c1f52-,standard1,standard2,standard3,standard4,standard5,.mp4.csmil/master.m3u8?caption=2017%2F16%2F156589847-1492488987.m3u8%3Afra%3AFrancais&audiotrack=0%3Afra%3AFrancais',
cb252080
S
222 'ext': 'mp4',
223 'format_id': '303',
224 'protocol': 'm3u8',
225 'acodec': 'mp4a.40.2',
226 'vcodec': 'avc1.66.30',
227 'tbr': 303,
228 'width': 320,
229 'height': 180,
230 }, {
231 'url': 'http://replayftv-vh.akamaihd.net/i/streaming-adaptatif_france-dom-tom/2017/S16/J2/156589847-58f59130c1f52-,standard1,standard2,standard3,standard4,standard5,.mp4.csmil/index_2_av.m3u8?null=0',
30bb6ce1 232 'manifest_url': 'http://replayftv-vh.akamaihd.net/i/streaming-adaptatif_france-dom-tom/2017/S16/J2/156589847-58f59130c1f52-,standard1,standard2,standard3,standard4,standard5,.mp4.csmil/master.m3u8?caption=2017%2F16%2F156589847-1492488987.m3u8%3Afra%3AFrancais&audiotrack=0%3Afra%3AFrancais',
cb252080
S
233 'ext': 'mp4',
234 'format_id': '575',
235 'protocol': 'm3u8',
236 'acodec': 'mp4a.40.2',
237 'vcodec': 'avc1.66.30',
238 'tbr': 575,
239 'width': 512,
240 'height': 288,
241 }, {
242 'url': 'http://replayftv-vh.akamaihd.net/i/streaming-adaptatif_france-dom-tom/2017/S16/J2/156589847-58f59130c1f52-,standard1,standard2,standard3,standard4,standard5,.mp4.csmil/index_3_av.m3u8?null=0',
30bb6ce1 243 'manifest_url': 'http://replayftv-vh.akamaihd.net/i/streaming-adaptatif_france-dom-tom/2017/S16/J2/156589847-58f59130c1f52-,standard1,standard2,standard3,standard4,standard5,.mp4.csmil/master.m3u8?caption=2017%2F16%2F156589847-1492488987.m3u8%3Afra%3AFrancais&audiotrack=0%3Afra%3AFrancais',
cb252080
S
244 'ext': 'mp4',
245 'format_id': '831',
246 'protocol': 'm3u8',
247 'acodec': 'mp4a.40.2',
248 'vcodec': 'avc1.77.30',
249 'tbr': 831,
250 'width': 704,
251 'height': 396,
252 }, {
253 'url': 'http://replayftv-vh.akamaihd.net/i/streaming-adaptatif_france-dom-tom/2017/S16/J2/156589847-58f59130c1f52-,standard1,standard2,standard3,standard4,standard5,.mp4.csmil/index_4_av.m3u8?null=0',
30bb6ce1 254 'manifest_url': 'http://replayftv-vh.akamaihd.net/i/streaming-adaptatif_france-dom-tom/2017/S16/J2/156589847-58f59130c1f52-,standard1,standard2,standard3,standard4,standard5,.mp4.csmil/master.m3u8?caption=2017%2F16%2F156589847-1492488987.m3u8%3Afra%3AFrancais&audiotrack=0%3Afra%3AFrancais',
cb252080
S
255 'ext': 'mp4',
256 'protocol': 'm3u8',
257 'format_id': '1467',
258 'acodec': 'mp4a.40.2',
259 'vcodec': 'avc1.77.30',
260 'tbr': 1467,
261 'width': 1024,
262 'height': 576,
263 }]
264 ),
265 (
067aa17e 266 # https://github.com/ytdl-org/youtube-dl/issues/11995
cb252080
S
267 # http://teamcoco.com/video/clueless-gamer-super-bowl-for-honor
268 'teamcoco_11995',
269 'http://ak.storage-w.teamcococdn.com/cdn/2017-02/98599/ed8f/main.m3u8',
270 [{
cb252080 271 'url': 'http://ak.storage-w.teamcococdn.com/cdn/2017-02/98599/ed8f/hls/CONAN_020217_Highlight_show-audio-160k_v4.m3u8',
30bb6ce1 272 'manifest_url': 'http://ak.storage-w.teamcococdn.com/cdn/2017-02/98599/ed8f/main.m3u8',
cb252080
S
273 'ext': 'mp4',
274 'format_id': 'audio-0-Default',
275 'protocol': 'm3u8',
276 'vcodec': 'none',
277 }, {
278 'url': 'http://ak.storage-w.teamcococdn.com/cdn/2017-02/98599/ed8f/hls/CONAN_020217_Highlight_show-audio-64k_v4.m3u8',
30bb6ce1 279 'manifest_url': 'http://ak.storage-w.teamcococdn.com/cdn/2017-02/98599/ed8f/main.m3u8',
cb252080
S
280 'ext': 'mp4',
281 'format_id': 'audio-1-Default',
282 'protocol': 'm3u8',
283 'vcodec': 'none',
284 }, {
285 'url': 'http://ak.storage-w.teamcococdn.com/cdn/2017-02/98599/ed8f/hls/CONAN_020217_Highlight_show-audio-64k_v4.m3u8',
30bb6ce1 286 'manifest_url': 'http://ak.storage-w.teamcococdn.com/cdn/2017-02/98599/ed8f/main.m3u8',
cb252080
S
287 'ext': 'mp4',
288 'format_id': '71',
289 'protocol': 'm3u8',
290 'acodec': 'mp4a.40.5',
291 'vcodec': 'none',
292 'tbr': 71,
293 }, {
294 'url': 'http://ak.storage-w.teamcococdn.com/cdn/2017-02/98599/ed8f/hls/CONAN_020217_Highlight_show-400k_v4.m3u8',
30bb6ce1 295 'manifest_url': 'http://ak.storage-w.teamcococdn.com/cdn/2017-02/98599/ed8f/main.m3u8',
cb252080
S
296 'ext': 'mp4',
297 'format_id': '413',
298 'protocol': 'm3u8',
299 'acodec': 'none',
300 'vcodec': 'avc1.42001e',
301 'tbr': 413,
302 'width': 400,
303 'height': 224,
304 }, {
305 'url': 'http://ak.storage-w.teamcococdn.com/cdn/2017-02/98599/ed8f/hls/CONAN_020217_Highlight_show-400k_v4.m3u8',
30bb6ce1 306 'manifest_url': 'http://ak.storage-w.teamcococdn.com/cdn/2017-02/98599/ed8f/main.m3u8',
cb252080
S
307 'ext': 'mp4',
308 'format_id': '522',
309 'protocol': 'm3u8',
310 'acodec': 'none',
311 'vcodec': 'avc1.42001e',
312 'tbr': 522,
313 'width': 400,
314 'height': 224,
315 }, {
316 'url': 'http://ak.storage-w.teamcococdn.com/cdn/2017-02/98599/ed8f/hls/CONAN_020217_Highlight_show-1m_v4.m3u8',
30bb6ce1 317 'manifest_url': 'http://ak.storage-w.teamcococdn.com/cdn/2017-02/98599/ed8f/main.m3u8',
cb252080
S
318 'ext': 'mp4',
319 'format_id': '1205',
320 'protocol': 'm3u8',
321 'acodec': 'none',
322 'vcodec': 'avc1.4d001e',
323 'tbr': 1205,
324 'width': 640,
325 'height': 360,
326 }, {
327 'url': 'http://ak.storage-w.teamcococdn.com/cdn/2017-02/98599/ed8f/hls/CONAN_020217_Highlight_show-2m_v4.m3u8',
30bb6ce1 328 'manifest_url': 'http://ak.storage-w.teamcococdn.com/cdn/2017-02/98599/ed8f/main.m3u8',
cb252080
S
329 'ext': 'mp4',
330 'format_id': '2374',
331 'protocol': 'm3u8',
332 'acodec': 'none',
333 'vcodec': 'avc1.4d001f',
334 'tbr': 2374,
335 'width': 1024,
336 'height': 576,
337 }]
338 ),
339 (
067aa17e 340 # https://github.com/ytdl-org/youtube-dl/issues/12211
cb252080
S
341 # http://video.toggle.sg/en/series/whoopie-s-world/ep3/478601
342 'toggle_mobile_12211',
343 'http://cdnapi.kaltura.com/p/2082311/sp/208231100/playManifest/protocol/http/entryId/0_89q6e8ku/format/applehttp/tags/mobile_sd/f/a.m3u8',
344 [{
cb252080 345 'url': 'http://k.toggle.sg/fhls/p/2082311/sp/208231100/serveFlavor/entryId/0_89q6e8ku/v/2/pv/1/flavorId/0_sa2ntrdg/name/a.mp4/index.m3u8',
30bb6ce1 346 'manifest_url': 'http://cdnapi.kaltura.com/p/2082311/sp/208231100/playManifest/protocol/http/entryId/0_89q6e8ku/format/applehttp/tags/mobile_sd/f/a.m3u8',
cb252080
S
347 'ext': 'mp4',
348 'format_id': 'audio-English',
349 'protocol': 'm3u8',
350 'language': 'eng',
351 'vcodec': 'none',
352 }, {
353 'url': 'http://k.toggle.sg/fhls/p/2082311/sp/208231100/serveFlavor/entryId/0_89q6e8ku/v/2/pv/1/flavorId/0_r7y0nitg/name/a.mp4/index.m3u8',
30bb6ce1 354 'manifest_url': 'http://cdnapi.kaltura.com/p/2082311/sp/208231100/playManifest/protocol/http/entryId/0_89q6e8ku/format/applehttp/tags/mobile_sd/f/a.m3u8',
cb252080
S
355 'ext': 'mp4',
356 'format_id': 'audio-Undefined',
357 'protocol': 'm3u8',
358 'language': 'und',
359 'vcodec': 'none',
360 }, {
361 'url': 'http://k.toggle.sg/fhls/p/2082311/sp/208231100/serveFlavor/entryId/0_89q6e8ku/v/2/pv/1/flavorId/0_qlk9hlzr/name/a.mp4/index.m3u8',
30bb6ce1 362 'manifest_url': 'http://cdnapi.kaltura.com/p/2082311/sp/208231100/playManifest/protocol/http/entryId/0_89q6e8ku/format/applehttp/tags/mobile_sd/f/a.m3u8',
cb252080
S
363 'ext': 'mp4',
364 'format_id': '155',
365 'protocol': 'm3u8',
ddd258f9 366 'tbr': 155.648,
cb252080
S
367 'width': 320,
368 'height': 180,
369 }, {
370 'url': 'http://k.toggle.sg/fhls/p/2082311/sp/208231100/serveFlavor/entryId/0_89q6e8ku/v/2/pv/1/flavorId/0_oefackmi/name/a.mp4/index.m3u8',
30bb6ce1 371 'manifest_url': 'http://cdnapi.kaltura.com/p/2082311/sp/208231100/playManifest/protocol/http/entryId/0_89q6e8ku/format/applehttp/tags/mobile_sd/f/a.m3u8',
cb252080
S
372 'ext': 'mp4',
373 'format_id': '502',
374 'protocol': 'm3u8',
ddd258f9 375 'tbr': 502.784,
cb252080
S
376 'width': 480,
377 'height': 270,
378 }, {
379 'url': 'http://k.toggle.sg/fhls/p/2082311/sp/208231100/serveFlavor/entryId/0_89q6e8ku/v/12/pv/1/flavorId/0_vyg9pj7k/name/a.mp4/index.m3u8',
30bb6ce1 380 'manifest_url': 'http://cdnapi.kaltura.com/p/2082311/sp/208231100/playManifest/protocol/http/entryId/0_89q6e8ku/format/applehttp/tags/mobile_sd/f/a.m3u8',
cb252080
S
381 'ext': 'mp4',
382 'format_id': '827',
383 'protocol': 'm3u8',
ddd258f9 384 'tbr': 827.392,
cb252080
S
385 'width': 640,
386 'height': 360,
387 }, {
388 'url': 'http://k.toggle.sg/fhls/p/2082311/sp/208231100/serveFlavor/entryId/0_89q6e8ku/v/12/pv/1/flavorId/0_50n4psvx/name/a.mp4/index.m3u8',
30bb6ce1 389 'manifest_url': 'http://cdnapi.kaltura.com/p/2082311/sp/208231100/playManifest/protocol/http/entryId/0_89q6e8ku/format/applehttp/tags/mobile_sd/f/a.m3u8',
cb252080
S
390 'ext': 'mp4',
391 'format_id': '1396',
392 'protocol': 'm3u8',
ddd258f9 393 'tbr': 1396.736,
cb252080
S
394 'width': 854,
395 'height': 480,
396 }]
397 ),
398 (
399 # http://www.twitch.tv/riotgames/v/6528877
400 'twitch_vod',
401 'https://usher.ttvnw.net/vod/6528877?allow_source=true&allow_audio_only=true&allow_spectre=true&player=twitchweb&nauth=%7B%22user_id%22%3Anull%2C%22vod_id%22%3A6528877%2C%22expires%22%3A1492887874%2C%22chansub%22%3A%7B%22restricted_bitrates%22%3A%5B%5D%7D%2C%22privileged%22%3Afalse%2C%22https_required%22%3Afalse%7D&nauthsig=3e29296a6824a0f48f9e731383f77a614fc79bee',
402 [{
cb252080 403 'url': 'https://vod.edgecast.hls.ttvnw.net/e5da31ab49_riotgames_15001215120_261543898/audio_only/index-muted-HM49I092CC.m3u8',
30bb6ce1 404 'manifest_url': 'https://usher.ttvnw.net/vod/6528877?allow_source=true&allow_audio_only=true&allow_spectre=true&player=twitchweb&nauth=%7B%22user_id%22%3Anull%2C%22vod_id%22%3A6528877%2C%22expires%22%3A1492887874%2C%22chansub%22%3A%7B%22restricted_bitrates%22%3A%5B%5D%7D%2C%22privileged%22%3Afalse%2C%22https_required%22%3Afalse%7D&nauthsig=3e29296a6824a0f48f9e731383f77a614fc79bee',
cb252080
S
405 'ext': 'mp4',
406 'format_id': 'Audio Only',
407 'protocol': 'm3u8',
408 'acodec': 'mp4a.40.2',
409 'vcodec': 'none',
ddd258f9 410 'tbr': 182.725,
cb252080
S
411 }, {
412 'url': 'https://vod.edgecast.hls.ttvnw.net/e5da31ab49_riotgames_15001215120_261543898/mobile/index-muted-HM49I092CC.m3u8',
30bb6ce1 413 'manifest_url': 'https://usher.ttvnw.net/vod/6528877?allow_source=true&allow_audio_only=true&allow_spectre=true&player=twitchweb&nauth=%7B%22user_id%22%3Anull%2C%22vod_id%22%3A6528877%2C%22expires%22%3A1492887874%2C%22chansub%22%3A%7B%22restricted_bitrates%22%3A%5B%5D%7D%2C%22privileged%22%3Afalse%2C%22https_required%22%3Afalse%7D&nauthsig=3e29296a6824a0f48f9e731383f77a614fc79bee',
cb252080
S
414 'ext': 'mp4',
415 'format_id': 'Mobile',
416 'protocol': 'm3u8',
417 'acodec': 'mp4a.40.2',
418 'vcodec': 'avc1.42C00D',
ddd258f9 419 'tbr': 280.474,
cb252080
S
420 'width': 400,
421 'height': 226,
422 }, {
423 'url': 'https://vod.edgecast.hls.ttvnw.net/e5da31ab49_riotgames_15001215120_261543898/low/index-muted-HM49I092CC.m3u8',
30bb6ce1 424 'manifest_url': 'https://usher.ttvnw.net/vod/6528877?allow_source=true&allow_audio_only=true&allow_spectre=true&player=twitchweb&nauth=%7B%22user_id%22%3Anull%2C%22vod_id%22%3A6528877%2C%22expires%22%3A1492887874%2C%22chansub%22%3A%7B%22restricted_bitrates%22%3A%5B%5D%7D%2C%22privileged%22%3Afalse%2C%22https_required%22%3Afalse%7D&nauthsig=3e29296a6824a0f48f9e731383f77a614fc79bee',
cb252080
S
425 'ext': 'mp4',
426 'format_id': 'Low',
427 'protocol': 'm3u8',
428 'acodec': 'mp4a.40.2',
429 'vcodec': 'avc1.42C01E',
ddd258f9 430 'tbr': 628.347,
cb252080
S
431 'width': 640,
432 'height': 360,
433 }, {
434 'url': 'https://vod.edgecast.hls.ttvnw.net/e5da31ab49_riotgames_15001215120_261543898/medium/index-muted-HM49I092CC.m3u8',
30bb6ce1 435 'manifest_url': 'https://usher.ttvnw.net/vod/6528877?allow_source=true&allow_audio_only=true&allow_spectre=true&player=twitchweb&nauth=%7B%22user_id%22%3Anull%2C%22vod_id%22%3A6528877%2C%22expires%22%3A1492887874%2C%22chansub%22%3A%7B%22restricted_bitrates%22%3A%5B%5D%7D%2C%22privileged%22%3Afalse%2C%22https_required%22%3Afalse%7D&nauthsig=3e29296a6824a0f48f9e731383f77a614fc79bee',
cb252080
S
436 'ext': 'mp4',
437 'format_id': 'Medium',
438 'protocol': 'm3u8',
439 'acodec': 'mp4a.40.2',
440 'vcodec': 'avc1.42C01E',
ddd258f9 441 'tbr': 893.387,
cb252080
S
442 'width': 852,
443 'height': 480,
444 }, {
445 'url': 'https://vod.edgecast.hls.ttvnw.net/e5da31ab49_riotgames_15001215120_261543898/high/index-muted-HM49I092CC.m3u8',
30bb6ce1 446 'manifest_url': 'https://usher.ttvnw.net/vod/6528877?allow_source=true&allow_audio_only=true&allow_spectre=true&player=twitchweb&nauth=%7B%22user_id%22%3Anull%2C%22vod_id%22%3A6528877%2C%22expires%22%3A1492887874%2C%22chansub%22%3A%7B%22restricted_bitrates%22%3A%5B%5D%7D%2C%22privileged%22%3Afalse%2C%22https_required%22%3Afalse%7D&nauthsig=3e29296a6824a0f48f9e731383f77a614fc79bee',
cb252080
S
447 'ext': 'mp4',
448 'format_id': 'High',
449 'protocol': 'm3u8',
450 'acodec': 'mp4a.40.2',
451 'vcodec': 'avc1.42C01F',
ddd258f9 452 'tbr': 1603.789,
cb252080
S
453 'width': 1280,
454 'height': 720,
455 }, {
456 'url': 'https://vod.edgecast.hls.ttvnw.net/e5da31ab49_riotgames_15001215120_261543898/chunked/index-muted-HM49I092CC.m3u8',
30bb6ce1 457 'manifest_url': 'https://usher.ttvnw.net/vod/6528877?allow_source=true&allow_audio_only=true&allow_spectre=true&player=twitchweb&nauth=%7B%22user_id%22%3Anull%2C%22vod_id%22%3A6528877%2C%22expires%22%3A1492887874%2C%22chansub%22%3A%7B%22restricted_bitrates%22%3A%5B%5D%7D%2C%22privileged%22%3Afalse%2C%22https_required%22%3Afalse%7D&nauthsig=3e29296a6824a0f48f9e731383f77a614fc79bee',
cb252080
S
458 'ext': 'mp4',
459 'format_id': 'Source',
460 'protocol': 'm3u8',
461 'acodec': 'mp4a.40.2',
462 'vcodec': 'avc1.100.31',
ddd258f9
S
463 'tbr': 3214.134,
464 'width': 1280,
465 'height': 720,
466 }]
467 ),
468 (
469 # http://www.vidio.com/watch/165683-dj_ambred-booyah-live-2015
470 # EXT-X-STREAM-INF tag with NAME attribute that is not defined
471 # in HLS specification
472 'vidio',
473 'https://www.vidio.com/videos/165683/playlist.m3u8',
474 [{
ddd258f9 475 'url': 'https://cdn1-a.production.vidio.static6.com/uploads/165683/dj_ambred-4383-b300.mp4.m3u8',
30bb6ce1 476 'manifest_url': 'https://www.vidio.com/videos/165683/playlist.m3u8',
ddd258f9
S
477 'ext': 'mp4',
478 'format_id': '270p 3G',
479 'protocol': 'm3u8',
480 'tbr': 300,
481 'width': 480,
482 'height': 270,
483 }, {
484 'url': 'https://cdn1-a.production.vidio.static6.com/uploads/165683/dj_ambred-4383-b600.mp4.m3u8',
30bb6ce1 485 'manifest_url': 'https://www.vidio.com/videos/165683/playlist.m3u8',
ddd258f9
S
486 'ext': 'mp4',
487 'format_id': '360p SD',
488 'protocol': 'm3u8',
489 'tbr': 600,
490 'width': 640,
491 'height': 360,
492 }, {
493 'url': 'https://cdn1-a.production.vidio.static6.com/uploads/165683/dj_ambred-4383-b1200.mp4.m3u8',
30bb6ce1 494 'manifest_url': 'https://www.vidio.com/videos/165683/playlist.m3u8',
ddd258f9
S
495 'ext': 'mp4',
496 'format_id': '720p HD',
497 'protocol': 'm3u8',
498 'tbr': 1200,
cb252080
S
499 'width': 1280,
500 'height': 720,
501 }]
fc746c3f
RA
502 ),
503 (
067aa17e 504 # https://github.com/ytdl-org/youtube-dl/issues/18923
fc746c3f
RA
505 # https://www.ted.com/talks/boris_hesser_a_grassroots_healthcare_revolution_in_africa
506 'ted_18923',
507 'http://hls.ted.com/talks/31241.m3u8',
508 [{
509 'url': 'http://hls.ted.com/videos/BorisHesser_2018S/audio/600k.m3u8?nobumpers=true&uniqueId=76011e2b',
510 'format_id': '600k-Audio',
511 'vcodec': 'none',
512 }, {
513 'url': 'http://hls.ted.com/videos/BorisHesser_2018S/audio/600k.m3u8?nobumpers=true&uniqueId=76011e2b',
514 'format_id': '68',
515 'vcodec': 'none',
516 }, {
517 'url': 'http://hls.ted.com/videos/BorisHesser_2018S/video/64k.m3u8?nobumpers=true&uniqueId=76011e2b',
518 'format_id': '163',
519 'acodec': 'none',
520 'width': 320,
521 'height': 180,
522 }, {
523 'url': 'http://hls.ted.com/videos/BorisHesser_2018S/video/180k.m3u8?nobumpers=true&uniqueId=76011e2b',
524 'format_id': '481',
525 'acodec': 'none',
526 'width': 512,
527 'height': 288,
528 }, {
529 'url': 'http://hls.ted.com/videos/BorisHesser_2018S/video/320k.m3u8?nobumpers=true&uniqueId=76011e2b',
530 'format_id': '769',
531 'acodec': 'none',
532 'width': 512,
533 'height': 288,
534 }, {
535 'url': 'http://hls.ted.com/videos/BorisHesser_2018S/video/450k.m3u8?nobumpers=true&uniqueId=76011e2b',
536 'format_id': '984',
537 'acodec': 'none',
538 'width': 512,
539 'height': 288,
540 }, {
541 'url': 'http://hls.ted.com/videos/BorisHesser_2018S/video/600k.m3u8?nobumpers=true&uniqueId=76011e2b',
542 'format_id': '1255',
543 'acodec': 'none',
544 'width': 640,
545 'height': 360,
546 }, {
547 'url': 'http://hls.ted.com/videos/BorisHesser_2018S/video/950k.m3u8?nobumpers=true&uniqueId=76011e2b',
548 'format_id': '1693',
549 'acodec': 'none',
550 'width': 853,
551 'height': 480,
552 }, {
553 'url': 'http://hls.ted.com/videos/BorisHesser_2018S/video/1500k.m3u8?nobumpers=true&uniqueId=76011e2b',
554 'format_id': '2462',
555 'acodec': 'none',
556 'width': 1280,
557 'height': 720,
558 }]
559 ),
cb252080
S
560 ]
561
562 for m3u8_file, m3u8_url, expected_formats in _TEST_CASES:
563 with io.open('./test/testdata/m3u8/%s.m3u8' % m3u8_file,
564 mode='r', encoding='utf-8') as f:
565 formats = self.ie._parse_m3u8_formats(
566 f.read(), m3u8_url, ext='mp4')
567 self.ie._sort_formats(formats)
568 expect_value(self, formats, expected_formats, None)
569
48504785
S
570 def test_parse_mpd_formats(self):
571 _TEST_CASES = [
572 (
067aa17e 573 # https://github.com/ytdl-org/youtube-dl/issues/13919
9d6ac71c 574 # Also tests duplicate representation ids, see
067aa17e 575 # https://github.com/ytdl-org/youtube-dl/issues/15111
48504785 576 'float_duration',
2e27421c
S
577 'http://unknown/manifest.mpd', # mpd_url
578 None, # mpd_base_url
48504785 579 [{
9d6ac71c
S
580 'manifest_url': 'http://unknown/manifest.mpd',
581 'ext': 'm4a',
582 'format_id': '318597',
583 'format_note': 'DASH audio',
584 'protocol': 'http_dash_segments',
585 'acodec': 'mp4a.40.2',
586 'vcodec': 'none',
587 'tbr': 61.587,
588 }, {
48504785
S
589 'manifest_url': 'http://unknown/manifest.mpd',
590 'ext': 'mp4',
591 'format_id': '318597',
592 'format_note': 'DASH video',
593 'protocol': 'http_dash_segments',
594 'acodec': 'none',
595 'vcodec': 'avc1.42001f',
596 'tbr': 318.597,
597 'width': 340,
598 'height': 192,
599 }, {
600 'manifest_url': 'http://unknown/manifest.mpd',
601 'ext': 'mp4',
602 'format_id': '638590',
603 'format_note': 'DASH video',
604 'protocol': 'http_dash_segments',
605 'acodec': 'none',
606 'vcodec': 'avc1.42001f',
607 'tbr': 638.59,
608 'width': 512,
609 'height': 288,
610 }, {
611 'manifest_url': 'http://unknown/manifest.mpd',
612 'ext': 'mp4',
613 'format_id': '1022565',
614 'format_note': 'DASH video',
615 'protocol': 'http_dash_segments',
616 'acodec': 'none',
617 'vcodec': 'avc1.4d001f',
618 'tbr': 1022.565,
619 'width': 688,
620 'height': 384,
621 }, {
622 'manifest_url': 'http://unknown/manifest.mpd',
623 'ext': 'mp4',
624 'format_id': '2046506',
625 'format_note': 'DASH video',
626 'protocol': 'http_dash_segments',
627 'acodec': 'none',
628 'vcodec': 'avc1.4d001f',
629 'tbr': 2046.506,
630 'width': 1024,
631 'height': 576,
632 }, {
633 'manifest_url': 'http://unknown/manifest.mpd',
634 'ext': 'mp4',
635 'format_id': '3998017',
636 'format_note': 'DASH video',
637 'protocol': 'http_dash_segments',
638 'acodec': 'none',
639 'vcodec': 'avc1.640029',
640 'tbr': 3998.017,
641 'width': 1280,
642 'height': 720,
643 }, {
644 'manifest_url': 'http://unknown/manifest.mpd',
645 'ext': 'mp4',
646 'format_id': '5997485',
647 'format_note': 'DASH video',
648 'protocol': 'http_dash_segments',
649 'acodec': 'none',
650 'vcodec': 'avc1.640032',
651 'tbr': 5997.485,
652 'width': 1920,
653 'height': 1080,
654 }]
41bf647e 655 ), (
067aa17e 656 # https://github.com/ytdl-org/youtube-dl/pull/14844
41bf647e 657 'urls_only',
2e27421c
S
658 'http://unknown/manifest.mpd', # mpd_url
659 None, # mpd_base_url
41bf647e
PN
660 [{
661 'manifest_url': 'http://unknown/manifest.mpd',
662 'ext': 'mp4',
663 'format_id': 'h264_aac_144p_m4s',
664 'format_note': 'DASH video',
665 'protocol': 'http_dash_segments',
666 'acodec': 'mp4a.40.2',
667 'vcodec': 'avc3.42c01e',
668 'tbr': 200,
669 'width': 256,
670 'height': 144,
671 }, {
672 'manifest_url': 'http://unknown/manifest.mpd',
673 'ext': 'mp4',
674 'format_id': 'h264_aac_240p_m4s',
675 'format_note': 'DASH video',
676 'protocol': 'http_dash_segments',
677 'acodec': 'mp4a.40.2',
678 'vcodec': 'avc3.42c01e',
679 'tbr': 400,
680 'width': 424,
681 'height': 240,
682 }, {
683 'manifest_url': 'http://unknown/manifest.mpd',
684 'ext': 'mp4',
685 'format_id': 'h264_aac_360p_m4s',
686 'format_note': 'DASH video',
687 'protocol': 'http_dash_segments',
688 'acodec': 'mp4a.40.2',
689 'vcodec': 'avc3.42c01e',
690 'tbr': 800,
691 'width': 640,
692 'height': 360,
693 }, {
694 'manifest_url': 'http://unknown/manifest.mpd',
695 'ext': 'mp4',
696 'format_id': 'h264_aac_480p_m4s',
697 'format_note': 'DASH video',
698 'protocol': 'http_dash_segments',
699 'acodec': 'mp4a.40.2',
700 'vcodec': 'avc3.42c01e',
701 'tbr': 1200,
702 'width': 856,
703 'height': 480,
704 }, {
705 'manifest_url': 'http://unknown/manifest.mpd',
706 'ext': 'mp4',
707 'format_id': 'h264_aac_576p_m4s',
708 'format_note': 'DASH video',
709 'protocol': 'http_dash_segments',
710 'acodec': 'mp4a.40.2',
711 'vcodec': 'avc3.42c01e',
712 'tbr': 1600,
713 'width': 1024,
714 'height': 576,
715 }, {
716 'manifest_url': 'http://unknown/manifest.mpd',
717 'ext': 'mp4',
718 'format_id': 'h264_aac_720p_m4s',
719 'format_note': 'DASH video',
720 'protocol': 'http_dash_segments',
721 'acodec': 'mp4a.40.2',
722 'vcodec': 'avc3.42c01e',
723 'tbr': 2400,
724 'width': 1280,
725 'height': 720,
726 }, {
727 'manifest_url': 'http://unknown/manifest.mpd',
728 'ext': 'mp4',
729 'format_id': 'h264_aac_1080p_m4s',
730 'format_note': 'DASH video',
731 'protocol': 'http_dash_segments',
732 'acodec': 'mp4a.40.2',
733 'vcodec': 'avc3.42c01e',
734 'tbr': 4400,
735 'width': 1920,
736 'height': 1080,
737 }]
2e27421c
S
738 ), (
739 # https://github.com/ytdl-org/youtube-dl/issues/20346
740 # Media considered unfragmented even though it contains
741 # Initialization tag
742 'unfragmented',
743 'https://v.redd.it/hw1x7rcg7zl21/DASHPlaylist.mpd', # mpd_url
744 'https://v.redd.it/hw1x7rcg7zl21', # mpd_base_url
745 [{
746 'url': 'https://v.redd.it/hw1x7rcg7zl21/audio',
747 'manifest_url': 'https://v.redd.it/hw1x7rcg7zl21/DASHPlaylist.mpd',
748 'ext': 'm4a',
749 'format_id': 'AUDIO-1',
750 'format_note': 'DASH audio',
751 'container': 'm4a_dash',
752 'acodec': 'mp4a.40.2',
753 'vcodec': 'none',
754 'tbr': 129.87,
755 'asr': 48000,
756
757 }, {
758 'url': 'https://v.redd.it/hw1x7rcg7zl21/DASH_240',
759 'manifest_url': 'https://v.redd.it/hw1x7rcg7zl21/DASHPlaylist.mpd',
760 'ext': 'mp4',
761 'format_id': 'VIDEO-2',
762 'format_note': 'DASH video',
763 'container': 'mp4_dash',
764 'acodec': 'none',
765 'vcodec': 'avc1.4d401e',
766 'tbr': 608.0,
767 'width': 240,
768 'height': 240,
769 'fps': 30,
770 }, {
771 'url': 'https://v.redd.it/hw1x7rcg7zl21/DASH_360',
772 'manifest_url': 'https://v.redd.it/hw1x7rcg7zl21/DASHPlaylist.mpd',
773 'ext': 'mp4',
774 'format_id': 'VIDEO-1',
775 'format_note': 'DASH video',
776 'container': 'mp4_dash',
777 'acodec': 'none',
778 'vcodec': 'avc1.4d401e',
779 'tbr': 804.261,
780 'width': 360,
781 'height': 360,
782 'fps': 30,
783 }]
41bf647e 784 )
48504785
S
785 ]
786
2e27421c 787 for mpd_file, mpd_url, mpd_base_url, expected_formats in _TEST_CASES:
48504785
S
788 with io.open('./test/testdata/mpd/%s.mpd' % mpd_file,
789 mode='r', encoding='utf-8') as f:
790 formats = self.ie._parse_mpd_formats(
791 compat_etree_fromstring(f.read().encode('utf-8')),
2e27421c 792 mpd_base_url=mpd_base_url, mpd_url=mpd_url)
48504785
S
793 self.ie._sort_formats(formats)
794 expect_value(self, formats, expected_formats, None)
795
181e381f
S
796 def test_parse_f4m_formats(self):
797 _TEST_CASES = [
798 (
067aa17e 799 # https://github.com/ytdl-org/youtube-dl/issues/14660
181e381f
S
800 'custom_base_url',
801 'http://api.new.livestream.com/accounts/6115179/events/6764928/videos/144884262.f4m',
802 [{
803 'manifest_url': 'http://api.new.livestream.com/accounts/6115179/events/6764928/videos/144884262.f4m',
804 'ext': 'flv',
805 'format_id': '2148',
806 'protocol': 'f4m',
807 'tbr': 2148,
808 'width': 1280,
809 'height': 720,
810 }]
811 ),
812 ]
813
814 for f4m_file, f4m_url, expected_formats in _TEST_CASES:
815 with io.open('./test/testdata/f4m/%s.f4m' % f4m_file,
816 mode='r', encoding='utf-8') as f:
817 formats = self.ie._parse_f4m_formats(
818 compat_etree_fromstring(f.read().encode('utf-8')),
819 f4m_url, None)
820 self.ie._sort_formats(formats)
821 expect_value(self, formats, expected_formats, None)
582be358 822
96b8b9ab
RC
823 def test_parse_xspf(self):
824 _TEST_CASES = [
825 (
826 'foo_xspf',
47a5cb77 827 'https://example.org/src/foo_xspf.xspf',
96b8b9ab 828 [{
47a5cb77
S
829 'id': 'foo_xspf',
830 'title': 'Pandemonium',
96b8b9ab
RC
831 'description': 'Visit http://bigbrother404.bandcamp.com',
832 'duration': 202.416,
47a5cb77
S
833 'formats': [{
834 'manifest_url': 'https://example.org/src/foo_xspf.xspf',
835 'url': 'https://example.org/src/cd1/track%201.mp3',
836 }],
837 }, {
96b8b9ab 838 'id': 'foo_xspf',
47a5cb77 839 'title': 'Final Cartridge (Nichico Twelve Remix)',
96b8b9ab
RC
840 'description': 'Visit http://bigbrother404.bandcamp.com',
841 'duration': 255.857,
47a5cb77
S
842 'formats': [{
843 'manifest_url': 'https://example.org/src/foo_xspf.xspf',
844 'url': 'https://example.org/%E3%83%88%E3%83%A9%E3%83%83%E3%82%AF%E3%80%80%EF%BC%92.mp3',
845 }],
846 }, {
96b8b9ab 847 'id': 'foo_xspf',
47a5cb77 848 'title': 'Rebuilding Nightingale',
96b8b9ab
RC
849 'description': 'Visit http://bigbrother404.bandcamp.com',
850 'duration': 287.915,
47a5cb77
S
851 'formats': [{
852 'manifest_url': 'https://example.org/src/foo_xspf.xspf',
853 'url': 'https://example.org/src/track3.mp3',
854 }, {
855 'manifest_url': 'https://example.org/src/foo_xspf.xspf',
856 'url': 'https://example.com/track3.mp3',
857 }]
96b8b9ab
RC
858 }]
859 ),
860 ]
861
47a5cb77 862 for xspf_file, xspf_url, expected_entries in _TEST_CASES:
96b8b9ab
RC
863 with io.open('./test/testdata/xspf/%s.xspf' % xspf_file,
864 mode='r', encoding='utf-8') as f:
865 entries = self.ie._parse_xspf(
866 compat_etree_fromstring(f.read().encode('utf-8')),
47a5cb77 867 xspf_file, xspf_url=xspf_url, xspf_base_url=xspf_url)
96b8b9ab
RC
868 expect_value(self, entries, expected_entries, None)
869 for i in range(len(entries)):
870 expect_dict(self, entries[i], expected_entries[i])
871
95e42d73
XDG
872 def test_response_with_expected_status_returns_content(self):
873 # Checks for mitigations against the effects of
874 # <https://bugs.python.org/issue15002> that affect Python 3.4.1+, which
875 # manifest as `_download_webpage`, `_download_xml`, `_download_json`,
876 # or the underlying `_download_webpage_handle` returning no content
877 # when a response matches `expected_status`.
878
879 httpd = compat_http_server.HTTPServer(
880 ('127.0.0.1', 0), InfoExtractorTestRequestHandler)
881 port = http_server_port(httpd)
882 server_thread = threading.Thread(target=httpd.serve_forever)
883 server_thread.daemon = True
884 server_thread.start()
885
886 (content, urlh) = self.ie._download_webpage_handle(
887 'http://127.0.0.1:%d/teapot' % port, None,
888 expected_status=TEAPOT_RESPONSE_STATUS)
889 self.assertEqual(content, TEAPOT_RESPONSE_BODY)
890
f58a5060 891
14719565
JMF
892if __name__ == '__main__':
893 unittest.main()