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.

493 lines
30 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.extractor.common import InfoExtractor
  11. from youtube_dl.extractor import YoutubeIE, get_info_extractor
  12. from youtube_dl.utils import encode_data_uri, strip_jsonp, ExtractorError, RegexNotFoundError
  13. class TestIE(InfoExtractor):
  14. pass
  15. class TestInfoExtractor(unittest.TestCase):
  16. def setUp(self):
  17. self.ie = TestIE(FakeYDL())
  18. def test_ie_key(self):
  19. self.assertEqual(get_info_extractor(YoutubeIE.ie_key()), YoutubeIE)
  20. def test_html_search_regex(self):
  21. html = '<p id="foo">Watch this <a href="http://www.youtube.com/watch?v=BaW_jenozKc">video</a></p>'
  22. search = lambda re, *args: self.ie._html_search_regex(re, html, *args)
  23. self.assertEqual(search(r'<p id="foo">(.+?)</p>', 'foo'), 'Watch this video')
  24. def test_opengraph(self):
  25. ie = self.ie
  26. html = '''
  27. <meta name="og:title" content='Foo'/>
  28. <meta content="Some video's description " name="og:description"/>
  29. <meta property='og:image' content='http://domain.com/pic.jpg?key1=val1&amp;key2=val2'/>
  30. <meta content='application/x-shockwave-flash' property='og:video:type'>
  31. <meta content='Foo' property=og:foobar>
  32. <meta name="og:test1" content='foo > < bar'/>
  33. <meta name="og:test2" content="foo >//< bar"/>
  34. '''
  35. self.assertEqual(ie._og_search_title(html), 'Foo')
  36. self.assertEqual(ie._og_search_description(html), 'Some video\'s description ')
  37. self.assertEqual(ie._og_search_thumbnail(html), 'http://domain.com/pic.jpg?key1=val1&key2=val2')
  38. self.assertEqual(ie._og_search_video_url(html, default=None), None)
  39. self.assertEqual(ie._og_search_property('foobar', html), 'Foo')
  40. self.assertEqual(ie._og_search_property('test1', html), 'foo > < bar')
  41. self.assertEqual(ie._og_search_property('test2', html), 'foo >//< bar')
  42. self.assertEqual(ie._og_search_property(('test0', 'test1'), html), 'foo > < bar')
  43. self.assertRaises(RegexNotFoundError, ie._og_search_property, 'test0', html, None, fatal=True)
  44. self.assertRaises(RegexNotFoundError, ie._og_search_property, ('test0', 'test00'), html, None, fatal=True)
  45. def test_html_search_meta(self):
  46. ie = self.ie
  47. html = '''
  48. <meta name="a" content="1" />
  49. <meta name='b' content='2'>
  50. <meta name="c" content='3'>
  51. <meta name=d content='4'>
  52. <meta property="e" content='5' >
  53. <meta content="6" name="f">
  54. '''
  55. self.assertEqual(ie._html_search_meta('a', html), '1')
  56. self.assertEqual(ie._html_search_meta('b', html), '2')
  57. self.assertEqual(ie._html_search_meta('c', html), '3')
  58. self.assertEqual(ie._html_search_meta('d', html), '4')
  59. self.assertEqual(ie._html_search_meta('e', html), '5')
  60. self.assertEqual(ie._html_search_meta('f', html), '6')
  61. self.assertEqual(ie._html_search_meta(('a', 'b', 'c'), html), '1')
  62. self.assertEqual(ie._html_search_meta(('c', 'b', 'a'), html), '3')
  63. self.assertEqual(ie._html_search_meta(('z', 'x', 'c'), html), '3')
  64. self.assertRaises(RegexNotFoundError, ie._html_search_meta, 'z', html, None, fatal=True)
  65. self.assertRaises(RegexNotFoundError, ie._html_search_meta, ('z', 'x'), html, None, fatal=True)
  66. def test_download_json(self):
  67. uri = encode_data_uri(b'{"foo": "blah"}', 'application/json')
  68. self.assertEqual(self.ie._download_json(uri, None), {'foo': 'blah'})
  69. uri = encode_data_uri(b'callback({"foo": "blah"})', 'application/javascript')
  70. self.assertEqual(self.ie._download_json(uri, None, transform_source=strip_jsonp), {'foo': 'blah'})
  71. uri = encode_data_uri(b'{"foo": invalid}', 'application/json')
  72. self.assertRaises(ExtractorError, self.ie._download_json, uri, None)
  73. self.assertEqual(self.ie._download_json(uri, None, fatal=False), None)
  74. def test_extract_jwplayer_data_realworld(self):
  75. # from http://www.suffolk.edu/sjc/
  76. expect_dict(
  77. self,
  78. self.ie._extract_jwplayer_data(r'''
  79. <script type='text/javascript'>
  80. jwplayer('my-video').setup({
  81. file: 'rtmp://192.138.214.154/live/sjclive',
  82. fallback: 'true',
  83. width: '95%',
  84. aspectratio: '16:9',
  85. primary: 'flash',
  86. mediaid:'XEgvuql4'
  87. });
  88. </script>
  89. ''', None, require_title=False),
  90. {
  91. 'id': 'XEgvuql4',
  92. 'formats': [{
  93. 'url': 'rtmp://192.138.214.154/live/sjclive',
  94. 'ext': 'flv'
  95. }]
  96. })
  97. # from https://www.pornoxo.com/videos/7564/striptease-from-sexy-secretary/
  98. expect_dict(
  99. self,
  100. self.ie._extract_jwplayer_data(r'''
  101. <script type="text/javascript">
  102. jwplayer("mediaplayer").setup({
  103. 'videoid': "7564",
  104. 'width': "100%",
  105. 'aspectratio': "16:9",
  106. 'stretching': "exactfit",
  107. 'autostart': 'false',
  108. 'flashplayer': "https://t04.vipstreamservice.com/jwplayer/v5.10/player.swf",
  109. '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",
  110. 'image': "https://t03.vipstreamservice.com/thumbs/pxo-full/2009-12/14/a4b2157147afe5efa93ce1978e0265289c193874e02597.flv-full-13.jpg",
  111. '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",
  112. 'logo.hide': true,
  113. 'skin': "https://t04.vipstreamservice.com/jwplayer/skin/modieus-blk.zip",
  114. 'plugins': "https://t04.vipstreamservice.com/jwplayer/dock/dockableskinnableplugin.swf",
  115. 'dockableskinnableplugin.piclink': "/index.php?key=ajax-videothumbsn&vid=7564&data=2009-12--14--4b2157147afe5efa93ce1978e0265289c193874e02597.flv--17370",
  116. 'controlbar': 'bottom',
  117. 'modes': [
  118. {type: 'flash', src: 'https://t04.vipstreamservice.com/jwplayer/v5.10/player.swf'}
  119. ],
  120. 'provider': 'http'
  121. });
  122. //noinspection JSAnnotator
  123. invideo.setup({
  124. adsUrl: "/banner-iframe/?zoneId=32",
  125. adsUrl2: "",
  126. autostart: false
  127. });
  128. </script>
  129. ''', 'dummy', require_title=False),
  130. {
  131. 'thumbnail': 'https://t03.vipstreamservice.com/thumbs/pxo-full/2009-12/14/a4b2157147afe5efa93ce1978e0265289c193874e02597.flv-full-13.jpg',
  132. 'formats': [{
  133. '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',
  134. 'ext': 'flv'
  135. }]
  136. })
  137. # from http://www.indiedb.com/games/king-machine/videos
  138. expect_dict(
  139. self,
  140. self.ie._extract_jwplayer_data(r'''
  141. <script>
  142. 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) {
  143. videoAnalytics("play");
  144. }).once("complete", function(event) {
  145. videoAnalytics("completed");
  146. });
  147. </script>
  148. ''', 'dummy'),
  149. {
  150. 'title': 'king machine trailer 1',
  151. 'thumbnail': 'http://media.indiedb.com/cache/images/games/1/50/49678/thumb_620x2000/king-machine-trailer.mp4.jpg',
  152. 'formats': [{
  153. 'url': 'http://cdn.dbolical.com/cache/videos/games/1/50/49678/encode_mp4/king-machine-trailer.mp4',
  154. 'height': 360,
  155. 'ext': 'mp4'
  156. }, {
  157. 'url': 'http://cdn.dbolical.com/cache/videos/games/1/50/49678/encode720p_mp4/king-machine-trailer.mp4',
  158. 'height': 720,
  159. 'ext': 'mp4'
  160. }]
  161. })
  162. def test_parse_m3u8_formats(self):
  163. _TEST_CASES = [
  164. (
  165. # https://github.com/rg3/youtube-dl/issues/11507
  166. # http://pluzz.francetv.fr/videos/le_ministere.html
  167. 'pluzz_francetv_11507',
  168. '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',
  169. [{
  170. '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',
  171. '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',
  172. 'ext': 'mp4',
  173. 'format_id': '180',
  174. 'protocol': 'm3u8',
  175. 'acodec': 'mp4a.40.2',
  176. 'vcodec': 'avc1.66.30',
  177. 'tbr': 180,
  178. 'width': 256,
  179. 'height': 144,
  180. }, {
  181. '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',
  182. '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',
  183. 'ext': 'mp4',
  184. 'format_id': '303',
  185. 'protocol': 'm3u8',
  186. 'acodec': 'mp4a.40.2',
  187. 'vcodec': 'avc1.66.30',
  188. 'tbr': 303,
  189. 'width': 320,
  190. 'height': 180,
  191. }, {
  192. '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',
  193. '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',
  194. 'ext': 'mp4',
  195. 'format_id': '575',
  196. 'protocol': 'm3u8',
  197. 'acodec': 'mp4a.40.2',
  198. 'vcodec': 'avc1.66.30',
  199. 'tbr': 575,
  200. 'width': 512,
  201. 'height': 288,
  202. }, {
  203. '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',
  204. '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',
  205. 'ext': 'mp4',
  206. 'format_id': '831',
  207. 'protocol': 'm3u8',
  208. 'acodec': 'mp4a.40.2',
  209. 'vcodec': 'avc1.77.30',
  210. 'tbr': 831,
  211. 'width': 704,
  212. 'height': 396,
  213. }, {
  214. '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',
  215. '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',
  216. 'ext': 'mp4',
  217. 'protocol': 'm3u8',
  218. 'format_id': '1467',
  219. 'acodec': 'mp4a.40.2',
  220. 'vcodec': 'avc1.77.30',
  221. 'tbr': 1467,
  222. 'width': 1024,
  223. 'height': 576,
  224. }]
  225. ),
  226. (
  227. # https://github.com/rg3/youtube-dl/issues/11995
  228. # http://teamcoco.com/video/clueless-gamer-super-bowl-for-honor
  229. 'teamcoco_11995',
  230. 'http://ak.storage-w.teamcococdn.com/cdn/2017-02/98599/ed8f/main.m3u8',
  231. [{
  232. 'url': 'http://ak.storage-w.teamcococdn.com/cdn/2017-02/98599/ed8f/hls/CONAN_020217_Highlight_show-audio-160k_v4.m3u8',
  233. 'manifest_url': 'http://ak.storage-w.teamcococdn.com/cdn/2017-02/98599/ed8f/main.m3u8',
  234. 'ext': 'mp4',
  235. 'format_id': 'audio-0-Default',
  236. 'protocol': 'm3u8',
  237. 'vcodec': 'none',
  238. }, {
  239. 'url': 'http://ak.storage-w.teamcococdn.com/cdn/2017-02/98599/ed8f/hls/CONAN_020217_Highlight_show-audio-64k_v4.m3u8',
  240. 'manifest_url': 'http://ak.storage-w.teamcococdn.com/cdn/2017-02/98599/ed8f/main.m3u8',
  241. 'ext': 'mp4',
  242. 'format_id': 'audio-1-Default',
  243. 'protocol': 'm3u8',
  244. 'vcodec': 'none',
  245. }, {
  246. 'url': 'http://ak.storage-w.teamcococdn.com/cdn/2017-02/98599/ed8f/hls/CONAN_020217_Highlight_show-audio-64k_v4.m3u8',
  247. 'manifest_url': 'http://ak.storage-w.teamcococdn.com/cdn/2017-02/98599/ed8f/main.m3u8',
  248. 'ext': 'mp4',
  249. 'format_id': '71',
  250. 'protocol': 'm3u8',
  251. 'acodec': 'mp4a.40.5',
  252. 'vcodec': 'none',
  253. 'tbr': 71,
  254. }, {
  255. 'url': 'http://ak.storage-w.teamcococdn.com/cdn/2017-02/98599/ed8f/hls/CONAN_020217_Highlight_show-400k_v4.m3u8',
  256. 'manifest_url': 'http://ak.storage-w.teamcococdn.com/cdn/2017-02/98599/ed8f/main.m3u8',
  257. 'ext': 'mp4',
  258. 'format_id': '413',
  259. 'protocol': 'm3u8',
  260. 'acodec': 'none',
  261. 'vcodec': 'avc1.42001e',
  262. 'tbr': 413,
  263. 'width': 400,
  264. 'height': 224,
  265. }, {
  266. 'url': 'http://ak.storage-w.teamcococdn.com/cdn/2017-02/98599/ed8f/hls/CONAN_020217_Highlight_show-400k_v4.m3u8',
  267. 'manifest_url': 'http://ak.storage-w.teamcococdn.com/cdn/2017-02/98599/ed8f/main.m3u8',
  268. 'ext': 'mp4',
  269. 'format_id': '522',
  270. 'protocol': 'm3u8',
  271. 'acodec': 'none',
  272. 'vcodec': 'avc1.42001e',
  273. 'tbr': 522,
  274. 'width': 400,
  275. 'height': 224,
  276. }, {
  277. 'url': 'http://ak.storage-w.teamcococdn.com/cdn/2017-02/98599/ed8f/hls/CONAN_020217_Highlight_show-1m_v4.m3u8',
  278. 'manifest_url': 'http://ak.storage-w.teamcococdn.com/cdn/2017-02/98599/ed8f/main.m3u8',
  279. 'ext': 'mp4',
  280. 'format_id': '1205',
  281. 'protocol': 'm3u8',
  282. 'acodec': 'none',
  283. 'vcodec': 'avc1.4d001e',
  284. 'tbr': 1205,
  285. 'width': 640,
  286. 'height': 360,
  287. }, {
  288. 'url': 'http://ak.storage-w.teamcococdn.com/cdn/2017-02/98599/ed8f/hls/CONAN_020217_Highlight_show-2m_v4.m3u8',
  289. 'manifest_url': 'http://ak.storage-w.teamcococdn.com/cdn/2017-02/98599/ed8f/main.m3u8',
  290. 'ext': 'mp4',
  291. 'format_id': '2374',
  292. 'protocol': 'm3u8',
  293. 'acodec': 'none',
  294. 'vcodec': 'avc1.4d001f',
  295. 'tbr': 2374,
  296. 'width': 1024,
  297. 'height': 576,
  298. }]
  299. ),
  300. (
  301. # https://github.com/rg3/youtube-dl/issues/12211
  302. # http://video.toggle.sg/en/series/whoopie-s-world/ep3/478601
  303. 'toggle_mobile_12211',
  304. 'http://cdnapi.kaltura.com/p/2082311/sp/208231100/playManifest/protocol/http/entryId/0_89q6e8ku/format/applehttp/tags/mobile_sd/f/a.m3u8',
  305. [{
  306. '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',
  307. 'manifest_url': 'http://cdnapi.kaltura.com/p/2082311/sp/208231100/playManifest/protocol/http/entryId/0_89q6e8ku/format/applehttp/tags/mobile_sd/f/a.m3u8',
  308. 'ext': 'mp4',
  309. 'format_id': 'audio-English',
  310. 'protocol': 'm3u8',
  311. 'language': 'eng',
  312. 'vcodec': 'none',
  313. }, {
  314. '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',
  315. 'manifest_url': 'http://cdnapi.kaltura.com/p/2082311/sp/208231100/playManifest/protocol/http/entryId/0_89q6e8ku/format/applehttp/tags/mobile_sd/f/a.m3u8',
  316. 'ext': 'mp4',
  317. 'format_id': 'audio-Undefined',
  318. 'protocol': 'm3u8',
  319. 'language': 'und',
  320. 'vcodec': 'none',
  321. }, {
  322. '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',
  323. 'manifest_url': 'http://cdnapi.kaltura.com/p/2082311/sp/208231100/playManifest/protocol/http/entryId/0_89q6e8ku/format/applehttp/tags/mobile_sd/f/a.m3u8',
  324. 'ext': 'mp4',
  325. 'format_id': '155',
  326. 'protocol': 'm3u8',
  327. 'tbr': 155.648,
  328. 'width': 320,
  329. 'height': 180,
  330. }, {
  331. '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',
  332. 'manifest_url': 'http://cdnapi.kaltura.com/p/2082311/sp/208231100/playManifest/protocol/http/entryId/0_89q6e8ku/format/applehttp/tags/mobile_sd/f/a.m3u8',
  333. 'ext': 'mp4',
  334. 'format_id': '502',
  335. 'protocol': 'm3u8',
  336. 'tbr': 502.784,
  337. 'width': 480,
  338. 'height': 270,
  339. }, {
  340. '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',
  341. 'manifest_url': 'http://cdnapi.kaltura.com/p/2082311/sp/208231100/playManifest/protocol/http/entryId/0_89q6e8ku/format/applehttp/tags/mobile_sd/f/a.m3u8',
  342. 'ext': 'mp4',
  343. 'format_id': '827',
  344. 'protocol': 'm3u8',
  345. 'tbr': 827.392,
  346. 'width': 640,
  347. 'height': 360,
  348. }, {
  349. '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',
  350. 'manifest_url': 'http://cdnapi.kaltura.com/p/2082311/sp/208231100/playManifest/protocol/http/entryId/0_89q6e8ku/format/applehttp/tags/mobile_sd/f/a.m3u8',
  351. 'ext': 'mp4',
  352. 'format_id': '1396',
  353. 'protocol': 'm3u8',
  354. 'tbr': 1396.736,
  355. 'width': 854,
  356. 'height': 480,
  357. }]
  358. ),
  359. (
  360. # http://www.twitch.tv/riotgames/v/6528877
  361. 'twitch_vod',
  362. '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',
  363. [{
  364. 'url': 'https://vod.edgecast.hls.ttvnw.net/e5da31ab49_riotgames_15001215120_261543898/audio_only/index-muted-HM49I092CC.m3u8',
  365. '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',
  366. 'ext': 'mp4',
  367. 'format_id': 'Audio Only',
  368. 'protocol': 'm3u8',
  369. 'acodec': 'mp4a.40.2',
  370. 'vcodec': 'none',
  371. 'tbr': 182.725,
  372. }, {
  373. 'url': 'https://vod.edgecast.hls.ttvnw.net/e5da31ab49_riotgames_15001215120_261543898/mobile/index-muted-HM49I092CC.m3u8',
  374. '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',
  375. 'ext': 'mp4',
  376. 'format_id': 'Mobile',
  377. 'protocol': 'm3u8',
  378. 'acodec': 'mp4a.40.2',
  379. 'vcodec': 'avc1.42C00D',
  380. 'tbr': 280.474,
  381. 'width': 400,
  382. 'height': 226,
  383. }, {
  384. 'url': 'https://vod.edgecast.hls.ttvnw.net/e5da31ab49_riotgames_15001215120_261543898/low/index-muted-HM49I092CC.m3u8',
  385. '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',
  386. 'ext': 'mp4',
  387. 'format_id': 'Low',
  388. 'protocol': 'm3u8',
  389. 'acodec': 'mp4a.40.2',
  390. 'vcodec': 'avc1.42C01E',
  391. 'tbr': 628.347,
  392. 'width': 640,
  393. 'height': 360,
  394. }, {
  395. 'url': 'https://vod.edgecast.hls.ttvnw.net/e5da31ab49_riotgames_15001215120_261543898/medium/index-muted-HM49I092CC.m3u8',
  396. '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',
  397. 'ext': 'mp4',
  398. 'format_id': 'Medium',
  399. 'protocol': 'm3u8',
  400. 'acodec': 'mp4a.40.2',
  401. 'vcodec': 'avc1.42C01E',
  402. 'tbr': 893.387,
  403. 'width': 852,
  404. 'height': 480,
  405. }, {
  406. 'url': 'https://vod.edgecast.hls.ttvnw.net/e5da31ab49_riotgames_15001215120_261543898/high/index-muted-HM49I092CC.m3u8',
  407. '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',
  408. 'ext': 'mp4',
  409. 'format_id': 'High',
  410. 'protocol': 'm3u8',
  411. 'acodec': 'mp4a.40.2',
  412. 'vcodec': 'avc1.42C01F',
  413. 'tbr': 1603.789,
  414. 'width': 1280,
  415. 'height': 720,
  416. }, {
  417. 'url': 'https://vod.edgecast.hls.ttvnw.net/e5da31ab49_riotgames_15001215120_261543898/chunked/index-muted-HM49I092CC.m3u8',
  418. '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',
  419. 'ext': 'mp4',
  420. 'format_id': 'Source',
  421. 'protocol': 'm3u8',
  422. 'acodec': 'mp4a.40.2',
  423. 'vcodec': 'avc1.100.31',
  424. 'tbr': 3214.134,
  425. 'width': 1280,
  426. 'height': 720,
  427. }]
  428. ),
  429. (
  430. # http://www.vidio.com/watch/165683-dj_ambred-booyah-live-2015
  431. # EXT-X-STREAM-INF tag with NAME attribute that is not defined
  432. # in HLS specification
  433. 'vidio',
  434. 'https://www.vidio.com/videos/165683/playlist.m3u8',
  435. [{
  436. 'url': 'https://cdn1-a.production.vidio.static6.com/uploads/165683/dj_ambred-4383-b300.mp4.m3u8',
  437. 'manifest_url': 'https://www.vidio.com/videos/165683/playlist.m3u8',
  438. 'ext': 'mp4',
  439. 'format_id': '270p 3G',
  440. 'protocol': 'm3u8',
  441. 'tbr': 300,
  442. 'width': 480,
  443. 'height': 270,
  444. }, {
  445. 'url': 'https://cdn1-a.production.vidio.static6.com/uploads/165683/dj_ambred-4383-b600.mp4.m3u8',
  446. 'manifest_url': 'https://www.vidio.com/videos/165683/playlist.m3u8',
  447. 'ext': 'mp4',
  448. 'format_id': '360p SD',
  449. 'protocol': 'm3u8',
  450. 'tbr': 600,
  451. 'width': 640,
  452. 'height': 360,
  453. }, {
  454. 'url': 'https://cdn1-a.production.vidio.static6.com/uploads/165683/dj_ambred-4383-b1200.mp4.m3u8',
  455. 'manifest_url': 'https://www.vidio.com/videos/165683/playlist.m3u8',
  456. 'ext': 'mp4',
  457. 'format_id': '720p HD',
  458. 'protocol': 'm3u8',
  459. 'tbr': 1200,
  460. 'width': 1280,
  461. 'height': 720,
  462. }]
  463. )
  464. ]
  465. for m3u8_file, m3u8_url, expected_formats in _TEST_CASES:
  466. with io.open('./test/testdata/m3u8/%s.m3u8' % m3u8_file,
  467. mode='r', encoding='utf-8') as f:
  468. formats = self.ie._parse_m3u8_formats(
  469. f.read(), m3u8_url, ext='mp4')
  470. self.ie._sort_formats(formats)
  471. expect_value(self, formats, expected_formats, None)
  472. if __name__ == '__main__':
  473. unittest.main()