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.

115 lines
4.4 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..utils import (
  6. determine_ext,
  7. float_or_none,
  8. int_or_none,
  9. mimetype2ext,
  10. parse_iso8601,
  11. strip_jsonp,
  12. )
  13. class ArkenaIE(InfoExtractor):
  14. _VALID_URL = r'https?://play\.arkena\.com/(?:config|embed)/avp/v\d/player/media/(?P<id>[^/]+)/[^/]+/(?P<account_id>\d+)'
  15. _TESTS = [{
  16. 'url': 'https://play.arkena.com/embed/avp/v2/player/media/b41dda37-d8e7-4d3f-b1b5-9a9db578bdfe/1/129411',
  17. 'md5': 'b96f2f71b359a8ecd05ce4e1daa72365',
  18. 'info_dict': {
  19. 'id': 'b41dda37-d8e7-4d3f-b1b5-9a9db578bdfe',
  20. 'ext': 'mp4',
  21. 'title': 'Big Buck Bunny',
  22. 'description': 'Royalty free test video',
  23. 'timestamp': 1432816365,
  24. 'upload_date': '20150528',
  25. 'is_live': False,
  26. },
  27. }, {
  28. 'url': 'https://play.arkena.com/config/avp/v2/player/media/b41dda37-d8e7-4d3f-b1b5-9a9db578bdfe/1/129411/?callbackMethod=jQuery1111023664739129262213_1469227693893',
  29. 'only_matching': True,
  30. }, {
  31. 'url': 'http://play.arkena.com/config/avp/v1/player/media/327336/darkmatter/131064/?callbackMethod=jQuery1111002221189684892677_1469227595972',
  32. 'only_matching': True,
  33. }, {
  34. 'url': 'http://play.arkena.com/embed/avp/v1/player/media/327336/darkmatter/131064/',
  35. 'only_matching': True,
  36. }]
  37. @staticmethod
  38. def _extract_url(webpage):
  39. # See https://support.arkena.com/display/PLAY/Ways+to+embed+your+video
  40. mobj = re.search(
  41. r'<iframe[^>]+src=(["\'])(?P<url>(?:https?:)?//play\.arkena\.com/embed/avp/.+?)\1',
  42. webpage)
  43. if mobj:
  44. return mobj.group('url')
  45. def _real_extract(self, url):
  46. mobj = re.match(self._VALID_URL, url)
  47. video_id = mobj.group('id')
  48. account_id = mobj.group('account_id')
  49. playlist = self._download_json(
  50. 'https://play.arkena.com/config/avp/v2/player/media/%s/0/%s/?callbackMethod=_'
  51. % (video_id, account_id),
  52. video_id, transform_source=strip_jsonp)['Playlist'][0]
  53. media_info = playlist['MediaInfo']
  54. title = media_info['Title']
  55. media_files = playlist['MediaFiles']
  56. is_live = False
  57. formats = []
  58. for kind_case, kind_formats in media_files.items():
  59. kind = kind_case.lower()
  60. for f in kind_formats:
  61. f_url = f.get('Url')
  62. if not f_url:
  63. continue
  64. is_live = f.get('Live') == 'true'
  65. exts = (mimetype2ext(f.get('Type')), determine_ext(f_url, None))
  66. if kind == 'm3u8' or 'm3u8' in exts:
  67. formats.extend(self._extract_m3u8_formats(
  68. f_url, video_id, 'mp4',
  69. entry_protocol='m3u8' if is_live else 'm3u8_native',
  70. m3u8_id=kind, fatal=False, live=is_live))
  71. elif kind == 'flash' or 'f4m' in exts:
  72. formats.extend(self._extract_f4m_formats(
  73. f_url, video_id, f4m_id=kind, fatal=False))
  74. elif kind == 'dash' or 'mpd' in exts:
  75. formats.extend(self._extract_mpd_formats(
  76. f_url, video_id, mpd_id=kind, fatal=False))
  77. elif kind == 'silverlight':
  78. # TODO: process when ism is supported (see
  79. # https://github.com/rg3/youtube-dl/issues/8118)
  80. continue
  81. else:
  82. tbr = float_or_none(f.get('Bitrate'), 1000)
  83. formats.append({
  84. 'url': f_url,
  85. 'format_id': '%s-%d' % (kind, tbr) if tbr else kind,
  86. 'tbr': tbr,
  87. })
  88. self._sort_formats(formats)
  89. description = media_info.get('Description')
  90. video_id = media_info.get('VideoId') or video_id
  91. timestamp = parse_iso8601(media_info.get('PublishDate'))
  92. thumbnails = [{
  93. 'url': thumbnail['Url'],
  94. 'width': int_or_none(thumbnail.get('Size')),
  95. } for thumbnail in (media_info.get('Poster') or []) if thumbnail.get('Url')]
  96. return {
  97. 'id': video_id,
  98. 'title': title,
  99. 'description': description,
  100. 'timestamp': timestamp,
  101. 'is_live': is_live,
  102. 'thumbnails': thumbnails,
  103. 'formats': formats,
  104. }