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.

843 lines
45 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. # https://github.com/rg3/youtube-dl/issues/18923
  481. # https://www.ted.com/talks/boris_hesser_a_grassroots_healthcare_revolution_in_africa
  482. 'ted_18923',
  483. 'http://hls.ted.com/talks/31241.m3u8',
  484. [{
  485. 'url': 'http://hls.ted.com/videos/BorisHesser_2018S/audio/600k.m3u8?nobumpers=true&uniqueId=76011e2b',
  486. 'format_id': '600k-Audio',
  487. 'vcodec': 'none',
  488. }, {
  489. 'url': 'http://hls.ted.com/videos/BorisHesser_2018S/audio/600k.m3u8?nobumpers=true&uniqueId=76011e2b',
  490. 'format_id': '68',
  491. 'vcodec': 'none',
  492. }, {
  493. 'url': 'http://hls.ted.com/videos/BorisHesser_2018S/video/64k.m3u8?nobumpers=true&uniqueId=76011e2b',
  494. 'format_id': '163',
  495. 'acodec': 'none',
  496. 'width': 320,
  497. 'height': 180,
  498. }, {
  499. 'url': 'http://hls.ted.com/videos/BorisHesser_2018S/video/180k.m3u8?nobumpers=true&uniqueId=76011e2b',
  500. 'format_id': '481',
  501. 'acodec': 'none',
  502. 'width': 512,
  503. 'height': 288,
  504. }, {
  505. 'url': 'http://hls.ted.com/videos/BorisHesser_2018S/video/320k.m3u8?nobumpers=true&uniqueId=76011e2b',
  506. 'format_id': '769',
  507. 'acodec': 'none',
  508. 'width': 512,
  509. 'height': 288,
  510. }, {
  511. 'url': 'http://hls.ted.com/videos/BorisHesser_2018S/video/450k.m3u8?nobumpers=true&uniqueId=76011e2b',
  512. 'format_id': '984',
  513. 'acodec': 'none',
  514. 'width': 512,
  515. 'height': 288,
  516. }, {
  517. 'url': 'http://hls.ted.com/videos/BorisHesser_2018S/video/600k.m3u8?nobumpers=true&uniqueId=76011e2b',
  518. 'format_id': '1255',
  519. 'acodec': 'none',
  520. 'width': 640,
  521. 'height': 360,
  522. }, {
  523. 'url': 'http://hls.ted.com/videos/BorisHesser_2018S/video/950k.m3u8?nobumpers=true&uniqueId=76011e2b',
  524. 'format_id': '1693',
  525. 'acodec': 'none',
  526. 'width': 853,
  527. 'height': 480,
  528. }, {
  529. 'url': 'http://hls.ted.com/videos/BorisHesser_2018S/video/1500k.m3u8?nobumpers=true&uniqueId=76011e2b',
  530. 'format_id': '2462',
  531. 'acodec': 'none',
  532. 'width': 1280,
  533. 'height': 720,
  534. }]
  535. ),
  536. ]
  537. for m3u8_file, m3u8_url, expected_formats in _TEST_CASES:
  538. with io.open('./test/testdata/m3u8/%s.m3u8' % m3u8_file,
  539. mode='r', encoding='utf-8') as f:
  540. formats = self.ie._parse_m3u8_formats(
  541. f.read(), m3u8_url, ext='mp4')
  542. self.ie._sort_formats(formats)
  543. expect_value(self, formats, expected_formats, None)
  544. def test_parse_mpd_formats(self):
  545. _TEST_CASES = [
  546. (
  547. # https://github.com/rg3/youtube-dl/issues/13919
  548. # Also tests duplicate representation ids, see
  549. # https://github.com/rg3/youtube-dl/issues/15111
  550. 'float_duration',
  551. 'http://unknown/manifest.mpd',
  552. [{
  553. 'manifest_url': 'http://unknown/manifest.mpd',
  554. 'ext': 'm4a',
  555. 'format_id': '318597',
  556. 'format_note': 'DASH audio',
  557. 'protocol': 'http_dash_segments',
  558. 'acodec': 'mp4a.40.2',
  559. 'vcodec': 'none',
  560. 'tbr': 61.587,
  561. }, {
  562. 'manifest_url': 'http://unknown/manifest.mpd',
  563. 'ext': 'mp4',
  564. 'format_id': '318597',
  565. 'format_note': 'DASH video',
  566. 'protocol': 'http_dash_segments',
  567. 'acodec': 'none',
  568. 'vcodec': 'avc1.42001f',
  569. 'tbr': 318.597,
  570. 'width': 340,
  571. 'height': 192,
  572. }, {
  573. 'manifest_url': 'http://unknown/manifest.mpd',
  574. 'ext': 'mp4',
  575. 'format_id': '638590',
  576. 'format_note': 'DASH video',
  577. 'protocol': 'http_dash_segments',
  578. 'acodec': 'none',
  579. 'vcodec': 'avc1.42001f',
  580. 'tbr': 638.59,
  581. 'width': 512,
  582. 'height': 288,
  583. }, {
  584. 'manifest_url': 'http://unknown/manifest.mpd',
  585. 'ext': 'mp4',
  586. 'format_id': '1022565',
  587. 'format_note': 'DASH video',
  588. 'protocol': 'http_dash_segments',
  589. 'acodec': 'none',
  590. 'vcodec': 'avc1.4d001f',
  591. 'tbr': 1022.565,
  592. 'width': 688,
  593. 'height': 384,
  594. }, {
  595. 'manifest_url': 'http://unknown/manifest.mpd',
  596. 'ext': 'mp4',
  597. 'format_id': '2046506',
  598. 'format_note': 'DASH video',
  599. 'protocol': 'http_dash_segments',
  600. 'acodec': 'none',
  601. 'vcodec': 'avc1.4d001f',
  602. 'tbr': 2046.506,
  603. 'width': 1024,
  604. 'height': 576,
  605. }, {
  606. 'manifest_url': 'http://unknown/manifest.mpd',
  607. 'ext': 'mp4',
  608. 'format_id': '3998017',
  609. 'format_note': 'DASH video',
  610. 'protocol': 'http_dash_segments',
  611. 'acodec': 'none',
  612. 'vcodec': 'avc1.640029',
  613. 'tbr': 3998.017,
  614. 'width': 1280,
  615. 'height': 720,
  616. }, {
  617. 'manifest_url': 'http://unknown/manifest.mpd',
  618. 'ext': 'mp4',
  619. 'format_id': '5997485',
  620. 'format_note': 'DASH video',
  621. 'protocol': 'http_dash_segments',
  622. 'acodec': 'none',
  623. 'vcodec': 'avc1.640032',
  624. 'tbr': 5997.485,
  625. 'width': 1920,
  626. 'height': 1080,
  627. }]
  628. ), (
  629. # https://github.com/rg3/youtube-dl/pull/14844
  630. 'urls_only',
  631. 'http://unknown/manifest.mpd',
  632. [{
  633. 'manifest_url': 'http://unknown/manifest.mpd',
  634. 'ext': 'mp4',
  635. 'format_id': 'h264_aac_144p_m4s',
  636. 'format_note': 'DASH video',
  637. 'protocol': 'http_dash_segments',
  638. 'acodec': 'mp4a.40.2',
  639. 'vcodec': 'avc3.42c01e',
  640. 'tbr': 200,
  641. 'width': 256,
  642. 'height': 144,
  643. }, {
  644. 'manifest_url': 'http://unknown/manifest.mpd',
  645. 'ext': 'mp4',
  646. 'format_id': 'h264_aac_240p_m4s',
  647. 'format_note': 'DASH video',
  648. 'protocol': 'http_dash_segments',
  649. 'acodec': 'mp4a.40.2',
  650. 'vcodec': 'avc3.42c01e',
  651. 'tbr': 400,
  652. 'width': 424,
  653. 'height': 240,
  654. }, {
  655. 'manifest_url': 'http://unknown/manifest.mpd',
  656. 'ext': 'mp4',
  657. 'format_id': 'h264_aac_360p_m4s',
  658. 'format_note': 'DASH video',
  659. 'protocol': 'http_dash_segments',
  660. 'acodec': 'mp4a.40.2',
  661. 'vcodec': 'avc3.42c01e',
  662. 'tbr': 800,
  663. 'width': 640,
  664. 'height': 360,
  665. }, {
  666. 'manifest_url': 'http://unknown/manifest.mpd',
  667. 'ext': 'mp4',
  668. 'format_id': 'h264_aac_480p_m4s',
  669. 'format_note': 'DASH video',
  670. 'protocol': 'http_dash_segments',
  671. 'acodec': 'mp4a.40.2',
  672. 'vcodec': 'avc3.42c01e',
  673. 'tbr': 1200,
  674. 'width': 856,
  675. 'height': 480,
  676. }, {
  677. 'manifest_url': 'http://unknown/manifest.mpd',
  678. 'ext': 'mp4',
  679. 'format_id': 'h264_aac_576p_m4s',
  680. 'format_note': 'DASH video',
  681. 'protocol': 'http_dash_segments',
  682. 'acodec': 'mp4a.40.2',
  683. 'vcodec': 'avc3.42c01e',
  684. 'tbr': 1600,
  685. 'width': 1024,
  686. 'height': 576,
  687. }, {
  688. 'manifest_url': 'http://unknown/manifest.mpd',
  689. 'ext': 'mp4',
  690. 'format_id': 'h264_aac_720p_m4s',
  691. 'format_note': 'DASH video',
  692. 'protocol': 'http_dash_segments',
  693. 'acodec': 'mp4a.40.2',
  694. 'vcodec': 'avc3.42c01e',
  695. 'tbr': 2400,
  696. 'width': 1280,
  697. 'height': 720,
  698. }, {
  699. 'manifest_url': 'http://unknown/manifest.mpd',
  700. 'ext': 'mp4',
  701. 'format_id': 'h264_aac_1080p_m4s',
  702. 'format_note': 'DASH video',
  703. 'protocol': 'http_dash_segments',
  704. 'acodec': 'mp4a.40.2',
  705. 'vcodec': 'avc3.42c01e',
  706. 'tbr': 4400,
  707. 'width': 1920,
  708. 'height': 1080,
  709. }]
  710. )
  711. ]
  712. for mpd_file, mpd_url, expected_formats in _TEST_CASES:
  713. with io.open('./test/testdata/mpd/%s.mpd' % mpd_file,
  714. mode='r', encoding='utf-8') as f:
  715. formats = self.ie._parse_mpd_formats(
  716. compat_etree_fromstring(f.read().encode('utf-8')),
  717. mpd_url=mpd_url)
  718. self.ie._sort_formats(formats)
  719. expect_value(self, formats, expected_formats, None)
  720. def test_parse_f4m_formats(self):
  721. _TEST_CASES = [
  722. (
  723. # https://github.com/rg3/youtube-dl/issues/14660
  724. 'custom_base_url',
  725. 'http://api.new.livestream.com/accounts/6115179/events/6764928/videos/144884262.f4m',
  726. [{
  727. 'manifest_url': 'http://api.new.livestream.com/accounts/6115179/events/6764928/videos/144884262.f4m',
  728. 'ext': 'flv',
  729. 'format_id': '2148',
  730. 'protocol': 'f4m',
  731. 'tbr': 2148,
  732. 'width': 1280,
  733. 'height': 720,
  734. }]
  735. ),
  736. ]
  737. for f4m_file, f4m_url, expected_formats in _TEST_CASES:
  738. with io.open('./test/testdata/f4m/%s.f4m' % f4m_file,
  739. mode='r', encoding='utf-8') as f:
  740. formats = self.ie._parse_f4m_formats(
  741. compat_etree_fromstring(f.read().encode('utf-8')),
  742. f4m_url, None)
  743. self.ie._sort_formats(formats)
  744. expect_value(self, formats, expected_formats, None)
  745. def test_parse_xspf(self):
  746. _TEST_CASES = [
  747. (
  748. 'foo_xspf',
  749. 'https://example.org/src/foo_xspf.xspf',
  750. [{
  751. 'id': 'foo_xspf',
  752. 'title': 'Pandemonium',
  753. 'description': 'Visit http://bigbrother404.bandcamp.com',
  754. 'duration': 202.416,
  755. 'formats': [{
  756. 'manifest_url': 'https://example.org/src/foo_xspf.xspf',
  757. 'url': 'https://example.org/src/cd1/track%201.mp3',
  758. }],
  759. }, {
  760. 'id': 'foo_xspf',
  761. 'title': 'Final Cartridge (Nichico Twelve Remix)',
  762. 'description': 'Visit http://bigbrother404.bandcamp.com',
  763. 'duration': 255.857,
  764. 'formats': [{
  765. 'manifest_url': 'https://example.org/src/foo_xspf.xspf',
  766. 'url': 'https://example.org/%E3%83%88%E3%83%A9%E3%83%83%E3%82%AF%E3%80%80%EF%BC%92.mp3',
  767. }],
  768. }, {
  769. 'id': 'foo_xspf',
  770. 'title': 'Rebuilding Nightingale',
  771. 'description': 'Visit http://bigbrother404.bandcamp.com',
  772. 'duration': 287.915,
  773. 'formats': [{
  774. 'manifest_url': 'https://example.org/src/foo_xspf.xspf',
  775. 'url': 'https://example.org/src/track3.mp3',
  776. }, {
  777. 'manifest_url': 'https://example.org/src/foo_xspf.xspf',
  778. 'url': 'https://example.com/track3.mp3',
  779. }]
  780. }]
  781. ),
  782. ]
  783. for xspf_file, xspf_url, expected_entries in _TEST_CASES:
  784. with io.open('./test/testdata/xspf/%s.xspf' % xspf_file,
  785. mode='r', encoding='utf-8') as f:
  786. entries = self.ie._parse_xspf(
  787. compat_etree_fromstring(f.read().encode('utf-8')),
  788. xspf_file, xspf_url=xspf_url, xspf_base_url=xspf_url)
  789. expect_value(self, entries, expected_entries, None)
  790. for i in range(len(entries)):
  791. expect_dict(self, entries[i], expected_entries[i])
  792. def test_response_with_expected_status_returns_content(self):
  793. # Checks for mitigations against the effects of
  794. # <https://bugs.python.org/issue15002> that affect Python 3.4.1+, which
  795. # manifest as `_download_webpage`, `_download_xml`, `_download_json`,
  796. # or the underlying `_download_webpage_handle` returning no content
  797. # when a response matches `expected_status`.
  798. httpd = compat_http_server.HTTPServer(
  799. ('127.0.0.1', 0), InfoExtractorTestRequestHandler)
  800. port = http_server_port(httpd)
  801. server_thread = threading.Thread(target=httpd.serve_forever)
  802. server_thread.daemon = True
  803. server_thread.start()
  804. (content, urlh) = self.ie._download_webpage_handle(
  805. 'http://127.0.0.1:%d/teapot' % port, None,
  806. expected_status=TEAPOT_RESPONSE_STATUS)
  807. self.assertEqual(content, TEAPOT_RESPONSE_BODY)
  808. if __name__ == '__main__':
  809. unittest.main()