]>
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 | ||
cb252080 | 12 | from test.helper import FakeYDL, expect_dict, expect_value |
48504785 | 13 | from youtube_dl.compat import compat_etree_fromstring |
14719565 JMF |
14 | from youtube_dl.extractor.common import InfoExtractor |
15 | from youtube_dl.extractor import YoutubeIE, get_info_extractor | |
88d9f6c0 | 16 | from youtube_dl.utils import encode_data_uri, strip_jsonp, ExtractorError, RegexNotFoundError |
14719565 JMF |
17 | |
18 | ||
19 | class TestIE(InfoExtractor): | |
20 | pass | |
21 | ||
22 | ||
23 | class TestInfoExtractor(unittest.TestCase): | |
24 | def setUp(self): | |
25 | self.ie = TestIE(FakeYDL()) | |
26 | ||
27 | def test_ie_key(self): | |
28 | self.assertEqual(get_info_extractor(YoutubeIE.ie_key()), YoutubeIE) | |
29 | ||
30 | def test_html_search_regex(self): | |
31 | html = '<p id="foo">Watch this <a href="http://www.youtube.com/watch?v=BaW_jenozKc">video</a></p>' | |
32 | search = lambda re, *args: self.ie._html_search_regex(re, html, *args) | |
33 | self.assertEqual(search(r'<p id="foo">(.+?)</p>', 'foo'), 'Watch this video') | |
34 | ||
35 | def test_opengraph(self): | |
36 | ie = self.ie | |
37 | html = ''' | |
38 | <meta name="og:title" content='Foo'/> | |
39 | <meta content="Some video's description " name="og:description"/> | |
40 | <meta property='og:image' content='http://domain.com/pic.jpg?key1=val1&key2=val2'/> | |
1c29e81e | 41 | <meta content='application/x-shockwave-flash' property='og:video:type'> |
db0a8ad9 | 42 | <meta content='Foo' property=og:foobar> |
448ef1f3 S |
43 | <meta name="og:test1" content='foo > < bar'/> |
44 | <meta name="og:test2" content="foo >//< bar"/> | |
14719565 JMF |
45 | ''' |
46 | self.assertEqual(ie._og_search_title(html), 'Foo') | |
47 | self.assertEqual(ie._og_search_description(html), 'Some video\'s description ') | |
48 | self.assertEqual(ie._og_search_thumbnail(html), 'http://domain.com/pic.jpg?key1=val1&key2=val2') | |
1c29e81e | 49 | self.assertEqual(ie._og_search_video_url(html, default=None), None) |
db0a8ad9 | 50 | self.assertEqual(ie._og_search_property('foobar', html), 'Foo') |
448ef1f3 S |
51 | self.assertEqual(ie._og_search_property('test1', html), 'foo > < bar') |
52 | self.assertEqual(ie._og_search_property('test2', html), 'foo >//< bar') | |
b070564e S |
53 | self.assertEqual(ie._og_search_property(('test0', 'test1'), html), 'foo > < bar') |
54 | self.assertRaises(RegexNotFoundError, ie._og_search_property, 'test0', html, None, fatal=True) | |
55 | self.assertRaises(RegexNotFoundError, ie._og_search_property, ('test0', 'test00'), html, None, fatal=True) | |
14719565 | 56 | |
bec22481 PH |
57 | def test_html_search_meta(self): |
58 | ie = self.ie | |
59 | html = ''' | |
60 | <meta name="a" content="1" /> | |
61 | <meta name='b' content='2'> | |
62 | <meta name="c" content='3'> | |
63 | <meta name=d content='4'> | |
64 | <meta property="e" content='5' > | |
65 | <meta content="6" name="f"> | |
66 | ''' | |
67 | ||
68 | self.assertEqual(ie._html_search_meta('a', html), '1') | |
69 | self.assertEqual(ie._html_search_meta('b', html), '2') | |
70 | self.assertEqual(ie._html_search_meta('c', html), '3') | |
71 | self.assertEqual(ie._html_search_meta('d', html), '4') | |
72 | self.assertEqual(ie._html_search_meta('e', html), '5') | |
73 | self.assertEqual(ie._html_search_meta('f', html), '6') | |
88d9f6c0 S |
74 | self.assertEqual(ie._html_search_meta(('a', 'b', 'c'), html), '1') |
75 | self.assertEqual(ie._html_search_meta(('c', 'b', 'a'), html), '3') | |
76 | self.assertEqual(ie._html_search_meta(('z', 'x', 'c'), html), '3') | |
77 | self.assertRaises(RegexNotFoundError, ie._html_search_meta, 'z', html, None, fatal=True) | |
78 | self.assertRaises(RegexNotFoundError, ie._html_search_meta, ('z', 'x'), html, None, fatal=True) | |
bec22481 | 79 | |
6a801f44 JMF |
80 | def test_download_json(self): |
81 | uri = encode_data_uri(b'{"foo": "blah"}', 'application/json') | |
82 | self.assertEqual(self.ie._download_json(uri, None), {'foo': 'blah'}) | |
83 | uri = encode_data_uri(b'callback({"foo": "blah"})', 'application/javascript') | |
84 | self.assertEqual(self.ie._download_json(uri, None, transform_source=strip_jsonp), {'foo': 'blah'}) | |
85 | uri = encode_data_uri(b'{"foo": invalid}', 'application/json') | |
86 | self.assertRaises(ExtractorError, self.ie._download_json, uri, None) | |
87 | self.assertEqual(self.ie._download_json(uri, None, fatal=False), None) | |
88 | ||
7f3590c4 S |
89 | def test_extract_jwplayer_data_realworld(self): |
90 | # from http://www.suffolk.edu/sjc/ | |
91 | expect_dict( | |
92 | self, | |
93 | self.ie._extract_jwplayer_data(r''' | |
94 | <script type='text/javascript'> | |
95 | jwplayer('my-video').setup({ | |
96 | file: 'rtmp://192.138.214.154/live/sjclive', | |
97 | fallback: 'true', | |
98 | width: '95%', | |
99 | aspectratio: '16:9', | |
100 | primary: 'flash', | |
101 | mediaid:'XEgvuql4' | |
102 | }); | |
103 | </script> | |
104 | ''', None, require_title=False), | |
105 | { | |
106 | 'id': 'XEgvuql4', | |
107 | 'formats': [{ | |
108 | 'url': 'rtmp://192.138.214.154/live/sjclive', | |
109 | 'ext': 'flv' | |
110 | }] | |
111 | }) | |
112 | ||
113 | # from https://www.pornoxo.com/videos/7564/striptease-from-sexy-secretary/ | |
114 | expect_dict( | |
115 | self, | |
116 | self.ie._extract_jwplayer_data(r''' | |
117 | <script type="text/javascript"> | |
118 | jwplayer("mediaplayer").setup({ | |
119 | 'videoid': "7564", | |
120 | 'width': "100%", | |
121 | 'aspectratio': "16:9", | |
122 | 'stretching': "exactfit", | |
123 | 'autostart': 'false', | |
124 | 'flashplayer': "https://t04.vipstreamservice.com/jwplayer/v5.10/player.swf", | |
125 | '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", | |
126 | 'image': "https://t03.vipstreamservice.com/thumbs/pxo-full/2009-12/14/a4b2157147afe5efa93ce1978e0265289c193874e02597.flv-full-13.jpg", | |
127 | '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", | |
128 | 'logo.hide': true, | |
129 | 'skin': "https://t04.vipstreamservice.com/jwplayer/skin/modieus-blk.zip", | |
130 | 'plugins': "https://t04.vipstreamservice.com/jwplayer/dock/dockableskinnableplugin.swf", | |
131 | 'dockableskinnableplugin.piclink': "/index.php?key=ajax-videothumbsn&vid=7564&data=2009-12--14--4b2157147afe5efa93ce1978e0265289c193874e02597.flv--17370", | |
132 | 'controlbar': 'bottom', | |
133 | 'modes': [ | |
134 | {type: 'flash', src: 'https://t04.vipstreamservice.com/jwplayer/v5.10/player.swf'} | |
135 | ], | |
136 | 'provider': 'http' | |
137 | }); | |
138 | //noinspection JSAnnotator | |
139 | invideo.setup({ | |
140 | adsUrl: "/banner-iframe/?zoneId=32", | |
141 | adsUrl2: "", | |
142 | autostart: false | |
143 | }); | |
144 | </script> | |
145 | ''', 'dummy', require_title=False), | |
146 | { | |
147 | 'thumbnail': 'https://t03.vipstreamservice.com/thumbs/pxo-full/2009-12/14/a4b2157147afe5efa93ce1978e0265289c193874e02597.flv-full-13.jpg', | |
148 | 'formats': [{ | |
149 | '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', | |
150 | 'ext': 'flv' | |
151 | }] | |
152 | }) | |
153 | ||
154 | # from http://www.indiedb.com/games/king-machine/videos | |
155 | expect_dict( | |
156 | self, | |
157 | self.ie._extract_jwplayer_data(r''' | |
158 | <script> | |
159 | 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) { | |
160 | videoAnalytics("play"); | |
161 | }).once("complete", function(event) { | |
162 | videoAnalytics("completed"); | |
163 | }); | |
164 | </script> | |
165 | ''', 'dummy'), | |
166 | { | |
167 | 'title': 'king machine trailer 1', | |
168 | 'thumbnail': 'http://media.indiedb.com/cache/images/games/1/50/49678/thumb_620x2000/king-machine-trailer.mp4.jpg', | |
169 | 'formats': [{ | |
170 | 'url': 'http://cdn.dbolical.com/cache/videos/games/1/50/49678/encode_mp4/king-machine-trailer.mp4', | |
171 | 'height': 360, | |
172 | 'ext': 'mp4' | |
173 | }, { | |
174 | 'url': 'http://cdn.dbolical.com/cache/videos/games/1/50/49678/encode720p_mp4/king-machine-trailer.mp4', | |
175 | 'height': 720, | |
176 | 'ext': 'mp4' | |
177 | }] | |
178 | }) | |
179 | ||
cb252080 S |
180 | def test_parse_m3u8_formats(self): |
181 | _TEST_CASES = [ | |
182 | ( | |
183 | # https://github.com/rg3/youtube-dl/issues/11507 | |
184 | # http://pluzz.francetv.fr/videos/le_ministere.html | |
185 | 'pluzz_francetv_11507', | |
186 | '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', | |
187 | [{ | |
cb252080 | 188 | '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 | 189 | '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 |
190 | 'ext': 'mp4', |
191 | 'format_id': '180', | |
192 | 'protocol': 'm3u8', | |
193 | 'acodec': 'mp4a.40.2', | |
194 | 'vcodec': 'avc1.66.30', | |
195 | 'tbr': 180, | |
196 | 'width': 256, | |
197 | 'height': 144, | |
198 | }, { | |
199 | '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 | 200 | '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 |
201 | 'ext': 'mp4', |
202 | 'format_id': '303', | |
203 | 'protocol': 'm3u8', | |
204 | 'acodec': 'mp4a.40.2', | |
205 | 'vcodec': 'avc1.66.30', | |
206 | 'tbr': 303, | |
207 | 'width': 320, | |
208 | 'height': 180, | |
209 | }, { | |
210 | '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 | 211 | '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 |
212 | 'ext': 'mp4', |
213 | 'format_id': '575', | |
214 | 'protocol': 'm3u8', | |
215 | 'acodec': 'mp4a.40.2', | |
216 | 'vcodec': 'avc1.66.30', | |
217 | 'tbr': 575, | |
218 | 'width': 512, | |
219 | 'height': 288, | |
220 | }, { | |
221 | '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 | 222 | '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 |
223 | 'ext': 'mp4', |
224 | 'format_id': '831', | |
225 | 'protocol': 'm3u8', | |
226 | 'acodec': 'mp4a.40.2', | |
227 | 'vcodec': 'avc1.77.30', | |
228 | 'tbr': 831, | |
229 | 'width': 704, | |
230 | 'height': 396, | |
231 | }, { | |
232 | '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 | 233 | '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 |
234 | 'ext': 'mp4', |
235 | 'protocol': 'm3u8', | |
236 | 'format_id': '1467', | |
237 | 'acodec': 'mp4a.40.2', | |
238 | 'vcodec': 'avc1.77.30', | |
239 | 'tbr': 1467, | |
240 | 'width': 1024, | |
241 | 'height': 576, | |
242 | }] | |
243 | ), | |
244 | ( | |
245 | # https://github.com/rg3/youtube-dl/issues/11995 | |
246 | # http://teamcoco.com/video/clueless-gamer-super-bowl-for-honor | |
247 | 'teamcoco_11995', | |
248 | 'http://ak.storage-w.teamcococdn.com/cdn/2017-02/98599/ed8f/main.m3u8', | |
249 | [{ | |
cb252080 | 250 | 'url': 'http://ak.storage-w.teamcococdn.com/cdn/2017-02/98599/ed8f/hls/CONAN_020217_Highlight_show-audio-160k_v4.m3u8', |
30bb6ce1 | 251 | 'manifest_url': 'http://ak.storage-w.teamcococdn.com/cdn/2017-02/98599/ed8f/main.m3u8', |
cb252080 S |
252 | 'ext': 'mp4', |
253 | 'format_id': 'audio-0-Default', | |
254 | 'protocol': 'm3u8', | |
255 | 'vcodec': 'none', | |
256 | }, { | |
257 | 'url': 'http://ak.storage-w.teamcococdn.com/cdn/2017-02/98599/ed8f/hls/CONAN_020217_Highlight_show-audio-64k_v4.m3u8', | |
30bb6ce1 | 258 | 'manifest_url': 'http://ak.storage-w.teamcococdn.com/cdn/2017-02/98599/ed8f/main.m3u8', |
cb252080 S |
259 | 'ext': 'mp4', |
260 | 'format_id': 'audio-1-Default', | |
261 | 'protocol': 'm3u8', | |
262 | 'vcodec': 'none', | |
263 | }, { | |
264 | 'url': 'http://ak.storage-w.teamcococdn.com/cdn/2017-02/98599/ed8f/hls/CONAN_020217_Highlight_show-audio-64k_v4.m3u8', | |
30bb6ce1 | 265 | 'manifest_url': 'http://ak.storage-w.teamcococdn.com/cdn/2017-02/98599/ed8f/main.m3u8', |
cb252080 S |
266 | 'ext': 'mp4', |
267 | 'format_id': '71', | |
268 | 'protocol': 'm3u8', | |
269 | 'acodec': 'mp4a.40.5', | |
270 | 'vcodec': 'none', | |
271 | 'tbr': 71, | |
272 | }, { | |
273 | 'url': 'http://ak.storage-w.teamcococdn.com/cdn/2017-02/98599/ed8f/hls/CONAN_020217_Highlight_show-400k_v4.m3u8', | |
30bb6ce1 | 274 | 'manifest_url': 'http://ak.storage-w.teamcococdn.com/cdn/2017-02/98599/ed8f/main.m3u8', |
cb252080 S |
275 | 'ext': 'mp4', |
276 | 'format_id': '413', | |
277 | 'protocol': 'm3u8', | |
278 | 'acodec': 'none', | |
279 | 'vcodec': 'avc1.42001e', | |
280 | 'tbr': 413, | |
281 | 'width': 400, | |
282 | 'height': 224, | |
283 | }, { | |
284 | 'url': 'http://ak.storage-w.teamcococdn.com/cdn/2017-02/98599/ed8f/hls/CONAN_020217_Highlight_show-400k_v4.m3u8', | |
30bb6ce1 | 285 | 'manifest_url': 'http://ak.storage-w.teamcococdn.com/cdn/2017-02/98599/ed8f/main.m3u8', |
cb252080 S |
286 | 'ext': 'mp4', |
287 | 'format_id': '522', | |
288 | 'protocol': 'm3u8', | |
289 | 'acodec': 'none', | |
290 | 'vcodec': 'avc1.42001e', | |
291 | 'tbr': 522, | |
292 | 'width': 400, | |
293 | 'height': 224, | |
294 | }, { | |
295 | 'url': 'http://ak.storage-w.teamcococdn.com/cdn/2017-02/98599/ed8f/hls/CONAN_020217_Highlight_show-1m_v4.m3u8', | |
30bb6ce1 | 296 | 'manifest_url': 'http://ak.storage-w.teamcococdn.com/cdn/2017-02/98599/ed8f/main.m3u8', |
cb252080 S |
297 | 'ext': 'mp4', |
298 | 'format_id': '1205', | |
299 | 'protocol': 'm3u8', | |
300 | 'acodec': 'none', | |
301 | 'vcodec': 'avc1.4d001e', | |
302 | 'tbr': 1205, | |
303 | 'width': 640, | |
304 | 'height': 360, | |
305 | }, { | |
306 | 'url': 'http://ak.storage-w.teamcococdn.com/cdn/2017-02/98599/ed8f/hls/CONAN_020217_Highlight_show-2m_v4.m3u8', | |
30bb6ce1 | 307 | 'manifest_url': 'http://ak.storage-w.teamcococdn.com/cdn/2017-02/98599/ed8f/main.m3u8', |
cb252080 S |
308 | 'ext': 'mp4', |
309 | 'format_id': '2374', | |
310 | 'protocol': 'm3u8', | |
311 | 'acodec': 'none', | |
312 | 'vcodec': 'avc1.4d001f', | |
313 | 'tbr': 2374, | |
314 | 'width': 1024, | |
315 | 'height': 576, | |
316 | }] | |
317 | ), | |
318 | ( | |
319 | # https://github.com/rg3/youtube-dl/issues/12211 | |
320 | # http://video.toggle.sg/en/series/whoopie-s-world/ep3/478601 | |
321 | 'toggle_mobile_12211', | |
322 | 'http://cdnapi.kaltura.com/p/2082311/sp/208231100/playManifest/protocol/http/entryId/0_89q6e8ku/format/applehttp/tags/mobile_sd/f/a.m3u8', | |
323 | [{ | |
cb252080 | 324 | '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 | 325 | '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 |
326 | 'ext': 'mp4', |
327 | 'format_id': 'audio-English', | |
328 | 'protocol': 'm3u8', | |
329 | 'language': 'eng', | |
330 | 'vcodec': 'none', | |
331 | }, { | |
332 | '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 | 333 | '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 |
334 | 'ext': 'mp4', |
335 | 'format_id': 'audio-Undefined', | |
336 | 'protocol': 'm3u8', | |
337 | 'language': 'und', | |
338 | 'vcodec': 'none', | |
339 | }, { | |
340 | '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 | 341 | '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 |
342 | 'ext': 'mp4', |
343 | 'format_id': '155', | |
344 | 'protocol': 'm3u8', | |
ddd258f9 | 345 | 'tbr': 155.648, |
cb252080 S |
346 | 'width': 320, |
347 | 'height': 180, | |
348 | }, { | |
349 | '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 | 350 | '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 |
351 | 'ext': 'mp4', |
352 | 'format_id': '502', | |
353 | 'protocol': 'm3u8', | |
ddd258f9 | 354 | 'tbr': 502.784, |
cb252080 S |
355 | 'width': 480, |
356 | 'height': 270, | |
357 | }, { | |
358 | '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 | 359 | '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 |
360 | 'ext': 'mp4', |
361 | 'format_id': '827', | |
362 | 'protocol': 'm3u8', | |
ddd258f9 | 363 | 'tbr': 827.392, |
cb252080 S |
364 | 'width': 640, |
365 | 'height': 360, | |
366 | }, { | |
367 | '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 | 368 | '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 |
369 | 'ext': 'mp4', |
370 | 'format_id': '1396', | |
371 | 'protocol': 'm3u8', | |
ddd258f9 | 372 | 'tbr': 1396.736, |
cb252080 S |
373 | 'width': 854, |
374 | 'height': 480, | |
375 | }] | |
376 | ), | |
377 | ( | |
378 | # http://www.twitch.tv/riotgames/v/6528877 | |
379 | 'twitch_vod', | |
380 | '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', | |
381 | [{ | |
cb252080 | 382 | 'url': 'https://vod.edgecast.hls.ttvnw.net/e5da31ab49_riotgames_15001215120_261543898/audio_only/index-muted-HM49I092CC.m3u8', |
30bb6ce1 | 383 | '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 |
384 | 'ext': 'mp4', |
385 | 'format_id': 'Audio Only', | |
386 | 'protocol': 'm3u8', | |
387 | 'acodec': 'mp4a.40.2', | |
388 | 'vcodec': 'none', | |
ddd258f9 | 389 | 'tbr': 182.725, |
cb252080 S |
390 | }, { |
391 | 'url': 'https://vod.edgecast.hls.ttvnw.net/e5da31ab49_riotgames_15001215120_261543898/mobile/index-muted-HM49I092CC.m3u8', | |
30bb6ce1 | 392 | '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 |
393 | 'ext': 'mp4', |
394 | 'format_id': 'Mobile', | |
395 | 'protocol': 'm3u8', | |
396 | 'acodec': 'mp4a.40.2', | |
397 | 'vcodec': 'avc1.42C00D', | |
ddd258f9 | 398 | 'tbr': 280.474, |
cb252080 S |
399 | 'width': 400, |
400 | 'height': 226, | |
401 | }, { | |
402 | 'url': 'https://vod.edgecast.hls.ttvnw.net/e5da31ab49_riotgames_15001215120_261543898/low/index-muted-HM49I092CC.m3u8', | |
30bb6ce1 | 403 | '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 |
404 | 'ext': 'mp4', |
405 | 'format_id': 'Low', | |
406 | 'protocol': 'm3u8', | |
407 | 'acodec': 'mp4a.40.2', | |
408 | 'vcodec': 'avc1.42C01E', | |
ddd258f9 | 409 | 'tbr': 628.347, |
cb252080 S |
410 | 'width': 640, |
411 | 'height': 360, | |
412 | }, { | |
413 | 'url': 'https://vod.edgecast.hls.ttvnw.net/e5da31ab49_riotgames_15001215120_261543898/medium/index-muted-HM49I092CC.m3u8', | |
30bb6ce1 | 414 | '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 |
415 | 'ext': 'mp4', |
416 | 'format_id': 'Medium', | |
417 | 'protocol': 'm3u8', | |
418 | 'acodec': 'mp4a.40.2', | |
419 | 'vcodec': 'avc1.42C01E', | |
ddd258f9 | 420 | 'tbr': 893.387, |
cb252080 S |
421 | 'width': 852, |
422 | 'height': 480, | |
423 | }, { | |
424 | 'url': 'https://vod.edgecast.hls.ttvnw.net/e5da31ab49_riotgames_15001215120_261543898/high/index-muted-HM49I092CC.m3u8', | |
30bb6ce1 | 425 | '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 |
426 | 'ext': 'mp4', |
427 | 'format_id': 'High', | |
428 | 'protocol': 'm3u8', | |
429 | 'acodec': 'mp4a.40.2', | |
430 | 'vcodec': 'avc1.42C01F', | |
ddd258f9 | 431 | 'tbr': 1603.789, |
cb252080 S |
432 | 'width': 1280, |
433 | 'height': 720, | |
434 | }, { | |
435 | 'url': 'https://vod.edgecast.hls.ttvnw.net/e5da31ab49_riotgames_15001215120_261543898/chunked/index-muted-HM49I092CC.m3u8', | |
30bb6ce1 | 436 | '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 |
437 | 'ext': 'mp4', |
438 | 'format_id': 'Source', | |
439 | 'protocol': 'm3u8', | |
440 | 'acodec': 'mp4a.40.2', | |
441 | 'vcodec': 'avc1.100.31', | |
ddd258f9 S |
442 | 'tbr': 3214.134, |
443 | 'width': 1280, | |
444 | 'height': 720, | |
445 | }] | |
446 | ), | |
447 | ( | |
448 | # http://www.vidio.com/watch/165683-dj_ambred-booyah-live-2015 | |
449 | # EXT-X-STREAM-INF tag with NAME attribute that is not defined | |
450 | # in HLS specification | |
451 | 'vidio', | |
452 | 'https://www.vidio.com/videos/165683/playlist.m3u8', | |
453 | [{ | |
ddd258f9 | 454 | 'url': 'https://cdn1-a.production.vidio.static6.com/uploads/165683/dj_ambred-4383-b300.mp4.m3u8', |
30bb6ce1 | 455 | 'manifest_url': 'https://www.vidio.com/videos/165683/playlist.m3u8', |
ddd258f9 S |
456 | 'ext': 'mp4', |
457 | 'format_id': '270p 3G', | |
458 | 'protocol': 'm3u8', | |
459 | 'tbr': 300, | |
460 | 'width': 480, | |
461 | 'height': 270, | |
462 | }, { | |
463 | 'url': 'https://cdn1-a.production.vidio.static6.com/uploads/165683/dj_ambred-4383-b600.mp4.m3u8', | |
30bb6ce1 | 464 | 'manifest_url': 'https://www.vidio.com/videos/165683/playlist.m3u8', |
ddd258f9 S |
465 | 'ext': 'mp4', |
466 | 'format_id': '360p SD', | |
467 | 'protocol': 'm3u8', | |
468 | 'tbr': 600, | |
469 | 'width': 640, | |
470 | 'height': 360, | |
471 | }, { | |
472 | 'url': 'https://cdn1-a.production.vidio.static6.com/uploads/165683/dj_ambred-4383-b1200.mp4.m3u8', | |
30bb6ce1 | 473 | 'manifest_url': 'https://www.vidio.com/videos/165683/playlist.m3u8', |
ddd258f9 S |
474 | 'ext': 'mp4', |
475 | 'format_id': '720p HD', | |
476 | 'protocol': 'm3u8', | |
477 | 'tbr': 1200, | |
cb252080 S |
478 | 'width': 1280, |
479 | 'height': 720, | |
480 | }] | |
481 | ) | |
482 | ] | |
483 | ||
484 | for m3u8_file, m3u8_url, expected_formats in _TEST_CASES: | |
485 | with io.open('./test/testdata/m3u8/%s.m3u8' % m3u8_file, | |
486 | mode='r', encoding='utf-8') as f: | |
487 | formats = self.ie._parse_m3u8_formats( | |
488 | f.read(), m3u8_url, ext='mp4') | |
489 | self.ie._sort_formats(formats) | |
490 | expect_value(self, formats, expected_formats, None) | |
491 | ||
48504785 S |
492 | def test_parse_mpd_formats(self): |
493 | _TEST_CASES = [ | |
494 | ( | |
495 | # https://github.com/rg3/youtube-dl/issues/13919 | |
9d6ac71c S |
496 | # Also tests duplicate representation ids, see |
497 | # https://github.com/rg3/youtube-dl/issues/15111 | |
48504785 S |
498 | 'float_duration', |
499 | 'http://unknown/manifest.mpd', | |
500 | [{ | |
9d6ac71c S |
501 | 'manifest_url': 'http://unknown/manifest.mpd', |
502 | 'ext': 'm4a', | |
503 | 'format_id': '318597', | |
504 | 'format_note': 'DASH audio', | |
505 | 'protocol': 'http_dash_segments', | |
506 | 'acodec': 'mp4a.40.2', | |
507 | 'vcodec': 'none', | |
508 | 'tbr': 61.587, | |
509 | }, { | |
48504785 S |
510 | 'manifest_url': 'http://unknown/manifest.mpd', |
511 | 'ext': 'mp4', | |
512 | 'format_id': '318597', | |
513 | 'format_note': 'DASH video', | |
514 | 'protocol': 'http_dash_segments', | |
515 | 'acodec': 'none', | |
516 | 'vcodec': 'avc1.42001f', | |
517 | 'tbr': 318.597, | |
518 | 'width': 340, | |
519 | 'height': 192, | |
520 | }, { | |
521 | 'manifest_url': 'http://unknown/manifest.mpd', | |
522 | 'ext': 'mp4', | |
523 | 'format_id': '638590', | |
524 | 'format_note': 'DASH video', | |
525 | 'protocol': 'http_dash_segments', | |
526 | 'acodec': 'none', | |
527 | 'vcodec': 'avc1.42001f', | |
528 | 'tbr': 638.59, | |
529 | 'width': 512, | |
530 | 'height': 288, | |
531 | }, { | |
532 | 'manifest_url': 'http://unknown/manifest.mpd', | |
533 | 'ext': 'mp4', | |
534 | 'format_id': '1022565', | |
535 | 'format_note': 'DASH video', | |
536 | 'protocol': 'http_dash_segments', | |
537 | 'acodec': 'none', | |
538 | 'vcodec': 'avc1.4d001f', | |
539 | 'tbr': 1022.565, | |
540 | 'width': 688, | |
541 | 'height': 384, | |
542 | }, { | |
543 | 'manifest_url': 'http://unknown/manifest.mpd', | |
544 | 'ext': 'mp4', | |
545 | 'format_id': '2046506', | |
546 | 'format_note': 'DASH video', | |
547 | 'protocol': 'http_dash_segments', | |
548 | 'acodec': 'none', | |
549 | 'vcodec': 'avc1.4d001f', | |
550 | 'tbr': 2046.506, | |
551 | 'width': 1024, | |
552 | 'height': 576, | |
553 | }, { | |
554 | 'manifest_url': 'http://unknown/manifest.mpd', | |
555 | 'ext': 'mp4', | |
556 | 'format_id': '3998017', | |
557 | 'format_note': 'DASH video', | |
558 | 'protocol': 'http_dash_segments', | |
559 | 'acodec': 'none', | |
560 | 'vcodec': 'avc1.640029', | |
561 | 'tbr': 3998.017, | |
562 | 'width': 1280, | |
563 | 'height': 720, | |
564 | }, { | |
565 | 'manifest_url': 'http://unknown/manifest.mpd', | |
566 | 'ext': 'mp4', | |
567 | 'format_id': '5997485', | |
568 | 'format_note': 'DASH video', | |
569 | 'protocol': 'http_dash_segments', | |
570 | 'acodec': 'none', | |
571 | 'vcodec': 'avc1.640032', | |
572 | 'tbr': 5997.485, | |
573 | 'width': 1920, | |
574 | 'height': 1080, | |
575 | }] | |
41bf647e | 576 | ), ( |
78593e29 | 577 | # https://github.com/rg3/youtube-dl/pull/14844 |
41bf647e PN |
578 | 'urls_only', |
579 | 'http://unknown/manifest.mpd', | |
580 | [{ | |
581 | 'manifest_url': 'http://unknown/manifest.mpd', | |
582 | 'ext': 'mp4', | |
583 | 'format_id': 'h264_aac_144p_m4s', | |
584 | 'format_note': 'DASH video', | |
585 | 'protocol': 'http_dash_segments', | |
586 | 'acodec': 'mp4a.40.2', | |
587 | 'vcodec': 'avc3.42c01e', | |
588 | 'tbr': 200, | |
589 | 'width': 256, | |
590 | 'height': 144, | |
591 | }, { | |
592 | 'manifest_url': 'http://unknown/manifest.mpd', | |
593 | 'ext': 'mp4', | |
594 | 'format_id': 'h264_aac_240p_m4s', | |
595 | 'format_note': 'DASH video', | |
596 | 'protocol': 'http_dash_segments', | |
597 | 'acodec': 'mp4a.40.2', | |
598 | 'vcodec': 'avc3.42c01e', | |
599 | 'tbr': 400, | |
600 | 'width': 424, | |
601 | 'height': 240, | |
602 | }, { | |
603 | 'manifest_url': 'http://unknown/manifest.mpd', | |
604 | 'ext': 'mp4', | |
605 | 'format_id': 'h264_aac_360p_m4s', | |
606 | 'format_note': 'DASH video', | |
607 | 'protocol': 'http_dash_segments', | |
608 | 'acodec': 'mp4a.40.2', | |
609 | 'vcodec': 'avc3.42c01e', | |
610 | 'tbr': 800, | |
611 | 'width': 640, | |
612 | 'height': 360, | |
613 | }, { | |
614 | 'manifest_url': 'http://unknown/manifest.mpd', | |
615 | 'ext': 'mp4', | |
616 | 'format_id': 'h264_aac_480p_m4s', | |
617 | 'format_note': 'DASH video', | |
618 | 'protocol': 'http_dash_segments', | |
619 | 'acodec': 'mp4a.40.2', | |
620 | 'vcodec': 'avc3.42c01e', | |
621 | 'tbr': 1200, | |
622 | 'width': 856, | |
623 | 'height': 480, | |
624 | }, { | |
625 | 'manifest_url': 'http://unknown/manifest.mpd', | |
626 | 'ext': 'mp4', | |
627 | 'format_id': 'h264_aac_576p_m4s', | |
628 | 'format_note': 'DASH video', | |
629 | 'protocol': 'http_dash_segments', | |
630 | 'acodec': 'mp4a.40.2', | |
631 | 'vcodec': 'avc3.42c01e', | |
632 | 'tbr': 1600, | |
633 | 'width': 1024, | |
634 | 'height': 576, | |
635 | }, { | |
636 | 'manifest_url': 'http://unknown/manifest.mpd', | |
637 | 'ext': 'mp4', | |
638 | 'format_id': 'h264_aac_720p_m4s', | |
639 | 'format_note': 'DASH video', | |
640 | 'protocol': 'http_dash_segments', | |
641 | 'acodec': 'mp4a.40.2', | |
642 | 'vcodec': 'avc3.42c01e', | |
643 | 'tbr': 2400, | |
644 | 'width': 1280, | |
645 | 'height': 720, | |
646 | }, { | |
647 | 'manifest_url': 'http://unknown/manifest.mpd', | |
648 | 'ext': 'mp4', | |
649 | 'format_id': 'h264_aac_1080p_m4s', | |
650 | 'format_note': 'DASH video', | |
651 | 'protocol': 'http_dash_segments', | |
652 | 'acodec': 'mp4a.40.2', | |
653 | 'vcodec': 'avc3.42c01e', | |
654 | 'tbr': 4400, | |
655 | 'width': 1920, | |
656 | 'height': 1080, | |
657 | }] | |
658 | ) | |
48504785 S |
659 | ] |
660 | ||
661 | for mpd_file, mpd_url, expected_formats in _TEST_CASES: | |
662 | with io.open('./test/testdata/mpd/%s.mpd' % mpd_file, | |
663 | mode='r', encoding='utf-8') as f: | |
664 | formats = self.ie._parse_mpd_formats( | |
665 | compat_etree_fromstring(f.read().encode('utf-8')), | |
666 | mpd_url=mpd_url) | |
667 | self.ie._sort_formats(formats) | |
668 | expect_value(self, formats, expected_formats, None) | |
669 | ||
181e381f S |
670 | def test_parse_f4m_formats(self): |
671 | _TEST_CASES = [ | |
672 | ( | |
673 | # https://github.com/rg3/youtube-dl/issues/14660 | |
674 | 'custom_base_url', | |
675 | 'http://api.new.livestream.com/accounts/6115179/events/6764928/videos/144884262.f4m', | |
676 | [{ | |
677 | 'manifest_url': 'http://api.new.livestream.com/accounts/6115179/events/6764928/videos/144884262.f4m', | |
678 | 'ext': 'flv', | |
679 | 'format_id': '2148', | |
680 | 'protocol': 'f4m', | |
681 | 'tbr': 2148, | |
682 | 'width': 1280, | |
683 | 'height': 720, | |
684 | }] | |
685 | ), | |
686 | ] | |
687 | ||
688 | for f4m_file, f4m_url, expected_formats in _TEST_CASES: | |
689 | with io.open('./test/testdata/f4m/%s.f4m' % f4m_file, | |
690 | mode='r', encoding='utf-8') as f: | |
691 | formats = self.ie._parse_f4m_formats( | |
692 | compat_etree_fromstring(f.read().encode('utf-8')), | |
693 | f4m_url, None) | |
694 | self.ie._sort_formats(formats) | |
695 | expect_value(self, formats, expected_formats, None) | |
582be358 | 696 | |
96b8b9ab RC |
697 | def test_parse_xspf(self): |
698 | _TEST_CASES = [ | |
699 | ( | |
700 | 'foo_xspf', | |
47a5cb77 | 701 | 'https://example.org/src/foo_xspf.xspf', |
96b8b9ab | 702 | [{ |
47a5cb77 S |
703 | 'id': 'foo_xspf', |
704 | 'title': 'Pandemonium', | |
96b8b9ab RC |
705 | 'description': 'Visit http://bigbrother404.bandcamp.com', |
706 | 'duration': 202.416, | |
47a5cb77 S |
707 | 'formats': [{ |
708 | 'manifest_url': 'https://example.org/src/foo_xspf.xspf', | |
709 | 'url': 'https://example.org/src/cd1/track%201.mp3', | |
710 | }], | |
711 | }, { | |
96b8b9ab | 712 | 'id': 'foo_xspf', |
47a5cb77 | 713 | 'title': 'Final Cartridge (Nichico Twelve Remix)', |
96b8b9ab RC |
714 | 'description': 'Visit http://bigbrother404.bandcamp.com', |
715 | 'duration': 255.857, | |
47a5cb77 S |
716 | 'formats': [{ |
717 | 'manifest_url': 'https://example.org/src/foo_xspf.xspf', | |
718 | 'url': 'https://example.org/%E3%83%88%E3%83%A9%E3%83%83%E3%82%AF%E3%80%80%EF%BC%92.mp3', | |
719 | }], | |
720 | }, { | |
96b8b9ab | 721 | 'id': 'foo_xspf', |
47a5cb77 | 722 | 'title': 'Rebuilding Nightingale', |
96b8b9ab RC |
723 | 'description': 'Visit http://bigbrother404.bandcamp.com', |
724 | 'duration': 287.915, | |
47a5cb77 S |
725 | 'formats': [{ |
726 | 'manifest_url': 'https://example.org/src/foo_xspf.xspf', | |
727 | 'url': 'https://example.org/src/track3.mp3', | |
728 | }, { | |
729 | 'manifest_url': 'https://example.org/src/foo_xspf.xspf', | |
730 | 'url': 'https://example.com/track3.mp3', | |
731 | }] | |
96b8b9ab RC |
732 | }] |
733 | ), | |
734 | ] | |
735 | ||
47a5cb77 | 736 | for xspf_file, xspf_url, expected_entries in _TEST_CASES: |
96b8b9ab RC |
737 | with io.open('./test/testdata/xspf/%s.xspf' % xspf_file, |
738 | mode='r', encoding='utf-8') as f: | |
739 | entries = self.ie._parse_xspf( | |
740 | compat_etree_fromstring(f.read().encode('utf-8')), | |
47a5cb77 | 741 | xspf_file, xspf_url=xspf_url, xspf_base_url=xspf_url) |
96b8b9ab RC |
742 | expect_value(self, entries, expected_entries, None) |
743 | for i in range(len(entries)): | |
744 | expect_dict(self, entries[i], expected_entries[i]) | |
745 | ||
f58a5060 | 746 | |
14719565 JMF |
747 | if __name__ == '__main__': |
748 | unittest.main() |