test_InfoExtractor.py 71 KB

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