logo

youtube-dl

[mirror] Download/Watch videos from video hostersgit clone https://hacktivis.me/git/mirror/youtube-dl.git

test_InfoExtractor.py (72432B)


  1. #!/usr/bin/env python
  2. from __future__ import unicode_literals
  3. # Allow direct execution
  4. import os
  5. import sys
  6. import unittest
  7. sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
  8. import threading
  9. from test.helper import (
  10. expect_dict,
  11. expect_value,
  12. FakeYDL,
  13. http_server_port,
  14. )
  15. from youtube_dl.compat import (
  16. compat_etree_fromstring,
  17. compat_http_server,
  18. compat_open as open,
  19. )
  20. from youtube_dl.extractor.common import InfoExtractor
  21. from youtube_dl.extractor import (
  22. get_info_extractor,
  23. YoutubeIE,
  24. )
  25. from youtube_dl.utils import (
  26. encode_data_uri,
  27. ExtractorError,
  28. RegexNotFoundError,
  29. strip_jsonp,
  30. )
  31. TEAPOT_RESPONSE_STATUS = 418
  32. TEAPOT_RESPONSE_BODY = "<h1>418 I'm a teapot</h1>"
  33. class InfoExtractorTestRequestHandler(compat_http_server.BaseHTTPRequestHandler):
  34. def log_message(self, format, *args):
  35. pass
  36. def do_GET(self):
  37. if self.path == '/teapot':
  38. self.send_response(TEAPOT_RESPONSE_STATUS)
  39. self.send_header('Content-Type', 'text/html; charset=utf-8')
  40. self.end_headers()
  41. self.wfile.write(TEAPOT_RESPONSE_BODY.encode())
  42. else:
  43. assert False
  44. class DummyIE(InfoExtractor):
  45. pass
  46. class TestInfoExtractor(unittest.TestCase):
  47. def setUp(self):
  48. self.ie = DummyIE(FakeYDL())
  49. def test_ie_key(self):
  50. self.assertEqual(get_info_extractor(YoutubeIE.ie_key()), YoutubeIE)
  51. def test_html_search_regex(self):
  52. html = '<p id="foo">Watch this <a href="http://www.youtube.com/watch?v=BaW_jenozKc">video</a></p>'
  53. search = lambda re, *args: self.ie._html_search_regex(re, html, *args)
  54. self.assertEqual(search(r'<p id="foo">(.+?)</p>', 'foo'), 'Watch this video')
  55. def test_opengraph(self):
  56. ie = self.ie
  57. html = '''
  58. <meta name="og:title" content='Foo'/>
  59. <meta content="Some video's description " name="og:description"/>
  60. <meta property='og:image' content='http://domain.com/pic.jpg?key1=val1&amp;key2=val2'/>
  61. <meta content='application/x-shockwave-flash' property='og:video:type'>
  62. <meta content='Foo' property=og:foobar>
  63. <meta name="og:test1" content='foo > < bar'/>
  64. <meta name="og:test2" content="foo >//< bar"/>
  65. <meta property=og-test3 content='Ill-formatted opengraph'/>
  66. <meta property=og:test4 content=unquoted-value/>
  67. '''
  68. self.assertEqual(ie._og_search_title(html), 'Foo')
  69. self.assertEqual(ie._og_search_description(html), 'Some video\'s description ')
  70. self.assertEqual(ie._og_search_thumbnail(html), 'http://domain.com/pic.jpg?key1=val1&key2=val2')
  71. self.assertEqual(ie._og_search_video_url(html, default=None), None)
  72. self.assertEqual(ie._og_search_property('foobar', html), 'Foo')
  73. self.assertEqual(ie._og_search_property('test1', html), 'foo > < bar')
  74. self.assertEqual(ie._og_search_property('test2', html), 'foo >//< bar')
  75. self.assertEqual(ie._og_search_property('test3', html), 'Ill-formatted opengraph')
  76. self.assertEqual(ie._og_search_property(('test0', 'test1'), html), 'foo > < bar')
  77. self.assertRaises(RegexNotFoundError, ie._og_search_property, 'test0', html, None, fatal=True)
  78. self.assertRaises(RegexNotFoundError, ie._og_search_property, ('test0', 'test00'), html, None, fatal=True)
  79. self.assertEqual(ie._og_search_property('test4', html), 'unquoted-value')
  80. def test_html_search_meta(self):
  81. ie = self.ie
  82. html = '''
  83. <meta name="a" content="1" />
  84. <meta name='b' content='2'>
  85. <meta name="c" content='3'>
  86. <meta name=d content='4'>
  87. <meta property="e" content='5' >
  88. <meta content="6" name="f">
  89. '''
  90. self.assertEqual(ie._html_search_meta('a', html), '1')
  91. self.assertEqual(ie._html_search_meta('b', html), '2')
  92. self.assertEqual(ie._html_search_meta('c', html), '3')
  93. self.assertEqual(ie._html_search_meta('d', html), '4')
  94. self.assertEqual(ie._html_search_meta('e', html), '5')
  95. self.assertEqual(ie._html_search_meta('f', html), '6')
  96. self.assertEqual(ie._html_search_meta(('a', 'b', 'c'), html), '1')
  97. self.assertEqual(ie._html_search_meta(('c', 'b', 'a'), html), '3')
  98. self.assertEqual(ie._html_search_meta(('z', 'x', 'c'), html), '3')
  99. self.assertRaises(RegexNotFoundError, ie._html_search_meta, 'z', html, None, fatal=True)
  100. self.assertRaises(RegexNotFoundError, ie._html_search_meta, ('z', 'x'), html, None, fatal=True)
  101. def test_search_nextjs_data(self):
  102. html = '''
  103. <!DOCTYPE html>
  104. <html>
  105. <head>
  106. <meta http-equiv="content-type" content=
  107. "text/html; charset=utf-8">
  108. <meta name="viewport" content="width=device-width">
  109. <title>Test _search_nextjs_data()</title>
  110. </head>
  111. <body>
  112. <div id="__next">
  113. <div style="background-color:#17171E" class="FU" dir="ltr">
  114. <div class="sc-93de261d-0 dyzzYE">
  115. <div>
  116. <header class="HD"></header>
  117. <main class="MN">
  118. <div style="height:0" class="HT0">
  119. <div style="width:NaN%" data-testid=
  120. "stream-container" class="WDN"></div>
  121. </div>
  122. </main>
  123. </div>
  124. <footer class="sc-6e5faf91-0 dEGaHS"></footer>
  125. </div>
  126. </div>
  127. </div>
  128. <script id="__NEXT_DATA__" type="application/json">
  129. {"props":{"pageProps":{"video":{"id":"testid"}}}}
  130. </script>
  131. </body>
  132. </html>
  133. '''
  134. search = self.ie._search_nextjs_data(html, 'testID')
  135. self.assertEqual(search['props']['pageProps']['video']['id'], 'testid')
  136. def test_search_nuxt_data(self):
  137. html = '''
  138. <!DOCTYPE html>
  139. <html>
  140. <head>
  141. <meta http-equiv="content-type" content=
  142. "text/html; charset=utf-8">
  143. <title>Nuxt.js Test Page</title>
  144. <meta name="viewport" content=
  145. "width=device-width, initial-scale=1">
  146. <meta data-hid="robots" name="robots" content="all">
  147. </head>
  148. <body class="BD">
  149. <div id="__layout">
  150. <h1 class="H1">Example heading</h1>
  151. <div class="IN">
  152. <p>Decoy text</p>
  153. </div>
  154. </div>
  155. <script>
  156. window.__NUXT__=(function(a,b,c,d,e,f,g,h){return {decoy:" default",data:[{track:{id:f,title:g}}]}}(null,null,"c",null,null,"testid","Nuxt.js title",null));
  157. </script>
  158. <script src="/_nuxt/a12345b.js" defer="defer"></script>
  159. </body>
  160. </html>
  161. '''
  162. search = self.ie._search_nuxt_data(html, 'testID')
  163. self.assertEqual(search['track']['id'], 'testid')
  164. def test_search_json_ld_realworld(self):
  165. # https://github.com/ytdl-org/youtube-dl/issues/23306
  166. expect_dict(
  167. self,
  168. self.ie._search_json_ld(r'''<script type="application/ld+json">
  169. {
  170. "@context": "http://schema.org/",
  171. "@type": "VideoObject",
  172. "name": "1 On 1 With Kleio",
  173. "url": "https://www.eporner.com/hd-porn/xN49A1cT3eB/1-On-1-With-Kleio/",
  174. "duration": "PT0H12M23S",
  175. "thumbnailUrl": ["https://static-eu-cdn.eporner.com/thumbs/static4/7/78/780/780814/9_360.jpg", "https://imggen.eporner.com/780814/1920/1080/9.jpg"],
  176. "contentUrl": "https://gvideo.eporner.com/xN49A1cT3eB/xN49A1cT3eB.mp4",
  177. "embedUrl": "https://www.eporner.com/embed/xN49A1cT3eB/1-On-1-With-Kleio/",
  178. "image": "https://static-eu-cdn.eporner.com/thumbs/static4/7/78/780/780814/9_360.jpg",
  179. "width": "1920",
  180. "height": "1080",
  181. "encodingFormat": "mp4",
  182. "bitrate": "6617kbps",
  183. "isFamilyFriendly": "False",
  184. "description": "Kleio Valentien",
  185. "uploadDate": "2015-12-05T21:24:35+01:00",
  186. "interactionStatistic": {
  187. "@type": "InteractionCounter",
  188. "interactionType": { "@type": "http://schema.org/WatchAction" },
  189. "userInteractionCount": 1120958
  190. }, "aggregateRating": {
  191. "@type": "AggregateRating",
  192. "ratingValue": "88",
  193. "ratingCount": "630",
  194. "bestRating": "100",
  195. "worstRating": "0"
  196. }, "actor": [{
  197. "@type": "Person",
  198. "name": "Kleio Valentien",
  199. "url": "https://www.eporner.com/pornstar/kleio-valentien/"
  200. }]}
  201. </script>''', None),
  202. {
  203. 'title': '1 On 1 With Kleio',
  204. 'description': 'Kleio Valentien',
  205. 'url': 'https://gvideo.eporner.com/xN49A1cT3eB/xN49A1cT3eB.mp4',
  206. 'timestamp': 1449347075,
  207. 'duration': 743.0,
  208. 'view_count': 1120958,
  209. 'width': 1920,
  210. 'height': 1080,
  211. })
  212. def test_download_json(self):
  213. uri = encode_data_uri(b'{"foo": "blah"}', 'application/json')
  214. self.assertEqual(self.ie._download_json(uri, None), {'foo': 'blah'})
  215. uri = encode_data_uri(b'callback({"foo": "blah"})', 'application/javascript')
  216. self.assertEqual(self.ie._download_json(uri, None, transform_source=strip_jsonp), {'foo': 'blah'})
  217. uri = encode_data_uri(b'{"foo": invalid}', 'application/json')
  218. self.assertRaises(ExtractorError, self.ie._download_json, uri, None)
  219. self.assertEqual(self.ie._download_json(uri, None, fatal=False), None)
  220. def test_parse_html5_media_entries(self):
  221. # inline video tag
  222. expect_dict(
  223. self,
  224. self.ie._parse_html5_media_entries(
  225. 'https://127.0.0.1/video.html',
  226. r'<html><video src="/vid.mp4" /></html>', None)[0],
  227. {
  228. 'formats': [{
  229. 'url': 'https://127.0.0.1/vid.mp4',
  230. }],
  231. })
  232. # from https://www.r18.com/
  233. # with kpbs in label
  234. expect_dict(
  235. self,
  236. self.ie._parse_html5_media_entries(
  237. 'https://www.r18.com/',
  238. r'''
  239. <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">
  240. <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">
  241. <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">
  242. <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">
  243. <p>Your browser does not support the video tag.</p>
  244. </video>
  245. ''', None)[0],
  246. {
  247. 'formats': [{
  248. 'url': 'https://awscc3001.r18.com/litevideo/freepv/m/mgm/mgmr105/mgmr105_sm_w.mp4',
  249. 'ext': 'mp4',
  250. 'format_id': '300kbps',
  251. 'height': 240,
  252. 'tbr': 300,
  253. }, {
  254. 'url': 'https://awscc3001.r18.com/litevideo/freepv/m/mgm/mgmr105/mgmr105_dm_w.mp4',
  255. 'ext': 'mp4',
  256. 'format_id': '1000kbps',
  257. 'height': 480,
  258. 'tbr': 1000,
  259. }, {
  260. 'url': 'https://awscc3001.r18.com/litevideo/freepv/m/mgm/mgmr105/mgmr105_dmb_w.mp4',
  261. 'ext': 'mp4',
  262. 'format_id': '1500kbps',
  263. 'height': 740,
  264. 'tbr': 1500,
  265. }],
  266. 'thumbnail': '//pics.r18.com/digital/amateur/mgmr105/mgmr105jp.jpg'
  267. })
  268. # from https://www.csfd.cz/
  269. # with width and height
  270. expect_dict(
  271. self,
  272. self.ie._parse_html5_media_entries(
  273. 'https://www.csfd.cz/',
  274. r'''
  275. <video width="770" height="328" preload="none" controls poster="https://img.csfd.cz/files/images/film/video/preview/163/344/163344118_748d20.png?h360" >
  276. <source src="https://video.csfd.cz/files/videos/157/750/157750813/163327358_eac647.mp4" type="video/mp4" width="640" height="360">
  277. <source src="https://video.csfd.cz/files/videos/157/750/157750813/163327360_3d2646.mp4" type="video/mp4" width="1280" height="720">
  278. <source src="https://video.csfd.cz/files/videos/157/750/157750813/163327356_91f258.mp4" type="video/mp4" width="1920" height="1080">
  279. <source src="https://video.csfd.cz/files/videos/157/750/157750813/163327359_962b4a.webm" type="video/webm" width="640" height="360">
  280. <source src="https://video.csfd.cz/files/videos/157/750/157750813/163327361_6feee0.webm" type="video/webm" width="1280" height="720">
  281. <source src="https://video.csfd.cz/files/videos/157/750/157750813/163327357_8ab472.webm" type="video/webm" width="1920" height="1080">
  282. <track src="https://video.csfd.cz/files/subtitles/163/344/163344115_4c388b.srt" type="text/x-srt" kind="subtitles" srclang="cs" label="cs">
  283. </video>
  284. ''', None)[0],
  285. {
  286. 'formats': [{
  287. 'url': 'https://video.csfd.cz/files/videos/157/750/157750813/163327358_eac647.mp4',
  288. 'ext': 'mp4',
  289. 'width': 640,
  290. 'height': 360,
  291. }, {
  292. 'url': 'https://video.csfd.cz/files/videos/157/750/157750813/163327360_3d2646.mp4',
  293. 'ext': 'mp4',
  294. 'width': 1280,
  295. 'height': 720,
  296. }, {
  297. 'url': 'https://video.csfd.cz/files/videos/157/750/157750813/163327356_91f258.mp4',
  298. 'ext': 'mp4',
  299. 'width': 1920,
  300. 'height': 1080,
  301. }, {
  302. 'url': 'https://video.csfd.cz/files/videos/157/750/157750813/163327359_962b4a.webm',
  303. 'ext': 'webm',
  304. 'width': 640,
  305. 'height': 360,
  306. }, {
  307. 'url': 'https://video.csfd.cz/files/videos/157/750/157750813/163327361_6feee0.webm',
  308. 'ext': 'webm',
  309. 'width': 1280,
  310. 'height': 720,
  311. }, {
  312. 'url': 'https://video.csfd.cz/files/videos/157/750/157750813/163327357_8ab472.webm',
  313. 'ext': 'webm',
  314. 'width': 1920,
  315. 'height': 1080,
  316. }],
  317. 'subtitles': {
  318. 'cs': [{'url': 'https://video.csfd.cz/files/subtitles/163/344/163344115_4c388b.srt'}]
  319. },
  320. 'thumbnail': 'https://img.csfd.cz/files/images/film/video/preview/163/344/163344118_748d20.png?h360'
  321. })
  322. # from https://tamasha.com/v/Kkdjw
  323. # with height in label
  324. expect_dict(
  325. self,
  326. self.ie._parse_html5_media_entries(
  327. 'https://tamasha.com/v/Kkdjw',
  328. r'''
  329. <video crossorigin="anonymous">
  330. <source src="https://s-v2.tamasha.com/statics/videos_file/19/8f/Kkdjw_198feff8577d0057536e905cce1fb61438dd64e0_n_240.mp4" type="video/mp4" label="AUTO" res="0"/>
  331. <source src="https://s-v2.tamasha.com/statics/videos_file/19/8f/Kkdjw_198feff8577d0057536e905cce1fb61438dd64e0_n_240.mp4" type="video/mp4"
  332. label="240p" res="240"/>
  333. <source src="https://s-v2.tamasha.com/statics/videos_file/20/00/Kkdjw_200041c66f657fc967db464d156eafbc1ed9fe6f_n_144.mp4" type="video/mp4"
  334. label="144p" res="144"/>
  335. </video>
  336. ''', None)[0],
  337. {
  338. 'formats': [{
  339. 'url': 'https://s-v2.tamasha.com/statics/videos_file/19/8f/Kkdjw_198feff8577d0057536e905cce1fb61438dd64e0_n_240.mp4',
  340. }, {
  341. 'url': 'https://s-v2.tamasha.com/statics/videos_file/19/8f/Kkdjw_198feff8577d0057536e905cce1fb61438dd64e0_n_240.mp4',
  342. 'ext': 'mp4',
  343. 'format_id': '240p',
  344. 'height': 240,
  345. }, {
  346. 'url': 'https://s-v2.tamasha.com/statics/videos_file/20/00/Kkdjw_200041c66f657fc967db464d156eafbc1ed9fe6f_n_144.mp4',
  347. 'ext': 'mp4',
  348. 'format_id': '144p',
  349. 'height': 144,
  350. }]
  351. })
  352. # from https://www.directvnow.com
  353. # with data-src
  354. expect_dict(
  355. self,
  356. self.ie._parse_html5_media_entries(
  357. 'https://www.directvnow.com',
  358. r'''
  359. <video id="vid1" class="header--video-masked active" muted playsinline>
  360. <source data-src="https://cdn.directv.com/content/dam/dtv/prod/website_directvnow-international/videos/DTVN_hdr_HBO_v3.mp4" type="video/mp4" />
  361. </video>
  362. ''', None)[0],
  363. {
  364. 'formats': [{
  365. 'ext': 'mp4',
  366. 'url': 'https://cdn.directv.com/content/dam/dtv/prod/website_directvnow-international/videos/DTVN_hdr_HBO_v3.mp4',
  367. }]
  368. })
  369. # from https://www.directvnow.com
  370. # with data-src
  371. expect_dict(
  372. self,
  373. self.ie._parse_html5_media_entries(
  374. 'https://www.directvnow.com',
  375. r'''
  376. <video id="vid1" class="header--video-masked active" muted playsinline>
  377. <source data-src="https://cdn.directv.com/content/dam/dtv/prod/website_directvnow-international/videos/DTVN_hdr_HBO_v3.mp4" type="video/mp4" />
  378. </video>
  379. ''', None)[0],
  380. {
  381. 'formats': [{
  382. 'url': 'https://cdn.directv.com/content/dam/dtv/prod/website_directvnow-international/videos/DTVN_hdr_HBO_v3.mp4',
  383. 'ext': 'mp4',
  384. }]
  385. })
  386. # from https://www.klarna.com/uk/
  387. # with data-video-src
  388. expect_dict(
  389. self,
  390. self.ie._parse_html5_media_entries(
  391. 'https://www.directvnow.com',
  392. r'''
  393. <video loop autoplay muted class="responsive-video block-kl__video video-on-medium">
  394. <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" />
  395. </video>
  396. ''', None)[0],
  397. {
  398. 'formats': [{
  399. 'url': 'https://www.klarna.com/uk/wp-content/uploads/sites/11/2019/01/KL062_Smooth3_0_DogWalking_5s_920x080_.mp4',
  400. 'ext': 'mp4',
  401. }],
  402. })
  403. # from https://0000.studio/
  404. # with type attribute but without extension in URL
  405. expect_dict(
  406. self,
  407. self.ie._parse_html5_media_entries(
  408. 'https://0000.studio',
  409. r'''
  410. <video src="https://d1ggyt9m8pwf3g.cloudfront.net/protected/ap-northeast-1:1864af40-28d5-492b-b739-b32314b1a527/archive/clip/838db6a7-8973-4cd6-840d-8517e4093c92"
  411. controls="controls" type="video/mp4" preload="metadata" autoplay="autoplay" playsinline class="object-contain">
  412. </video>
  413. ''', None)[0],
  414. {
  415. 'formats': [{
  416. 'url': 'https://d1ggyt9m8pwf3g.cloudfront.net/protected/ap-northeast-1:1864af40-28d5-492b-b739-b32314b1a527/archive/clip/838db6a7-8973-4cd6-840d-8517e4093c92',
  417. 'ext': 'mp4',
  418. }],
  419. })
  420. def test_extract_jwplayer_data_realworld(self):
  421. # from http://www.suffolk.edu/sjc/
  422. expect_dict(
  423. self,
  424. self.ie._extract_jwplayer_data(r'''
  425. <script type='text/javascript'>
  426. jwplayer('my-video').setup({
  427. file: 'rtmp://192.138.214.154/live/sjclive',
  428. fallback: 'true',
  429. width: '95%',
  430. aspectratio: '16:9',
  431. primary: 'flash',
  432. mediaid:'XEgvuql4'
  433. });
  434. </script>
  435. ''', None, require_title=False),
  436. {
  437. 'id': 'XEgvuql4',
  438. 'formats': [{
  439. 'url': 'rtmp://192.138.214.154/live/sjclive',
  440. 'ext': 'flv'
  441. }]
  442. })
  443. # from https://www.pornoxo.com/videos/7564/striptease-from-sexy-secretary/
  444. expect_dict(
  445. self,
  446. self.ie._extract_jwplayer_data(r'''
  447. <script type="text/javascript">
  448. jwplayer("mediaplayer").setup({
  449. 'videoid': "7564",
  450. 'width': "100%",
  451. 'aspectratio': "16:9",
  452. 'stretching': "exactfit",
  453. 'autostart': 'false',
  454. 'flashplayer': "https://t04.vipstreamservice.com/jwplayer/v5.10/player.swf",
  455. '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",
  456. 'image': "https://t03.vipstreamservice.com/thumbs/pxo-full/2009-12/14/a4b2157147afe5efa93ce1978e0265289c193874e02597.flv-full-13.jpg",
  457. '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",
  458. 'logo.hide': true,
  459. 'skin': "https://t04.vipstreamservice.com/jwplayer/skin/modieus-blk.zip",
  460. 'plugins': "https://t04.vipstreamservice.com/jwplayer/dock/dockableskinnableplugin.swf",
  461. 'dockableskinnableplugin.piclink': "/index.php?key=ajax-videothumbsn&vid=7564&data=2009-12--14--4b2157147afe5efa93ce1978e0265289c193874e02597.flv--17370",
  462. 'controlbar': 'bottom',
  463. 'modes': [
  464. {type: 'flash', src: 'https://t04.vipstreamservice.com/jwplayer/v5.10/player.swf'}
  465. ],
  466. 'provider': 'http'
  467. });
  468. //noinspection JSAnnotator
  469. invideo.setup({
  470. adsUrl: "/banner-iframe/?zoneId=32",
  471. adsUrl2: "",
  472. autostart: false
  473. });
  474. </script>
  475. ''', 'dummy', require_title=False),
  476. {
  477. 'thumbnail': 'https://t03.vipstreamservice.com/thumbs/pxo-full/2009-12/14/a4b2157147afe5efa93ce1978e0265289c193874e02597.flv-full-13.jpg',
  478. 'formats': [{
  479. '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',
  480. 'ext': 'flv'
  481. }]
  482. })
  483. # from http://www.indiedb.com/games/king-machine/videos
  484. expect_dict(
  485. self,
  486. self.ie._extract_jwplayer_data(r'''
  487. <script>
  488. 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) {
  489. videoAnalytics("play");
  490. }).once("complete", function(event) {
  491. videoAnalytics("completed");
  492. });
  493. </script>
  494. ''', 'dummy'),
  495. {
  496. 'title': 'king machine trailer 1',
  497. 'thumbnail': 'http://media.indiedb.com/cache/images/games/1/50/49678/thumb_620x2000/king-machine-trailer.mp4.jpg',
  498. 'formats': [{
  499. 'url': 'http://cdn.dbolical.com/cache/videos/games/1/50/49678/encode_mp4/king-machine-trailer.mp4',
  500. 'height': 360,
  501. 'ext': 'mp4'
  502. }, {
  503. 'url': 'http://cdn.dbolical.com/cache/videos/games/1/50/49678/encode720p_mp4/king-machine-trailer.mp4',
  504. 'height': 720,
  505. 'ext': 'mp4'
  506. }]
  507. })
  508. def test_parse_m3u8_formats(self):
  509. _TEST_CASES = [
  510. (
  511. # https://github.com/ytdl-org/youtube-dl/issues/11507
  512. # http://pluzz.francetv.fr/videos/le_ministere.html
  513. 'pluzz_francetv_11507',
  514. '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',
  515. [{
  516. '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',
  517. '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',
  518. 'ext': 'mp4',
  519. 'format_id': '180',
  520. 'protocol': 'm3u8',
  521. 'acodec': 'mp4a.40.2',
  522. 'vcodec': 'avc1.66.30',
  523. 'tbr': 180,
  524. 'width': 256,
  525. 'height': 144,
  526. }, {
  527. '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',
  528. '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',
  529. 'ext': 'mp4',
  530. 'format_id': '303',
  531. 'protocol': 'm3u8',
  532. 'acodec': 'mp4a.40.2',
  533. 'vcodec': 'avc1.66.30',
  534. 'tbr': 303,
  535. 'width': 320,
  536. 'height': 180,
  537. }, {
  538. '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',
  539. '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',
  540. 'ext': 'mp4',
  541. 'format_id': '575',
  542. 'protocol': 'm3u8',
  543. 'acodec': 'mp4a.40.2',
  544. 'vcodec': 'avc1.66.30',
  545. 'tbr': 575,
  546. 'width': 512,
  547. 'height': 288,
  548. }, {
  549. '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',
  550. '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',
  551. 'ext': 'mp4',
  552. 'format_id': '831',
  553. 'protocol': 'm3u8',
  554. 'acodec': 'mp4a.40.2',
  555. 'vcodec': 'avc1.77.30',
  556. 'tbr': 831,
  557. 'width': 704,
  558. 'height': 396,
  559. }, {
  560. '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',
  561. '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',
  562. 'ext': 'mp4',
  563. 'protocol': 'm3u8',
  564. 'format_id': '1467',
  565. 'acodec': 'mp4a.40.2',
  566. 'vcodec': 'avc1.77.30',
  567. 'tbr': 1467,
  568. 'width': 1024,
  569. 'height': 576,
  570. }]
  571. ),
  572. (
  573. # https://github.com/ytdl-org/youtube-dl/issues/11995
  574. # http://teamcoco.com/video/clueless-gamer-super-bowl-for-honor
  575. 'teamcoco_11995',
  576. 'http://ak.storage-w.teamcococdn.com/cdn/2017-02/98599/ed8f/main.m3u8',
  577. [{
  578. 'url': 'http://ak.storage-w.teamcococdn.com/cdn/2017-02/98599/ed8f/hls/CONAN_020217_Highlight_show-audio-160k_v4.m3u8',
  579. 'manifest_url': 'http://ak.storage-w.teamcococdn.com/cdn/2017-02/98599/ed8f/main.m3u8',
  580. 'ext': 'mp4',
  581. 'format_id': 'audio-0-Default',
  582. 'protocol': 'm3u8',
  583. 'vcodec': 'none',
  584. }, {
  585. 'url': 'http://ak.storage-w.teamcococdn.com/cdn/2017-02/98599/ed8f/hls/CONAN_020217_Highlight_show-audio-64k_v4.m3u8',
  586. 'manifest_url': 'http://ak.storage-w.teamcococdn.com/cdn/2017-02/98599/ed8f/main.m3u8',
  587. 'ext': 'mp4',
  588. 'format_id': 'audio-1-Default',
  589. 'protocol': 'm3u8',
  590. 'vcodec': 'none',
  591. }, {
  592. 'url': 'http://ak.storage-w.teamcococdn.com/cdn/2017-02/98599/ed8f/hls/CONAN_020217_Highlight_show-audio-64k_v4.m3u8',
  593. 'manifest_url': 'http://ak.storage-w.teamcococdn.com/cdn/2017-02/98599/ed8f/main.m3u8',
  594. 'ext': 'mp4',
  595. 'format_id': '71',
  596. 'protocol': 'm3u8',
  597. 'acodec': 'mp4a.40.5',
  598. 'vcodec': 'none',
  599. 'tbr': 71,
  600. }, {
  601. 'url': 'http://ak.storage-w.teamcococdn.com/cdn/2017-02/98599/ed8f/hls/CONAN_020217_Highlight_show-400k_v4.m3u8',
  602. 'manifest_url': 'http://ak.storage-w.teamcococdn.com/cdn/2017-02/98599/ed8f/main.m3u8',
  603. 'ext': 'mp4',
  604. 'format_id': '413',
  605. 'protocol': 'm3u8',
  606. 'acodec': 'none',
  607. 'vcodec': 'avc1.42001e',
  608. 'tbr': 413,
  609. 'width': 400,
  610. 'height': 224,
  611. }, {
  612. 'url': 'http://ak.storage-w.teamcococdn.com/cdn/2017-02/98599/ed8f/hls/CONAN_020217_Highlight_show-400k_v4.m3u8',
  613. 'manifest_url': 'http://ak.storage-w.teamcococdn.com/cdn/2017-02/98599/ed8f/main.m3u8',
  614. 'ext': 'mp4',
  615. 'format_id': '522',
  616. 'protocol': 'm3u8',
  617. 'acodec': 'none',
  618. 'vcodec': 'avc1.42001e',
  619. 'tbr': 522,
  620. 'width': 400,
  621. 'height': 224,
  622. }, {
  623. 'url': 'http://ak.storage-w.teamcococdn.com/cdn/2017-02/98599/ed8f/hls/CONAN_020217_Highlight_show-1m_v4.m3u8',
  624. 'manifest_url': 'http://ak.storage-w.teamcococdn.com/cdn/2017-02/98599/ed8f/main.m3u8',
  625. 'ext': 'mp4',
  626. 'format_id': '1205',
  627. 'protocol': 'm3u8',
  628. 'acodec': 'none',
  629. 'vcodec': 'avc1.4d001e',
  630. 'tbr': 1205,
  631. 'width': 640,
  632. 'height': 360,
  633. }, {
  634. 'url': 'http://ak.storage-w.teamcococdn.com/cdn/2017-02/98599/ed8f/hls/CONAN_020217_Highlight_show-2m_v4.m3u8',
  635. 'manifest_url': 'http://ak.storage-w.teamcococdn.com/cdn/2017-02/98599/ed8f/main.m3u8',
  636. 'ext': 'mp4',
  637. 'format_id': '2374',
  638. 'protocol': 'm3u8',
  639. 'acodec': 'none',
  640. 'vcodec': 'avc1.4d001f',
  641. 'tbr': 2374,
  642. 'width': 1024,
  643. 'height': 576,
  644. }]
  645. ),
  646. (
  647. # https://github.com/ytdl-org/youtube-dl/issues/12211
  648. # http://video.toggle.sg/en/series/whoopie-s-world/ep3/478601
  649. 'toggle_mobile_12211',
  650. 'http://cdnapi.kaltura.com/p/2082311/sp/208231100/playManifest/protocol/http/entryId/0_89q6e8ku/format/applehttp/tags/mobile_sd/f/a.m3u8',
  651. [{
  652. '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',
  653. 'manifest_url': 'http://cdnapi.kaltura.com/p/2082311/sp/208231100/playManifest/protocol/http/entryId/0_89q6e8ku/format/applehttp/tags/mobile_sd/f/a.m3u8',
  654. 'ext': 'mp4',
  655. 'format_id': 'audio-English',
  656. 'protocol': 'm3u8',
  657. 'language': 'eng',
  658. 'vcodec': 'none',
  659. }, {
  660. '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',
  661. 'manifest_url': 'http://cdnapi.kaltura.com/p/2082311/sp/208231100/playManifest/protocol/http/entryId/0_89q6e8ku/format/applehttp/tags/mobile_sd/f/a.m3u8',
  662. 'ext': 'mp4',
  663. 'format_id': 'audio-Undefined',
  664. 'protocol': 'm3u8',
  665. 'language': 'und',
  666. 'vcodec': 'none',
  667. }, {
  668. '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',
  669. 'manifest_url': 'http://cdnapi.kaltura.com/p/2082311/sp/208231100/playManifest/protocol/http/entryId/0_89q6e8ku/format/applehttp/tags/mobile_sd/f/a.m3u8',
  670. 'ext': 'mp4',
  671. 'format_id': '155',
  672. 'protocol': 'm3u8',
  673. 'tbr': 155.648,
  674. 'width': 320,
  675. 'height': 180,
  676. }, {
  677. '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',
  678. 'manifest_url': 'http://cdnapi.kaltura.com/p/2082311/sp/208231100/playManifest/protocol/http/entryId/0_89q6e8ku/format/applehttp/tags/mobile_sd/f/a.m3u8',
  679. 'ext': 'mp4',
  680. 'format_id': '502',
  681. 'protocol': 'm3u8',
  682. 'tbr': 502.784,
  683. 'width': 480,
  684. 'height': 270,
  685. }, {
  686. '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',
  687. 'manifest_url': 'http://cdnapi.kaltura.com/p/2082311/sp/208231100/playManifest/protocol/http/entryId/0_89q6e8ku/format/applehttp/tags/mobile_sd/f/a.m3u8',
  688. 'ext': 'mp4',
  689. 'format_id': '827',
  690. 'protocol': 'm3u8',
  691. 'tbr': 827.392,
  692. 'width': 640,
  693. 'height': 360,
  694. }, {
  695. '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',
  696. 'manifest_url': 'http://cdnapi.kaltura.com/p/2082311/sp/208231100/playManifest/protocol/http/entryId/0_89q6e8ku/format/applehttp/tags/mobile_sd/f/a.m3u8',
  697. 'ext': 'mp4',
  698. 'format_id': '1396',
  699. 'protocol': 'm3u8',
  700. 'tbr': 1396.736,
  701. 'width': 854,
  702. 'height': 480,
  703. }]
  704. ),
  705. (
  706. # http://www.twitch.tv/riotgames/v/6528877
  707. 'twitch_vod',
  708. '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',
  709. [{
  710. 'url': 'https://vod.edgecast.hls.ttvnw.net/e5da31ab49_riotgames_15001215120_261543898/audio_only/index-muted-HM49I092CC.m3u8',
  711. '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',
  712. 'ext': 'mp4',
  713. 'format_id': 'Audio Only',
  714. 'protocol': 'm3u8',
  715. 'acodec': 'mp4a.40.2',
  716. 'vcodec': 'none',
  717. 'tbr': 182.725,
  718. }, {
  719. 'url': 'https://vod.edgecast.hls.ttvnw.net/e5da31ab49_riotgames_15001215120_261543898/mobile/index-muted-HM49I092CC.m3u8',
  720. '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',
  721. 'ext': 'mp4',
  722. 'format_id': 'Mobile',
  723. 'protocol': 'm3u8',
  724. 'acodec': 'mp4a.40.2',
  725. 'vcodec': 'avc1.42C00D',
  726. 'tbr': 280.474,
  727. 'width': 400,
  728. 'height': 226,
  729. }, {
  730. 'url': 'https://vod.edgecast.hls.ttvnw.net/e5da31ab49_riotgames_15001215120_261543898/low/index-muted-HM49I092CC.m3u8',
  731. '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',
  732. 'ext': 'mp4',
  733. 'format_id': 'Low',
  734. 'protocol': 'm3u8',
  735. 'acodec': 'mp4a.40.2',
  736. 'vcodec': 'avc1.42C01E',
  737. 'tbr': 628.347,
  738. 'width': 640,
  739. 'height': 360,
  740. }, {
  741. 'url': 'https://vod.edgecast.hls.ttvnw.net/e5da31ab49_riotgames_15001215120_261543898/medium/index-muted-HM49I092CC.m3u8',
  742. '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',
  743. 'ext': 'mp4',
  744. 'format_id': 'Medium',
  745. 'protocol': 'm3u8',
  746. 'acodec': 'mp4a.40.2',
  747. 'vcodec': 'avc1.42C01E',
  748. 'tbr': 893.387,
  749. 'width': 852,
  750. 'height': 480,
  751. }, {
  752. 'url': 'https://vod.edgecast.hls.ttvnw.net/e5da31ab49_riotgames_15001215120_261543898/high/index-muted-HM49I092CC.m3u8',
  753. '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',
  754. 'ext': 'mp4',
  755. 'format_id': 'High',
  756. 'protocol': 'm3u8',
  757. 'acodec': 'mp4a.40.2',
  758. 'vcodec': 'avc1.42C01F',
  759. 'tbr': 1603.789,
  760. 'width': 1280,
  761. 'height': 720,
  762. }, {
  763. 'url': 'https://vod.edgecast.hls.ttvnw.net/e5da31ab49_riotgames_15001215120_261543898/chunked/index-muted-HM49I092CC.m3u8',
  764. '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',
  765. 'ext': 'mp4',
  766. 'format_id': 'Source',
  767. 'protocol': 'm3u8',
  768. 'acodec': 'mp4a.40.2',
  769. 'vcodec': 'avc1.100.31',
  770. 'tbr': 3214.134,
  771. 'width': 1280,
  772. 'height': 720,
  773. }]
  774. ),
  775. (
  776. # http://www.vidio.com/watch/165683-dj_ambred-booyah-live-2015
  777. # EXT-X-STREAM-INF tag with NAME attribute that is not defined
  778. # in HLS specification
  779. 'vidio',
  780. 'https://www.vidio.com/videos/165683/playlist.m3u8',
  781. [{
  782. 'url': 'https://cdn1-a.production.vidio.static6.com/uploads/165683/dj_ambred-4383-b300.mp4.m3u8',
  783. 'manifest_url': 'https://www.vidio.com/videos/165683/playlist.m3u8',
  784. 'ext': 'mp4',
  785. 'format_id': '270p 3G',
  786. 'protocol': 'm3u8',
  787. 'tbr': 300,
  788. 'width': 480,
  789. 'height': 270,
  790. }, {
  791. 'url': 'https://cdn1-a.production.vidio.static6.com/uploads/165683/dj_ambred-4383-b600.mp4.m3u8',
  792. 'manifest_url': 'https://www.vidio.com/videos/165683/playlist.m3u8',
  793. 'ext': 'mp4',
  794. 'format_id': '360p SD',
  795. 'protocol': 'm3u8',
  796. 'tbr': 600,
  797. 'width': 640,
  798. 'height': 360,
  799. }, {
  800. 'url': 'https://cdn1-a.production.vidio.static6.com/uploads/165683/dj_ambred-4383-b1200.mp4.m3u8',
  801. 'manifest_url': 'https://www.vidio.com/videos/165683/playlist.m3u8',
  802. 'ext': 'mp4',
  803. 'format_id': '720p HD',
  804. 'protocol': 'm3u8',
  805. 'tbr': 1200,
  806. 'width': 1280,
  807. 'height': 720,
  808. }]
  809. ),
  810. (
  811. # https://github.com/ytdl-org/youtube-dl/issues/18923
  812. # https://www.ted.com/talks/boris_hesser_a_grassroots_healthcare_revolution_in_africa
  813. 'ted_18923',
  814. 'http://hls.ted.com/talks/31241.m3u8',
  815. [{
  816. 'url': 'http://hls.ted.com/videos/BorisHesser_2018S/audio/600k.m3u8?nobumpers=true&uniqueId=76011e2b',
  817. 'format_id': '600k-Audio',
  818. 'vcodec': 'none',
  819. }, {
  820. 'url': 'http://hls.ted.com/videos/BorisHesser_2018S/audio/600k.m3u8?nobumpers=true&uniqueId=76011e2b',
  821. 'format_id': '68',
  822. 'vcodec': 'none',
  823. }, {
  824. 'url': 'http://hls.ted.com/videos/BorisHesser_2018S/video/64k.m3u8?nobumpers=true&uniqueId=76011e2b',
  825. 'format_id': '163',
  826. 'acodec': 'none',
  827. 'width': 320,
  828. 'height': 180,
  829. }, {
  830. 'url': 'http://hls.ted.com/videos/BorisHesser_2018S/video/180k.m3u8?nobumpers=true&uniqueId=76011e2b',
  831. 'format_id': '481',
  832. 'acodec': 'none',
  833. 'width': 512,
  834. 'height': 288,
  835. }, {
  836. 'url': 'http://hls.ted.com/videos/BorisHesser_2018S/video/320k.m3u8?nobumpers=true&uniqueId=76011e2b',
  837. 'format_id': '769',
  838. 'acodec': 'none',
  839. 'width': 512,
  840. 'height': 288,
  841. }, {
  842. 'url': 'http://hls.ted.com/videos/BorisHesser_2018S/video/450k.m3u8?nobumpers=true&uniqueId=76011e2b',
  843. 'format_id': '984',
  844. 'acodec': 'none',
  845. 'width': 512,
  846. 'height': 288,
  847. }, {
  848. 'url': 'http://hls.ted.com/videos/BorisHesser_2018S/video/600k.m3u8?nobumpers=true&uniqueId=76011e2b',
  849. 'format_id': '1255',
  850. 'acodec': 'none',
  851. 'width': 640,
  852. 'height': 360,
  853. }, {
  854. 'url': 'http://hls.ted.com/videos/BorisHesser_2018S/video/950k.m3u8?nobumpers=true&uniqueId=76011e2b',
  855. 'format_id': '1693',
  856. 'acodec': 'none',
  857. 'width': 853,
  858. 'height': 480,
  859. }, {
  860. 'url': 'http://hls.ted.com/videos/BorisHesser_2018S/video/1500k.m3u8?nobumpers=true&uniqueId=76011e2b',
  861. 'format_id': '2462',
  862. 'acodec': 'none',
  863. 'width': 1280,
  864. 'height': 720,
  865. }]
  866. ),
  867. ]
  868. for m3u8_file, m3u8_url, expected_formats in _TEST_CASES:
  869. with open('./test/testdata/m3u8/%s.m3u8' % m3u8_file,
  870. mode='r', encoding='utf-8') as f:
  871. formats = self.ie._parse_m3u8_formats(
  872. f.read(), m3u8_url, ext='mp4')
  873. self.ie._sort_formats(formats)
  874. expect_value(self, formats, expected_formats, None)
  875. def test_parse_mpd_formats(self):
  876. _TEST_CASES = [
  877. (
  878. # https://github.com/ytdl-org/youtube-dl/issues/13919
  879. # Also tests duplicate representation ids, see
  880. # https://github.com/ytdl-org/youtube-dl/issues/15111
  881. 'float_duration',
  882. 'http://unknown/manifest.mpd', # mpd_url
  883. None, # mpd_base_url
  884. [{
  885. 'manifest_url': 'http://unknown/manifest.mpd',
  886. 'ext': 'm4a',
  887. 'format_id': '318597',
  888. 'format_note': 'DASH audio',
  889. 'protocol': 'http_dash_segments',
  890. 'acodec': 'mp4a.40.2',
  891. 'vcodec': 'none',
  892. 'tbr': 61.587,
  893. }, {
  894. 'manifest_url': 'http://unknown/manifest.mpd',
  895. 'ext': 'mp4',
  896. 'format_id': '318597',
  897. 'format_note': 'DASH video',
  898. 'protocol': 'http_dash_segments',
  899. 'acodec': 'none',
  900. 'vcodec': 'avc1.42001f',
  901. 'tbr': 318.597,
  902. 'width': 340,
  903. 'height': 192,
  904. }, {
  905. 'manifest_url': 'http://unknown/manifest.mpd',
  906. 'ext': 'mp4',
  907. 'format_id': '638590',
  908. 'format_note': 'DASH video',
  909. 'protocol': 'http_dash_segments',
  910. 'acodec': 'none',
  911. 'vcodec': 'avc1.42001f',
  912. 'tbr': 638.59,
  913. 'width': 512,
  914. 'height': 288,
  915. }, {
  916. 'manifest_url': 'http://unknown/manifest.mpd',
  917. 'ext': 'mp4',
  918. 'format_id': '1022565',
  919. 'format_note': 'DASH video',
  920. 'protocol': 'http_dash_segments',
  921. 'acodec': 'none',
  922. 'vcodec': 'avc1.4d001f',
  923. 'tbr': 1022.565,
  924. 'width': 688,
  925. 'height': 384,
  926. }, {
  927. 'manifest_url': 'http://unknown/manifest.mpd',
  928. 'ext': 'mp4',
  929. 'format_id': '2046506',
  930. 'format_note': 'DASH video',
  931. 'protocol': 'http_dash_segments',
  932. 'acodec': 'none',
  933. 'vcodec': 'avc1.4d001f',
  934. 'tbr': 2046.506,
  935. 'width': 1024,
  936. 'height': 576,
  937. }, {
  938. 'manifest_url': 'http://unknown/manifest.mpd',
  939. 'ext': 'mp4',
  940. 'format_id': '3998017',
  941. 'format_note': 'DASH video',
  942. 'protocol': 'http_dash_segments',
  943. 'acodec': 'none',
  944. 'vcodec': 'avc1.640029',
  945. 'tbr': 3998.017,
  946. 'width': 1280,
  947. 'height': 720,
  948. }, {
  949. 'manifest_url': 'http://unknown/manifest.mpd',
  950. 'ext': 'mp4',
  951. 'format_id': '5997485',
  952. 'format_note': 'DASH video',
  953. 'protocol': 'http_dash_segments',
  954. 'acodec': 'none',
  955. 'vcodec': 'avc1.640032',
  956. 'tbr': 5997.485,
  957. 'width': 1920,
  958. 'height': 1080,
  959. }],
  960. {},
  961. ), (
  962. # https://github.com/ytdl-org/youtube-dl/pull/14844
  963. 'urls_only',
  964. 'http://unknown/manifest.mpd', # mpd_url
  965. None, # mpd_base_url
  966. [{
  967. 'manifest_url': 'http://unknown/manifest.mpd',
  968. 'ext': 'mp4',
  969. 'format_id': 'h264_aac_144p_m4s',
  970. 'format_note': 'DASH video',
  971. 'protocol': 'http_dash_segments',
  972. 'acodec': 'mp4a.40.2',
  973. 'vcodec': 'avc3.42c01e',
  974. 'tbr': 200,
  975. 'width': 256,
  976. 'height': 144,
  977. }, {
  978. 'manifest_url': 'http://unknown/manifest.mpd',
  979. 'ext': 'mp4',
  980. 'format_id': 'h264_aac_240p_m4s',
  981. 'format_note': 'DASH video',
  982. 'protocol': 'http_dash_segments',
  983. 'acodec': 'mp4a.40.2',
  984. 'vcodec': 'avc3.42c01e',
  985. 'tbr': 400,
  986. 'width': 424,
  987. 'height': 240,
  988. }, {
  989. 'manifest_url': 'http://unknown/manifest.mpd',
  990. 'ext': 'mp4',
  991. 'format_id': 'h264_aac_360p_m4s',
  992. 'format_note': 'DASH video',
  993. 'protocol': 'http_dash_segments',
  994. 'acodec': 'mp4a.40.2',
  995. 'vcodec': 'avc3.42c01e',
  996. 'tbr': 800,
  997. 'width': 640,
  998. 'height': 360,
  999. }, {
  1000. 'manifest_url': 'http://unknown/manifest.mpd',
  1001. 'ext': 'mp4',
  1002. 'format_id': 'h264_aac_480p_m4s',
  1003. 'format_note': 'DASH video',
  1004. 'protocol': 'http_dash_segments',
  1005. 'acodec': 'mp4a.40.2',
  1006. 'vcodec': 'avc3.42c01e',
  1007. 'tbr': 1200,
  1008. 'width': 856,
  1009. 'height': 480,
  1010. }, {
  1011. 'manifest_url': 'http://unknown/manifest.mpd',
  1012. 'ext': 'mp4',
  1013. 'format_id': 'h264_aac_576p_m4s',
  1014. 'format_note': 'DASH video',
  1015. 'protocol': 'http_dash_segments',
  1016. 'acodec': 'mp4a.40.2',
  1017. 'vcodec': 'avc3.42c01e',
  1018. 'tbr': 1600,
  1019. 'width': 1024,
  1020. 'height': 576,
  1021. }, {
  1022. 'manifest_url': 'http://unknown/manifest.mpd',
  1023. 'ext': 'mp4',
  1024. 'format_id': 'h264_aac_720p_m4s',
  1025. 'format_note': 'DASH video',
  1026. 'protocol': 'http_dash_segments',
  1027. 'acodec': 'mp4a.40.2',
  1028. 'vcodec': 'avc3.42c01e',
  1029. 'tbr': 2400,
  1030. 'width': 1280,
  1031. 'height': 720,
  1032. }, {
  1033. 'manifest_url': 'http://unknown/manifest.mpd',
  1034. 'ext': 'mp4',
  1035. 'format_id': 'h264_aac_1080p_m4s',
  1036. 'format_note': 'DASH video',
  1037. 'protocol': 'http_dash_segments',
  1038. 'acodec': 'mp4a.40.2',
  1039. 'vcodec': 'avc3.42c01e',
  1040. 'tbr': 4400,
  1041. 'width': 1920,
  1042. 'height': 1080,
  1043. }],
  1044. {},
  1045. ), (
  1046. # https://github.com/ytdl-org/youtube-dl/issues/20346
  1047. # Media considered unfragmented even though it contains
  1048. # Initialization tag
  1049. 'unfragmented',
  1050. 'https://v.redd.it/hw1x7rcg7zl21/DASHPlaylist.mpd', # mpd_url
  1051. 'https://v.redd.it/hw1x7rcg7zl21', # mpd_base_url
  1052. [{
  1053. 'url': 'https://v.redd.it/hw1x7rcg7zl21/audio',
  1054. 'manifest_url': 'https://v.redd.it/hw1x7rcg7zl21/DASHPlaylist.mpd',
  1055. 'ext': 'm4a',
  1056. 'format_id': 'AUDIO-1',
  1057. 'format_note': 'DASH audio',
  1058. 'container': 'm4a_dash',
  1059. 'acodec': 'mp4a.40.2',
  1060. 'vcodec': 'none',
  1061. 'tbr': 129.87,
  1062. 'asr': 48000,
  1063. }, {
  1064. 'url': 'https://v.redd.it/hw1x7rcg7zl21/DASH_240',
  1065. 'manifest_url': 'https://v.redd.it/hw1x7rcg7zl21/DASHPlaylist.mpd',
  1066. 'ext': 'mp4',
  1067. 'format_id': 'VIDEO-2',
  1068. 'format_note': 'DASH video',
  1069. 'container': 'mp4_dash',
  1070. 'acodec': 'none',
  1071. 'vcodec': 'avc1.4d401e',
  1072. 'tbr': 608.0,
  1073. 'width': 240,
  1074. 'height': 240,
  1075. 'fps': 30,
  1076. }, {
  1077. 'url': 'https://v.redd.it/hw1x7rcg7zl21/DASH_360',
  1078. 'manifest_url': 'https://v.redd.it/hw1x7rcg7zl21/DASHPlaylist.mpd',
  1079. 'ext': 'mp4',
  1080. 'format_id': 'VIDEO-1',
  1081. 'format_note': 'DASH video',
  1082. 'container': 'mp4_dash',
  1083. 'acodec': 'none',
  1084. 'vcodec': 'avc1.4d401e',
  1085. 'tbr': 804.261,
  1086. 'width': 360,
  1087. 'height': 360,
  1088. 'fps': 30,
  1089. }],
  1090. {},
  1091. ), (
  1092. # https://github.com/ytdl-org/youtube-dl/issues/30235
  1093. # Bento4 generated test mpd
  1094. # mp4dash --mpd-name=manifest.mpd --no-split --use-segment-list mediafiles
  1095. 'url_and_range',
  1096. 'http://unknown/manifest.mpd', # mpd_url
  1097. 'http://unknown/', # mpd_base_url
  1098. [{
  1099. 'manifest_url': 'http://unknown/manifest.mpd',
  1100. 'fragment_base_url': 'http://unknown/',
  1101. 'ext': 'm4a',
  1102. 'format_id': 'audio-und-mp4a.40.2',
  1103. 'format_note': 'DASH audio',
  1104. 'container': 'm4a_dash',
  1105. 'protocol': 'http_dash_segments',
  1106. 'acodec': 'mp4a.40.2',
  1107. 'vcodec': 'none',
  1108. 'tbr': 98.808,
  1109. }, {
  1110. 'manifest_url': 'http://unknown/manifest.mpd',
  1111. 'fragment_base_url': 'http://unknown/',
  1112. 'ext': 'mp4',
  1113. 'format_id': 'video-avc1',
  1114. 'format_note': 'DASH video',
  1115. 'container': 'mp4_dash',
  1116. 'protocol': 'http_dash_segments',
  1117. 'acodec': 'none',
  1118. 'vcodec': 'avc1.4D401E',
  1119. 'tbr': 699.597,
  1120. 'width': 768,
  1121. 'height': 432
  1122. }],
  1123. {},
  1124. ), (
  1125. # https://github.com/ytdl-org/youtube-dl/issues/27575
  1126. # GPAC generated test mpd
  1127. # MP4Box -dash 10000 -single-file -out manifest.mpd mediafiles
  1128. 'range_only',
  1129. 'http://unknown/manifest.mpd', # mpd_url
  1130. 'http://unknown/', # mpd_base_url
  1131. [{
  1132. 'manifest_url': 'http://unknown/manifest.mpd',
  1133. 'fragment_base_url': 'http://unknown/audio_dashinit.mp4',
  1134. 'ext': 'm4a',
  1135. 'format_id': '2',
  1136. 'format_note': 'DASH audio',
  1137. 'container': 'm4a_dash',
  1138. 'protocol': 'http_dash_segments',
  1139. 'acodec': 'mp4a.40.2',
  1140. 'vcodec': 'none',
  1141. 'tbr': 98.096,
  1142. }, {
  1143. 'manifest_url': 'http://unknown/manifest.mpd',
  1144. 'fragment_base_url': 'http://unknown/video_dashinit.mp4',
  1145. 'ext': 'mp4',
  1146. 'format_id': '1',
  1147. 'format_note': 'DASH video',
  1148. 'container': 'mp4_dash',
  1149. 'protocol': 'http_dash_segments',
  1150. 'acodec': 'none',
  1151. 'vcodec': 'avc1.4D401E',
  1152. 'tbr': 526.987,
  1153. 'width': 768,
  1154. 'height': 432
  1155. }],
  1156. {},
  1157. ), (
  1158. 'subtitles',
  1159. 'https://sdn-global-streaming-cache-3qsdn.akamaized.net/stream/3144/files/17/07/672975/3144-kZT4LWMQw6Rh7Kpd.ism/manifest.mpd',
  1160. 'https://sdn-global-streaming-cache-3qsdn.akamaized.net/stream/3144/files/17/07/672975/3144-kZT4LWMQw6Rh7Kpd.ism/',
  1161. [{
  1162. 'format_id': 'audio=128001',
  1163. 'manifest_url': 'https://sdn-global-streaming-cache-3qsdn.akamaized.net/stream/3144/files/17/07/672975/3144-kZT4LWMQw6Rh7Kpd.ism/manifest.mpd',
  1164. 'ext': 'm4a',
  1165. 'tbr': 128.001,
  1166. 'asr': 48000,
  1167. 'format_note': 'DASH audio',
  1168. 'container': 'm4a_dash',
  1169. 'vcodec': 'none',
  1170. 'acodec': 'mp4a.40.2',
  1171. 'url': 'https://sdn-global-streaming-cache-3qsdn.akamaized.net/stream/3144/files/17/07/672975/3144-kZT4LWMQw6Rh7Kpd.ism/manifest.mpd',
  1172. 'fragment_base_url': 'https://sdn-global-streaming-cache-3qsdn.akamaized.net/stream/3144/files/17/07/672975/3144-kZT4LWMQw6Rh7Kpd.ism/dash/',
  1173. 'protocol': 'http_dash_segments',
  1174. }, {
  1175. 'format_id': 'video=100000',
  1176. 'manifest_url': 'https://sdn-global-streaming-cache-3qsdn.akamaized.net/stream/3144/files/17/07/672975/3144-kZT4LWMQw6Rh7Kpd.ism/manifest.mpd',
  1177. 'ext': 'mp4',
  1178. 'width': 336,
  1179. 'height': 144,
  1180. 'tbr': 100,
  1181. 'format_note': 'DASH video',
  1182. 'container': 'mp4_dash',
  1183. 'vcodec': 'avc1.4D401F',
  1184. 'acodec': 'none',
  1185. 'url': 'https://sdn-global-streaming-cache-3qsdn.akamaized.net/stream/3144/files/17/07/672975/3144-kZT4LWMQw6Rh7Kpd.ism/manifest.mpd',
  1186. 'fragment_base_url': 'https://sdn-global-streaming-cache-3qsdn.akamaized.net/stream/3144/files/17/07/672975/3144-kZT4LWMQw6Rh7Kpd.ism/dash/',
  1187. 'protocol': 'http_dash_segments',
  1188. }, {
  1189. 'format_id': 'video=326000',
  1190. 'manifest_url': 'https://sdn-global-streaming-cache-3qsdn.akamaized.net/stream/3144/files/17/07/672975/3144-kZT4LWMQw6Rh7Kpd.ism/manifest.mpd',
  1191. 'ext': 'mp4',
  1192. 'width': 562,
  1193. 'height': 240,
  1194. 'tbr': 326,
  1195. 'format_note': 'DASH video',
  1196. 'container': 'mp4_dash',
  1197. 'vcodec': 'avc1.4D401F',
  1198. 'acodec': 'none',
  1199. 'url': 'https://sdn-global-streaming-cache-3qsdn.akamaized.net/stream/3144/files/17/07/672975/3144-kZT4LWMQw6Rh7Kpd.ism/manifest.mpd',
  1200. 'fragment_base_url': 'https://sdn-global-streaming-cache-3qsdn.akamaized.net/stream/3144/files/17/07/672975/3144-kZT4LWMQw6Rh7Kpd.ism/dash/',
  1201. 'protocol': 'http_dash_segments',
  1202. }, {
  1203. 'format_id': 'video=698000',
  1204. 'manifest_url': 'https://sdn-global-streaming-cache-3qsdn.akamaized.net/stream/3144/files/17/07/672975/3144-kZT4LWMQw6Rh7Kpd.ism/manifest.mpd',
  1205. 'ext': 'mp4',
  1206. 'width': 844,
  1207. 'height': 360,
  1208. 'tbr': 698,
  1209. 'format_note': 'DASH video',
  1210. 'container': 'mp4_dash',
  1211. 'vcodec': 'avc1.4D401F',
  1212. 'acodec': 'none',
  1213. 'url': 'https://sdn-global-streaming-cache-3qsdn.akamaized.net/stream/3144/files/17/07/672975/3144-kZT4LWMQw6Rh7Kpd.ism/manifest.mpd',
  1214. 'fragment_base_url': 'https://sdn-global-streaming-cache-3qsdn.akamaized.net/stream/3144/files/17/07/672975/3144-kZT4LWMQw6Rh7Kpd.ism/dash/',
  1215. 'protocol': 'http_dash_segments',
  1216. }, {
  1217. 'format_id': 'video=1493000',
  1218. 'manifest_url': 'https://sdn-global-streaming-cache-3qsdn.akamaized.net/stream/3144/files/17/07/672975/3144-kZT4LWMQw6Rh7Kpd.ism/manifest.mpd',
  1219. 'ext': 'mp4',
  1220. 'width': 1126,
  1221. 'height': 480,
  1222. 'tbr': 1493,
  1223. 'format_note': 'DASH video',
  1224. 'container': 'mp4_dash',
  1225. 'vcodec': 'avc1.4D401F',
  1226. 'acodec': 'none',
  1227. 'url': 'https://sdn-global-streaming-cache-3qsdn.akamaized.net/stream/3144/files/17/07/672975/3144-kZT4LWMQw6Rh7Kpd.ism/manifest.mpd',
  1228. 'fragment_base_url': 'https://sdn-global-streaming-cache-3qsdn.akamaized.net/stream/3144/files/17/07/672975/3144-kZT4LWMQw6Rh7Kpd.ism/dash/',
  1229. 'protocol': 'http_dash_segments',
  1230. }, {
  1231. 'format_id': 'video=4482000',
  1232. 'manifest_url': 'https://sdn-global-streaming-cache-3qsdn.akamaized.net/stream/3144/files/17/07/672975/3144-kZT4LWMQw6Rh7Kpd.ism/manifest.mpd',
  1233. 'ext': 'mp4',
  1234. 'width': 1688,
  1235. 'height': 720,
  1236. 'tbr': 4482,
  1237. 'format_note': 'DASH video',
  1238. 'container': 'mp4_dash',
  1239. 'vcodec': 'avc1.4D401F',
  1240. 'acodec': 'none',
  1241. 'url': 'https://sdn-global-streaming-cache-3qsdn.akamaized.net/stream/3144/files/17/07/672975/3144-kZT4LWMQw6Rh7Kpd.ism/manifest.mpd',
  1242. 'fragment_base_url': 'https://sdn-global-streaming-cache-3qsdn.akamaized.net/stream/3144/files/17/07/672975/3144-kZT4LWMQw6Rh7Kpd.ism/dash/',
  1243. 'protocol': 'http_dash_segments',
  1244. }],
  1245. {
  1246. 'en': [
  1247. {
  1248. 'ext': 'mp4',
  1249. 'manifest_url': 'https://sdn-global-streaming-cache-3qsdn.akamaized.net/stream/3144/files/17/07/672975/3144-kZT4LWMQw6Rh7Kpd.ism/manifest.mpd',
  1250. 'url': 'https://sdn-global-streaming-cache-3qsdn.akamaized.net/stream/3144/files/17/07/672975/3144-kZT4LWMQw6Rh7Kpd.ism/manifest.mpd',
  1251. 'fragment_base_url': 'https://sdn-global-streaming-cache-3qsdn.akamaized.net/stream/3144/files/17/07/672975/3144-kZT4LWMQw6Rh7Kpd.ism/dash/',
  1252. 'protocol': 'http_dash_segments',
  1253. }
  1254. ]
  1255. },
  1256. )
  1257. ]
  1258. for mpd_file, mpd_url, mpd_base_url, expected_formats, expected_subtitles in _TEST_CASES:
  1259. with open('./test/testdata/mpd/%s.mpd' % mpd_file,
  1260. mode='r', encoding='utf-8') as f:
  1261. formats, subtitles = self.ie._parse_mpd_formats_and_subtitles(
  1262. compat_etree_fromstring(f.read().encode('utf-8')),
  1263. mpd_base_url=mpd_base_url, mpd_url=mpd_url)
  1264. self.ie._sort_formats(formats)
  1265. expect_value(self, formats, expected_formats, None)
  1266. expect_value(self, subtitles, expected_subtitles, None)
  1267. def test_parse_f4m_formats(self):
  1268. _TEST_CASES = [
  1269. (
  1270. # https://github.com/ytdl-org/youtube-dl/issues/14660
  1271. 'custom_base_url',
  1272. 'http://api.new.livestream.com/accounts/6115179/events/6764928/videos/144884262.f4m',
  1273. [{
  1274. 'manifest_url': 'http://api.new.livestream.com/accounts/6115179/events/6764928/videos/144884262.f4m',
  1275. 'ext': 'flv',
  1276. 'format_id': '2148',
  1277. 'protocol': 'f4m',
  1278. 'tbr': 2148,
  1279. 'width': 1280,
  1280. 'height': 720,
  1281. }]
  1282. ),
  1283. ]
  1284. for f4m_file, f4m_url, expected_formats in _TEST_CASES:
  1285. with open('./test/testdata/f4m/%s.f4m' % f4m_file,
  1286. mode='r', encoding='utf-8') as f:
  1287. formats = self.ie._parse_f4m_formats(
  1288. compat_etree_fromstring(f.read().encode('utf-8')),
  1289. f4m_url, None)
  1290. self.ie._sort_formats(formats)
  1291. expect_value(self, formats, expected_formats, None)
  1292. def test_parse_xspf(self):
  1293. _TEST_CASES = [
  1294. (
  1295. 'foo_xspf',
  1296. 'https://example.org/src/foo_xspf.xspf',
  1297. [{
  1298. 'id': 'foo_xspf',
  1299. 'title': 'Pandemonium',
  1300. 'description': 'Visit http://bigbrother404.bandcamp.com',
  1301. 'duration': 202.416,
  1302. 'formats': [{
  1303. 'manifest_url': 'https://example.org/src/foo_xspf.xspf',
  1304. 'url': 'https://example.org/src/cd1/track%201.mp3',
  1305. }],
  1306. }, {
  1307. 'id': 'foo_xspf',
  1308. 'title': 'Final Cartridge (Nichico Twelve Remix)',
  1309. 'description': 'Visit http://bigbrother404.bandcamp.com',
  1310. 'duration': 255.857,
  1311. 'formats': [{
  1312. 'manifest_url': 'https://example.org/src/foo_xspf.xspf',
  1313. 'url': 'https://example.org/%E3%83%88%E3%83%A9%E3%83%83%E3%82%AF%E3%80%80%EF%BC%92.mp3',
  1314. }],
  1315. }, {
  1316. 'id': 'foo_xspf',
  1317. 'title': 'Rebuilding Nightingale',
  1318. 'description': 'Visit http://bigbrother404.bandcamp.com',
  1319. 'duration': 287.915,
  1320. 'formats': [{
  1321. 'manifest_url': 'https://example.org/src/foo_xspf.xspf',
  1322. 'url': 'https://example.org/src/track3.mp3',
  1323. }, {
  1324. 'manifest_url': 'https://example.org/src/foo_xspf.xspf',
  1325. 'url': 'https://example.com/track3.mp3',
  1326. }]
  1327. }]
  1328. ),
  1329. ]
  1330. for xspf_file, xspf_url, expected_entries in _TEST_CASES:
  1331. with open('./test/testdata/xspf/%s.xspf' % xspf_file,
  1332. mode='r', encoding='utf-8') as f:
  1333. entries = self.ie._parse_xspf(
  1334. compat_etree_fromstring(f.read().encode('utf-8')),
  1335. xspf_file, xspf_url=xspf_url, xspf_base_url=xspf_url)
  1336. expect_value(self, entries, expected_entries, None)
  1337. for i in range(len(entries)):
  1338. expect_dict(self, entries[i], expected_entries[i])
  1339. def test_response_with_expected_status_returns_content(self):
  1340. # Checks for mitigations against the effects of
  1341. # <https://bugs.python.org/issue15002> that affect Python 3.4.1+, which
  1342. # manifest as `_download_webpage`, `_download_xml`, `_download_json`,
  1343. # or the underlying `_download_webpage_handle` returning no content
  1344. # when a response matches `expected_status`.
  1345. httpd = compat_http_server.HTTPServer(
  1346. ('127.0.0.1', 0), InfoExtractorTestRequestHandler)
  1347. port = http_server_port(httpd)
  1348. server_thread = threading.Thread(target=httpd.serve_forever)
  1349. server_thread.daemon = True
  1350. server_thread.start()
  1351. (content, urlh) = self.ie._download_webpage_handle(
  1352. 'http://127.0.0.1:%d/teapot' % port, None,
  1353. expected_status=TEAPOT_RESPONSE_STATUS)
  1354. self.assertEqual(content, TEAPOT_RESPONSE_BODY)
  1355. if __name__ == '__main__':
  1356. unittest.main()