You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

786 lines
42 KiB

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