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.

94 lines
3.7 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..compat import (
  6. compat_parse_qs,
  7. compat_urllib_parse_urlparse
  8. )
  9. from ..utils import (
  10. extract_attributes,
  11. float_or_none,
  12. int_or_none,
  13. str_or_none,
  14. )
  15. class STVPlayerIE(InfoExtractor):
  16. IE_NAME = 'stv:player'
  17. _VALID_URL = r'https?://player\.stv\.tv/(?P<type>episode|video)/(?P<id>[a-z0-9]{4})'
  18. _TEST = {
  19. 'url': 'https://player.stv.tv/video/7srz/victoria/interview-with-the-cast-ahead-of-new-victoria/',
  20. 'md5': '2ad867d4afd641fa14187596e0fbc91b',
  21. 'info_dict': {
  22. 'id': '6016487034001',
  23. 'ext': 'mp4',
  24. 'upload_date': '20190321',
  25. 'title': 'Interview with the cast ahead of new Victoria',
  26. 'description': 'Nell Hudson and Lily Travers tell us what to expect in the new season of Victoria.',
  27. 'timestamp': 1553179628,
  28. 'uploader_id': '1486976045',
  29. },
  30. 'skip': 'this resource is unavailable outside of the UK',
  31. }
  32. _PUBLISHER_ID = '1486976045'
  33. _PTYPE_MAP = {
  34. 'episode': 'episodes',
  35. 'video': 'shortform',
  36. }
  37. def _real_extract(self, url):
  38. ptype, video_id = re.match(self._VALID_URL, url).groups()
  39. webpage = self._download_webpage(url, video_id)
  40. qs = compat_parse_qs(compat_urllib_parse_urlparse(self._search_regex(
  41. r'itemprop="embedURL"[^>]+href="([^"]+)',
  42. webpage, 'embed URL', default=None)).query)
  43. publisher_id = qs.get('publisherID', [None])[0] or self._PUBLISHER_ID
  44. player_attr = extract_attributes(self._search_regex(
  45. r'(<[^>]+class="bcplayer"[^>]+>)', webpage, 'player', default=None)) or {}
  46. info = {}
  47. duration = ref_id = series = video_id = None
  48. api_ref_id = player_attr.get('data-player-api-refid')
  49. if api_ref_id:
  50. resp = self._download_json(
  51. 'https://player.api.stv.tv/v1/%s/%s' % (self._PTYPE_MAP[ptype], api_ref_id),
  52. api_ref_id, fatal=False)
  53. if resp:
  54. result = resp.get('results') or {}
  55. video = result.get('video') or {}
  56. video_id = str_or_none(video.get('id'))
  57. ref_id = video.get('guid')
  58. duration = video.get('length')
  59. programme = result.get('programme') or {}
  60. series = programme.get('name') or programme.get('shortName')
  61. subtitles = {}
  62. _subtitles = result.get('_subtitles') or {}
  63. for ext, sub_url in _subtitles.items():
  64. subtitles.setdefault('en', []).append({
  65. 'ext': 'vtt' if ext == 'webvtt' else ext,
  66. 'url': sub_url,
  67. })
  68. info.update({
  69. 'description': result.get('summary'),
  70. 'subtitles': subtitles,
  71. 'view_count': int_or_none(result.get('views')),
  72. })
  73. if not video_id:
  74. video_id = qs.get('videoId', [None])[0] or self._search_regex(
  75. r'<link\s+itemprop="url"\s+href="(\d+)"',
  76. webpage, 'video id', default=None) or 'ref:' + (ref_id or player_attr['data-refid'])
  77. info.update({
  78. '_type': 'url_transparent',
  79. 'duration': float_or_none(duration or player_attr.get('data-duration'), 1000),
  80. 'id': video_id,
  81. 'ie_key': 'BrightcoveNew',
  82. 'series': series or player_attr.get('data-programme-name'),
  83. 'url': 'http://players.brightcove.net/%s/default_default/index.html?videoId=%s' % (publisher_id, video_id),
  84. })
  85. return info