[plutotv] Extract subtitles from manifests

This commit is contained in:
pukkandan 2021-05-06 00:20:28 +05:30
parent c28cfda81f
commit 7700b37f39
No known key found for this signature in database
GPG Key ID: 0F00D95A001F4698
1 changed files with 19 additions and 15 deletions

View File

@ -78,9 +78,8 @@ class PlutoTVIE(InfoExtractor):
}, },
] ]
def _to_ad_free_formats(self, video_id, formats): def _to_ad_free_formats(self, video_id, formats, subtitles):
ad_free_formats = [] ad_free_formats, ad_free_subtitles, m3u8_urls = [], {}, set()
m3u8_urls = set()
for format in formats: for format in formats:
res = self._download_webpage( res = self._download_webpage(
format.get('url'), video_id, note='Downloading m3u8 playlist', format.get('url'), video_id, note='Downloading m3u8 playlist',
@ -96,27 +95,32 @@ class PlutoTVIE(InfoExtractor):
compat_urlparse.urljoin(first_segment_url.group(1), '0-end/master.m3u8')) compat_urlparse.urljoin(first_segment_url.group(1), '0-end/master.m3u8'))
for m3u8_url in m3u8_urls: for m3u8_url in m3u8_urls:
ad_free_formats.extend( fmts, subs = self._extract_m3u8_formats_and_subtitles(
self._extract_m3u8_formats( m3u8_url, video_id, 'mp4', 'm3u8_native', m3u8_id='hls', fatal=False)
m3u8_url, video_id, 'mp4', 'm3u8_native', ad_free_formats.extend(fmts)
m3u8_id='hls', fatal=False)) ad_free_subtitles = self._merge_subtitles(ad_free_subtitles, subs)
self._sort_formats(ad_free_formats) return ad_free_formats, ad_free_subtitles
return ad_free_formats
def _get_video_info(self, video_json, slug, series_name=None): def _get_video_info(self, video_json, slug, series_name=None):
video_id = video_json.get('_id', slug) video_id = video_json.get('_id', slug)
formats = [] formats, subtitles = [], {}
for video_url in try_get(video_json, lambda x: x['stitched']['urls'], list) or []: for video_url in try_get(video_json, lambda x: x['stitched']['urls'], list) or []:
if video_url.get('type') != 'hls': if video_url.get('type') != 'hls':
continue continue
url = url_or_none(video_url.get('url')) url = url_or_none(video_url.get('url'))
formats.extend(
self._extract_m3u8_formats( fmts, subs = self._extract_m3u8_formats_and_subtitles(
url, video_id, 'mp4', 'm3u8_native', url, video_id, 'mp4', 'm3u8_native', m3u8_id='hls', fatal=False)
m3u8_id='hls', fatal=False)) formats.extend(fmts)
subtitles = self._merge_subtitles(subtitles, subs)
formats, subtitles = self._to_ad_free_formats(video_id, formats, subtitles)
self._sort_formats(formats)
info = { info = {
'id': video_id, 'id': video_id,
'formats': self._to_ad_free_formats(video_id, formats), 'formats': formats,
'subtitles': subtitles,
'title': video_json.get('name'), 'title': video_json.get('name'),
'description': video_json.get('description'), 'description': video_json.get('description'),
'duration': float_or_none(video_json.get('duration'), scale=1000), 'duration': float_or_none(video_json.get('duration'), scale=1000),