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.

134 lines
5.3 KiB

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