3 from __future__ import unicode_literals
5 # Allow direct execution
10 sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
12 from test.helper import FakeYDL, expect_dict, expect_value, http_server_port
13 from youtube_dl.compat import compat_etree_fromstring, compat_http_server
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
20 TEAPOT_RESPONSE_STATUS = 418
21 TEAPOT_RESPONSE_BODY = "<h1>418 I'm a teapot</h1>"
24 class InfoExtractorTestRequestHandler(compat_http_server.BaseHTTPRequestHandler):
25 def log_message(self, format, *args):
29 if self.path == '/teapot':
30 self.send_response(TEAPOT_RESPONSE_STATUS)
31 self.send_header('Content-Type', 'text/html; charset=utf-8')
33 self.wfile.write(TEAPOT_RESPONSE_BODY.encode())
38 class TestIE(InfoExtractor):
42 class TestInfoExtractor(unittest.TestCase):
44 self.ie = TestIE(FakeYDL())
46 def test_ie_key(self):
47 self.assertEqual(get_info_extractor(YoutubeIE.ie_key()), YoutubeIE)
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')
54 def test_opengraph(self):
57 <meta name="og:title" content='Foo'/>
58 <meta content="Some video's description " name="og:description"/>
59 <meta property='og:image' content='http://domain.com/pic.jpg?key1=val1&key2=val2'/>
60 <meta content='application/x-shockwave-flash' property='og:video:type'>
61 <meta content='Foo' property=og:foobar>
62 <meta name="og:test1" content='foo > < bar'/>
63 <meta name="og:test2" content="foo >//< bar"/>
64 <meta property=og-test3 content='Ill-formatted opengraph'/>
66 self.assertEqual(ie._og_search_title(html), 'Foo')
67 self.assertEqual(ie._og_search_description(html), 'Some video\'s description ')
68 self.assertEqual(ie._og_search_thumbnail(html), 'http://domain.com/pic.jpg?key1=val1&key2=val2')
69 self.assertEqual(ie._og_search_video_url(html, default=None), None)
70 self.assertEqual(ie._og_search_property('foobar', html), 'Foo')
71 self.assertEqual(ie._og_search_property('test1', html), 'foo > < bar')
72 self.assertEqual(ie._og_search_property('test2', html), 'foo >//< bar')
73 self.assertEqual(ie._og_search_property('test3', html), 'Ill-formatted opengraph')
74 self.assertEqual(ie._og_search_property(('test0', 'test1'), html), 'foo > < bar')
75 self.assertRaises(RegexNotFoundError, ie._og_search_property, 'test0', html, None, fatal=True)
76 self.assertRaises(RegexNotFoundError, ie._og_search_property, ('test0', 'test00'), html, None, fatal=True)
78 def test_html_search_meta(self):
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">
89 self.assertEqual(ie._html_search_meta('a', html), '1')
90 self.assertEqual(ie._html_search_meta('b', html), '2')
91 self.assertEqual(ie._html_search_meta('c', html), '3')
92 self.assertEqual(ie._html_search_meta('d', html), '4')
93 self.assertEqual(ie._html_search_meta('e', html), '5')
94 self.assertEqual(ie._html_search_meta('f', html), '6')
95 self.assertEqual(ie._html_search_meta(('a', 'b', 'c'), html), '1')
96 self.assertEqual(ie._html_search_meta(('c', 'b', 'a'), html), '3')
97 self.assertEqual(ie._html_search_meta(('z', 'x', 'c'), html), '3')
98 self.assertRaises(RegexNotFoundError, ie._html_search_meta, 'z', html, None, fatal=True)
99 self.assertRaises(RegexNotFoundError, ie._html_search_meta, ('z', 'x'), html, None, fatal=True)
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)
110 def test_parse_html5_media_entries(self):
111 # from https://www.r18.com/
115 self.ie._parse_html5_media_entries(
116 'https://www.r18.com/',
118 <video id="samplevideo_amateur" class="js-samplevideo video-js vjs-default-skin vjs-big-play-centered" controls preload="auto" width="400" height="225" poster="//pics.r18.com/digital/amateur/mgmr105/mgmr105jp.jpg">
119 <source id="video_source" src="https://awscc3001.r18.com/litevideo/freepv/m/mgm/mgmr105/mgmr105_sm_w.mp4" type="video/mp4" res="240" label="300kbps">
120 <source id="video_source" src="https://awscc3001.r18.com/litevideo/freepv/m/mgm/mgmr105/mgmr105_dm_w.mp4" type="video/mp4" res="480" label="1000kbps">
121 <source id="video_source" src="https://awscc3001.r18.com/litevideo/freepv/m/mgm/mgmr105/mgmr105_dmb_w.mp4" type="video/mp4" res="740" label="1500kbps">
122 <p>Your browser does not support the video tag.</p>
127 'url': 'https://awscc3001.r18.com/litevideo/freepv/m/mgm/mgmr105/mgmr105_sm_w.mp4',
129 'format_id': '300kbps',
133 'url': 'https://awscc3001.r18.com/litevideo/freepv/m/mgm/mgmr105/mgmr105_dm_w.mp4',
135 'format_id': '1000kbps',
139 'url': 'https://awscc3001.r18.com/litevideo/freepv/m/mgm/mgmr105/mgmr105_dmb_w.mp4',
141 'format_id': '1500kbps',
145 'thumbnail': '//pics.r18.com/digital/amateur/mgmr105/mgmr105jp.jpg'
148 # from https://www.csfd.cz/
149 # with width and height
152 self.ie._parse_html5_media_entries(
153 'https://www.csfd.cz/',
155 <video width="770" height="328" preload="none" controls poster="https://img.csfd.cz/files/images/film/video/preview/163/344/163344118_748d20.png?h360" >
156 <source src="https://video.csfd.cz/files/videos/157/750/157750813/163327358_eac647.mp4" type="video/mp4" width="640" height="360">
157 <source src="https://video.csfd.cz/files/videos/157/750/157750813/163327360_3d2646.mp4" type="video/mp4" width="1280" height="720">
158 <source src="https://video.csfd.cz/files/videos/157/750/157750813/163327356_91f258.mp4" type="video/mp4" width="1920" height="1080">
159 <source src="https://video.csfd.cz/files/videos/157/750/157750813/163327359_962b4a.webm" type="video/webm" width="640" height="360">
160 <source src="https://video.csfd.cz/files/videos/157/750/157750813/163327361_6feee0.webm" type="video/webm" width="1280" height="720">
161 <source src="https://video.csfd.cz/files/videos/157/750/157750813/163327357_8ab472.webm" type="video/webm" width="1920" height="1080">
162 <track src="https://video.csfd.cz/files/subtitles/163/344/163344115_4c388b.srt" type="text/x-srt" kind="subtitles" srclang="cs" label="cs">
167 'url': 'https://video.csfd.cz/files/videos/157/750/157750813/163327358_eac647.mp4',
172 'url': 'https://video.csfd.cz/files/videos/157/750/157750813/163327360_3d2646.mp4',
177 'url': 'https://video.csfd.cz/files/videos/157/750/157750813/163327356_91f258.mp4',
182 'url': 'https://video.csfd.cz/files/videos/157/750/157750813/163327359_962b4a.webm',
187 'url': 'https://video.csfd.cz/files/videos/157/750/157750813/163327361_6feee0.webm',
192 'url': 'https://video.csfd.cz/files/videos/157/750/157750813/163327357_8ab472.webm',
198 'cs': [{'url': 'https://video.csfd.cz/files/subtitles/163/344/163344115_4c388b.srt'}]
200 'thumbnail': 'https://img.csfd.cz/files/images/film/video/preview/163/344/163344118_748d20.png?h360'
203 # from https://tamasha.com/v/Kkdjw
204 # with height in label
207 self.ie._parse_html5_media_entries(
208 'https://tamasha.com/v/Kkdjw',
210 <video crossorigin="anonymous">
211 <source src="https://s-v2.tamasha.com/statics/videos_file/19/8f/Kkdjw_198feff8577d0057536e905cce1fb61438dd64e0_n_240.mp4" type="video/mp4" label="AUTO" res="0"/>
212 <source src="https://s-v2.tamasha.com/statics/videos_file/19/8f/Kkdjw_198feff8577d0057536e905cce1fb61438dd64e0_n_240.mp4" type="video/mp4"
213 label="240p" res="240"/>
214 <source src="https://s-v2.tamasha.com/statics/videos_file/20/00/Kkdjw_200041c66f657fc967db464d156eafbc1ed9fe6f_n_144.mp4" type="video/mp4"
215 label="144p" res="144"/>
220 'url': 'https://s-v2.tamasha.com/statics/videos_file/19/8f/Kkdjw_198feff8577d0057536e905cce1fb61438dd64e0_n_240.mp4',
222 'url': 'https://s-v2.tamasha.com/statics/videos_file/19/8f/Kkdjw_198feff8577d0057536e905cce1fb61438dd64e0_n_240.mp4',
227 'url': 'https://s-v2.tamasha.com/statics/videos_file/20/00/Kkdjw_200041c66f657fc967db464d156eafbc1ed9fe6f_n_144.mp4',
234 # from https://www.directvnow.com
238 self.ie._parse_html5_media_entries(
239 'https://www.directvnow.com',
241 <video id="vid1" class="header--video-masked active" muted playsinline>
242 <source data-src="https://cdn.directv.com/content/dam/dtv/prod/website_directvnow-international/videos/DTVN_hdr_HBO_v3.mp4" type="video/mp4" />
248 'url': 'https://cdn.directv.com/content/dam/dtv/prod/website_directvnow-international/videos/DTVN_hdr_HBO_v3.mp4',
252 # from https://www.directvnow.com
256 self.ie._parse_html5_media_entries(
257 'https://www.directvnow.com',
259 <video id="vid1" class="header--video-masked active" muted playsinline>
260 <source data-src="https://cdn.directv.com/content/dam/dtv/prod/website_directvnow-international/videos/DTVN_hdr_HBO_v3.mp4" type="video/mp4" />
265 'url': 'https://cdn.directv.com/content/dam/dtv/prod/website_directvnow-international/videos/DTVN_hdr_HBO_v3.mp4',
270 # from https://www.klarna.com/uk/
271 # with data-video-src
274 self.ie._parse_html5_media_entries(
275 'https://www.directvnow.com',
277 <video loop autoplay muted class="responsive-video block-kl__video video-on-medium">
278 <source src="" data-video-desktop data-video-src="https://www.klarna.com/uk/wp-content/uploads/sites/11/2019/01/KL062_Smooth3_0_DogWalking_5s_920x080_.mp4" type="video/mp4" />
283 'url': 'https://www.klarna.com/uk/wp-content/uploads/sites/11/2019/01/KL062_Smooth3_0_DogWalking_5s_920x080_.mp4',
288 def test_extract_jwplayer_data_realworld(self):
289 # from http://www.suffolk.edu/sjc/
292 self.ie._extract_jwplayer_data(r'''
293 <script type='text/javascript'>
294 jwplayer('my-video').setup({
295 file: 'rtmp://192.138.214.154/live/sjclive',
303 ''', None, require_title=False),
307 'url': 'rtmp://192.138.214.154/live/sjclive',
312 # from https://www.pornoxo.com/videos/7564/striptease-from-sexy-secretary/
315 self.ie._extract_jwplayer_data(r'''
316 <script type="text/javascript">
317 jwplayer("mediaplayer").setup({
320 'aspectratio': "16:9",
321 'stretching': "exactfit",
322 'autostart': 'false',
323 'flashplayer': "https://t04.vipstreamservice.com/jwplayer/v5.10/player.swf",
324 '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",
325 'image': "https://t03.vipstreamservice.com/thumbs/pxo-full/2009-12/14/a4b2157147afe5efa93ce1978e0265289c193874e02597.flv-full-13.jpg",
326 '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",
328 'skin': "https://t04.vipstreamservice.com/jwplayer/skin/modieus-blk.zip",
329 'plugins': "https://t04.vipstreamservice.com/jwplayer/dock/dockableskinnableplugin.swf",
330 'dockableskinnableplugin.piclink': "/index.php?key=ajax-videothumbsn&vid=7564&data=2009-12--14--4b2157147afe5efa93ce1978e0265289c193874e02597.flv--17370",
331 'controlbar': 'bottom',
333 {type: 'flash', src: 'https://t04.vipstreamservice.com/jwplayer/v5.10/player.swf'}
337 //noinspection JSAnnotator
339 adsUrl: "/banner-iframe/?zoneId=32",
344 ''', 'dummy', require_title=False),
346 'thumbnail': 'https://t03.vipstreamservice.com/thumbs/pxo-full/2009-12/14/a4b2157147afe5efa93ce1978e0265289c193874e02597.flv-full-13.jpg',
348 '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',
353 # from http://www.indiedb.com/games/king-machine/videos
356 self.ie._extract_jwplayer_data(r'''
358 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) {
359 videoAnalytics("play");
360 }).once("complete", function(event) {
361 videoAnalytics("completed");
366 'title': 'king machine trailer 1',
367 'thumbnail': 'http://media.indiedb.com/cache/images/games/1/50/49678/thumb_620x2000/king-machine-trailer.mp4.jpg',
369 'url': 'http://cdn.dbolical.com/cache/videos/games/1/50/49678/encode_mp4/king-machine-trailer.mp4',
373 'url': 'http://cdn.dbolical.com/cache/videos/games/1/50/49678/encode720p_mp4/king-machine-trailer.mp4',
379 def test_parse_m3u8_formats(self):
382 # https://github.com/ytdl-org/youtube-dl/issues/11507
383 # http://pluzz.francetv.fr/videos/le_ministere.html
384 'pluzz_francetv_11507',
385 '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',
387 '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',
388 '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',
392 'acodec': 'mp4a.40.2',
393 'vcodec': 'avc1.66.30',
398 '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',
399 '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',
403 'acodec': 'mp4a.40.2',
404 'vcodec': 'avc1.66.30',
409 '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',
410 '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',
414 'acodec': 'mp4a.40.2',
415 'vcodec': 'avc1.66.30',
420 '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',
421 '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',
425 'acodec': 'mp4a.40.2',
426 'vcodec': 'avc1.77.30',
431 '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',
432 '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',
436 'acodec': 'mp4a.40.2',
437 'vcodec': 'avc1.77.30',
444 # https://github.com/ytdl-org/youtube-dl/issues/11995
445 # http://teamcoco.com/video/clueless-gamer-super-bowl-for-honor
447 'http://ak.storage-w.teamcococdn.com/cdn/2017-02/98599/ed8f/main.m3u8',
449 'url': 'http://ak.storage-w.teamcococdn.com/cdn/2017-02/98599/ed8f/hls/CONAN_020217_Highlight_show-audio-160k_v4.m3u8',
450 'manifest_url': 'http://ak.storage-w.teamcococdn.com/cdn/2017-02/98599/ed8f/main.m3u8',
452 'format_id': 'audio-0-Default',
456 'url': 'http://ak.storage-w.teamcococdn.com/cdn/2017-02/98599/ed8f/hls/CONAN_020217_Highlight_show-audio-64k_v4.m3u8',
457 'manifest_url': 'http://ak.storage-w.teamcococdn.com/cdn/2017-02/98599/ed8f/main.m3u8',
459 'format_id': 'audio-1-Default',
463 'url': 'http://ak.storage-w.teamcococdn.com/cdn/2017-02/98599/ed8f/hls/CONAN_020217_Highlight_show-audio-64k_v4.m3u8',
464 'manifest_url': 'http://ak.storage-w.teamcococdn.com/cdn/2017-02/98599/ed8f/main.m3u8',
468 'acodec': 'mp4a.40.5',
472 'url': 'http://ak.storage-w.teamcococdn.com/cdn/2017-02/98599/ed8f/hls/CONAN_020217_Highlight_show-400k_v4.m3u8',
473 'manifest_url': 'http://ak.storage-w.teamcococdn.com/cdn/2017-02/98599/ed8f/main.m3u8',
478 'vcodec': 'avc1.42001e',
483 'url': 'http://ak.storage-w.teamcococdn.com/cdn/2017-02/98599/ed8f/hls/CONAN_020217_Highlight_show-400k_v4.m3u8',
484 'manifest_url': 'http://ak.storage-w.teamcococdn.com/cdn/2017-02/98599/ed8f/main.m3u8',
489 'vcodec': 'avc1.42001e',
494 'url': 'http://ak.storage-w.teamcococdn.com/cdn/2017-02/98599/ed8f/hls/CONAN_020217_Highlight_show-1m_v4.m3u8',
495 'manifest_url': 'http://ak.storage-w.teamcococdn.com/cdn/2017-02/98599/ed8f/main.m3u8',
500 'vcodec': 'avc1.4d001e',
505 'url': 'http://ak.storage-w.teamcococdn.com/cdn/2017-02/98599/ed8f/hls/CONAN_020217_Highlight_show-2m_v4.m3u8',
506 'manifest_url': 'http://ak.storage-w.teamcococdn.com/cdn/2017-02/98599/ed8f/main.m3u8',
511 'vcodec': 'avc1.4d001f',
518 # https://github.com/ytdl-org/youtube-dl/issues/12211
519 # http://video.toggle.sg/en/series/whoopie-s-world/ep3/478601
520 'toggle_mobile_12211',
521 'http://cdnapi.kaltura.com/p/2082311/sp/208231100/playManifest/protocol/http/entryId/0_89q6e8ku/format/applehttp/tags/mobile_sd/f/a.m3u8',
523 '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',
524 'manifest_url': 'http://cdnapi.kaltura.com/p/2082311/sp/208231100/playManifest/protocol/http/entryId/0_89q6e8ku/format/applehttp/tags/mobile_sd/f/a.m3u8',
526 'format_id': 'audio-English',
531 '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',
532 'manifest_url': 'http://cdnapi.kaltura.com/p/2082311/sp/208231100/playManifest/protocol/http/entryId/0_89q6e8ku/format/applehttp/tags/mobile_sd/f/a.m3u8',
534 'format_id': 'audio-Undefined',
539 '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',
540 'manifest_url': 'http://cdnapi.kaltura.com/p/2082311/sp/208231100/playManifest/protocol/http/entryId/0_89q6e8ku/format/applehttp/tags/mobile_sd/f/a.m3u8',
548 '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',
549 'manifest_url': 'http://cdnapi.kaltura.com/p/2082311/sp/208231100/playManifest/protocol/http/entryId/0_89q6e8ku/format/applehttp/tags/mobile_sd/f/a.m3u8',
557 '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',
558 'manifest_url': 'http://cdnapi.kaltura.com/p/2082311/sp/208231100/playManifest/protocol/http/entryId/0_89q6e8ku/format/applehttp/tags/mobile_sd/f/a.m3u8',
566 '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',
567 'manifest_url': 'http://cdnapi.kaltura.com/p/2082311/sp/208231100/playManifest/protocol/http/entryId/0_89q6e8ku/format/applehttp/tags/mobile_sd/f/a.m3u8',
577 # http://www.twitch.tv/riotgames/v/6528877
579 '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',
581 'url': 'https://vod.edgecast.hls.ttvnw.net/e5da31ab49_riotgames_15001215120_261543898/audio_only/index-muted-HM49I092CC.m3u8',
582 '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',
584 'format_id': 'Audio Only',
586 'acodec': 'mp4a.40.2',
590 'url': 'https://vod.edgecast.hls.ttvnw.net/e5da31ab49_riotgames_15001215120_261543898/mobile/index-muted-HM49I092CC.m3u8',
591 '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',
593 'format_id': 'Mobile',
595 'acodec': 'mp4a.40.2',
596 'vcodec': 'avc1.42C00D',
601 'url': 'https://vod.edgecast.hls.ttvnw.net/e5da31ab49_riotgames_15001215120_261543898/low/index-muted-HM49I092CC.m3u8',
602 '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',
606 'acodec': 'mp4a.40.2',
607 'vcodec': 'avc1.42C01E',
612 'url': 'https://vod.edgecast.hls.ttvnw.net/e5da31ab49_riotgames_15001215120_261543898/medium/index-muted-HM49I092CC.m3u8',
613 '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',
615 'format_id': 'Medium',
617 'acodec': 'mp4a.40.2',
618 'vcodec': 'avc1.42C01E',
623 'url': 'https://vod.edgecast.hls.ttvnw.net/e5da31ab49_riotgames_15001215120_261543898/high/index-muted-HM49I092CC.m3u8',
624 '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',
628 'acodec': 'mp4a.40.2',
629 'vcodec': 'avc1.42C01F',
634 'url': 'https://vod.edgecast.hls.ttvnw.net/e5da31ab49_riotgames_15001215120_261543898/chunked/index-muted-HM49I092CC.m3u8',
635 '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',
637 'format_id': 'Source',
639 'acodec': 'mp4a.40.2',
640 'vcodec': 'avc1.100.31',
647 # http://www.vidio.com/watch/165683-dj_ambred-booyah-live-2015
648 # EXT-X-STREAM-INF tag with NAME attribute that is not defined
649 # in HLS specification
651 'https://www.vidio.com/videos/165683/playlist.m3u8',
653 'url': 'https://cdn1-a.production.vidio.static6.com/uploads/165683/dj_ambred-4383-b300.mp4.m3u8',
654 'manifest_url': 'https://www.vidio.com/videos/165683/playlist.m3u8',
656 'format_id': '270p 3G',
662 'url': 'https://cdn1-a.production.vidio.static6.com/uploads/165683/dj_ambred-4383-b600.mp4.m3u8',
663 'manifest_url': 'https://www.vidio.com/videos/165683/playlist.m3u8',
665 'format_id': '360p SD',
671 'url': 'https://cdn1-a.production.vidio.static6.com/uploads/165683/dj_ambred-4383-b1200.mp4.m3u8',
672 'manifest_url': 'https://www.vidio.com/videos/165683/playlist.m3u8',
674 'format_id': '720p HD',
682 # https://github.com/ytdl-org/youtube-dl/issues/18923
683 # https://www.ted.com/talks/boris_hesser_a_grassroots_healthcare_revolution_in_africa
685 'http://hls.ted.com/talks/31241.m3u8',
687 'url': 'http://hls.ted.com/videos/BorisHesser_2018S/audio/600k.m3u8?nobumpers=true&uniqueId=76011e2b',
688 'format_id': '600k-Audio',
691 'url': 'http://hls.ted.com/videos/BorisHesser_2018S/audio/600k.m3u8?nobumpers=true&uniqueId=76011e2b',
695 'url': 'http://hls.ted.com/videos/BorisHesser_2018S/video/64k.m3u8?nobumpers=true&uniqueId=76011e2b',
701 'url': 'http://hls.ted.com/videos/BorisHesser_2018S/video/180k.m3u8?nobumpers=true&uniqueId=76011e2b',
707 'url': 'http://hls.ted.com/videos/BorisHesser_2018S/video/320k.m3u8?nobumpers=true&uniqueId=76011e2b',
713 'url': 'http://hls.ted.com/videos/BorisHesser_2018S/video/450k.m3u8?nobumpers=true&uniqueId=76011e2b',
719 'url': 'http://hls.ted.com/videos/BorisHesser_2018S/video/600k.m3u8?nobumpers=true&uniqueId=76011e2b',
725 'url': 'http://hls.ted.com/videos/BorisHesser_2018S/video/950k.m3u8?nobumpers=true&uniqueId=76011e2b',
731 'url': 'http://hls.ted.com/videos/BorisHesser_2018S/video/1500k.m3u8?nobumpers=true&uniqueId=76011e2b',
740 for m3u8_file, m3u8_url, expected_formats in _TEST_CASES:
741 with io.open('./test/testdata/m3u8/%s.m3u8' % m3u8_file,
742 mode='r', encoding='utf-8') as f:
743 formats = self.ie._parse_m3u8_formats(
744 f.read(), m3u8_url, ext='mp4')
745 self.ie._sort_formats(formats)
746 expect_value(self, formats, expected_formats, None)
748 def test_parse_mpd_formats(self):
751 # https://github.com/ytdl-org/youtube-dl/issues/13919
752 # Also tests duplicate representation ids, see
753 # https://github.com/ytdl-org/youtube-dl/issues/15111
755 'http://unknown/manifest.mpd', # mpd_url
758 'manifest_url': 'http://unknown/manifest.mpd',
760 'format_id': '318597',
761 'format_note': 'DASH audio',
762 'protocol': 'http_dash_segments',
763 'acodec': 'mp4a.40.2',
767 'manifest_url': 'http://unknown/manifest.mpd',
769 'format_id': '318597',
770 'format_note': 'DASH video',
771 'protocol': 'http_dash_segments',
773 'vcodec': 'avc1.42001f',
778 'manifest_url': 'http://unknown/manifest.mpd',
780 'format_id': '638590',
781 'format_note': 'DASH video',
782 'protocol': 'http_dash_segments',
784 'vcodec': 'avc1.42001f',
789 'manifest_url': 'http://unknown/manifest.mpd',
791 'format_id': '1022565',
792 'format_note': 'DASH video',
793 'protocol': 'http_dash_segments',
795 'vcodec': 'avc1.4d001f',
800 'manifest_url': 'http://unknown/manifest.mpd',
802 'format_id': '2046506',
803 'format_note': 'DASH video',
804 'protocol': 'http_dash_segments',
806 'vcodec': 'avc1.4d001f',
811 'manifest_url': 'http://unknown/manifest.mpd',
813 'format_id': '3998017',
814 'format_note': 'DASH video',
815 'protocol': 'http_dash_segments',
817 'vcodec': 'avc1.640029',
822 'manifest_url': 'http://unknown/manifest.mpd',
824 'format_id': '5997485',
825 'format_note': 'DASH video',
826 'protocol': 'http_dash_segments',
828 'vcodec': 'avc1.640032',
834 # https://github.com/ytdl-org/youtube-dl/pull/14844
836 'http://unknown/manifest.mpd', # mpd_url
839 'manifest_url': 'http://unknown/manifest.mpd',
841 'format_id': 'h264_aac_144p_m4s',
842 'format_note': 'DASH video',
843 'protocol': 'http_dash_segments',
844 'acodec': 'mp4a.40.2',
845 'vcodec': 'avc3.42c01e',
850 'manifest_url': 'http://unknown/manifest.mpd',
852 'format_id': 'h264_aac_240p_m4s',
853 'format_note': 'DASH video',
854 'protocol': 'http_dash_segments',
855 'acodec': 'mp4a.40.2',
856 'vcodec': 'avc3.42c01e',
861 'manifest_url': 'http://unknown/manifest.mpd',
863 'format_id': 'h264_aac_360p_m4s',
864 'format_note': 'DASH video',
865 'protocol': 'http_dash_segments',
866 'acodec': 'mp4a.40.2',
867 'vcodec': 'avc3.42c01e',
872 'manifest_url': 'http://unknown/manifest.mpd',
874 'format_id': 'h264_aac_480p_m4s',
875 'format_note': 'DASH video',
876 'protocol': 'http_dash_segments',
877 'acodec': 'mp4a.40.2',
878 'vcodec': 'avc3.42c01e',
883 'manifest_url': 'http://unknown/manifest.mpd',
885 'format_id': 'h264_aac_576p_m4s',
886 'format_note': 'DASH video',
887 'protocol': 'http_dash_segments',
888 'acodec': 'mp4a.40.2',
889 'vcodec': 'avc3.42c01e',
894 'manifest_url': 'http://unknown/manifest.mpd',
896 'format_id': 'h264_aac_720p_m4s',
897 'format_note': 'DASH video',
898 'protocol': 'http_dash_segments',
899 'acodec': 'mp4a.40.2',
900 'vcodec': 'avc3.42c01e',
905 'manifest_url': 'http://unknown/manifest.mpd',
907 'format_id': 'h264_aac_1080p_m4s',
908 'format_note': 'DASH video',
909 'protocol': 'http_dash_segments',
910 'acodec': 'mp4a.40.2',
911 'vcodec': 'avc3.42c01e',
917 # https://github.com/ytdl-org/youtube-dl/issues/20346
918 # Media considered unfragmented even though it contains
921 'https://v.redd.it/hw1x7rcg7zl21/DASHPlaylist.mpd', # mpd_url
922 'https://v.redd.it/hw1x7rcg7zl21', # mpd_base_url
924 'url': 'https://v.redd.it/hw1x7rcg7zl21/audio',
925 'manifest_url': 'https://v.redd.it/hw1x7rcg7zl21/DASHPlaylist.mpd',
927 'format_id': 'AUDIO-1',
928 'format_note': 'DASH audio',
929 'container': 'm4a_dash',
930 'acodec': 'mp4a.40.2',
936 'url': 'https://v.redd.it/hw1x7rcg7zl21/DASH_240',
937 'manifest_url': 'https://v.redd.it/hw1x7rcg7zl21/DASHPlaylist.mpd',
939 'format_id': 'VIDEO-2',
940 'format_note': 'DASH video',
941 'container': 'mp4_dash',
943 'vcodec': 'avc1.4d401e',
949 'url': 'https://v.redd.it/hw1x7rcg7zl21/DASH_360',
950 'manifest_url': 'https://v.redd.it/hw1x7rcg7zl21/DASHPlaylist.mpd',
952 'format_id': 'VIDEO-1',
953 'format_note': 'DASH video',
954 'container': 'mp4_dash',
956 'vcodec': 'avc1.4d401e',
965 for mpd_file, mpd_url, mpd_base_url, expected_formats in _TEST_CASES:
966 with io.open('./test/testdata/mpd/%s.mpd' % mpd_file,
967 mode='r', encoding='utf-8') as f:
968 formats = self.ie._parse_mpd_formats(
969 compat_etree_fromstring(f.read().encode('utf-8')),
970 mpd_base_url=mpd_base_url, mpd_url=mpd_url)
971 self.ie._sort_formats(formats)
972 expect_value(self, formats, expected_formats, None)
974 def test_parse_f4m_formats(self):
977 # https://github.com/ytdl-org/youtube-dl/issues/14660
979 'http://api.new.livestream.com/accounts/6115179/events/6764928/videos/144884262.f4m',
981 'manifest_url': 'http://api.new.livestream.com/accounts/6115179/events/6764928/videos/144884262.f4m',
992 for f4m_file, f4m_url, expected_formats in _TEST_CASES:
993 with io.open('./test/testdata/f4m/%s.f4m' % f4m_file,
994 mode='r', encoding='utf-8') as f:
995 formats = self.ie._parse_f4m_formats(
996 compat_etree_fromstring(f.read().encode('utf-8')),
998 self.ie._sort_formats(formats)
999 expect_value(self, formats, expected_formats, None)
1001 def test_parse_xspf(self):
1005 'https://example.org/src/foo_xspf.xspf',
1008 'title': 'Pandemonium',
1009 'description': 'Visit http://bigbrother404.bandcamp.com',
1010 'duration': 202.416,
1012 'manifest_url': 'https://example.org/src/foo_xspf.xspf',
1013 'url': 'https://example.org/src/cd1/track%201.mp3',
1017 'title': 'Final Cartridge (Nichico Twelve Remix)',
1018 'description': 'Visit http://bigbrother404.bandcamp.com',
1019 'duration': 255.857,
1021 'manifest_url': 'https://example.org/src/foo_xspf.xspf',
1022 'url': 'https://example.org/%E3%83%88%E3%83%A9%E3%83%83%E3%82%AF%E3%80%80%EF%BC%92.mp3',
1026 'title': 'Rebuilding Nightingale',
1027 'description': 'Visit http://bigbrother404.bandcamp.com',
1028 'duration': 287.915,
1030 'manifest_url': 'https://example.org/src/foo_xspf.xspf',
1031 'url': 'https://example.org/src/track3.mp3',
1033 'manifest_url': 'https://example.org/src/foo_xspf.xspf',
1034 'url': 'https://example.com/track3.mp3',
1040 for xspf_file, xspf_url, expected_entries in _TEST_CASES:
1041 with io.open('./test/testdata/xspf/%s.xspf' % xspf_file,
1042 mode='r', encoding='utf-8') as f:
1043 entries = self.ie._parse_xspf(
1044 compat_etree_fromstring(f.read().encode('utf-8')),
1045 xspf_file, xspf_url=xspf_url, xspf_base_url=xspf_url)
1046 expect_value(self, entries, expected_entries, None)
1047 for i in range(len(entries)):
1048 expect_dict(self, entries[i], expected_entries[i])
1050 def test_response_with_expected_status_returns_content(self):
1051 # Checks for mitigations against the effects of
1052 # <https://bugs.python.org/issue15002> that affect Python 3.4.1+, which
1053 # manifest as `_download_webpage`, `_download_xml`, `_download_json`,
1054 # or the underlying `_download_webpage_handle` returning no content
1055 # when a response matches `expected_status`.
1057 httpd = compat_http_server.HTTPServer(
1058 ('127.0.0.1', 0), InfoExtractorTestRequestHandler)
1059 port = http_server_port(httpd)
1060 server_thread = threading.Thread(target=httpd.serve_forever)
1061 server_thread.daemon = True
1062 server_thread.start()
1064 (content, urlh) = self.ie._download_webpage_handle(
1065 'http://127.0.0.1:%d/teapot' % port, None,
1066 expected_status=TEAPOT_RESPONSE_STATUS)
1067 self.assertEqual(content, TEAPOT_RESPONSE_BODY)
1070 if __name__ == '__main__':