2
0

test_InfoExtractor.py 58 KB

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