[raiplay] Extract subtitles

This commit is contained in:
Sergey M․ 2017-04-08 14:11:03 +07:00
parent 80b2fdf9ac
commit 1b3feca0a7
No known key found for this signature in database
GPG Key ID: 2C393E0F18A9236D

View File

@ -97,6 +97,25 @@ def _extract_relinker_info(self, relinker_url, video_id):
'formats': formats, 'formats': formats,
}.items() if v is not None) }.items() if v is not None)
@staticmethod
def _extract_subtitles(url, subtitle_url):
subtitles = {}
if subtitle_url and isinstance(subtitle_url, compat_str):
subtitle_url = urljoin(url, subtitle_url)
STL_EXT = '.stl'
SRT_EXT = '.srt'
subtitles['it'] = [{
'ext': 'stl',
'url': subtitle_url,
}]
if subtitle_url.endswith(STL_EXT):
srt_url = subtitle_url[:-len(STL_EXT)] + SRT_EXT
subtitles['it'].append({
'ext': 'srt',
'url': srt_url,
})
return subtitles
class RaiPlayIE(RaiBaseIE): class RaiPlayIE(RaiBaseIE):
_VALID_URL = r'(?P<url>https?://(?:www\.)?raiplay\.it/.+?-(?P<id>%s)\.html)' % RaiBaseIE._UUID_RE _VALID_URL = r'(?P<url>https?://(?:www\.)?raiplay\.it/.+?-(?P<id>%s)\.html)' % RaiBaseIE._UUID_RE
@ -168,6 +187,8 @@ def _real_extract(self, url):
timestamp = unified_timestamp(try_get( timestamp = unified_timestamp(try_get(
media, lambda x: x['availabilities'][0]['start'], compat_str)) media, lambda x: x['availabilities'][0]['start'], compat_str))
subtitles = self._extract_subtitles(url, video.get('subtitles'))
info = { info = {
'id': video_id, 'id': video_id,
'title': title, 'title': title,
@ -183,6 +204,7 @@ def _real_extract(self, url):
'season_number': int_or_none(try_get( 'season_number': int_or_none(try_get(
media, lambda x: x['isPartOf']['numeroStagioni'])), media, lambda x: x['isPartOf']['numeroStagioni'])),
'season': media.get('stagione') or None, 'season': media.get('stagione') or None,
'subtitles': subtitles,
} }
info.update(relinker_info) info.update(relinker_info)
@ -307,17 +329,7 @@ def _extract_from_content_id(self, content_id, url):
'url': compat_urlparse.urljoin(url, thumbnail_url), 'url': compat_urlparse.urljoin(url, thumbnail_url),
}) })
subtitles = {} subtitles = self._extract_subtitles(url, media.get('subtitlesUrl'))
captions = media.get('subtitlesUrl')
if captions:
STL_EXT = '.stl'
SRT_EXT = '.srt'
if captions.endswith(STL_EXT):
captions = captions[:-len(STL_EXT)] + SRT_EXT
subtitles['it'] = [{
'ext': 'srt',
'url': captions,
}]
info = { info = {
'id': content_id, 'id': content_id,