You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

748 lines
40 KiB

  1. #!/usr/bin/env python
  2. from __future__ import unicode_literals
  3. # Allow direct execution
  4. import io
  5. import os
  6. import sys
  7. import unittest
  8. sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
  9. from test.helper import FakeYDL, expect_dict, expect_value
  10. from youtube_dl.compat import compat_etree_fromstring
  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. class TestIE(InfoExtractor):
  15. pass
  16. class TestInfoExtractor(unittest.TestCase):
  17. def setUp(self):
  18. self.ie = TestIE(FakeYDL())
  19. def test_ie_key(self):
  20. self.assertEqual(get_info_extractor(YoutubeIE.ie_key()), YoutubeIE)
  21. def test_html_search_regex(self):
  22. html = '<p id="foo">Watch this <a href="http://www.youtube.com/watch?v=BaW_jenozKc">video</a></p>'
  23. search = lambda re, *args: self.ie._html_search_regex(re, html, *args)
  24. self.assertEqual(search(r'<p id="foo">(.+?)</p>', 'foo'), 'Watch this video')
  25. def test_opengraph(self):
  26. ie = self.ie
  27. html = '''
  28. <meta name="og:title" content='Foo'/>
  29. <meta content="Some video's description " name="og:description"/>
  30. <meta property='og:image' content='http://domain.com/pic.jpg?key1=val1&amp;key2=val2'/>
  31. <meta content='application/x-shockwave-flash' property='og:video:type'>
  32. <meta content='Foo' property=og:foobar>
  33. <meta name="og:test1" content='foo > < bar'/>
  34. <meta name="og:test2" content="foo >//< bar"/>
  35. '''
  36. self.assertEqual(ie._og_search_title(html), 'Foo')
  37. self.assertEqual(ie._og_search_description(html), 'Some video\'s description ')
  38. self.assertEqual(ie._og_search_thumbnail(html), 'http://domain.com/pic.jpg?key1=val1&key2=val2')
  39. self.assertEqual(ie._og_search_video_url(html, default=None), None)
  40. self.assertEqual(ie._og_search_property('foobar', html), 'Foo')
  41. self.assertEqual(ie._og_search_property('test1', html), 'foo > < bar')
  42. self.assertEqual(ie._og_search_property('test2', html), 'foo >//< bar')
  43. self.assertEqual(ie._og_search_property(('test0', 'test1'), html), 'foo > < bar')
  44. self.assertRaises(RegexNotFoundError, ie._og_search_property, 'test0', html, None, fatal=True)
  45. self.assertRaises(RegexNotFoundError, ie._og_search_property, ('test0', 'test00'), html, None, fatal=True)
  46. def test_html_search_meta(self):
  47. ie = self.ie
  48. html = '''
  49. <meta name="a" content="1" />
  50. <meta name='b' content='2'>
  51. <meta name="c" content='3'>
  52. <meta name=d content='4'>
  53. <meta property="e" content='5' >
  54. <meta content="6" name="f">
  55. '''
  56. self.assertEqual(ie._html_search_meta('a', html), '1')
  57. self.assertEqual(ie._html_search_meta('b', html), '2')
  58. self.assertEqual(ie._html_search_meta('c', html), '3')
  59. self.assertEqual(ie._html_search_meta('d', html), '4')
  60. self.assertEqual(ie._html_search_meta('e', html), '5')
  61. self.assertEqual(ie._html_search_meta('f', html), '6')
  62. self.assertEqual(ie._html_search_meta(('a', 'b', 'c'), html), '1')
  63. self.assertEqual(ie._html_search_meta(('c', 'b', 'a'), html), '3')
  64. self.assertEqual(ie._html_search_meta(('z', 'x', 'c'), html), '3')
  65. self.assertRaises(RegexNotFoundError, ie._html_search_meta, 'z', html, None, fatal=True)
  66. self.assertRaises(RegexNotFoundError, ie._html_search_meta, ('z', 'x'), html, None, fatal=True)
  67. def test_download_json(self):
  68. uri = encode_data_uri(b'{"foo": "blah"}', 'application/json')
  69. self.assertEqual(self.ie._download_json(uri, None), {'foo': 'blah'})
  70. uri = encode_data_uri(b'callback({"foo": "blah"})', 'application/javascript')
  71. self.assertEqual(self.ie._download_json(uri, None, transform_source=strip_jsonp), {'foo': 'blah'})
  72. uri = encode_data_uri(b'{"foo": invalid}', 'application/json')
  73. self.assertRaises(ExtractorError, self.ie._download_json, uri, None)
  74. self.assertEqual(self.ie._download_json(uri, None, fatal=False), None)
  75. def test_extract_jwplayer_data_realworld(self):
  76. # from http://www.suffolk.edu/sjc/
  77. expect_dict(
  78. self,
  79. self.ie._extract_jwplayer_data(r'''
  80. <script type='text/javascript'>
  81. jwplayer('my-video').setup({
  82. file: 'rtmp://192.138.214.154/live/sjclive',
  83. fallback: 'true',
  84. width: '95%',
  85. aspectratio: '16:9',
  86. primary: 'flash',
  87. mediaid:'XEgvuql4'
  88. });
  89. </script>
  90. ''', None, require_title=False),
  91. {
  92. 'id': 'XEgvuql4',
  93. 'formats': [{
  94. 'url': 'rtmp://192.138.214.154/live/sjclive',
  95. 'ext': 'flv'
  96. }]
  97. })
  98. # from https://www.pornoxo.com/videos/7564/striptease-from-sexy-secretary/
  99. expect_dict(
  100. self,
  101. self.ie._extract_jwplayer_data(r'''
  102. <script type="text/javascript">
  103. jwplayer("mediaplayer").setup({
  104. 'videoid': "7564",
  105. 'width': "100%",
  106. 'aspectratio': "16:9",
  107. 'stretching': "exactfit",
  108. 'autostart': 'false',
  109. 'flashplayer': "https://t04.vipstreamservice.com/jwplayer/v5.10/player.swf",
  110. '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",
  111. 'image': "https://t03.vipstreamservice.com/thumbs/pxo-full/2009-12/14/a4b2157147afe5efa93ce1978e0265289c193874e02597.flv-full-13.jpg",
  112. '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",
  113. 'logo.hide': true,
  114. 'skin': "https://t04.vipstreamservice.com/jwplayer/skin/modieus-blk.zip",
  115. 'plugins': "https://t04.vipstreamservice.com/jwplayer/dock/dockableskinnableplugin.swf",
  116. 'dockableskinnableplugin.piclink': "/index.php?key=ajax-videothumbsn&vid=7564&data=2009-12--14--4b2157147afe5efa93ce1978e0265289c193874e02597.flv--17370",
  117. 'controlbar': 'bottom',
  118. 'modes': [
  119. {type: 'flash', src: 'https://t04.vipstreamservice.com/jwplayer/v5.10/player.swf'}
  120. ],
  121. 'provider': 'http'
  122. });
  123. //noinspection JSAnnotator
  124. invideo.setup({
  125. adsUrl: "/banner-iframe/?zoneId=32",
  126. adsUrl2: "",
  127. autostart: false
  128. });
  129. </script>
  130. ''', 'dummy', require_title=False),
  131. {
  132. 'thumbnail': 'https://t03.vipstreamservice.com/thumbs/pxo-full/2009-12/14/a4b2157147afe5efa93ce1978e0265289c193874e02597.flv-full-13.jpg',
  133. 'formats': [{
  134. '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',
  135. 'ext': 'flv'
  136. }]
  137. })
  138. # from http://www.indiedb.com/games/king-machine/videos
  139. expect_dict(
  140. self,
  141. self.ie._extract_jwplayer_data(r'''
  142. <script>
  143. 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) {
  144. videoAnalytics("play");
  145. }).once("complete", function(event) {
  146. videoAnalytics("completed");
  147. });
  148. </script>
  149. ''', 'dummy'),
  150. {
  151. 'title': 'king machine trailer 1',
  152. 'thumbnail': 'http://media.indiedb.com/cache/images/games/1/50/49678/thumb_620x2000/king-machine-trailer.mp4.jpg',
  153. 'formats': [{
  154. 'url': 'http://cdn.dbolical.com/cache/videos/games/1/50/49678/encode_mp4/king-machine-trailer.mp4',
  155. 'height': 360,
  156. 'ext': 'mp4'
  157. }, {
  158. 'url': 'http://cdn.dbolical.com/cache/videos/games/1/50/49678/encode720p_mp4/king-machine-trailer.mp4',
  159. 'height': 720,
  160. 'ext': 'mp4'
  161. }]
  162. })
  163. def test_parse_m3u8_formats(self):
  164. _TEST_CASES = [
  165. (
  166. # https://github.com/rg3/youtube-dl/issues/11507
  167. # http://pluzz.francetv.fr/videos/le_ministere.html
  168. 'pluzz_francetv_11507',
  169. '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',
  170. [{
  171. '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',
  172. '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',
  173. 'ext': 'mp4',
  174. 'format_id': '180',
  175. 'protocol': 'm3u8',
  176. 'acodec': 'mp4a.40.2',
  177. 'vcodec': 'avc1.66.30',
  178. 'tbr': 180,
  179. 'width': 256,
  180. 'height': 144,
  181. }, {
  182. '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',
  183. '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',
  184. 'ext': 'mp4',
  185. 'format_id': '303',
  186. 'protocol': 'm3u8',
  187. 'acodec': 'mp4a.40.2',
  188. 'vcodec': 'avc1.66.30',
  189. 'tbr': 303,
  190. 'width': 320,
  191. 'height': 180,
  192. }, {
  193. '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',
  194. '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',
  195. 'ext': 'mp4',
  196. 'format_id': '575',
  197. 'protocol': 'm3u8',
  198. 'acodec': 'mp4a.40.2',
  199. 'vcodec': 'avc1.66.30',
  200. 'tbr': 575,
  201. 'width': 512,
  202. 'height': 288,
  203. }, {
  204. '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',
  205. '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',
  206. 'ext': 'mp4',
  207. 'format_id': '831',
  208. 'protocol': 'm3u8',
  209. 'acodec': 'mp4a.40.2',
  210. 'vcodec': 'avc1.77.30',
  211. 'tbr': 831,
  212. 'width': 704,
  213. 'height': 396,
  214. }, {
  215. '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',
  216. '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',
  217. 'ext': 'mp4',
  218. 'protocol': 'm3u8',
  219. 'format_id': '1467',
  220. 'acodec': 'mp4a.40.2',
  221. 'vcodec': 'avc1.77.30',
  222. 'tbr': 1467,
  223. 'width': 1024,
  224. 'height': 576,
  225. }]
  226. ),
  227. (
  228. # https://github.com/rg3/youtube-dl/issues/11995
  229. # http://teamcoco.com/video/clueless-gamer-super-bowl-for-honor
  230. 'teamcoco_11995',
  231. 'http://ak.storage-w.teamcococdn.com/cdn/2017-02/98599/ed8f/main.m3u8',
  232. [{
  233. 'url': 'http://ak.storage-w.teamcococdn.com/cdn/2017-02/98599/ed8f/hls/CONAN_020217_Highlight_show-audio-160k_v4.m3u8',
  234. 'manifest_url': 'http://ak.storage-w.teamcococdn.com/cdn/2017-02/98599/ed8f/main.m3u8',
  235. 'ext': 'mp4',
  236. 'format_id': 'audio-0-Default',
  237. 'protocol': 'm3u8',
  238. 'vcodec': 'none',
  239. }, {
  240. 'url': 'http://ak.storage-w.teamcococdn.com/cdn/2017-02/98599/ed8f/hls/CONAN_020217_Highlight_show-audio-64k_v4.m3u8',
  241. 'manifest_url': 'http://ak.storage-w.teamcococdn.com/cdn/2017-02/98599/ed8f/main.m3u8',
  242. 'ext': 'mp4',
  243. 'format_id': 'audio-1-Default',
  244. 'protocol': 'm3u8',
  245. 'vcodec': 'none',
  246. }, {
  247. 'url': 'http://ak.storage-w.teamcococdn.com/cdn/2017-02/98599/ed8f/hls/CONAN_020217_Highlight_show-audio-64k_v4.m3u8',
  248. 'manifest_url': 'http://ak.storage-w.teamcococdn.com/cdn/2017-02/98599/ed8f/main.m3u8',
  249. 'ext': 'mp4',
  250. 'format_id': '71',
  251. 'protocol': 'm3u8',
  252. 'acodec': 'mp4a.40.5',
  253. 'vcodec': 'none',
  254. 'tbr': 71,
  255. }, {
  256. 'url': 'http://ak.storage-w.teamcococdn.com/cdn/2017-02/98599/ed8f/hls/CONAN_020217_Highlight_show-400k_v4.m3u8',
  257. 'manifest_url': 'http://ak.storage-w.teamcococdn.com/cdn/2017-02/98599/ed8f/main.m3u8',
  258. 'ext': 'mp4',
  259. 'format_id': '413',
  260. 'protocol': 'm3u8',
  261. 'acodec': 'none',
  262. 'vcodec': 'avc1.42001e',
  263. 'tbr': 413,
  264. 'width': 400,
  265. 'height': 224,
  266. }, {
  267. 'url': 'http://ak.storage-w.teamcococdn.com/cdn/2017-02/98599/ed8f/hls/CONAN_020217_Highlight_show-400k_v4.m3u8',
  268. 'manifest_url': 'http://ak.storage-w.teamcococdn.com/cdn/2017-02/98599/ed8f/main.m3u8',
  269. 'ext': 'mp4',
  270. 'format_id': '522',
  271. 'protocol': 'm3u8',
  272. 'acodec': 'none',
  273. 'vcodec': 'avc1.42001e',
  274. 'tbr': 522,
  275. 'width': 400,
  276. 'height': 224,
  277. }, {
  278. 'url': 'http://ak.storage-w.teamcococdn.com/cdn/2017-02/98599/ed8f/hls/CONAN_020217_Highlight_show-1m_v4.m3u8',
  279. 'manifest_url': 'http://ak.storage-w.teamcococdn.com/cdn/2017-02/98599/ed8f/main.m3u8',
  280. 'ext': 'mp4',
  281. 'format_id': '1205',
  282. 'protocol': 'm3u8',
  283. 'acodec': 'none',
  284. 'vcodec': 'avc1.4d001e',
  285. 'tbr': 1205,
  286. 'width': 640,
  287. 'height': 360,
  288. }, {
  289. 'url': 'http://ak.storage-w.teamcococdn.com/cdn/2017-02/98599/ed8f/hls/CONAN_020217_Highlight_show-2m_v4.m3u8',
  290. 'manifest_url': 'http://ak.storage-w.teamcococdn.com/cdn/2017-02/98599/ed8f/main.m3u8',
  291. 'ext': 'mp4',
  292. 'format_id': '2374',
  293. 'protocol': 'm3u8',
  294. 'acodec': 'none',
  295. 'vcodec': 'avc1.4d001f',
  296. 'tbr': 2374,
  297. 'width': 1024,
  298. 'height': 576,
  299. }]
  300. ),
  301. (
  302. # https://github.com/rg3/youtube-dl/issues/12211
  303. # http://video.toggle.sg/en/series/whoopie-s-world/ep3/478601
  304. 'toggle_mobile_12211',
  305. 'http://cdnapi.kaltura.com/p/2082311/sp/208231100/playManifest/protocol/http/entryId/0_89q6e8ku/format/applehttp/tags/mobile_sd/f/a.m3u8',
  306. [{
  307. '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',
  308. 'manifest_url': 'http://cdnapi.kaltura.com/p/2082311/sp/208231100/playManifest/protocol/http/entryId/0_89q6e8ku/format/applehttp/tags/mobile_sd/f/a.m3u8',
  309. 'ext': 'mp4',
  310. 'format_id': 'audio-English',
  311. 'protocol': 'm3u8',
  312. 'language': 'eng',
  313. 'vcodec': 'none',
  314. }, {
  315. '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',
  316. 'manifest_url': 'http://cdnapi.kaltura.com/p/2082311/sp/208231100/playManifest/protocol/http/entryId/0_89q6e8ku/format/applehttp/tags/mobile_sd/f/a.m3u8',
  317. 'ext': 'mp4',
  318. 'format_id': 'audio-Undefined',
  319. 'protocol': 'm3u8',
  320. 'language': 'und',
  321. 'vcodec': 'none',
  322. }, {
  323. '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',
  324. 'manifest_url': 'http://cdnapi.kaltura.com/p/2082311/sp/208231100/playManifest/protocol/http/entryId/0_89q6e8ku/format/applehttp/tags/mobile_sd/f/a.m3u8',
  325. 'ext': 'mp4',
  326. 'format_id': '155',
  327. 'protocol': 'm3u8',
  328. 'tbr': 155.648,
  329. 'width': 320,
  330. 'height': 180,
  331. }, {
  332. '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',
  333. 'manifest_url': 'http://cdnapi.kaltura.com/p/2082311/sp/208231100/playManifest/protocol/http/entryId/0_89q6e8ku/format/applehttp/tags/mobile_sd/f/a.m3u8',
  334. 'ext': 'mp4',
  335. 'format_id': '502',
  336. 'protocol': 'm3u8',
  337. 'tbr': 502.784,
  338. 'width': 480,
  339. 'height': 270,
  340. }, {
  341. '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',
  342. 'manifest_url': 'http://cdnapi.kaltura.com/p/2082311/sp/208231100/playManifest/protocol/http/entryId/0_89q6e8ku/format/applehttp/tags/mobile_sd/f/a.m3u8',
  343. 'ext': 'mp4',
  344. 'format_id': '827',
  345. 'protocol': 'm3u8',
  346. 'tbr': 827.392,
  347. 'width': 640,
  348. 'height': 360,
  349. }, {
  350. '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',
  351. 'manifest_url': 'http://cdnapi.kaltura.com/p/2082311/sp/208231100/playManifest/protocol/http/entryId/0_89q6e8ku/format/applehttp/tags/mobile_sd/f/a.m3u8',
  352. 'ext': 'mp4',
  353. 'format_id': '1396',
  354. 'protocol': 'm3u8',
  355. 'tbr': 1396.736,
  356. 'width': 854,
  357. 'height': 480,
  358. }]
  359. ),
  360. (
  361. # http://www.twitch.tv/riotgames/v/6528877
  362. 'twitch_vod',
  363. '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',
  364. [{
  365. 'url': 'https://vod.edgecast.hls.ttvnw.net/e5da31ab49_riotgames_15001215120_261543898/audio_only/index-muted-HM49I092CC.m3u8',
  366. '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',
  367. 'ext': 'mp4',
  368. 'format_id': 'Audio Only',
  369. 'protocol': 'm3u8',
  370. 'acodec': 'mp4a.40.2',
  371. 'vcodec': 'none',
  372. 'tbr': 182.725,
  373. }, {
  374. 'url': 'https://vod.edgecast.hls.ttvnw.net/e5da31ab49_riotgames_15001215120_261543898/mobile/index-muted-HM49I092CC.m3u8',
  375. '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',
  376. 'ext': 'mp4',
  377. 'format_id': 'Mobile',
  378. 'protocol': 'm3u8',
  379. 'acodec': 'mp4a.40.2',
  380. 'vcodec': 'avc1.42C00D',
  381. 'tbr': 280.474,
  382. 'width': 400,
  383. 'height': 226,
  384. }, {
  385. 'url': 'https://vod.edgecast.hls.ttvnw.net/e5da31ab49_riotgames_15001215120_261543898/low/index-muted-HM49I092CC.m3u8',
  386. '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',
  387. 'ext': 'mp4',
  388. 'format_id': 'Low',
  389. 'protocol': 'm3u8',
  390. 'acodec': 'mp4a.40.2',
  391. 'vcodec': 'avc1.42C01E',
  392. 'tbr': 628.347,
  393. 'width': 640,
  394. 'height': 360,
  395. }, {
  396. 'url': 'https://vod.edgecast.hls.ttvnw.net/e5da31ab49_riotgames_15001215120_261543898/medium/index-muted-HM49I092CC.m3u8',
  397. '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',
  398. 'ext': 'mp4',
  399. 'format_id': 'Medium',
  400. 'protocol': 'm3u8',
  401. 'acodec': 'mp4a.40.2',
  402. 'vcodec': 'avc1.42C01E',
  403. 'tbr': 893.387,
  404. 'width': 852,
  405. 'height': 480,
  406. }, {
  407. 'url': 'https://vod.edgecast.hls.ttvnw.net/e5da31ab49_riotgames_15001215120_261543898/high/index-muted-HM49I092CC.m3u8',
  408. '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',
  409. 'ext': 'mp4',
  410. 'format_id': 'High',
  411. 'protocol': 'm3u8',
  412. 'acodec': 'mp4a.40.2',
  413. 'vcodec': 'avc1.42C01F',
  414. 'tbr': 1603.789,
  415. 'width': 1280,
  416. 'height': 720,
  417. }, {
  418. 'url': 'https://vod.edgecast.hls.ttvnw.net/e5da31ab49_riotgames_15001215120_261543898/chunked/index-muted-HM49I092CC.m3u8',
  419. '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',
  420. 'ext': 'mp4',
  421. 'format_id': 'Source',
  422. 'protocol': 'm3u8',
  423. 'acodec': 'mp4a.40.2',
  424. 'vcodec': 'avc1.100.31',
  425. 'tbr': 3214.134,
  426. 'width': 1280,
  427. 'height': 720,
  428. }]
  429. ),
  430. (
  431. # http://www.vidio.com/watch/165683-dj_ambred-booyah-live-2015
  432. # EXT-X-STREAM-INF tag with NAME attribute that is not defined
  433. # in HLS specification
  434. 'vidio',
  435. 'https://www.vidio.com/videos/165683/playlist.m3u8',
  436. [{
  437. 'url': 'https://cdn1-a.production.vidio.static6.com/uploads/165683/dj_ambred-4383-b300.mp4.m3u8',
  438. 'manifest_url': 'https://www.vidio.com/videos/165683/playlist.m3u8',
  439. 'ext': 'mp4',
  440. 'format_id': '270p 3G',
  441. 'protocol': 'm3u8',
  442. 'tbr': 300,
  443. 'width': 480,
  444. 'height': 270,
  445. }, {
  446. 'url': 'https://cdn1-a.production.vidio.static6.com/uploads/165683/dj_ambred-4383-b600.mp4.m3u8',
  447. 'manifest_url': 'https://www.vidio.com/videos/165683/playlist.m3u8',
  448. 'ext': 'mp4',
  449. 'format_id': '360p SD',
  450. 'protocol': 'm3u8',
  451. 'tbr': 600,
  452. 'width': 640,
  453. 'height': 360,
  454. }, {
  455. 'url': 'https://cdn1-a.production.vidio.static6.com/uploads/165683/dj_ambred-4383-b1200.mp4.m3u8',
  456. 'manifest_url': 'https://www.vidio.com/videos/165683/playlist.m3u8',
  457. 'ext': 'mp4',
  458. 'format_id': '720p HD',
  459. 'protocol': 'm3u8',
  460. 'tbr': 1200,
  461. 'width': 1280,
  462. 'height': 720,
  463. }]
  464. )
  465. ]
  466. for m3u8_file, m3u8_url, expected_formats in _TEST_CASES:
  467. with io.open('./test/testdata/m3u8/%s.m3u8' % m3u8_file,
  468. mode='r', encoding='utf-8') as f:
  469. formats = self.ie._parse_m3u8_formats(
  470. f.read(), m3u8_url, ext='mp4')
  471. self.ie._sort_formats(formats)
  472. expect_value(self, formats, expected_formats, None)
  473. def test_parse_mpd_formats(self):
  474. _TEST_CASES = [
  475. (
  476. # https://github.com/rg3/youtube-dl/issues/13919
  477. # Also tests duplicate representation ids, see
  478. # https://github.com/rg3/youtube-dl/issues/15111
  479. 'float_duration',
  480. 'http://unknown/manifest.mpd',
  481. [{
  482. 'manifest_url': 'http://unknown/manifest.mpd',
  483. 'ext': 'm4a',
  484. 'format_id': '318597',
  485. 'format_note': 'DASH audio',
  486. 'protocol': 'http_dash_segments',
  487. 'acodec': 'mp4a.40.2',
  488. 'vcodec': 'none',
  489. 'tbr': 61.587,
  490. }, {
  491. 'manifest_url': 'http://unknown/manifest.mpd',
  492. 'ext': 'mp4',
  493. 'format_id': '318597',
  494. 'format_note': 'DASH video',
  495. 'protocol': 'http_dash_segments',
  496. 'acodec': 'none',
  497. 'vcodec': 'avc1.42001f',
  498. 'tbr': 318.597,
  499. 'width': 340,
  500. 'height': 192,
  501. }, {
  502. 'manifest_url': 'http://unknown/manifest.mpd',
  503. 'ext': 'mp4',
  504. 'format_id': '638590',
  505. 'format_note': 'DASH video',
  506. 'protocol': 'http_dash_segments',
  507. 'acodec': 'none',
  508. 'vcodec': 'avc1.42001f',
  509. 'tbr': 638.59,
  510. 'width': 512,
  511. 'height': 288,
  512. }, {
  513. 'manifest_url': 'http://unknown/manifest.mpd',
  514. 'ext': 'mp4',
  515. 'format_id': '1022565',
  516. 'format_note': 'DASH video',
  517. 'protocol': 'http_dash_segments',
  518. 'acodec': 'none',
  519. 'vcodec': 'avc1.4d001f',
  520. 'tbr': 1022.565,
  521. 'width': 688,
  522. 'height': 384,
  523. }, {
  524. 'manifest_url': 'http://unknown/manifest.mpd',
  525. 'ext': 'mp4',
  526. 'format_id': '2046506',
  527. 'format_note': 'DASH video',
  528. 'protocol': 'http_dash_segments',
  529. 'acodec': 'none',
  530. 'vcodec': 'avc1.4d001f',
  531. 'tbr': 2046.506,
  532. 'width': 1024,
  533. 'height': 576,
  534. }, {
  535. 'manifest_url': 'http://unknown/manifest.mpd',
  536. 'ext': 'mp4',
  537. 'format_id': '3998017',
  538. 'format_note': 'DASH video',
  539. 'protocol': 'http_dash_segments',
  540. 'acodec': 'none',
  541. 'vcodec': 'avc1.640029',
  542. 'tbr': 3998.017,
  543. 'width': 1280,
  544. 'height': 720,
  545. }, {
  546. 'manifest_url': 'http://unknown/manifest.mpd',
  547. 'ext': 'mp4',
  548. 'format_id': '5997485',
  549. 'format_note': 'DASH video',
  550. 'protocol': 'http_dash_segments',
  551. 'acodec': 'none',
  552. 'vcodec': 'avc1.640032',
  553. 'tbr': 5997.485,
  554. 'width': 1920,
  555. 'height': 1080,
  556. }]
  557. ), (
  558. # https://github.com/rg3/youtube-dl/pull/14844
  559. 'urls_only',
  560. 'http://unknown/manifest.mpd',
  561. [{
  562. 'manifest_url': 'http://unknown/manifest.mpd',
  563. 'ext': 'mp4',
  564. 'format_id': 'h264_aac_144p_m4s',
  565. 'format_note': 'DASH video',
  566. 'protocol': 'http_dash_segments',
  567. 'acodec': 'mp4a.40.2',
  568. 'vcodec': 'avc3.42c01e',
  569. 'tbr': 200,
  570. 'width': 256,
  571. 'height': 144,
  572. }, {
  573. 'manifest_url': 'http://unknown/manifest.mpd',
  574. 'ext': 'mp4',
  575. 'format_id': 'h264_aac_240p_m4s',
  576. 'format_note': 'DASH video',
  577. 'protocol': 'http_dash_segments',
  578. 'acodec': 'mp4a.40.2',
  579. 'vcodec': 'avc3.42c01e',
  580. 'tbr': 400,
  581. 'width': 424,
  582. 'height': 240,
  583. }, {
  584. 'manifest_url': 'http://unknown/manifest.mpd',
  585. 'ext': 'mp4',
  586. 'format_id': 'h264_aac_360p_m4s',
  587. 'format_note': 'DASH video',
  588. 'protocol': 'http_dash_segments',
  589. 'acodec': 'mp4a.40.2',
  590. 'vcodec': 'avc3.42c01e',
  591. 'tbr': 800,
  592. 'width': 640,
  593. 'height': 360,
  594. }, {
  595. 'manifest_url': 'http://unknown/manifest.mpd',
  596. 'ext': 'mp4',
  597. 'format_id': 'h264_aac_480p_m4s',
  598. 'format_note': 'DASH video',
  599. 'protocol': 'http_dash_segments',
  600. 'acodec': 'mp4a.40.2',
  601. 'vcodec': 'avc3.42c01e',
  602. 'tbr': 1200,
  603. 'width': 856,
  604. 'height': 480,
  605. }, {
  606. 'manifest_url': 'http://unknown/manifest.mpd',
  607. 'ext': 'mp4',
  608. 'format_id': 'h264_aac_576p_m4s',
  609. 'format_note': 'DASH video',
  610. 'protocol': 'http_dash_segments',
  611. 'acodec': 'mp4a.40.2',
  612. 'vcodec': 'avc3.42c01e',
  613. 'tbr': 1600,
  614. 'width': 1024,
  615. 'height': 576,
  616. }, {
  617. 'manifest_url': 'http://unknown/manifest.mpd',
  618. 'ext': 'mp4',
  619. 'format_id': 'h264_aac_720p_m4s',
  620. 'format_note': 'DASH video',
  621. 'protocol': 'http_dash_segments',
  622. 'acodec': 'mp4a.40.2',
  623. 'vcodec': 'avc3.42c01e',
  624. 'tbr': 2400,
  625. 'width': 1280,
  626. 'height': 720,
  627. }, {
  628. 'manifest_url': 'http://unknown/manifest.mpd',
  629. 'ext': 'mp4',
  630. 'format_id': 'h264_aac_1080p_m4s',
  631. 'format_note': 'DASH video',
  632. 'protocol': 'http_dash_segments',
  633. 'acodec': 'mp4a.40.2',
  634. 'vcodec': 'avc3.42c01e',
  635. 'tbr': 4400,
  636. 'width': 1920,
  637. 'height': 1080,
  638. }]
  639. )
  640. ]
  641. for mpd_file, mpd_url, expected_formats in _TEST_CASES:
  642. with io.open('./test/testdata/mpd/%s.mpd' % mpd_file,
  643. mode='r', encoding='utf-8') as f:
  644. formats = self.ie._parse_mpd_formats(
  645. compat_etree_fromstring(f.read().encode('utf-8')),
  646. mpd_url=mpd_url)
  647. self.ie._sort_formats(formats)
  648. expect_value(self, formats, expected_formats, None)
  649. def test_parse_f4m_formats(self):
  650. _TEST_CASES = [
  651. (
  652. # https://github.com/rg3/youtube-dl/issues/14660
  653. 'custom_base_url',
  654. 'http://api.new.livestream.com/accounts/6115179/events/6764928/videos/144884262.f4m',
  655. [{
  656. 'manifest_url': 'http://api.new.livestream.com/accounts/6115179/events/6764928/videos/144884262.f4m',
  657. 'ext': 'flv',
  658. 'format_id': '2148',
  659. 'protocol': 'f4m',
  660. 'tbr': 2148,
  661. 'width': 1280,
  662. 'height': 720,
  663. }]
  664. ),
  665. ]
  666. for f4m_file, f4m_url, expected_formats in _TEST_CASES:
  667. with io.open('./test/testdata/f4m/%s.f4m' % f4m_file,
  668. mode='r', encoding='utf-8') as f:
  669. formats = self.ie._parse_f4m_formats(
  670. compat_etree_fromstring(f.read().encode('utf-8')),
  671. f4m_url, None)
  672. self.ie._sort_formats(formats)
  673. expect_value(self, formats, expected_formats, None)
  674. def test_parse_xspf(self):
  675. _TEST_CASES = [
  676. (
  677. 'foo_xspf',
  678. 'https://example.org/src/foo_xspf.xspf',
  679. [{
  680. 'id': 'foo_xspf',
  681. 'title': 'Pandemonium',
  682. 'description': 'Visit http://bigbrother404.bandcamp.com',
  683. 'duration': 202.416,
  684. 'formats': [{
  685. 'manifest_url': 'https://example.org/src/foo_xspf.xspf',
  686. 'url': 'https://example.org/src/cd1/track%201.mp3',
  687. }],
  688. }, {
  689. 'id': 'foo_xspf',
  690. 'title': 'Final Cartridge (Nichico Twelve Remix)',
  691. 'description': 'Visit http://bigbrother404.bandcamp.com',
  692. 'duration': 255.857,
  693. 'formats': [{
  694. 'manifest_url': 'https://example.org/src/foo_xspf.xspf',
  695. 'url': 'https://example.org/%E3%83%88%E3%83%A9%E3%83%83%E3%82%AF%E3%80%80%EF%BC%92.mp3',
  696. }],
  697. }, {
  698. 'id': 'foo_xspf',
  699. 'title': 'Rebuilding Nightingale',
  700. 'description': 'Visit http://bigbrother404.bandcamp.com',
  701. 'duration': 287.915,
  702. 'formats': [{
  703. 'manifest_url': 'https://example.org/src/foo_xspf.xspf',
  704. 'url': 'https://example.org/src/track3.mp3',
  705. }, {
  706. 'manifest_url': 'https://example.org/src/foo_xspf.xspf',
  707. 'url': 'https://example.com/track3.mp3',
  708. }]
  709. }]
  710. ),
  711. ]
  712. for xspf_file, xspf_url, expected_entries in _TEST_CASES:
  713. with io.open('./test/testdata/xspf/%s.xspf' % xspf_file,
  714. mode='r', encoding='utf-8') as f:
  715. entries = self.ie._parse_xspf(
  716. compat_etree_fromstring(f.read().encode('utf-8')),
  717. xspf_file, xspf_url=xspf_url, xspf_base_url=xspf_url)
  718. expect_value(self, entries, expected_entries, None)
  719. for i in range(len(entries)):
  720. expect_dict(self, entries[i], expected_entries[i])
  721. if __name__ == '__main__':
  722. unittest.main()