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"/>
65 self.assertEqual(ie._og_search_title(html), 'Foo')
66 self.assertEqual(ie._og_search_description(html), 'Some video\'s description ')
67 self.assertEqual(ie._og_search_thumbnail(html), 'http://domain.com/pic.jpg?key1=val1&key2=val2')
68 self.assertEqual(ie._og_search_video_url(html, default=None), None)
69 self.assertEqual(ie._og_search_property('foobar', html), 'Foo')
70 self.assertEqual(ie._og_search_property('test1', html), 'foo > < bar')
71 self.assertEqual(ie._og_search_property('test2', html), 'foo >//< bar')
72 self.assertEqual(ie._og_search_property(('test0', 'test1'), html), 'foo > < bar')
73 self.assertRaises(RegexNotFoundError, ie._og_search_property, 'test0', html, None, fatal=True)
74 self.assertRaises(RegexNotFoundError, ie._og_search_property, ('test0', 'test00'), html, None, fatal=True)
76 def test_html_search_meta(self):
79 <meta name="a" content="1" />
80 <meta name='b' content='2'>
81 <meta name="c" content='3'>
82 <meta name=d content='4'>
83 <meta property="e" content='5' >
84 <meta content="6" name="f">
87 self.assertEqual(ie._html_search_meta('a', html), '1')
88 self.assertEqual(ie._html_search_meta('b', html), '2')
89 self.assertEqual(ie._html_search_meta('c', html), '3')
90 self.assertEqual(ie._html_search_meta('d', html), '4')
91 self.assertEqual(ie._html_search_meta('e', html), '5')
92 self.assertEqual(ie._html_search_meta('f', html), '6')
93 self.assertEqual(ie._html_search_meta(('a', 'b', 'c'), html), '1')
94 self.assertEqual(ie._html_search_meta(('c', 'b', 'a'), html), '3')
95 self.assertEqual(ie._html_search_meta(('z', 'x', 'c'), html), '3')
96 self.assertRaises(RegexNotFoundError, ie._html_search_meta, 'z', html, None, fatal=True)
97 self.assertRaises(RegexNotFoundError, ie._html_search_meta, ('z', 'x'), html, None, fatal=True)
99 def test_download_json(self):
100 uri = encode_data_uri(b'{"foo": "blah"}', 'application/json')
101 self.assertEqual(self.ie._download_json(uri, None), {'foo': 'blah'})
102 uri = encode_data_uri(b'callback({"foo": "blah"})', 'application/javascript')
103 self.assertEqual(self.ie._download_json(uri, None, transform_source=strip_jsonp), {'foo': 'blah'})
104 uri = encode_data_uri(b'{"foo": invalid}', 'application/json')
105 self.assertRaises(ExtractorError, self.ie._download_json, uri, None)
106 self.assertEqual(self.ie._download_json(uri, None, fatal=False), None)
108 def test_extract_jwplayer_data_realworld(self):
109 # from http://www.suffolk.edu/sjc/
112 self.ie._extract_jwplayer_data(r'''
113 <script type='text/javascript'>
114 jwplayer('my-video').setup({
115 file: 'rtmp://192.138.214.154/live/sjclive',
123 ''', None, require_title=False),
127 'url': 'rtmp://192.138.214.154/live/sjclive',
132 # from https://www.pornoxo.com/videos/7564/striptease-from-sexy-secretary/
135 self.ie._extract_jwplayer_data(r'''
136 <script type="text/javascript">
137 jwplayer("mediaplayer").setup({
140 'aspectratio': "16:9",
141 'stretching': "exactfit",
142 'autostart': 'false',
143 'flashplayer': "https://t04.vipstreamservice.com/jwplayer/v5.10/player.swf",
144 '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",
145 'image': "https://t03.vipstreamservice.com/thumbs/pxo-full/2009-12/14/a4b2157147afe5efa93ce1978e0265289c193874e02597.flv-full-13.jpg",
146 '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",
148 'skin': "https://t04.vipstreamservice.com/jwplayer/skin/modieus-blk.zip",
149 'plugins': "https://t04.vipstreamservice.com/jwplayer/dock/dockableskinnableplugin.swf",
150 'dockableskinnableplugin.piclink': "/index.php?key=ajax-videothumbsn&vid=7564&data=2009-12--14--4b2157147afe5efa93ce1978e0265289c193874e02597.flv--17370",
151 'controlbar': 'bottom',
153 {type: 'flash', src: 'https://t04.vipstreamservice.com/jwplayer/v5.10/player.swf'}
157 //noinspection JSAnnotator
159 adsUrl: "/banner-iframe/?zoneId=32",
164 ''', 'dummy', require_title=False),
166 'thumbnail': 'https://t03.vipstreamservice.com/thumbs/pxo-full/2009-12/14/a4b2157147afe5efa93ce1978e0265289c193874e02597.flv-full-13.jpg',
168 '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',
173 # from http://www.indiedb.com/games/king-machine/videos
176 self.ie._extract_jwplayer_data(r'''
178 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) {
179 videoAnalytics("play");
180 }).once("complete", function(event) {
181 videoAnalytics("completed");
186 'title': 'king machine trailer 1',
187 'thumbnail': 'http://media.indiedb.com/cache/images/games/1/50/49678/thumb_620x2000/king-machine-trailer.mp4.jpg',
189 'url': 'http://cdn.dbolical.com/cache/videos/games/1/50/49678/encode_mp4/king-machine-trailer.mp4',
193 'url': 'http://cdn.dbolical.com/cache/videos/games/1/50/49678/encode720p_mp4/king-machine-trailer.mp4',
199 def test_parse_m3u8_formats(self):
202 # https://github.com/rg3/youtube-dl/issues/11507
203 # http://pluzz.francetv.fr/videos/le_ministere.html
204 'pluzz_francetv_11507',
205 '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',
207 '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',
208 '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 'acodec': 'mp4a.40.2',
213 'vcodec': 'avc1.66.30',
218 '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',
219 '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 'acodec': 'mp4a.40.2',
224 'vcodec': 'avc1.66.30',
229 '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',
230 '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 'acodec': 'mp4a.40.2',
235 'vcodec': 'avc1.66.30',
240 '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',
241 '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',
245 'acodec': 'mp4a.40.2',
246 'vcodec': 'avc1.77.30',
251 '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',
252 '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',
256 'acodec': 'mp4a.40.2',
257 'vcodec': 'avc1.77.30',
264 # https://github.com/rg3/youtube-dl/issues/11995
265 # http://teamcoco.com/video/clueless-gamer-super-bowl-for-honor
267 'http://ak.storage-w.teamcococdn.com/cdn/2017-02/98599/ed8f/main.m3u8',
269 'url': 'http://ak.storage-w.teamcococdn.com/cdn/2017-02/98599/ed8f/hls/CONAN_020217_Highlight_show-audio-160k_v4.m3u8',
270 'manifest_url': 'http://ak.storage-w.teamcococdn.com/cdn/2017-02/98599/ed8f/main.m3u8',
272 'format_id': 'audio-0-Default',
276 'url': 'http://ak.storage-w.teamcococdn.com/cdn/2017-02/98599/ed8f/hls/CONAN_020217_Highlight_show-audio-64k_v4.m3u8',
277 'manifest_url': 'http://ak.storage-w.teamcococdn.com/cdn/2017-02/98599/ed8f/main.m3u8',
279 'format_id': 'audio-1-Default',
283 'url': 'http://ak.storage-w.teamcococdn.com/cdn/2017-02/98599/ed8f/hls/CONAN_020217_Highlight_show-audio-64k_v4.m3u8',
284 'manifest_url': 'http://ak.storage-w.teamcococdn.com/cdn/2017-02/98599/ed8f/main.m3u8',
288 'acodec': 'mp4a.40.5',
292 'url': 'http://ak.storage-w.teamcococdn.com/cdn/2017-02/98599/ed8f/hls/CONAN_020217_Highlight_show-400k_v4.m3u8',
293 'manifest_url': 'http://ak.storage-w.teamcococdn.com/cdn/2017-02/98599/ed8f/main.m3u8',
298 'vcodec': 'avc1.42001e',
303 'url': 'http://ak.storage-w.teamcococdn.com/cdn/2017-02/98599/ed8f/hls/CONAN_020217_Highlight_show-400k_v4.m3u8',
304 'manifest_url': 'http://ak.storage-w.teamcococdn.com/cdn/2017-02/98599/ed8f/main.m3u8',
309 'vcodec': 'avc1.42001e',
314 'url': 'http://ak.storage-w.teamcococdn.com/cdn/2017-02/98599/ed8f/hls/CONAN_020217_Highlight_show-1m_v4.m3u8',
315 'manifest_url': 'http://ak.storage-w.teamcococdn.com/cdn/2017-02/98599/ed8f/main.m3u8',
320 'vcodec': 'avc1.4d001e',
325 'url': 'http://ak.storage-w.teamcococdn.com/cdn/2017-02/98599/ed8f/hls/CONAN_020217_Highlight_show-2m_v4.m3u8',
326 'manifest_url': 'http://ak.storage-w.teamcococdn.com/cdn/2017-02/98599/ed8f/main.m3u8',
331 'vcodec': 'avc1.4d001f',
338 # https://github.com/rg3/youtube-dl/issues/12211
339 # http://video.toggle.sg/en/series/whoopie-s-world/ep3/478601
340 'toggle_mobile_12211',
341 'http://cdnapi.kaltura.com/p/2082311/sp/208231100/playManifest/protocol/http/entryId/0_89q6e8ku/format/applehttp/tags/mobile_sd/f/a.m3u8',
343 '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',
344 'manifest_url': 'http://cdnapi.kaltura.com/p/2082311/sp/208231100/playManifest/protocol/http/entryId/0_89q6e8ku/format/applehttp/tags/mobile_sd/f/a.m3u8',
346 'format_id': 'audio-English',
351 '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',
352 'manifest_url': 'http://cdnapi.kaltura.com/p/2082311/sp/208231100/playManifest/protocol/http/entryId/0_89q6e8ku/format/applehttp/tags/mobile_sd/f/a.m3u8',
354 'format_id': 'audio-Undefined',
359 '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',
360 'manifest_url': 'http://cdnapi.kaltura.com/p/2082311/sp/208231100/playManifest/protocol/http/entryId/0_89q6e8ku/format/applehttp/tags/mobile_sd/f/a.m3u8',
368 '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',
369 'manifest_url': 'http://cdnapi.kaltura.com/p/2082311/sp/208231100/playManifest/protocol/http/entryId/0_89q6e8ku/format/applehttp/tags/mobile_sd/f/a.m3u8',
377 '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',
378 'manifest_url': 'http://cdnapi.kaltura.com/p/2082311/sp/208231100/playManifest/protocol/http/entryId/0_89q6e8ku/format/applehttp/tags/mobile_sd/f/a.m3u8',
386 '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',
387 'manifest_url': 'http://cdnapi.kaltura.com/p/2082311/sp/208231100/playManifest/protocol/http/entryId/0_89q6e8ku/format/applehttp/tags/mobile_sd/f/a.m3u8',
397 # http://www.twitch.tv/riotgames/v/6528877
399 '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',
401 'url': 'https://vod.edgecast.hls.ttvnw.net/e5da31ab49_riotgames_15001215120_261543898/audio_only/index-muted-HM49I092CC.m3u8',
402 '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 'format_id': 'Audio Only',
406 'acodec': 'mp4a.40.2',
410 'url': 'https://vod.edgecast.hls.ttvnw.net/e5da31ab49_riotgames_15001215120_261543898/mobile/index-muted-HM49I092CC.m3u8',
411 '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',
413 'format_id': 'Mobile',
415 'acodec': 'mp4a.40.2',
416 'vcodec': 'avc1.42C00D',
421 'url': 'https://vod.edgecast.hls.ttvnw.net/e5da31ab49_riotgames_15001215120_261543898/low/index-muted-HM49I092CC.m3u8',
422 '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 'acodec': 'mp4a.40.2',
427 'vcodec': 'avc1.42C01E',
432 'url': 'https://vod.edgecast.hls.ttvnw.net/e5da31ab49_riotgames_15001215120_261543898/medium/index-muted-HM49I092CC.m3u8',
433 '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',
435 'format_id': 'Medium',
437 'acodec': 'mp4a.40.2',
438 'vcodec': 'avc1.42C01E',
443 'url': 'https://vod.edgecast.hls.ttvnw.net/e5da31ab49_riotgames_15001215120_261543898/high/index-muted-HM49I092CC.m3u8',
444 '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',
448 'acodec': 'mp4a.40.2',
449 'vcodec': 'avc1.42C01F',
454 'url': 'https://vod.edgecast.hls.ttvnw.net/e5da31ab49_riotgames_15001215120_261543898/chunked/index-muted-HM49I092CC.m3u8',
455 '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',
457 'format_id': 'Source',
459 'acodec': 'mp4a.40.2',
460 'vcodec': 'avc1.100.31',
467 # http://www.vidio.com/watch/165683-dj_ambred-booyah-live-2015
468 # EXT-X-STREAM-INF tag with NAME attribute that is not defined
469 # in HLS specification
471 'https://www.vidio.com/videos/165683/playlist.m3u8',
473 'url': 'https://cdn1-a.production.vidio.static6.com/uploads/165683/dj_ambred-4383-b300.mp4.m3u8',
474 'manifest_url': 'https://www.vidio.com/videos/165683/playlist.m3u8',
476 'format_id': '270p 3G',
482 'url': 'https://cdn1-a.production.vidio.static6.com/uploads/165683/dj_ambred-4383-b600.mp4.m3u8',
483 'manifest_url': 'https://www.vidio.com/videos/165683/playlist.m3u8',
485 'format_id': '360p SD',
491 'url': 'https://cdn1-a.production.vidio.static6.com/uploads/165683/dj_ambred-4383-b1200.mp4.m3u8',
492 'manifest_url': 'https://www.vidio.com/videos/165683/playlist.m3u8',
494 'format_id': '720p HD',
503 for m3u8_file, m3u8_url, expected_formats in _TEST_CASES:
504 with io.open('./test/testdata/m3u8/%s.m3u8' % m3u8_file,
505 mode='r', encoding='utf-8') as f:
506 formats = self.ie._parse_m3u8_formats(
507 f.read(), m3u8_url, ext='mp4')
508 self.ie._sort_formats(formats)
509 expect_value(self, formats, expected_formats, None)
511 def test_parse_mpd_formats(self):
514 # https://github.com/rg3/youtube-dl/issues/13919
515 # Also tests duplicate representation ids, see
516 # https://github.com/rg3/youtube-dl/issues/15111
518 'http://unknown/manifest.mpd',
520 'manifest_url': 'http://unknown/manifest.mpd',
522 'format_id': '318597',
523 'format_note': 'DASH audio',
524 'protocol': 'http_dash_segments',
525 'acodec': 'mp4a.40.2',
529 'manifest_url': 'http://unknown/manifest.mpd',
531 'format_id': '318597',
532 'format_note': 'DASH video',
533 'protocol': 'http_dash_segments',
535 'vcodec': 'avc1.42001f',
540 'manifest_url': 'http://unknown/manifest.mpd',
542 'format_id': '638590',
543 'format_note': 'DASH video',
544 'protocol': 'http_dash_segments',
546 'vcodec': 'avc1.42001f',
551 'manifest_url': 'http://unknown/manifest.mpd',
553 'format_id': '1022565',
554 'format_note': 'DASH video',
555 'protocol': 'http_dash_segments',
557 'vcodec': 'avc1.4d001f',
562 'manifest_url': 'http://unknown/manifest.mpd',
564 'format_id': '2046506',
565 'format_note': 'DASH video',
566 'protocol': 'http_dash_segments',
568 'vcodec': 'avc1.4d001f',
573 'manifest_url': 'http://unknown/manifest.mpd',
575 'format_id': '3998017',
576 'format_note': 'DASH video',
577 'protocol': 'http_dash_segments',
579 'vcodec': 'avc1.640029',
584 'manifest_url': 'http://unknown/manifest.mpd',
586 'format_id': '5997485',
587 'format_note': 'DASH video',
588 'protocol': 'http_dash_segments',
590 'vcodec': 'avc1.640032',
596 # https://github.com/rg3/youtube-dl/pull/14844
598 'http://unknown/manifest.mpd',
600 'manifest_url': 'http://unknown/manifest.mpd',
602 'format_id': 'h264_aac_144p_m4s',
603 'format_note': 'DASH video',
604 'protocol': 'http_dash_segments',
605 'acodec': 'mp4a.40.2',
606 'vcodec': 'avc3.42c01e',
611 'manifest_url': 'http://unknown/manifest.mpd',
613 'format_id': 'h264_aac_240p_m4s',
614 'format_note': 'DASH video',
615 'protocol': 'http_dash_segments',
616 'acodec': 'mp4a.40.2',
617 'vcodec': 'avc3.42c01e',
622 'manifest_url': 'http://unknown/manifest.mpd',
624 'format_id': 'h264_aac_360p_m4s',
625 'format_note': 'DASH video',
626 'protocol': 'http_dash_segments',
627 'acodec': 'mp4a.40.2',
628 'vcodec': 'avc3.42c01e',
633 'manifest_url': 'http://unknown/manifest.mpd',
635 'format_id': 'h264_aac_480p_m4s',
636 'format_note': 'DASH video',
637 'protocol': 'http_dash_segments',
638 'acodec': 'mp4a.40.2',
639 'vcodec': 'avc3.42c01e',
644 'manifest_url': 'http://unknown/manifest.mpd',
646 'format_id': 'h264_aac_576p_m4s',
647 'format_note': 'DASH video',
648 'protocol': 'http_dash_segments',
649 'acodec': 'mp4a.40.2',
650 'vcodec': 'avc3.42c01e',
655 'manifest_url': 'http://unknown/manifest.mpd',
657 'format_id': 'h264_aac_720p_m4s',
658 'format_note': 'DASH video',
659 'protocol': 'http_dash_segments',
660 'acodec': 'mp4a.40.2',
661 'vcodec': 'avc3.42c01e',
666 'manifest_url': 'http://unknown/manifest.mpd',
668 'format_id': 'h264_aac_1080p_m4s',
669 'format_note': 'DASH video',
670 'protocol': 'http_dash_segments',
671 'acodec': 'mp4a.40.2',
672 'vcodec': 'avc3.42c01e',
680 for mpd_file, mpd_url, expected_formats in _TEST_CASES:
681 with io.open('./test/testdata/mpd/%s.mpd' % mpd_file,
682 mode='r', encoding='utf-8') as f:
683 formats = self.ie._parse_mpd_formats(
684 compat_etree_fromstring(f.read().encode('utf-8')),
686 self.ie._sort_formats(formats)
687 expect_value(self, formats, expected_formats, None)
689 def test_parse_f4m_formats(self):
692 # https://github.com/rg3/youtube-dl/issues/14660
694 'http://api.new.livestream.com/accounts/6115179/events/6764928/videos/144884262.f4m',
696 'manifest_url': 'http://api.new.livestream.com/accounts/6115179/events/6764928/videos/144884262.f4m',
707 for f4m_file, f4m_url, expected_formats in _TEST_CASES:
708 with io.open('./test/testdata/f4m/%s.f4m' % f4m_file,
709 mode='r', encoding='utf-8') as f:
710 formats = self.ie._parse_f4m_formats(
711 compat_etree_fromstring(f.read().encode('utf-8')),
713 self.ie._sort_formats(formats)
714 expect_value(self, formats, expected_formats, None)
716 def test_parse_xspf(self):
720 'https://example.org/src/foo_xspf.xspf',
723 'title': 'Pandemonium',
724 'description': 'Visit http://bigbrother404.bandcamp.com',
727 'manifest_url': 'https://example.org/src/foo_xspf.xspf',
728 'url': 'https://example.org/src/cd1/track%201.mp3',
732 'title': 'Final Cartridge (Nichico Twelve Remix)',
733 'description': 'Visit http://bigbrother404.bandcamp.com',
736 'manifest_url': 'https://example.org/src/foo_xspf.xspf',
737 'url': 'https://example.org/%E3%83%88%E3%83%A9%E3%83%83%E3%82%AF%E3%80%80%EF%BC%92.mp3',
741 'title': 'Rebuilding Nightingale',
742 'description': 'Visit http://bigbrother404.bandcamp.com',
745 'manifest_url': 'https://example.org/src/foo_xspf.xspf',
746 'url': 'https://example.org/src/track3.mp3',
748 'manifest_url': 'https://example.org/src/foo_xspf.xspf',
749 'url': 'https://example.com/track3.mp3',
755 for xspf_file, xspf_url, expected_entries in _TEST_CASES:
756 with io.open('./test/testdata/xspf/%s.xspf' % xspf_file,
757 mode='r', encoding='utf-8') as f:
758 entries = self.ie._parse_xspf(
759 compat_etree_fromstring(f.read().encode('utf-8')),
760 xspf_file, xspf_url=xspf_url, xspf_base_url=xspf_url)
761 expect_value(self, entries, expected_entries, None)
762 for i in range(len(entries)):
763 expect_dict(self, entries[i], expected_entries[i])
765 def test_response_with_expected_status_returns_content(self):
766 # Checks for mitigations against the effects of
767 # <https://bugs.python.org/issue15002> that affect Python 3.4.1+, which
768 # manifest as `_download_webpage`, `_download_xml`, `_download_json`,
769 # or the underlying `_download_webpage_handle` returning no content
770 # when a response matches `expected_status`.
772 httpd = compat_http_server.HTTPServer(
773 ('127.0.0.1', 0), InfoExtractorTestRequestHandler)
774 port = http_server_port(httpd)
775 server_thread = threading.Thread(target=httpd.serve_forever)
776 server_thread.daemon = True
777 server_thread.start()
779 (content, urlh) = self.ie._download_webpage_handle(
780 'http://127.0.0.1:%d/teapot' % port, None,
781 expected_status=TEAPOT_RESPONSE_STATUS)
782 self.assertEqual(content, TEAPOT_RESPONSE_BODY)
785 if __name__ == '__main__':