]> git.bitcoin.ninja Git - youtube-dl/blob - test/test_InfoExtractor.py
Credit @luboss for joj (#13268)
[youtube-dl] / test / test_InfoExtractor.py
1 #!/usr/bin/env python
2
3 from __future__ import unicode_literals
4
5 # Allow direct execution
6 import io
7 import os
8 import sys
9 import unittest
10 sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
11
12 from test.helper import FakeYDL, expect_dict, expect_value
13 from youtube_dl.compat import compat_etree_fromstring
14 from youtube_dl.extractor.common import InfoExtractor
15 from youtube_dl.extractor import YoutubeIE, get_info_extractor
16 from youtube_dl.utils import encode_data_uri, strip_jsonp, ExtractorError, RegexNotFoundError
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&amp;key2=val2'/>
41             <meta content='application/x-shockwave-flash' property='og:video:type'>
42             <meta content='Foo' property=og:foobar>
43             <meta name="og:test1" content='foo > < bar'/>
44             <meta name="og:test2" content="foo >//< bar"/>
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')
49         self.assertEqual(ie._og_search_video_url(html, default=None), None)
50         self.assertEqual(ie._og_search_property('foobar', html), 'Foo')
51         self.assertEqual(ie._og_search_property('test1', html), 'foo > < bar')
52         self.assertEqual(ie._og_search_property('test2', html), 'foo >//< bar')
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)
56
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')
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)
79
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
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
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                 [{
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',
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',
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',
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',
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',
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',
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',
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',
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',
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',
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                 [{
250                     'url': 'http://ak.storage-w.teamcococdn.com/cdn/2017-02/98599/ed8f/hls/CONAN_020217_Highlight_show-audio-160k_v4.m3u8',
251                     'manifest_url': 'http://ak.storage-w.teamcococdn.com/cdn/2017-02/98599/ed8f/main.m3u8',
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',
258                     'manifest_url': 'http://ak.storage-w.teamcococdn.com/cdn/2017-02/98599/ed8f/main.m3u8',
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',
265                     'manifest_url': 'http://ak.storage-w.teamcococdn.com/cdn/2017-02/98599/ed8f/main.m3u8',
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',
274                     'manifest_url': 'http://ak.storage-w.teamcococdn.com/cdn/2017-02/98599/ed8f/main.m3u8',
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',
285                     'manifest_url': 'http://ak.storage-w.teamcococdn.com/cdn/2017-02/98599/ed8f/main.m3u8',
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',
296                     'manifest_url': 'http://ak.storage-w.teamcococdn.com/cdn/2017-02/98599/ed8f/main.m3u8',
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',
307                     'manifest_url': 'http://ak.storage-w.teamcococdn.com/cdn/2017-02/98599/ed8f/main.m3u8',
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                 [{
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',
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',
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',
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',
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',
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',
342                     'ext': 'mp4',
343                     'format_id': '155',
344                     'protocol': 'm3u8',
345                     'tbr': 155.648,
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',
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',
351                     'ext': 'mp4',
352                     'format_id': '502',
353                     'protocol': 'm3u8',
354                     'tbr': 502.784,
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',
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',
360                     'ext': 'mp4',
361                     'format_id': '827',
362                     'protocol': 'm3u8',
363                     'tbr': 827.392,
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',
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',
369                     'ext': 'mp4',
370                     'format_id': '1396',
371                     'protocol': 'm3u8',
372                     'tbr': 1396.736,
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                 [{
382                     'url': 'https://vod.edgecast.hls.ttvnw.net/e5da31ab49_riotgames_15001215120_261543898/audio_only/index-muted-HM49I092CC.m3u8',
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',
384                     'ext': 'mp4',
385                     'format_id': 'Audio Only',
386                     'protocol': 'm3u8',
387                     'acodec': 'mp4a.40.2',
388                     'vcodec': 'none',
389                     'tbr': 182.725,
390                 }, {
391                     'url': 'https://vod.edgecast.hls.ttvnw.net/e5da31ab49_riotgames_15001215120_261543898/mobile/index-muted-HM49I092CC.m3u8',
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',
393                     'ext': 'mp4',
394                     'format_id': 'Mobile',
395                     'protocol': 'm3u8',
396                     'acodec': 'mp4a.40.2',
397                     'vcodec': 'avc1.42C00D',
398                     'tbr': 280.474,
399                     'width': 400,
400                     'height': 226,
401                 }, {
402                     'url': 'https://vod.edgecast.hls.ttvnw.net/e5da31ab49_riotgames_15001215120_261543898/low/index-muted-HM49I092CC.m3u8',
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',
404                     'ext': 'mp4',
405                     'format_id': 'Low',
406                     'protocol': 'm3u8',
407                     'acodec': 'mp4a.40.2',
408                     'vcodec': 'avc1.42C01E',
409                     'tbr': 628.347,
410                     'width': 640,
411                     'height': 360,
412                 }, {
413                     'url': 'https://vod.edgecast.hls.ttvnw.net/e5da31ab49_riotgames_15001215120_261543898/medium/index-muted-HM49I092CC.m3u8',
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',
415                     'ext': 'mp4',
416                     'format_id': 'Medium',
417                     'protocol': 'm3u8',
418                     'acodec': 'mp4a.40.2',
419                     'vcodec': 'avc1.42C01E',
420                     'tbr': 893.387,
421                     'width': 852,
422                     'height': 480,
423                 }, {
424                     'url': 'https://vod.edgecast.hls.ttvnw.net/e5da31ab49_riotgames_15001215120_261543898/high/index-muted-HM49I092CC.m3u8',
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',
426                     'ext': 'mp4',
427                     'format_id': 'High',
428                     'protocol': 'm3u8',
429                     'acodec': 'mp4a.40.2',
430                     'vcodec': 'avc1.42C01F',
431                     'tbr': 1603.789,
432                     'width': 1280,
433                     'height': 720,
434                 }, {
435                     'url': 'https://vod.edgecast.hls.ttvnw.net/e5da31ab49_riotgames_15001215120_261543898/chunked/index-muted-HM49I092CC.m3u8',
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',
437                     'ext': 'mp4',
438                     'format_id': 'Source',
439                     'protocol': 'm3u8',
440                     'acodec': 'mp4a.40.2',
441                     'vcodec': 'avc1.100.31',
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                 [{
454                     'url': 'https://cdn1-a.production.vidio.static6.com/uploads/165683/dj_ambred-4383-b300.mp4.m3u8',
455                     'manifest_url': 'https://www.vidio.com/videos/165683/playlist.m3u8',
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',
464                     'manifest_url': 'https://www.vidio.com/videos/165683/playlist.m3u8',
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',
473                     'manifest_url': 'https://www.vidio.com/videos/165683/playlist.m3u8',
474                     'ext': 'mp4',
475                     'format_id': '720p HD',
476                     'protocol': 'm3u8',
477                     'tbr': 1200,
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
492     def test_parse_mpd_formats(self):
493         _TEST_CASES = [
494             (
495                 # https://github.com/rg3/youtube-dl/issues/13919
496                 'float_duration',
497                 'http://unknown/manifest.mpd',
498                 [{
499                     'manifest_url': 'http://unknown/manifest.mpd',
500                     'ext': 'mp4',
501                     'format_id': '318597',
502                     'format_note': 'DASH video',
503                     'protocol': 'http_dash_segments',
504                     'acodec': 'none',
505                     'vcodec': 'avc1.42001f',
506                     'tbr': 318.597,
507                     'width': 340,
508                     'height': 192,
509                 }, {
510                     'manifest_url': 'http://unknown/manifest.mpd',
511                     'ext': 'mp4',
512                     'format_id': '638590',
513                     'format_note': 'DASH video',
514                     'protocol': 'http_dash_segments',
515                     'acodec': 'none',
516                     'vcodec': 'avc1.42001f',
517                     'tbr': 638.59,
518                     'width': 512,
519                     'height': 288,
520                 }, {
521                     'manifest_url': 'http://unknown/manifest.mpd',
522                     'ext': 'mp4',
523                     'format_id': '1022565',
524                     'format_note': 'DASH video',
525                     'protocol': 'http_dash_segments',
526                     'acodec': 'none',
527                     'vcodec': 'avc1.4d001f',
528                     'tbr': 1022.565,
529                     'width': 688,
530                     'height': 384,
531                 }, {
532                     'manifest_url': 'http://unknown/manifest.mpd',
533                     'ext': 'mp4',
534                     'format_id': '2046506',
535                     'format_note': 'DASH video',
536                     'protocol': 'http_dash_segments',
537                     'acodec': 'none',
538                     'vcodec': 'avc1.4d001f',
539                     'tbr': 2046.506,
540                     'width': 1024,
541                     'height': 576,
542                 }, {
543                     'manifest_url': 'http://unknown/manifest.mpd',
544                     'ext': 'mp4',
545                     'format_id': '3998017',
546                     'format_note': 'DASH video',
547                     'protocol': 'http_dash_segments',
548                     'acodec': 'none',
549                     'vcodec': 'avc1.640029',
550                     'tbr': 3998.017,
551                     'width': 1280,
552                     'height': 720,
553                 }, {
554                     'manifest_url': 'http://unknown/manifest.mpd',
555                     'ext': 'mp4',
556                     'format_id': '5997485',
557                     'format_note': 'DASH video',
558                     'protocol': 'http_dash_segments',
559                     'acodec': 'none',
560                     'vcodec': 'avc1.640032',
561                     'tbr': 5997.485,
562                     'width': 1920,
563                     'height': 1080,
564                 }]
565             ),
566         ]
567
568         for mpd_file, mpd_url, expected_formats in _TEST_CASES:
569             with io.open('./test/testdata/mpd/%s.mpd' % mpd_file,
570                          mode='r', encoding='utf-8') as f:
571                 formats = self.ie._parse_mpd_formats(
572                     compat_etree_fromstring(f.read().encode('utf-8')),
573                     mpd_url=mpd_url)
574                 self.ie._sort_formats(formats)
575                 expect_value(self, formats, expected_formats, None)
576
577
578 if __name__ == '__main__':
579     unittest.main()