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.

67 lines
2.3 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..utils import (
  6. compat_str,
  7. float_or_none,
  8. int_or_none,
  9. )
  10. class STVPlayerIE(InfoExtractor):
  11. IE_NAME = 'stv:player'
  12. _VALID_URL = r'https?://player\.stv\.tv/(?P<type>episode|video)/(?P<id>[a-z0-9]{4})'
  13. _TEST = {
  14. 'url': 'https://player.stv.tv/video/4gwd/emmerdale/60-seconds-on-set-with-laura-norton/',
  15. 'md5': '5adf9439c31d554f8be0707c7abe7e0a',
  16. 'info_dict': {
  17. 'id': '5333973339001',
  18. 'ext': 'mp4',
  19. 'upload_date': '20170301',
  20. 'title': '60 seconds on set with Laura Norton',
  21. 'description': "How many questions can Laura - a.k.a Kerry Wyatt - answer in 60 seconds? Let\'s find out!",
  22. 'timestamp': 1488388054,
  23. 'uploader_id': '1486976045',
  24. },
  25. 'skip': 'this resource is unavailable outside of the UK',
  26. }
  27. BRIGHTCOVE_URL_TEMPLATE = 'http://players.brightcove.net/1486976045/default_default/index.html?videoId=%s'
  28. _PTYPE_MAP = {
  29. 'episode': 'episodes',
  30. 'video': 'shortform',
  31. }
  32. def _real_extract(self, url):
  33. ptype, video_id = re.match(self._VALID_URL, url).groups()
  34. resp = self._download_json(
  35. 'https://player.api.stv.tv/v1/%s/%s' % (self._PTYPE_MAP[ptype], video_id),
  36. video_id)
  37. result = resp['results']
  38. video = result['video']
  39. video_id = compat_str(video['id'])
  40. subtitles = {}
  41. _subtitles = result.get('_subtitles') or {}
  42. for ext, sub_url in _subtitles.items():
  43. subtitles.setdefault('en', []).append({
  44. 'ext': 'vtt' if ext == 'webvtt' else ext,
  45. 'url': sub_url,
  46. })
  47. programme = result.get('programme') or {}
  48. return {
  49. '_type': 'url_transparent',
  50. 'id': video_id,
  51. 'url': self.BRIGHTCOVE_URL_TEMPLATE % video_id,
  52. 'description': result.get('summary'),
  53. 'duration': float_or_none(video.get('length'), 1000),
  54. 'subtitles': subtitles,
  55. 'view_count': int_or_none(result.get('views')),
  56. 'series': programme.get('name') or programme.get('shortName'),
  57. 'ie_key': 'BrightcoveNew',
  58. }