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_extract_jwplayer_data_realworld(self
):
111 # from http://www.suffolk.edu/sjc/
114 self
.ie
._extract
_jwplayer
_data
(r
'''
115 <script type='text/javascript'>
116 jwplayer('my-video').setup({
117 file: 'rtmp://192.138.214.154/live/sjclive',
125 ''', None, require_title
=False),
129 'url': 'rtmp://192.138.214.154/live/sjclive',
134 # from https://www.pornoxo.com/videos/7564/striptease-from-sexy-secretary/
137 self
.ie
._extract
_jwplayer
_data
(r
'''
138 <script type="text/javascript">
139 jwplayer("mediaplayer").setup({
142 'aspectratio': "16:9",
143 'stretching': "exactfit",
144 'autostart': 'false',
145 'flashplayer': "https://t04.vipstreamservice.com/jwplayer/v5.10/player.swf",
146 'file': "https://cdn.pornoxo.com/key=MF+oEbaxqTKb50P-w9G3nA,end=1489689259,ip=104.199.146.27/ip=104.199.146.27/speed=6573765/buffer=3.0/2009-12/4b2157147afe5efa93ce1978e0265289c193874e02597.flv",
147 'image': "https://t03.vipstreamservice.com/thumbs/pxo-full/2009-12/14/a4b2157147afe5efa93ce1978e0265289c193874e02597.flv-full-13.jpg",
148 'filefallback': "https://cdn.pornoxo.com/key=9ZPsTR5EvPLQrBaak2MUGA,end=1489689259,ip=104.199.146.27/ip=104.199.146.27/speed=6573765/buffer=3.0/2009-12/m_4b2157147afe5efa93ce1978e0265289c193874e02597.mp4",
150 'skin': "https://t04.vipstreamservice.com/jwplayer/skin/modieus-blk.zip",
151 'plugins': "https://t04.vipstreamservice.com/jwplayer/dock/dockableskinnableplugin.swf",
152 'dockableskinnableplugin.piclink': "/index.php?key=ajax-videothumbsn&vid=7564&data=2009-12--14--4b2157147afe5efa93ce1978e0265289c193874e02597.flv--17370",
153 'controlbar': 'bottom',
155 {type: 'flash', src: 'https://t04.vipstreamservice.com/jwplayer/v5.10/player.swf'}
159 //noinspection JSAnnotator
161 adsUrl: "/banner-iframe/?zoneId=32",
166 ''', 'dummy', require_title
=False),
168 'thumbnail': 'https://t03.vipstreamservice.com/thumbs/pxo-full/2009-12/14/a4b2157147afe5efa93ce1978e0265289c193874e02597.flv-full-13.jpg',
170 'url': 'https://cdn.pornoxo.com/key=MF+oEbaxqTKb50P-w9G3nA,end=1489689259,ip=104.199.146.27/ip=104.199.146.27/speed=6573765/buffer=3.0/2009-12/4b2157147afe5efa93ce1978e0265289c193874e02597.flv',
175 # from http://www.indiedb.com/games/king-machine/videos
178 self
.ie
._extract
_jwplayer
_data
(r
'''
180 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) {
181 videoAnalytics("play");
182 }).once("complete", function(event) {
183 videoAnalytics("completed");
188 'title': 'king machine trailer 1',
189 'thumbnail': 'http://media.indiedb.com/cache/images/games/1/50/49678/thumb_620x2000/king-machine-trailer.mp4.jpg',
191 'url': 'http://cdn.dbolical.com/cache/videos/games/1/50/49678/encode_mp4/king-machine-trailer.mp4',
195 'url': 'http://cdn.dbolical.com/cache/videos/games/1/50/49678/encode720p_mp4/king-machine-trailer.mp4',
201 def test_parse_m3u8_formats(self
):
204 # https://github.com/rg3/youtube-dl/issues/11507
205 # http://pluzz.francetv.fr/videos/le_ministere.html
206 'pluzz_francetv_11507',
207 'http://replayftv-vh.akamaihd.net/i/streaming-adaptatif_france-dom-tom/2017/S16/J2/156589847-58f59130c1f52-,standard1,standard2,standard3,standard4,standard5,.mp4.csmil/master.m3u8?caption=2017%2F16%2F156589847-1492488987.m3u8%3Afra%3AFrancais&audiotrack=0%3Afra%3AFrancais',
209 'url': 'http://replayftv-vh.akamaihd.net/i/streaming-adaptatif_france-dom-tom/2017/S16/J2/156589847-58f59130c1f52-,standard1,standard2,standard3,standard4,standard5,.mp4.csmil/index_0_av.m3u8?null=0',
210 'manifest_url': 'http://replayftv-vh.akamaihd.net/i/streaming-adaptatif_france-dom-tom/2017/S16/J2/156589847-58f59130c1f52-,standard1,standard2,standard3,standard4,standard5,.mp4.csmil/master.m3u8?caption=2017%2F16%2F156589847-1492488987.m3u8%3Afra%3AFrancais&audiotrack=0%3Afra%3AFrancais',
214 'acodec': 'mp4a.40.2',
215 'vcodec': 'avc1.66.30',
220 'url': 'http://replayftv-vh.akamaihd.net/i/streaming-adaptatif_france-dom-tom/2017/S16/J2/156589847-58f59130c1f52-,standard1,standard2,standard3,standard4,standard5,.mp4.csmil/index_1_av.m3u8?null=0',
221 'manifest_url': 'http://replayftv-vh.akamaihd.net/i/streaming-adaptatif_france-dom-tom/2017/S16/J2/156589847-58f59130c1f52-,standard1,standard2,standard3,standard4,standard5,.mp4.csmil/master.m3u8?caption=2017%2F16%2F156589847-1492488987.m3u8%3Afra%3AFrancais&audiotrack=0%3Afra%3AFrancais',
225 'acodec': 'mp4a.40.2',
226 'vcodec': 'avc1.66.30',
231 'url': 'http://replayftv-vh.akamaihd.net/i/streaming-adaptatif_france-dom-tom/2017/S16/J2/156589847-58f59130c1f52-,standard1,standard2,standard3,standard4,standard5,.mp4.csmil/index_2_av.m3u8?null=0',
232 'manifest_url': 'http://replayftv-vh.akamaihd.net/i/streaming-adaptatif_france-dom-tom/2017/S16/J2/156589847-58f59130c1f52-,standard1,standard2,standard3,standard4,standard5,.mp4.csmil/master.m3u8?caption=2017%2F16%2F156589847-1492488987.m3u8%3Afra%3AFrancais&audiotrack=0%3Afra%3AFrancais',
236 'acodec': 'mp4a.40.2',
237 'vcodec': 'avc1.66.30',
242 'url': 'http://replayftv-vh.akamaihd.net/i/streaming-adaptatif_france-dom-tom/2017/S16/J2/156589847-58f59130c1f52-,standard1,standard2,standard3,standard4,standard5,.mp4.csmil/index_3_av.m3u8?null=0',
243 'manifest_url': 'http://replayftv-vh.akamaihd.net/i/streaming-adaptatif_france-dom-tom/2017/S16/J2/156589847-58f59130c1f52-,standard1,standard2,standard3,standard4,standard5,.mp4.csmil/master.m3u8?caption=2017%2F16%2F156589847-1492488987.m3u8%3Afra%3AFrancais&audiotrack=0%3Afra%3AFrancais',
247 'acodec': 'mp4a.40.2',
248 'vcodec': 'avc1.77.30',
253 'url': 'http://replayftv-vh.akamaihd.net/i/streaming-adaptatif_france-dom-tom/2017/S16/J2/156589847-58f59130c1f52-,standard1,standard2,standard3,standard4,standard5,.mp4.csmil/index_4_av.m3u8?null=0',
254 'manifest_url': 'http://replayftv-vh.akamaihd.net/i/streaming-adaptatif_france-dom-tom/2017/S16/J2/156589847-58f59130c1f52-,standard1,standard2,standard3,standard4,standard5,.mp4.csmil/master.m3u8?caption=2017%2F16%2F156589847-1492488987.m3u8%3Afra%3AFrancais&audiotrack=0%3Afra%3AFrancais',
258 'acodec': 'mp4a.40.2',
259 'vcodec': 'avc1.77.30',
266 # https://github.com/rg3/youtube-dl/issues/11995
267 # http://teamcoco.com/video/clueless-gamer-super-bowl-for-honor
269 'http://ak.storage-w.teamcococdn.com/cdn/2017-02/98599/ed8f/main.m3u8',
271 'url': 'http://ak.storage-w.teamcococdn.com/cdn/2017-02/98599/ed8f/hls/CONAN_020217_Highlight_show-audio-160k_v4.m3u8',
272 'manifest_url': 'http://ak.storage-w.teamcococdn.com/cdn/2017-02/98599/ed8f/main.m3u8',
274 'format_id': 'audio-0-Default',
278 'url': 'http://ak.storage-w.teamcococdn.com/cdn/2017-02/98599/ed8f/hls/CONAN_020217_Highlight_show-audio-64k_v4.m3u8',
279 'manifest_url': 'http://ak.storage-w.teamcococdn.com/cdn/2017-02/98599/ed8f/main.m3u8',
281 'format_id': 'audio-1-Default',
285 'url': 'http://ak.storage-w.teamcococdn.com/cdn/2017-02/98599/ed8f/hls/CONAN_020217_Highlight_show-audio-64k_v4.m3u8',
286 'manifest_url': 'http://ak.storage-w.teamcococdn.com/cdn/2017-02/98599/ed8f/main.m3u8',
290 'acodec': 'mp4a.40.5',
294 'url': 'http://ak.storage-w.teamcococdn.com/cdn/2017-02/98599/ed8f/hls/CONAN_020217_Highlight_show-400k_v4.m3u8',
295 'manifest_url': 'http://ak.storage-w.teamcococdn.com/cdn/2017-02/98599/ed8f/main.m3u8',
300 'vcodec': 'avc1.42001e',
305 'url': 'http://ak.storage-w.teamcococdn.com/cdn/2017-02/98599/ed8f/hls/CONAN_020217_Highlight_show-400k_v4.m3u8',
306 'manifest_url': 'http://ak.storage-w.teamcococdn.com/cdn/2017-02/98599/ed8f/main.m3u8',
311 'vcodec': 'avc1.42001e',
316 'url': 'http://ak.storage-w.teamcococdn.com/cdn/2017-02/98599/ed8f/hls/CONAN_020217_Highlight_show-1m_v4.m3u8',
317 'manifest_url': 'http://ak.storage-w.teamcococdn.com/cdn/2017-02/98599/ed8f/main.m3u8',
322 'vcodec': 'avc1.4d001e',
327 'url': 'http://ak.storage-w.teamcococdn.com/cdn/2017-02/98599/ed8f/hls/CONAN_020217_Highlight_show-2m_v4.m3u8',
328 'manifest_url': 'http://ak.storage-w.teamcococdn.com/cdn/2017-02/98599/ed8f/main.m3u8',
333 'vcodec': 'avc1.4d001f',
340 # https://github.com/rg3/youtube-dl/issues/12211
341 # http://video.toggle.sg/en/series/whoopie-s-world/ep3/478601
342 'toggle_mobile_12211',
343 'http://cdnapi.kaltura.com/p/2082311/sp/208231100/playManifest/protocol/http/entryId/0_89q6e8ku/format/applehttp/tags/mobile_sd/f/a.m3u8',
345 'url': 'http://k.toggle.sg/fhls/p/2082311/sp/208231100/serveFlavor/entryId/0_89q6e8ku/v/2/pv/1/flavorId/0_sa2ntrdg/name/a.mp4/index.m3u8',
346 'manifest_url': 'http://cdnapi.kaltura.com/p/2082311/sp/208231100/playManifest/protocol/http/entryId/0_89q6e8ku/format/applehttp/tags/mobile_sd/f/a.m3u8',
348 'format_id': 'audio-English',
353 'url': 'http://k.toggle.sg/fhls/p/2082311/sp/208231100/serveFlavor/entryId/0_89q6e8ku/v/2/pv/1/flavorId/0_r7y0nitg/name/a.mp4/index.m3u8',
354 'manifest_url': 'http://cdnapi.kaltura.com/p/2082311/sp/208231100/playManifest/protocol/http/entryId/0_89q6e8ku/format/applehttp/tags/mobile_sd/f/a.m3u8',
356 'format_id': 'audio-Undefined',
361 'url': 'http://k.toggle.sg/fhls/p/2082311/sp/208231100/serveFlavor/entryId/0_89q6e8ku/v/2/pv/1/flavorId/0_qlk9hlzr/name/a.mp4/index.m3u8',
362 'manifest_url': 'http://cdnapi.kaltura.com/p/2082311/sp/208231100/playManifest/protocol/http/entryId/0_89q6e8ku/format/applehttp/tags/mobile_sd/f/a.m3u8',
370 'url': 'http://k.toggle.sg/fhls/p/2082311/sp/208231100/serveFlavor/entryId/0_89q6e8ku/v/2/pv/1/flavorId/0_oefackmi/name/a.mp4/index.m3u8',
371 'manifest_url': 'http://cdnapi.kaltura.com/p/2082311/sp/208231100/playManifest/protocol/http/entryId/0_89q6e8ku/format/applehttp/tags/mobile_sd/f/a.m3u8',
379 'url': 'http://k.toggle.sg/fhls/p/2082311/sp/208231100/serveFlavor/entryId/0_89q6e8ku/v/12/pv/1/flavorId/0_vyg9pj7k/name/a.mp4/index.m3u8',
380 'manifest_url': 'http://cdnapi.kaltura.com/p/2082311/sp/208231100/playManifest/protocol/http/entryId/0_89q6e8ku/format/applehttp/tags/mobile_sd/f/a.m3u8',
388 'url': 'http://k.toggle.sg/fhls/p/2082311/sp/208231100/serveFlavor/entryId/0_89q6e8ku/v/12/pv/1/flavorId/0_50n4psvx/name/a.mp4/index.m3u8',
389 'manifest_url': 'http://cdnapi.kaltura.com/p/2082311/sp/208231100/playManifest/protocol/http/entryId/0_89q6e8ku/format/applehttp/tags/mobile_sd/f/a.m3u8',
399 # http://www.twitch.tv/riotgames/v/6528877
401 'https://usher.ttvnw.net/vod/6528877?allow_source=true&allow_audio_only=true&allow_spectre=true&player=twitchweb&nauth=%7B%22user_id%22%3Anull%2C%22vod_id%22%3A6528877%2C%22expires%22%3A1492887874%2C%22chansub%22%3A%7B%22restricted_bitrates%22%3A%5B%5D%7D%2C%22privileged%22%3Afalse%2C%22https_required%22%3Afalse%7D&nauthsig=3e29296a6824a0f48f9e731383f77a614fc79bee',
403 'url': 'https://vod.edgecast.hls.ttvnw.net/e5da31ab49_riotgames_15001215120_261543898/audio_only/index-muted-HM49I092CC.m3u8',
404 'manifest_url': 'https://usher.ttvnw.net/vod/6528877?allow_source=true&allow_audio_only=true&allow_spectre=true&player=twitchweb&nauth=%7B%22user_id%22%3Anull%2C%22vod_id%22%3A6528877%2C%22expires%22%3A1492887874%2C%22chansub%22%3A%7B%22restricted_bitrates%22%3A%5B%5D%7D%2C%22privileged%22%3Afalse%2C%22https_required%22%3Afalse%7D&nauthsig=3e29296a6824a0f48f9e731383f77a614fc79bee',
406 'format_id': 'Audio Only',
408 'acodec': 'mp4a.40.2',
412 'url': 'https://vod.edgecast.hls.ttvnw.net/e5da31ab49_riotgames_15001215120_261543898/mobile/index-muted-HM49I092CC.m3u8',
413 'manifest_url': 'https://usher.ttvnw.net/vod/6528877?allow_source=true&allow_audio_only=true&allow_spectre=true&player=twitchweb&nauth=%7B%22user_id%22%3Anull%2C%22vod_id%22%3A6528877%2C%22expires%22%3A1492887874%2C%22chansub%22%3A%7B%22restricted_bitrates%22%3A%5B%5D%7D%2C%22privileged%22%3Afalse%2C%22https_required%22%3Afalse%7D&nauthsig=3e29296a6824a0f48f9e731383f77a614fc79bee',
415 'format_id': 'Mobile',
417 'acodec': 'mp4a.40.2',
418 'vcodec': 'avc1.42C00D',
423 'url': 'https://vod.edgecast.hls.ttvnw.net/e5da31ab49_riotgames_15001215120_261543898/low/index-muted-HM49I092CC.m3u8',
424 'manifest_url': 'https://usher.ttvnw.net/vod/6528877?allow_source=true&allow_audio_only=true&allow_spectre=true&player=twitchweb&nauth=%7B%22user_id%22%3Anull%2C%22vod_id%22%3A6528877%2C%22expires%22%3A1492887874%2C%22chansub%22%3A%7B%22restricted_bitrates%22%3A%5B%5D%7D%2C%22privileged%22%3Afalse%2C%22https_required%22%3Afalse%7D&nauthsig=3e29296a6824a0f48f9e731383f77a614fc79bee',
428 'acodec': 'mp4a.40.2',
429 'vcodec': 'avc1.42C01E',
434 'url': 'https://vod.edgecast.hls.ttvnw.net/e5da31ab49_riotgames_15001215120_261543898/medium/index-muted-HM49I092CC.m3u8',
435 'manifest_url': 'https://usher.ttvnw.net/vod/6528877?allow_source=true&allow_audio_only=true&allow_spectre=true&player=twitchweb&nauth=%7B%22user_id%22%3Anull%2C%22vod_id%22%3A6528877%2C%22expires%22%3A1492887874%2C%22chansub%22%3A%7B%22restricted_bitrates%22%3A%5B%5D%7D%2C%22privileged%22%3Afalse%2C%22https_required%22%3Afalse%7D&nauthsig=3e29296a6824a0f48f9e731383f77a614fc79bee',
437 'format_id': 'Medium',
439 'acodec': 'mp4a.40.2',
440 'vcodec': 'avc1.42C01E',
445 'url': 'https://vod.edgecast.hls.ttvnw.net/e5da31ab49_riotgames_15001215120_261543898/high/index-muted-HM49I092CC.m3u8',
446 'manifest_url': 'https://usher.ttvnw.net/vod/6528877?allow_source=true&allow_audio_only=true&allow_spectre=true&player=twitchweb&nauth=%7B%22user_id%22%3Anull%2C%22vod_id%22%3A6528877%2C%22expires%22%3A1492887874%2C%22chansub%22%3A%7B%22restricted_bitrates%22%3A%5B%5D%7D%2C%22privileged%22%3Afalse%2C%22https_required%22%3Afalse%7D&nauthsig=3e29296a6824a0f48f9e731383f77a614fc79bee',
450 'acodec': 'mp4a.40.2',
451 'vcodec': 'avc1.42C01F',
456 'url': 'https://vod.edgecast.hls.ttvnw.net/e5da31ab49_riotgames_15001215120_261543898/chunked/index-muted-HM49I092CC.m3u8',
457 'manifest_url': 'https://usher.ttvnw.net/vod/6528877?allow_source=true&allow_audio_only=true&allow_spectre=true&player=twitchweb&nauth=%7B%22user_id%22%3Anull%2C%22vod_id%22%3A6528877%2C%22expires%22%3A1492887874%2C%22chansub%22%3A%7B%22restricted_bitrates%22%3A%5B%5D%7D%2C%22privileged%22%3Afalse%2C%22https_required%22%3Afalse%7D&nauthsig=3e29296a6824a0f48f9e731383f77a614fc79bee',
459 'format_id': 'Source',
461 'acodec': 'mp4a.40.2',
462 'vcodec': 'avc1.100.31',
469 # http://www.vidio.com/watch/165683-dj_ambred-booyah-live-2015
470 # EXT-X-STREAM-INF tag with NAME attribute that is not defined
471 # in HLS specification
473 'https://www.vidio.com/videos/165683/playlist.m3u8',
475 'url': 'https://cdn1-a.production.vidio.static6.com/uploads/165683/dj_ambred-4383-b300.mp4.m3u8',
476 'manifest_url': 'https://www.vidio.com/videos/165683/playlist.m3u8',
478 'format_id': '270p 3G',
484 'url': 'https://cdn1-a.production.vidio.static6.com/uploads/165683/dj_ambred-4383-b600.mp4.m3u8',
485 'manifest_url': 'https://www.vidio.com/videos/165683/playlist.m3u8',
487 'format_id': '360p SD',
493 'url': 'https://cdn1-a.production.vidio.static6.com/uploads/165683/dj_ambred-4383-b1200.mp4.m3u8',
494 'manifest_url': 'https://www.vidio.com/videos/165683/playlist.m3u8',
496 'format_id': '720p HD',
504 # https://github.com/rg3/youtube-dl/issues/18923
505 # https://www.ted.com/talks/boris_hesser_a_grassroots_healthcare_revolution_in_africa
507 'http://hls.ted.com/talks/31241.m3u8',
509 'url': 'http://hls.ted.com/videos/BorisHesser_2018S/audio/600k.m3u8?nobumpers=true&uniqueId=76011e2b',
510 'format_id': '600k-Audio',
513 'url': 'http://hls.ted.com/videos/BorisHesser_2018S/audio/600k.m3u8?nobumpers=true&uniqueId=76011e2b',
517 'url': 'http://hls.ted.com/videos/BorisHesser_2018S/video/64k.m3u8?nobumpers=true&uniqueId=76011e2b',
523 'url': 'http://hls.ted.com/videos/BorisHesser_2018S/video/180k.m3u8?nobumpers=true&uniqueId=76011e2b',
529 'url': 'http://hls.ted.com/videos/BorisHesser_2018S/video/320k.m3u8?nobumpers=true&uniqueId=76011e2b',
535 'url': 'http://hls.ted.com/videos/BorisHesser_2018S/video/450k.m3u8?nobumpers=true&uniqueId=76011e2b',
541 'url': 'http://hls.ted.com/videos/BorisHesser_2018S/video/600k.m3u8?nobumpers=true&uniqueId=76011e2b',
547 'url': 'http://hls.ted.com/videos/BorisHesser_2018S/video/950k.m3u8?nobumpers=true&uniqueId=76011e2b',
553 'url': 'http://hls.ted.com/videos/BorisHesser_2018S/video/1500k.m3u8?nobumpers=true&uniqueId=76011e2b',
562 for m3u8_file
, m3u8_url
, expected_formats
in _TEST_CASES
:
563 with io
.open('./test/testdata/m3u8/%s.m3u8' % m3u8_file
,
564 mode
='r', encoding
='utf-8') as f
:
565 formats
= self
.ie
._parse
_m
3u8_formats
(
566 f
.read(), m3u8_url
, ext
='mp4')
567 self
.ie
._sort
_formats
(formats
)
568 expect_value(self
, formats
, expected_formats
, None)
570 def test_parse_mpd_formats(self
):
573 # https://github.com/rg3/youtube-dl/issues/13919
574 # Also tests duplicate representation ids, see
575 # https://github.com/rg3/youtube-dl/issues/15111
577 'http://unknown/manifest.mpd',
579 'manifest_url': 'http://unknown/manifest.mpd',
581 'format_id': '318597',
582 'format_note': 'DASH audio',
583 'protocol': 'http_dash_segments',
584 'acodec': 'mp4a.40.2',
588 'manifest_url': 'http://unknown/manifest.mpd',
590 'format_id': '318597',
591 'format_note': 'DASH video',
592 'protocol': 'http_dash_segments',
594 'vcodec': 'avc1.42001f',
599 'manifest_url': 'http://unknown/manifest.mpd',
601 'format_id': '638590',
602 'format_note': 'DASH video',
603 'protocol': 'http_dash_segments',
605 'vcodec': 'avc1.42001f',
610 'manifest_url': 'http://unknown/manifest.mpd',
612 'format_id': '1022565',
613 'format_note': 'DASH video',
614 'protocol': 'http_dash_segments',
616 'vcodec': 'avc1.4d001f',
621 'manifest_url': 'http://unknown/manifest.mpd',
623 'format_id': '2046506',
624 'format_note': 'DASH video',
625 'protocol': 'http_dash_segments',
627 'vcodec': 'avc1.4d001f',
632 'manifest_url': 'http://unknown/manifest.mpd',
634 'format_id': '3998017',
635 'format_note': 'DASH video',
636 'protocol': 'http_dash_segments',
638 'vcodec': 'avc1.640029',
643 'manifest_url': 'http://unknown/manifest.mpd',
645 'format_id': '5997485',
646 'format_note': 'DASH video',
647 'protocol': 'http_dash_segments',
649 'vcodec': 'avc1.640032',
655 # https://github.com/rg3/youtube-dl/pull/14844
657 'http://unknown/manifest.mpd',
659 'manifest_url': 'http://unknown/manifest.mpd',
661 'format_id': 'h264_aac_144p_m4s',
662 'format_note': 'DASH video',
663 'protocol': 'http_dash_segments',
664 'acodec': 'mp4a.40.2',
665 'vcodec': 'avc3.42c01e',
670 'manifest_url': 'http://unknown/manifest.mpd',
672 'format_id': 'h264_aac_240p_m4s',
673 'format_note': 'DASH video',
674 'protocol': 'http_dash_segments',
675 'acodec': 'mp4a.40.2',
676 'vcodec': 'avc3.42c01e',
681 'manifest_url': 'http://unknown/manifest.mpd',
683 'format_id': 'h264_aac_360p_m4s',
684 'format_note': 'DASH video',
685 'protocol': 'http_dash_segments',
686 'acodec': 'mp4a.40.2',
687 'vcodec': 'avc3.42c01e',
692 'manifest_url': 'http://unknown/manifest.mpd',
694 'format_id': 'h264_aac_480p_m4s',
695 'format_note': 'DASH video',
696 'protocol': 'http_dash_segments',
697 'acodec': 'mp4a.40.2',
698 'vcodec': 'avc3.42c01e',
703 'manifest_url': 'http://unknown/manifest.mpd',
705 'format_id': 'h264_aac_576p_m4s',
706 'format_note': 'DASH video',
707 'protocol': 'http_dash_segments',
708 'acodec': 'mp4a.40.2',
709 'vcodec': 'avc3.42c01e',
714 'manifest_url': 'http://unknown/manifest.mpd',
716 'format_id': 'h264_aac_720p_m4s',
717 'format_note': 'DASH video',
718 'protocol': 'http_dash_segments',
719 'acodec': 'mp4a.40.2',
720 'vcodec': 'avc3.42c01e',
725 'manifest_url': 'http://unknown/manifest.mpd',
727 'format_id': 'h264_aac_1080p_m4s',
728 'format_note': 'DASH video',
729 'protocol': 'http_dash_segments',
730 'acodec': 'mp4a.40.2',
731 'vcodec': 'avc3.42c01e',
739 for mpd_file
, mpd_url
, expected_formats
in _TEST_CASES
:
740 with io
.open('./test/testdata/mpd/%s.mpd' % mpd_file
,
741 mode
='r', encoding
='utf-8') as f
:
742 formats
= self
.ie
._parse
_mpd
_formats
(
743 compat_etree_fromstring(f
.read().encode('utf-8')),
745 self
.ie
._sort
_formats
(formats
)
746 expect_value(self
, formats
, expected_formats
, None)
748 def test_parse_f4m_formats(self
):
751 # https://github.com/rg3/youtube-dl/issues/14660
753 'http://api.new.livestream.com/accounts/6115179/events/6764928/videos/144884262.f4m',
755 'manifest_url': 'http://api.new.livestream.com/accounts/6115179/events/6764928/videos/144884262.f4m',
766 for f4m_file
, f4m_url
, expected_formats
in _TEST_CASES
:
767 with io
.open('./test/testdata/f4m/%s.f4m' % f4m_file
,
768 mode
='r', encoding
='utf-8') as f
:
769 formats
= self
.ie
._parse
_f
4m
_formats
(
770 compat_etree_fromstring(f
.read().encode('utf-8')),
772 self
.ie
._sort
_formats
(formats
)
773 expect_value(self
, formats
, expected_formats
, None)
775 def test_parse_xspf(self
):
779 'https://example.org/src/foo_xspf.xspf',
782 'title': 'Pandemonium',
783 'description': 'Visit http://bigbrother404.bandcamp.com',
786 'manifest_url': 'https://example.org/src/foo_xspf.xspf',
787 'url': 'https://example.org/src/cd1/track%201.mp3',
791 'title': 'Final Cartridge (Nichico Twelve Remix)',
792 'description': 'Visit http://bigbrother404.bandcamp.com',
795 'manifest_url': 'https://example.org/src/foo_xspf.xspf',
796 'url': 'https://example.org/%E3%83%88%E3%83%A9%E3%83%83%E3%82%AF%E3%80%80%EF%BC%92.mp3',
800 'title': 'Rebuilding Nightingale',
801 'description': 'Visit http://bigbrother404.bandcamp.com',
804 'manifest_url': 'https://example.org/src/foo_xspf.xspf',
805 'url': 'https://example.org/src/track3.mp3',
807 'manifest_url': 'https://example.org/src/foo_xspf.xspf',
808 'url': 'https://example.com/track3.mp3',
814 for xspf_file
, xspf_url
, expected_entries
in _TEST_CASES
:
815 with io
.open('./test/testdata/xspf/%s.xspf' % xspf_file
,
816 mode
='r', encoding
='utf-8') as f
:
817 entries
= self
.ie
._parse
_xspf
(
818 compat_etree_fromstring(f
.read().encode('utf-8')),
819 xspf_file
, xspf_url
=xspf_url
, xspf_base_url
=xspf_url
)
820 expect_value(self
, entries
, expected_entries
, None)
821 for i
in range(len(entries
)):
822 expect_dict(self
, entries
[i
], expected_entries
[i
])
824 def test_response_with_expected_status_returns_content(self
):
825 # Checks for mitigations against the effects of
826 # <https://bugs.python.org/issue15002> that affect Python 3.4.1+, which
827 # manifest as `_download_webpage`, `_download_xml`, `_download_json`,
828 # or the underlying `_download_webpage_handle` returning no content
829 # when a response matches `expected_status`.
831 httpd
= compat_http_server
.HTTPServer(
832 ('127.0.0.1', 0), InfoExtractorTestRequestHandler
)
833 port
= http_server_port(httpd
)
834 server_thread
= threading
.Thread(target
=httpd
.serve_forever
)
835 server_thread
.daemon
= True
836 server_thread
.start()
838 (content
, urlh
) = self
.ie
._download
_webpage
_handle
(
839 'http://127.0.0.1:%d/teapot' % port
, None,
840 expected_status
=TEAPOT_RESPONSE_STATUS
)
841 self
.assertEqual(content
, TEAPOT_RESPONSE_BODY
)
844 if __name__
== '__main__':