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.

1071 lines
56 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. <meta property=og-test3 content='Ill-formatted opengraph'/>
  50. '''
  51. self.assertEqual(ie._og_search_title(html), 'Foo')
  52. self.assertEqual(ie._og_search_description(html), 'Some video\'s description ')
  53. self.assertEqual(ie._og_search_thumbnail(html), 'http://domain.com/pic.jpg?key1=val1&key2=val2')
  54. self.assertEqual(ie._og_search_video_url(html, default=None), None)
  55. self.assertEqual(ie._og_search_property('foobar', html), 'Foo')
  56. self.assertEqual(ie._og_search_property('test1', html), 'foo > < bar')
  57. self.assertEqual(ie._og_search_property('test2', html), 'foo >//< bar')
  58. self.assertEqual(ie._og_search_property('test3', html), 'Ill-formatted opengraph')
  59. self.assertEqual(ie._og_search_property(('test0', 'test1'), html), 'foo > < bar')
  60. self.assertRaises(RegexNotFoundError, ie._og_search_property, 'test0', html, None, fatal=True)
  61. self.assertRaises(RegexNotFoundError, ie._og_search_property, ('test0', 'test00'), html, None, fatal=True)
  62. def test_html_search_meta(self):
  63. ie = self.ie
  64. html = '''
  65. <meta name="a" content="1" />
  66. <meta name='b' content='2'>
  67. <meta name="c" content='3'>
  68. <meta name=d content='4'>
  69. <meta property="e" content='5' >
  70. <meta content="6" name="f">
  71. '''
  72. self.assertEqual(ie._html_search_meta('a', html), '1')
  73. self.assertEqual(ie._html_search_meta('b', html), '2')
  74. self.assertEqual(ie._html_search_meta('c', html), '3')
  75. self.assertEqual(ie._html_search_meta('d', html), '4')
  76. self.assertEqual(ie._html_search_meta('e', html), '5')
  77. self.assertEqual(ie._html_search_meta('f', html), '6')
  78. self.assertEqual(ie._html_search_meta(('a', 'b', 'c'), html), '1')
  79. self.assertEqual(ie._html_search_meta(('c', 'b', 'a'), html), '3')
  80. self.assertEqual(ie._html_search_meta(('z', 'x', 'c'), html), '3')
  81. self.assertRaises(RegexNotFoundError, ie._html_search_meta, 'z', html, None, fatal=True)
  82. self.assertRaises(RegexNotFoundError, ie._html_search_meta, ('z', 'x'), html, None, fatal=True)
  83. def test_download_json(self):
  84. uri = encode_data_uri(b'{"foo": "blah"}', 'application/json')
  85. self.assertEqual(self.ie._download_json(uri, None), {'foo': 'blah'})
  86. uri = encode_data_uri(b'callback({"foo": "blah"})', 'application/javascript')
  87. self.assertEqual(self.ie._download_json(uri, None, transform_source=strip_jsonp), {'foo': 'blah'})
  88. uri = encode_data_uri(b'{"foo": invalid}', 'application/json')
  89. self.assertRaises(ExtractorError, self.ie._download_json, uri, None)
  90. self.assertEqual(self.ie._download_json(uri, None, fatal=False), None)
  91. def test_parse_html5_media_entries(self):
  92. # from https://www.r18.com/
  93. # with kpbs in label
  94. expect_dict(
  95. self,
  96. self.ie._parse_html5_media_entries(
  97. 'https://www.r18.com/',
  98. r'''
  99. <video id="samplevideo_amateur" class="js-samplevideo video-js vjs-default-skin vjs-big-play-centered" controls preload="auto" width="400" height="225" poster="//pics.r18.com/digital/amateur/mgmr105/mgmr105jp.jpg">
  100. <source id="video_source" src="https://awscc3001.r18.com/litevideo/freepv/m/mgm/mgmr105/mgmr105_sm_w.mp4" type="video/mp4" res="240" label="300kbps">
  101. <source id="video_source" src="https://awscc3001.r18.com/litevideo/freepv/m/mgm/mgmr105/mgmr105_dm_w.mp4" type="video/mp4" res="480" label="1000kbps">
  102. <source id="video_source" src="https://awscc3001.r18.com/litevideo/freepv/m/mgm/mgmr105/mgmr105_dmb_w.mp4" type="video/mp4" res="740" label="1500kbps">
  103. <p>Your browser does not support the video tag.</p>
  104. </video>
  105. ''', None)[0],
  106. {
  107. 'formats': [{
  108. 'url': 'https://awscc3001.r18.com/litevideo/freepv/m/mgm/mgmr105/mgmr105_sm_w.mp4',
  109. 'ext': 'mp4',
  110. 'format_id': '300kbps',
  111. 'height': 240,
  112. 'tbr': 300,
  113. }, {
  114. 'url': 'https://awscc3001.r18.com/litevideo/freepv/m/mgm/mgmr105/mgmr105_dm_w.mp4',
  115. 'ext': 'mp4',
  116. 'format_id': '1000kbps',
  117. 'height': 480,
  118. 'tbr': 1000,
  119. }, {
  120. 'url': 'https://awscc3001.r18.com/litevideo/freepv/m/mgm/mgmr105/mgmr105_dmb_w.mp4',
  121. 'ext': 'mp4',
  122. 'format_id': '1500kbps',
  123. 'height': 740,
  124. 'tbr': 1500,
  125. }],
  126. 'thumbnail': '//pics.r18.com/digital/amateur/mgmr105/mgmr105jp.jpg'
  127. })
  128. # from https://www.csfd.cz/
  129. # with width and height
  130. expect_dict(
  131. self,
  132. self.ie._parse_html5_media_entries(
  133. 'https://www.csfd.cz/',
  134. r'''
  135. <video width="770" height="328" preload="none" controls poster="https://img.csfd.cz/files/images/film/video/preview/163/344/163344118_748d20.png?h360" >
  136. <source src="https://video.csfd.cz/files/videos/157/750/157750813/163327358_eac647.mp4" type="video/mp4" width="640" height="360">
  137. <source src="https://video.csfd.cz/files/videos/157/750/157750813/163327360_3d2646.mp4" type="video/mp4" width="1280" height="720">
  138. <source src="https://video.csfd.cz/files/videos/157/750/157750813/163327356_91f258.mp4" type="video/mp4" width="1920" height="1080">
  139. <source src="https://video.csfd.cz/files/videos/157/750/157750813/163327359_962b4a.webm" type="video/webm" width="640" height="360">
  140. <source src="https://video.csfd.cz/files/videos/157/750/157750813/163327361_6feee0.webm" type="video/webm" width="1280" height="720">
  141. <source src="https://video.csfd.cz/files/videos/157/750/157750813/163327357_8ab472.webm" type="video/webm" width="1920" height="1080">
  142. <track src="https://video.csfd.cz/files/subtitles/163/344/163344115_4c388b.srt" type="text/x-srt" kind="subtitles" srclang="cs" label="cs">
  143. </video>
  144. ''', None)[0],
  145. {
  146. 'formats': [{
  147. 'url': 'https://video.csfd.cz/files/videos/157/750/157750813/163327358_eac647.mp4',
  148. 'ext': 'mp4',
  149. 'width': 640,
  150. 'height': 360,
  151. }, {
  152. 'url': 'https://video.csfd.cz/files/videos/157/750/157750813/163327360_3d2646.mp4',
  153. 'ext': 'mp4',
  154. 'width': 1280,
  155. 'height': 720,
  156. }, {
  157. 'url': 'https://video.csfd.cz/files/videos/157/750/157750813/163327356_91f258.mp4',
  158. 'ext': 'mp4',
  159. 'width': 1920,
  160. 'height': 1080,
  161. }, {
  162. 'url': 'https://video.csfd.cz/files/videos/157/750/157750813/163327359_962b4a.webm',
  163. 'ext': 'webm',
  164. 'width': 640,
  165. 'height': 360,
  166. }, {
  167. 'url': 'https://video.csfd.cz/files/videos/157/750/157750813/163327361_6feee0.webm',
  168. 'ext': 'webm',
  169. 'width': 1280,
  170. 'height': 720,
  171. }, {
  172. 'url': 'https://video.csfd.cz/files/videos/157/750/157750813/163327357_8ab472.webm',
  173. 'ext': 'webm',
  174. 'width': 1920,
  175. 'height': 1080,
  176. }],
  177. 'subtitles': {
  178. 'cs': [{'url': 'https://video.csfd.cz/files/subtitles/163/344/163344115_4c388b.srt'}]
  179. },
  180. 'thumbnail': 'https://img.csfd.cz/files/images/film/video/preview/163/344/163344118_748d20.png?h360'
  181. })
  182. # from https://tamasha.com/v/Kkdjw
  183. # with height in label
  184. expect_dict(
  185. self,
  186. self.ie._parse_html5_media_entries(
  187. 'https://tamasha.com/v/Kkdjw',
  188. r'''
  189. <video crossorigin="anonymous">
  190. <source src="https://s-v2.tamasha.com/statics/videos_file/19/8f/Kkdjw_198feff8577d0057536e905cce1fb61438dd64e0_n_240.mp4" type="video/mp4" label="AUTO" res="0"/>
  191. <source src="https://s-v2.tamasha.com/statics/videos_file/19/8f/Kkdjw_198feff8577d0057536e905cce1fb61438dd64e0_n_240.mp4" type="video/mp4"
  192. label="240p" res="240"/>
  193. <source src="https://s-v2.tamasha.com/statics/videos_file/20/00/Kkdjw_200041c66f657fc967db464d156eafbc1ed9fe6f_n_144.mp4" type="video/mp4"
  194. label="144p" res="144"/>
  195. </video>
  196. ''', None)[0],
  197. {
  198. 'formats': [{
  199. 'url': 'https://s-v2.tamasha.com/statics/videos_file/19/8f/Kkdjw_198feff8577d0057536e905cce1fb61438dd64e0_n_240.mp4',
  200. }, {
  201. 'url': 'https://s-v2.tamasha.com/statics/videos_file/19/8f/Kkdjw_198feff8577d0057536e905cce1fb61438dd64e0_n_240.mp4',
  202. 'ext': 'mp4',
  203. 'format_id': '240p',
  204. 'height': 240,
  205. }, {
  206. 'url': 'https://s-v2.tamasha.com/statics/videos_file/20/00/Kkdjw_200041c66f657fc967db464d156eafbc1ed9fe6f_n_144.mp4',
  207. 'ext': 'mp4',
  208. 'format_id': '144p',
  209. 'height': 144,
  210. }]
  211. })
  212. # from https://www.directvnow.com
  213. # with data-src
  214. expect_dict(
  215. self,
  216. self.ie._parse_html5_media_entries(
  217. 'https://www.directvnow.com',
  218. r'''
  219. <video id="vid1" class="header--video-masked active" muted playsinline>
  220. <source data-src="https://cdn.directv.com/content/dam/dtv/prod/website_directvnow-international/videos/DTVN_hdr_HBO_v3.mp4" type="video/mp4" />
  221. </video>
  222. ''', None)[0],
  223. {
  224. 'formats': [{
  225. 'ext': 'mp4',
  226. 'url': 'https://cdn.directv.com/content/dam/dtv/prod/website_directvnow-international/videos/DTVN_hdr_HBO_v3.mp4',
  227. }]
  228. })
  229. # from https://www.directvnow.com
  230. # with data-src
  231. expect_dict(
  232. self,
  233. self.ie._parse_html5_media_entries(
  234. 'https://www.directvnow.com',
  235. r'''
  236. <video id="vid1" class="header--video-masked active" muted playsinline>
  237. <source data-src="https://cdn.directv.com/content/dam/dtv/prod/website_directvnow-international/videos/DTVN_hdr_HBO_v3.mp4" type="video/mp4" />
  238. </video>
  239. ''', None)[0],
  240. {
  241. 'formats': [{
  242. 'url': 'https://cdn.directv.com/content/dam/dtv/prod/website_directvnow-international/videos/DTVN_hdr_HBO_v3.mp4',
  243. 'ext': 'mp4',
  244. }]
  245. })
  246. # from https://www.klarna.com/uk/
  247. # with data-video-src
  248. expect_dict(
  249. self,
  250. self.ie._parse_html5_media_entries(
  251. 'https://www.directvnow.com',
  252. r'''
  253. <video loop autoplay muted class="responsive-video block-kl__video video-on-medium">
  254. <source src="" data-video-desktop data-video-src="https://www.klarna.com/uk/wp-content/uploads/sites/11/2019/01/KL062_Smooth3_0_DogWalking_5s_920x080_.mp4" type="video/mp4" />
  255. </video>
  256. ''', None)[0],
  257. {
  258. 'formats': [{
  259. 'url': 'https://www.klarna.com/uk/wp-content/uploads/sites/11/2019/01/KL062_Smooth3_0_DogWalking_5s_920x080_.mp4',
  260. 'ext': 'mp4',
  261. }],
  262. })
  263. def test_extract_jwplayer_data_realworld(self):
  264. # from http://www.suffolk.edu/sjc/
  265. expect_dict(
  266. self,
  267. self.ie._extract_jwplayer_data(r'''
  268. <script type='text/javascript'>
  269. jwplayer('my-video').setup({
  270. file: 'rtmp://192.138.214.154/live/sjclive',
  271. fallback: 'true',
  272. width: '95%',
  273. aspectratio: '16:9',
  274. primary: 'flash',
  275. mediaid:'XEgvuql4'
  276. });
  277. </script>
  278. ''', None, require_title=False),
  279. {
  280. 'id': 'XEgvuql4',
  281. 'formats': [{
  282. 'url': 'rtmp://192.138.214.154/live/sjclive',
  283. 'ext': 'flv'
  284. }]
  285. })
  286. # from https://www.pornoxo.com/videos/7564/striptease-from-sexy-secretary/
  287. expect_dict(
  288. self,
  289. self.ie._extract_jwplayer_data(r'''
  290. <script type="text/javascript">
  291. jwplayer("mediaplayer").setup({
  292. 'videoid': "7564",
  293. 'width': "100%",
  294. 'aspectratio': "16:9",
  295. 'stretching': "exactfit",
  296. 'autostart': 'false',
  297. 'flashplayer': "https://t04.vipstreamservice.com/jwplayer/v5.10/player.swf",
  298. '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",
  299. 'image': "https://t03.vipstreamservice.com/thumbs/pxo-full/2009-12/14/a4b2157147afe5efa93ce1978e0265289c193874e02597.flv-full-13.jpg",
  300. '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",
  301. 'logo.hide': true,
  302. 'skin': "https://t04.vipstreamservice.com/jwplayer/skin/modieus-blk.zip",
  303. 'plugins': "https://t04.vipstreamservice.com/jwplayer/dock/dockableskinnableplugin.swf",
  304. 'dockableskinnableplugin.piclink': "/index.php?key=ajax-videothumbsn&vid=7564&data=2009-12--14--4b2157147afe5efa93ce1978e0265289c193874e02597.flv--17370",
  305. 'controlbar': 'bottom',
  306. 'modes': [
  307. {type: 'flash', src: 'https://t04.vipstreamservice.com/jwplayer/v5.10/player.swf'}
  308. ],
  309. 'provider': 'http'
  310. });
  311. //noinspection JSAnnotator
  312. invideo.setup({
  313. adsUrl: "/banner-iframe/?zoneId=32",
  314. adsUrl2: "",
  315. autostart: false
  316. });
  317. </script>
  318. ''', 'dummy', require_title=False),
  319. {
  320. 'thumbnail': 'https://t03.vipstreamservice.com/thumbs/pxo-full/2009-12/14/a4b2157147afe5efa93ce1978e0265289c193874e02597.flv-full-13.jpg',
  321. 'formats': [{
  322. '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',
  323. 'ext': 'flv'
  324. }]
  325. })
  326. # from http://www.indiedb.com/games/king-machine/videos
  327. expect_dict(
  328. self,
  329. self.ie._extract_jwplayer_data(r'''
  330. <script>
  331. 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) {
  332. videoAnalytics("play");
  333. }).once("complete", function(event) {
  334. videoAnalytics("completed");
  335. });
  336. </script>
  337. ''', 'dummy'),
  338. {
  339. 'title': 'king machine trailer 1',
  340. 'thumbnail': 'http://media.indiedb.com/cache/images/games/1/50/49678/thumb_620x2000/king-machine-trailer.mp4.jpg',
  341. 'formats': [{
  342. 'url': 'http://cdn.dbolical.com/cache/videos/games/1/50/49678/encode_mp4/king-machine-trailer.mp4',
  343. 'height': 360,
  344. 'ext': 'mp4'
  345. }, {
  346. 'url': 'http://cdn.dbolical.com/cache/videos/games/1/50/49678/encode720p_mp4/king-machine-trailer.mp4',
  347. 'height': 720,
  348. 'ext': 'mp4'
  349. }]
  350. })
  351. def test_parse_m3u8_formats(self):
  352. _TEST_CASES = [
  353. (
  354. # https://github.com/ytdl-org/youtube-dl/issues/11507
  355. # http://pluzz.francetv.fr/videos/le_ministere.html
  356. 'pluzz_francetv_11507',
  357. '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',
  358. [{
  359. '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',
  360. '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',
  361. 'ext': 'mp4',
  362. 'format_id': '180',
  363. 'protocol': 'm3u8',
  364. 'acodec': 'mp4a.40.2',
  365. 'vcodec': 'avc1.66.30',
  366. 'tbr': 180,
  367. 'width': 256,
  368. 'height': 144,
  369. }, {
  370. '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',
  371. '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',
  372. 'ext': 'mp4',
  373. 'format_id': '303',
  374. 'protocol': 'm3u8',
  375. 'acodec': 'mp4a.40.2',
  376. 'vcodec': 'avc1.66.30',
  377. 'tbr': 303,
  378. 'width': 320,
  379. 'height': 180,
  380. }, {
  381. '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',
  382. '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',
  383. 'ext': 'mp4',
  384. 'format_id': '575',
  385. 'protocol': 'm3u8',
  386. 'acodec': 'mp4a.40.2',
  387. 'vcodec': 'avc1.66.30',
  388. 'tbr': 575,
  389. 'width': 512,
  390. 'height': 288,
  391. }, {
  392. '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',
  393. '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',
  394. 'ext': 'mp4',
  395. 'format_id': '831',
  396. 'protocol': 'm3u8',
  397. 'acodec': 'mp4a.40.2',
  398. 'vcodec': 'avc1.77.30',
  399. 'tbr': 831,
  400. 'width': 704,
  401. 'height': 396,
  402. }, {
  403. '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',
  404. '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',
  405. 'ext': 'mp4',
  406. 'protocol': 'm3u8',
  407. 'format_id': '1467',
  408. 'acodec': 'mp4a.40.2',
  409. 'vcodec': 'avc1.77.30',
  410. 'tbr': 1467,
  411. 'width': 1024,
  412. 'height': 576,
  413. }]
  414. ),
  415. (
  416. # https://github.com/ytdl-org/youtube-dl/issues/11995
  417. # http://teamcoco.com/video/clueless-gamer-super-bowl-for-honor
  418. 'teamcoco_11995',
  419. 'http://ak.storage-w.teamcococdn.com/cdn/2017-02/98599/ed8f/main.m3u8',
  420. [{
  421. 'url': 'http://ak.storage-w.teamcococdn.com/cdn/2017-02/98599/ed8f/hls/CONAN_020217_Highlight_show-audio-160k_v4.m3u8',
  422. 'manifest_url': 'http://ak.storage-w.teamcococdn.com/cdn/2017-02/98599/ed8f/main.m3u8',
  423. 'ext': 'mp4',
  424. 'format_id': 'audio-0-Default',
  425. 'protocol': 'm3u8',
  426. 'vcodec': 'none',
  427. }, {
  428. 'url': 'http://ak.storage-w.teamcococdn.com/cdn/2017-02/98599/ed8f/hls/CONAN_020217_Highlight_show-audio-64k_v4.m3u8',
  429. 'manifest_url': 'http://ak.storage-w.teamcococdn.com/cdn/2017-02/98599/ed8f/main.m3u8',
  430. 'ext': 'mp4',
  431. 'format_id': 'audio-1-Default',
  432. 'protocol': 'm3u8',
  433. 'vcodec': 'none',
  434. }, {
  435. 'url': 'http://ak.storage-w.teamcococdn.com/cdn/2017-02/98599/ed8f/hls/CONAN_020217_Highlight_show-audio-64k_v4.m3u8',
  436. 'manifest_url': 'http://ak.storage-w.teamcococdn.com/cdn/2017-02/98599/ed8f/main.m3u8',
  437. 'ext': 'mp4',
  438. 'format_id': '71',
  439. 'protocol': 'm3u8',
  440. 'acodec': 'mp4a.40.5',
  441. 'vcodec': 'none',
  442. 'tbr': 71,
  443. }, {
  444. 'url': 'http://ak.storage-w.teamcococdn.com/cdn/2017-02/98599/ed8f/hls/CONAN_020217_Highlight_show-400k_v4.m3u8',
  445. 'manifest_url': 'http://ak.storage-w.teamcococdn.com/cdn/2017-02/98599/ed8f/main.m3u8',
  446. 'ext': 'mp4',
  447. 'format_id': '413',
  448. 'protocol': 'm3u8',
  449. 'acodec': 'none',
  450. 'vcodec': 'avc1.42001e',
  451. 'tbr': 413,
  452. 'width': 400,
  453. 'height': 224,
  454. }, {
  455. 'url': 'http://ak.storage-w.teamcococdn.com/cdn/2017-02/98599/ed8f/hls/CONAN_020217_Highlight_show-400k_v4.m3u8',
  456. 'manifest_url': 'http://ak.storage-w.teamcococdn.com/cdn/2017-02/98599/ed8f/main.m3u8',
  457. 'ext': 'mp4',
  458. 'format_id': '522',
  459. 'protocol': 'm3u8',
  460. 'acodec': 'none',
  461. 'vcodec': 'avc1.42001e',
  462. 'tbr': 522,
  463. 'width': 400,
  464. 'height': 224,
  465. }, {
  466. 'url': 'http://ak.storage-w.teamcococdn.com/cdn/2017-02/98599/ed8f/hls/CONAN_020217_Highlight_show-1m_v4.m3u8',
  467. 'manifest_url': 'http://ak.storage-w.teamcococdn.com/cdn/2017-02/98599/ed8f/main.m3u8',
  468. 'ext': 'mp4',
  469. 'format_id': '1205',
  470. 'protocol': 'm3u8',
  471. 'acodec': 'none',
  472. 'vcodec': 'avc1.4d001e',
  473. 'tbr': 1205,
  474. 'width': 640,
  475. 'height': 360,
  476. }, {
  477. 'url': 'http://ak.storage-w.teamcococdn.com/cdn/2017-02/98599/ed8f/hls/CONAN_020217_Highlight_show-2m_v4.m3u8',
  478. 'manifest_url': 'http://ak.storage-w.teamcococdn.com/cdn/2017-02/98599/ed8f/main.m3u8',
  479. 'ext': 'mp4',
  480. 'format_id': '2374',
  481. 'protocol': 'm3u8',
  482. 'acodec': 'none',
  483. 'vcodec': 'avc1.4d001f',
  484. 'tbr': 2374,
  485. 'width': 1024,
  486. 'height': 576,
  487. }]
  488. ),
  489. (
  490. # https://github.com/ytdl-org/youtube-dl/issues/12211
  491. # http://video.toggle.sg/en/series/whoopie-s-world/ep3/478601
  492. 'toggle_mobile_12211',
  493. 'http://cdnapi.kaltura.com/p/2082311/sp/208231100/playManifest/protocol/http/entryId/0_89q6e8ku/format/applehttp/tags/mobile_sd/f/a.m3u8',
  494. [{
  495. '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',
  496. 'manifest_url': 'http://cdnapi.kaltura.com/p/2082311/sp/208231100/playManifest/protocol/http/entryId/0_89q6e8ku/format/applehttp/tags/mobile_sd/f/a.m3u8',
  497. 'ext': 'mp4',
  498. 'format_id': 'audio-English',
  499. 'protocol': 'm3u8',
  500. 'language': 'eng',
  501. 'vcodec': 'none',
  502. }, {
  503. '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',
  504. 'manifest_url': 'http://cdnapi.kaltura.com/p/2082311/sp/208231100/playManifest/protocol/http/entryId/0_89q6e8ku/format/applehttp/tags/mobile_sd/f/a.m3u8',
  505. 'ext': 'mp4',
  506. 'format_id': 'audio-Undefined',
  507. 'protocol': 'm3u8',
  508. 'language': 'und',
  509. 'vcodec': 'none',
  510. }, {
  511. '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',
  512. 'manifest_url': 'http://cdnapi.kaltura.com/p/2082311/sp/208231100/playManifest/protocol/http/entryId/0_89q6e8ku/format/applehttp/tags/mobile_sd/f/a.m3u8',
  513. 'ext': 'mp4',
  514. 'format_id': '155',
  515. 'protocol': 'm3u8',
  516. 'tbr': 155.648,
  517. 'width': 320,
  518. 'height': 180,
  519. }, {
  520. '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',
  521. 'manifest_url': 'http://cdnapi.kaltura.com/p/2082311/sp/208231100/playManifest/protocol/http/entryId/0_89q6e8ku/format/applehttp/tags/mobile_sd/f/a.m3u8',
  522. 'ext': 'mp4',
  523. 'format_id': '502',
  524. 'protocol': 'm3u8',
  525. 'tbr': 502.784,
  526. 'width': 480,
  527. 'height': 270,
  528. }, {
  529. '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',
  530. 'manifest_url': 'http://cdnapi.kaltura.com/p/2082311/sp/208231100/playManifest/protocol/http/entryId/0_89q6e8ku/format/applehttp/tags/mobile_sd/f/a.m3u8',
  531. 'ext': 'mp4',
  532. 'format_id': '827',
  533. 'protocol': 'm3u8',
  534. 'tbr': 827.392,
  535. 'width': 640,
  536. 'height': 360,
  537. }, {
  538. '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',
  539. 'manifest_url': 'http://cdnapi.kaltura.com/p/2082311/sp/208231100/playManifest/protocol/http/entryId/0_89q6e8ku/format/applehttp/tags/mobile_sd/f/a.m3u8',
  540. 'ext': 'mp4',
  541. 'format_id': '1396',
  542. 'protocol': 'm3u8',
  543. 'tbr': 1396.736,
  544. 'width': 854,
  545. 'height': 480,
  546. }]
  547. ),
  548. (
  549. # http://www.twitch.tv/riotgames/v/6528877
  550. 'twitch_vod',
  551. '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',
  552. [{
  553. 'url': 'https://vod.edgecast.hls.ttvnw.net/e5da31ab49_riotgames_15001215120_261543898/audio_only/index-muted-HM49I092CC.m3u8',
  554. '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',
  555. 'ext': 'mp4',
  556. 'format_id': 'Audio Only',
  557. 'protocol': 'm3u8',
  558. 'acodec': 'mp4a.40.2',
  559. 'vcodec': 'none',
  560. 'tbr': 182.725,
  561. }, {
  562. 'url': 'https://vod.edgecast.hls.ttvnw.net/e5da31ab49_riotgames_15001215120_261543898/mobile/index-muted-HM49I092CC.m3u8',
  563. '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',
  564. 'ext': 'mp4',
  565. 'format_id': 'Mobile',
  566. 'protocol': 'm3u8',
  567. 'acodec': 'mp4a.40.2',
  568. 'vcodec': 'avc1.42C00D',
  569. 'tbr': 280.474,
  570. 'width': 400,
  571. 'height': 226,
  572. }, {
  573. 'url': 'https://vod.edgecast.hls.ttvnw.net/e5da31ab49_riotgames_15001215120_261543898/low/index-muted-HM49I092CC.m3u8',
  574. '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',
  575. 'ext': 'mp4',
  576. 'format_id': 'Low',
  577. 'protocol': 'm3u8',
  578. 'acodec': 'mp4a.40.2',
  579. 'vcodec': 'avc1.42C01E',
  580. 'tbr': 628.347,
  581. 'width': 640,
  582. 'height': 360,
  583. }, {
  584. 'url': 'https://vod.edgecast.hls.ttvnw.net/e5da31ab49_riotgames_15001215120_261543898/medium/index-muted-HM49I092CC.m3u8',
  585. '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',
  586. 'ext': 'mp4',
  587. 'format_id': 'Medium',
  588. 'protocol': 'm3u8',
  589. 'acodec': 'mp4a.40.2',
  590. 'vcodec': 'avc1.42C01E',
  591. 'tbr': 893.387,
  592. 'width': 852,
  593. 'height': 480,
  594. }, {
  595. 'url': 'https://vod.edgecast.hls.ttvnw.net/e5da31ab49_riotgames_15001215120_261543898/high/index-muted-HM49I092CC.m3u8',
  596. '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',
  597. 'ext': 'mp4',
  598. 'format_id': 'High',
  599. 'protocol': 'm3u8',
  600. 'acodec': 'mp4a.40.2',
  601. 'vcodec': 'avc1.42C01F',
  602. 'tbr': 1603.789,
  603. 'width': 1280,
  604. 'height': 720,
  605. }, {
  606. 'url': 'https://vod.edgecast.hls.ttvnw.net/e5da31ab49_riotgames_15001215120_261543898/chunked/index-muted-HM49I092CC.m3u8',
  607. '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',
  608. 'ext': 'mp4',
  609. 'format_id': 'Source',
  610. 'protocol': 'm3u8',
  611. 'acodec': 'mp4a.40.2',
  612. 'vcodec': 'avc1.100.31',
  613. 'tbr': 3214.134,
  614. 'width': 1280,
  615. 'height': 720,
  616. }]
  617. ),
  618. (
  619. # http://www.vidio.com/watch/165683-dj_ambred-booyah-live-2015
  620. # EXT-X-STREAM-INF tag with NAME attribute that is not defined
  621. # in HLS specification
  622. 'vidio',
  623. 'https://www.vidio.com/videos/165683/playlist.m3u8',
  624. [{
  625. 'url': 'https://cdn1-a.production.vidio.static6.com/uploads/165683/dj_ambred-4383-b300.mp4.m3u8',
  626. 'manifest_url': 'https://www.vidio.com/videos/165683/playlist.m3u8',
  627. 'ext': 'mp4',
  628. 'format_id': '270p 3G',
  629. 'protocol': 'm3u8',
  630. 'tbr': 300,
  631. 'width': 480,
  632. 'height': 270,
  633. }, {
  634. 'url': 'https://cdn1-a.production.vidio.static6.com/uploads/165683/dj_ambred-4383-b600.mp4.m3u8',
  635. 'manifest_url': 'https://www.vidio.com/videos/165683/playlist.m3u8',
  636. 'ext': 'mp4',
  637. 'format_id': '360p SD',
  638. 'protocol': 'm3u8',
  639. 'tbr': 600,
  640. 'width': 640,
  641. 'height': 360,
  642. }, {
  643. 'url': 'https://cdn1-a.production.vidio.static6.com/uploads/165683/dj_ambred-4383-b1200.mp4.m3u8',
  644. 'manifest_url': 'https://www.vidio.com/videos/165683/playlist.m3u8',
  645. 'ext': 'mp4',
  646. 'format_id': '720p HD',
  647. 'protocol': 'm3u8',
  648. 'tbr': 1200,
  649. 'width': 1280,
  650. 'height': 720,
  651. }]
  652. ),
  653. (
  654. # https://github.com/ytdl-org/youtube-dl/issues/18923
  655. # https://www.ted.com/talks/boris_hesser_a_grassroots_healthcare_revolution_in_africa
  656. 'ted_18923',
  657. 'http://hls.ted.com/talks/31241.m3u8',
  658. [{
  659. 'url': 'http://hls.ted.com/videos/BorisHesser_2018S/audio/600k.m3u8?nobumpers=true&uniqueId=76011e2b',
  660. 'format_id': '600k-Audio',
  661. 'vcodec': 'none',
  662. }, {
  663. 'url': 'http://hls.ted.com/videos/BorisHesser_2018S/audio/600k.m3u8?nobumpers=true&uniqueId=76011e2b',
  664. 'format_id': '68',
  665. 'vcodec': 'none',
  666. }, {
  667. 'url': 'http://hls.ted.com/videos/BorisHesser_2018S/video/64k.m3u8?nobumpers=true&uniqueId=76011e2b',
  668. 'format_id': '163',
  669. 'acodec': 'none',
  670. 'width': 320,
  671. 'height': 180,
  672. }, {
  673. 'url': 'http://hls.ted.com/videos/BorisHesser_2018S/video/180k.m3u8?nobumpers=true&uniqueId=76011e2b',
  674. 'format_id': '481',
  675. 'acodec': 'none',
  676. 'width': 512,
  677. 'height': 288,
  678. }, {
  679. 'url': 'http://hls.ted.com/videos/BorisHesser_2018S/video/320k.m3u8?nobumpers=true&uniqueId=76011e2b',
  680. 'format_id': '769',
  681. 'acodec': 'none',
  682. 'width': 512,
  683. 'height': 288,
  684. }, {
  685. 'url': 'http://hls.ted.com/videos/BorisHesser_2018S/video/450k.m3u8?nobumpers=true&uniqueId=76011e2b',
  686. 'format_id': '984',
  687. 'acodec': 'none',
  688. 'width': 512,
  689. 'height': 288,
  690. }, {
  691. 'url': 'http://hls.ted.com/videos/BorisHesser_2018S/video/600k.m3u8?nobumpers=true&uniqueId=76011e2b',
  692. 'format_id': '1255',
  693. 'acodec': 'none',
  694. 'width': 640,
  695. 'height': 360,
  696. }, {
  697. 'url': 'http://hls.ted.com/videos/BorisHesser_2018S/video/950k.m3u8?nobumpers=true&uniqueId=76011e2b',
  698. 'format_id': '1693',
  699. 'acodec': 'none',
  700. 'width': 853,
  701. 'height': 480,
  702. }, {
  703. 'url': 'http://hls.ted.com/videos/BorisHesser_2018S/video/1500k.m3u8?nobumpers=true&uniqueId=76011e2b',
  704. 'format_id': '2462',
  705. 'acodec': 'none',
  706. 'width': 1280,
  707. 'height': 720,
  708. }]
  709. ),
  710. ]
  711. for m3u8_file, m3u8_url, expected_formats in _TEST_CASES:
  712. with io.open('./test/testdata/m3u8/%s.m3u8' % m3u8_file,
  713. mode='r', encoding='utf-8') as f:
  714. formats = self.ie._parse_m3u8_formats(
  715. f.read(), m3u8_url, ext='mp4')
  716. self.ie._sort_formats(formats)
  717. expect_value(self, formats, expected_formats, None)
  718. def test_parse_mpd_formats(self):
  719. _TEST_CASES = [
  720. (
  721. # https://github.com/ytdl-org/youtube-dl/issues/13919
  722. # Also tests duplicate representation ids, see
  723. # https://github.com/ytdl-org/youtube-dl/issues/15111
  724. 'float_duration',
  725. 'http://unknown/manifest.mpd', # mpd_url
  726. None, # mpd_base_url
  727. [{
  728. 'manifest_url': 'http://unknown/manifest.mpd',
  729. 'ext': 'm4a',
  730. 'format_id': '318597',
  731. 'format_note': 'DASH audio',
  732. 'protocol': 'http_dash_segments',
  733. 'acodec': 'mp4a.40.2',
  734. 'vcodec': 'none',
  735. 'tbr': 61.587,
  736. }, {
  737. 'manifest_url': 'http://unknown/manifest.mpd',
  738. 'ext': 'mp4',
  739. 'format_id': '318597',
  740. 'format_note': 'DASH video',
  741. 'protocol': 'http_dash_segments',
  742. 'acodec': 'none',
  743. 'vcodec': 'avc1.42001f',
  744. 'tbr': 318.597,
  745. 'width': 340,
  746. 'height': 192,
  747. }, {
  748. 'manifest_url': 'http://unknown/manifest.mpd',
  749. 'ext': 'mp4',
  750. 'format_id': '638590',
  751. 'format_note': 'DASH video',
  752. 'protocol': 'http_dash_segments',
  753. 'acodec': 'none',
  754. 'vcodec': 'avc1.42001f',
  755. 'tbr': 638.59,
  756. 'width': 512,
  757. 'height': 288,
  758. }, {
  759. 'manifest_url': 'http://unknown/manifest.mpd',
  760. 'ext': 'mp4',
  761. 'format_id': '1022565',
  762. 'format_note': 'DASH video',
  763. 'protocol': 'http_dash_segments',
  764. 'acodec': 'none',
  765. 'vcodec': 'avc1.4d001f',
  766. 'tbr': 1022.565,
  767. 'width': 688,
  768. 'height': 384,
  769. }, {
  770. 'manifest_url': 'http://unknown/manifest.mpd',
  771. 'ext': 'mp4',
  772. 'format_id': '2046506',
  773. 'format_note': 'DASH video',
  774. 'protocol': 'http_dash_segments',
  775. 'acodec': 'none',
  776. 'vcodec': 'avc1.4d001f',
  777. 'tbr': 2046.506,
  778. 'width': 1024,
  779. 'height': 576,
  780. }, {
  781. 'manifest_url': 'http://unknown/manifest.mpd',
  782. 'ext': 'mp4',
  783. 'format_id': '3998017',
  784. 'format_note': 'DASH video',
  785. 'protocol': 'http_dash_segments',
  786. 'acodec': 'none',
  787. 'vcodec': 'avc1.640029',
  788. 'tbr': 3998.017,
  789. 'width': 1280,
  790. 'height': 720,
  791. }, {
  792. 'manifest_url': 'http://unknown/manifest.mpd',
  793. 'ext': 'mp4',
  794. 'format_id': '5997485',
  795. 'format_note': 'DASH video',
  796. 'protocol': 'http_dash_segments',
  797. 'acodec': 'none',
  798. 'vcodec': 'avc1.640032',
  799. 'tbr': 5997.485,
  800. 'width': 1920,
  801. 'height': 1080,
  802. }]
  803. ), (
  804. # https://github.com/ytdl-org/youtube-dl/pull/14844
  805. 'urls_only',
  806. 'http://unknown/manifest.mpd', # mpd_url
  807. None, # mpd_base_url
  808. [{
  809. 'manifest_url': 'http://unknown/manifest.mpd',
  810. 'ext': 'mp4',
  811. 'format_id': 'h264_aac_144p_m4s',
  812. 'format_note': 'DASH video',
  813. 'protocol': 'http_dash_segments',
  814. 'acodec': 'mp4a.40.2',
  815. 'vcodec': 'avc3.42c01e',
  816. 'tbr': 200,
  817. 'width': 256,
  818. 'height': 144,
  819. }, {
  820. 'manifest_url': 'http://unknown/manifest.mpd',
  821. 'ext': 'mp4',
  822. 'format_id': 'h264_aac_240p_m4s',
  823. 'format_note': 'DASH video',
  824. 'protocol': 'http_dash_segments',
  825. 'acodec': 'mp4a.40.2',
  826. 'vcodec': 'avc3.42c01e',
  827. 'tbr': 400,
  828. 'width': 424,
  829. 'height': 240,
  830. }, {
  831. 'manifest_url': 'http://unknown/manifest.mpd',
  832. 'ext': 'mp4',
  833. 'format_id': 'h264_aac_360p_m4s',
  834. 'format_note': 'DASH video',
  835. 'protocol': 'http_dash_segments',
  836. 'acodec': 'mp4a.40.2',
  837. 'vcodec': 'avc3.42c01e',
  838. 'tbr': 800,
  839. 'width': 640,
  840. 'height': 360,
  841. }, {
  842. 'manifest_url': 'http://unknown/manifest.mpd',
  843. 'ext': 'mp4',
  844. 'format_id': 'h264_aac_480p_m4s',
  845. 'format_note': 'DASH video',
  846. 'protocol': 'http_dash_segments',
  847. 'acodec': 'mp4a.40.2',
  848. 'vcodec': 'avc3.42c01e',
  849. 'tbr': 1200,
  850. 'width': 856,
  851. 'height': 480,
  852. }, {
  853. 'manifest_url': 'http://unknown/manifest.mpd',
  854. 'ext': 'mp4',
  855. 'format_id': 'h264_aac_576p_m4s',
  856. 'format_note': 'DASH video',
  857. 'protocol': 'http_dash_segments',
  858. 'acodec': 'mp4a.40.2',
  859. 'vcodec': 'avc3.42c01e',
  860. 'tbr': 1600,
  861. 'width': 1024,
  862. 'height': 576,
  863. }, {
  864. 'manifest_url': 'http://unknown/manifest.mpd',
  865. 'ext': 'mp4',
  866. 'format_id': 'h264_aac_720p_m4s',
  867. 'format_note': 'DASH video',
  868. 'protocol': 'http_dash_segments',
  869. 'acodec': 'mp4a.40.2',
  870. 'vcodec': 'avc3.42c01e',
  871. 'tbr': 2400,
  872. 'width': 1280,
  873. 'height': 720,
  874. }, {
  875. 'manifest_url': 'http://unknown/manifest.mpd',
  876. 'ext': 'mp4',
  877. 'format_id': 'h264_aac_1080p_m4s',
  878. 'format_note': 'DASH video',
  879. 'protocol': 'http_dash_segments',
  880. 'acodec': 'mp4a.40.2',
  881. 'vcodec': 'avc3.42c01e',
  882. 'tbr': 4400,
  883. 'width': 1920,
  884. 'height': 1080,
  885. }]
  886. ), (
  887. # https://github.com/ytdl-org/youtube-dl/issues/20346
  888. # Media considered unfragmented even though it contains
  889. # Initialization tag
  890. 'unfragmented',
  891. 'https://v.redd.it/hw1x7rcg7zl21/DASHPlaylist.mpd', # mpd_url
  892. 'https://v.redd.it/hw1x7rcg7zl21', # mpd_base_url
  893. [{
  894. 'url': 'https://v.redd.it/hw1x7rcg7zl21/audio',
  895. 'manifest_url': 'https://v.redd.it/hw1x7rcg7zl21/DASHPlaylist.mpd',
  896. 'ext': 'm4a',
  897. 'format_id': 'AUDIO-1',
  898. 'format_note': 'DASH audio',
  899. 'container': 'm4a_dash',
  900. 'acodec': 'mp4a.40.2',
  901. 'vcodec': 'none',
  902. 'tbr': 129.87,
  903. 'asr': 48000,
  904. }, {
  905. 'url': 'https://v.redd.it/hw1x7rcg7zl21/DASH_240',
  906. 'manifest_url': 'https://v.redd.it/hw1x7rcg7zl21/DASHPlaylist.mpd',
  907. 'ext': 'mp4',
  908. 'format_id': 'VIDEO-2',
  909. 'format_note': 'DASH video',
  910. 'container': 'mp4_dash',
  911. 'acodec': 'none',
  912. 'vcodec': 'avc1.4d401e',
  913. 'tbr': 608.0,
  914. 'width': 240,
  915. 'height': 240,
  916. 'fps': 30,
  917. }, {
  918. 'url': 'https://v.redd.it/hw1x7rcg7zl21/DASH_360',
  919. 'manifest_url': 'https://v.redd.it/hw1x7rcg7zl21/DASHPlaylist.mpd',
  920. 'ext': 'mp4',
  921. 'format_id': 'VIDEO-1',
  922. 'format_note': 'DASH video',
  923. 'container': 'mp4_dash',
  924. 'acodec': 'none',
  925. 'vcodec': 'avc1.4d401e',
  926. 'tbr': 804.261,
  927. 'width': 360,
  928. 'height': 360,
  929. 'fps': 30,
  930. }]
  931. )
  932. ]
  933. for mpd_file, mpd_url, mpd_base_url, expected_formats in _TEST_CASES:
  934. with io.open('./test/testdata/mpd/%s.mpd' % mpd_file,
  935. mode='r', encoding='utf-8') as f:
  936. formats = self.ie._parse_mpd_formats(
  937. compat_etree_fromstring(f.read().encode('utf-8')),
  938. mpd_base_url=mpd_base_url, mpd_url=mpd_url)
  939. self.ie._sort_formats(formats)
  940. expect_value(self, formats, expected_formats, None)
  941. def test_parse_f4m_formats(self):
  942. _TEST_CASES = [
  943. (
  944. # https://github.com/ytdl-org/youtube-dl/issues/14660
  945. 'custom_base_url',
  946. 'http://api.new.livestream.com/accounts/6115179/events/6764928/videos/144884262.f4m',
  947. [{
  948. 'manifest_url': 'http://api.new.livestream.com/accounts/6115179/events/6764928/videos/144884262.f4m',
  949. 'ext': 'flv',
  950. 'format_id': '2148',
  951. 'protocol': 'f4m',
  952. 'tbr': 2148,
  953. 'width': 1280,
  954. 'height': 720,
  955. }]
  956. ),
  957. ]
  958. for f4m_file, f4m_url, expected_formats in _TEST_CASES:
  959. with io.open('./test/testdata/f4m/%s.f4m' % f4m_file,
  960. mode='r', encoding='utf-8') as f:
  961. formats = self.ie._parse_f4m_formats(
  962. compat_etree_fromstring(f.read().encode('utf-8')),
  963. f4m_url, None)
  964. self.ie._sort_formats(formats)
  965. expect_value(self, formats, expected_formats, None)
  966. def test_parse_xspf(self):
  967. _TEST_CASES = [
  968. (
  969. 'foo_xspf',
  970. 'https://example.org/src/foo_xspf.xspf',
  971. [{
  972. 'id': 'foo_xspf',
  973. 'title': 'Pandemonium',
  974. 'description': 'Visit http://bigbrother404.bandcamp.com',
  975. 'duration': 202.416,
  976. 'formats': [{
  977. 'manifest_url': 'https://example.org/src/foo_xspf.xspf',
  978. 'url': 'https://example.org/src/cd1/track%201.mp3',
  979. }],
  980. }, {
  981. 'id': 'foo_xspf',
  982. 'title': 'Final Cartridge (Nichico Twelve Remix)',
  983. 'description': 'Visit http://bigbrother404.bandcamp.com',
  984. 'duration': 255.857,
  985. 'formats': [{
  986. 'manifest_url': 'https://example.org/src/foo_xspf.xspf',
  987. 'url': 'https://example.org/%E3%83%88%E3%83%A9%E3%83%83%E3%82%AF%E3%80%80%EF%BC%92.mp3',
  988. }],
  989. }, {
  990. 'id': 'foo_xspf',
  991. 'title': 'Rebuilding Nightingale',
  992. 'description': 'Visit http://bigbrother404.bandcamp.com',
  993. 'duration': 287.915,
  994. 'formats': [{
  995. 'manifest_url': 'https://example.org/src/foo_xspf.xspf',
  996. 'url': 'https://example.org/src/track3.mp3',
  997. }, {
  998. 'manifest_url': 'https://example.org/src/foo_xspf.xspf',
  999. 'url': 'https://example.com/track3.mp3',
  1000. }]
  1001. }]
  1002. ),
  1003. ]
  1004. for xspf_file, xspf_url, expected_entries in _TEST_CASES:
  1005. with io.open('./test/testdata/xspf/%s.xspf' % xspf_file,
  1006. mode='r', encoding='utf-8') as f:
  1007. entries = self.ie._parse_xspf(
  1008. compat_etree_fromstring(f.read().encode('utf-8')),
  1009. xspf_file, xspf_url=xspf_url, xspf_base_url=xspf_url)
  1010. expect_value(self, entries, expected_entries, None)
  1011. for i in range(len(entries)):
  1012. expect_dict(self, entries[i], expected_entries[i])
  1013. def test_response_with_expected_status_returns_content(self):
  1014. # Checks for mitigations against the effects of
  1015. # <https://bugs.python.org/issue15002> that affect Python 3.4.1+, which
  1016. # manifest as `_download_webpage`, `_download_xml`, `_download_json`,
  1017. # or the underlying `_download_webpage_handle` returning no content
  1018. # when a response matches `expected_status`.
  1019. httpd = compat_http_server.HTTPServer(
  1020. ('127.0.0.1', 0), InfoExtractorTestRequestHandler)
  1021. port = http_server_port(httpd)
  1022. server_thread = threading.Thread(target=httpd.serve_forever)
  1023. server_thread.daemon = True
  1024. server_thread.start()
  1025. (content, urlh) = self.ie._download_webpage_handle(
  1026. 'http://127.0.0.1:%d/teapot' % port, None,
  1027. expected_status=TEAPOT_RESPONSE_STATUS)
  1028. self.assertEqual(content, TEAPOT_RESPONSE_BODY)
  1029. if __name__ == '__main__':
  1030. unittest.main()