mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2024-12-15 07:42:42 +00:00
[stv] fix extraction(closes #22928)
This commit is contained in:
parent
5e36b63486
commit
e54924c46f
1 changed files with 31 additions and 58 deletions
|
@ -4,15 +4,10 @@ from __future__ import unicode_literals
|
||||||
import re
|
import re
|
||||||
|
|
||||||
from .common import InfoExtractor
|
from .common import InfoExtractor
|
||||||
from ..compat import (
|
|
||||||
compat_parse_qs,
|
|
||||||
compat_urllib_parse_urlparse
|
|
||||||
)
|
|
||||||
from ..utils import (
|
from ..utils import (
|
||||||
extract_attributes,
|
compat_str,
|
||||||
float_or_none,
|
float_or_none,
|
||||||
int_or_none,
|
int_or_none,
|
||||||
str_or_none,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -20,20 +15,20 @@ class STVPlayerIE(InfoExtractor):
|
||||||
IE_NAME = 'stv:player'
|
IE_NAME = 'stv:player'
|
||||||
_VALID_URL = r'https?://player\.stv\.tv/(?P<type>episode|video)/(?P<id>[a-z0-9]{4})'
|
_VALID_URL = r'https?://player\.stv\.tv/(?P<type>episode|video)/(?P<id>[a-z0-9]{4})'
|
||||||
_TEST = {
|
_TEST = {
|
||||||
'url': 'https://player.stv.tv/video/7srz/victoria/interview-with-the-cast-ahead-of-new-victoria/',
|
'url': 'https://player.stv.tv/video/4gwd/emmerdale/60-seconds-on-set-with-laura-norton/',
|
||||||
'md5': '2ad867d4afd641fa14187596e0fbc91b',
|
'md5': '5adf9439c31d554f8be0707c7abe7e0a',
|
||||||
'info_dict': {
|
'info_dict': {
|
||||||
'id': '6016487034001',
|
'id': '5333973339001',
|
||||||
'ext': 'mp4',
|
'ext': 'mp4',
|
||||||
'upload_date': '20190321',
|
'upload_date': '20170301',
|
||||||
'title': 'Interview with the cast ahead of new Victoria',
|
'title': '60 seconds on set with Laura Norton',
|
||||||
'description': 'Nell Hudson and Lily Travers tell us what to expect in the new season of Victoria.',
|
'description': "How many questions can Laura - a.k.a Kerry Wyatt - answer in 60 seconds? Let\'s find out!",
|
||||||
'timestamp': 1553179628,
|
'timestamp': 1488388054,
|
||||||
'uploader_id': '1486976045',
|
'uploader_id': '1486976045',
|
||||||
},
|
},
|
||||||
'skip': 'this resource is unavailable outside of the UK',
|
'skip': 'this resource is unavailable outside of the UK',
|
||||||
}
|
}
|
||||||
_PUBLISHER_ID = '1486976045'
|
BRIGHTCOVE_URL_TEMPLATE = 'http://players.brightcove.net/1486976045/default_default/index.html?videoId=%s'
|
||||||
_PTYPE_MAP = {
|
_PTYPE_MAP = {
|
||||||
'episode': 'episodes',
|
'episode': 'episodes',
|
||||||
'video': 'shortform',
|
'video': 'shortform',
|
||||||
|
@ -41,31 +36,14 @@ class STVPlayerIE(InfoExtractor):
|
||||||
|
|
||||||
def _real_extract(self, url):
|
def _real_extract(self, url):
|
||||||
ptype, video_id = re.match(self._VALID_URL, url).groups()
|
ptype, video_id = re.match(self._VALID_URL, url).groups()
|
||||||
webpage = self._download_webpage(url, video_id)
|
|
||||||
|
|
||||||
qs = compat_parse_qs(compat_urllib_parse_urlparse(self._search_regex(
|
|
||||||
r'itemprop="embedURL"[^>]+href="([^"]+)',
|
|
||||||
webpage, 'embed URL', default=None)).query)
|
|
||||||
publisher_id = qs.get('publisherID', [None])[0] or self._PUBLISHER_ID
|
|
||||||
|
|
||||||
player_attr = extract_attributes(self._search_regex(
|
|
||||||
r'(<[^>]+class="bcplayer"[^>]+>)', webpage, 'player', default=None)) or {}
|
|
||||||
|
|
||||||
info = {}
|
|
||||||
duration = ref_id = series = video_id = None
|
|
||||||
api_ref_id = player_attr.get('data-player-api-refid')
|
|
||||||
if api_ref_id:
|
|
||||||
resp = self._download_json(
|
resp = self._download_json(
|
||||||
'https://player.api.stv.tv/v1/%s/%s' % (self._PTYPE_MAP[ptype], api_ref_id),
|
'https://player.api.stv.tv/v1/%s/%s' % (self._PTYPE_MAP[ptype], video_id),
|
||||||
api_ref_id, fatal=False)
|
video_id)
|
||||||
if resp:
|
|
||||||
result = resp.get('results') or {}
|
result = resp['results']
|
||||||
video = result.get('video') or {}
|
video = result['video']
|
||||||
video_id = str_or_none(video.get('id'))
|
video_id = compat_str(video['id'])
|
||||||
ref_id = video.get('guid')
|
|
||||||
duration = video.get('length')
|
|
||||||
programme = result.get('programme') or {}
|
|
||||||
series = programme.get('name') or programme.get('shortName')
|
|
||||||
subtitles = {}
|
subtitles = {}
|
||||||
_subtitles = result.get('_subtitles') or {}
|
_subtitles = result.get('_subtitles') or {}
|
||||||
for ext, sub_url in _subtitles.items():
|
for ext, sub_url in _subtitles.items():
|
||||||
|
@ -73,22 +51,17 @@ class STVPlayerIE(InfoExtractor):
|
||||||
'ext': 'vtt' if ext == 'webvtt' else ext,
|
'ext': 'vtt' if ext == 'webvtt' else ext,
|
||||||
'url': sub_url,
|
'url': sub_url,
|
||||||
})
|
})
|
||||||
info.update({
|
|
||||||
|
programme = result.get('programme') or {}
|
||||||
|
|
||||||
|
return {
|
||||||
|
'_type': 'url_transparent',
|
||||||
|
'id': video_id,
|
||||||
|
'url': self.BRIGHTCOVE_URL_TEMPLATE % video_id,
|
||||||
'description': result.get('summary'),
|
'description': result.get('summary'),
|
||||||
|
'duration': float_or_none(video.get('length'), 1000),
|
||||||
'subtitles': subtitles,
|
'subtitles': subtitles,
|
||||||
'view_count': int_or_none(result.get('views')),
|
'view_count': int_or_none(result.get('views')),
|
||||||
})
|
'series': programme.get('name') or programme.get('shortName'),
|
||||||
if not video_id:
|
|
||||||
video_id = qs.get('videoId', [None])[0] or self._search_regex(
|
|
||||||
r'<link\s+itemprop="url"\s+href="(\d+)"',
|
|
||||||
webpage, 'video id', default=None) or 'ref:' + (ref_id or player_attr['data-refid'])
|
|
||||||
|
|
||||||
info.update({
|
|
||||||
'_type': 'url_transparent',
|
|
||||||
'duration': float_or_none(duration or player_attr.get('data-duration'), 1000),
|
|
||||||
'id': video_id,
|
|
||||||
'ie_key': 'BrightcoveNew',
|
'ie_key': 'BrightcoveNew',
|
||||||
'series': series or player_attr.get('data-programme-name'),
|
}
|
||||||
'url': 'http://players.brightcove.net/%s/default_default/index.html?videoId=%s' % (publisher_id, video_id),
|
|
||||||
})
|
|
||||||
return info
|
|
||||||
|
|
Loading…
Reference in a new issue