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