From 7700b37f391f8cdf8afc66af2e0050e3ad93c083 Mon Sep 17 00:00:00 2001 From: pukkandan Date: Thu, 6 May 2021 00:20:28 +0530 Subject: [PATCH] [plutotv] Extract subtitles from manifests --- yt_dlp/extractor/plutotv.py | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/yt_dlp/extractor/plutotv.py b/yt_dlp/extractor/plutotv.py index a05752413..4ec2626bc 100644 --- a/yt_dlp/extractor/plutotv.py +++ b/yt_dlp/extractor/plutotv.py @@ -78,9 +78,8 @@ class PlutoTVIE(InfoExtractor): }, ] - def _to_ad_free_formats(self, video_id, formats): - ad_free_formats = [] - m3u8_urls = set() + def _to_ad_free_formats(self, video_id, formats, subtitles): + ad_free_formats, ad_free_subtitles, m3u8_urls = [], {}, set() for format in formats: res = self._download_webpage( 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')) for m3u8_url in m3u8_urls: - ad_free_formats.extend( - self._extract_m3u8_formats( - m3u8_url, video_id, 'mp4', 'm3u8_native', - m3u8_id='hls', fatal=False)) - self._sort_formats(ad_free_formats) - return ad_free_formats + fmts, subs = self._extract_m3u8_formats_and_subtitles( + m3u8_url, video_id, 'mp4', 'm3u8_native', m3u8_id='hls', fatal=False) + ad_free_formats.extend(fmts) + ad_free_subtitles = self._merge_subtitles(ad_free_subtitles, subs) + return ad_free_formats, ad_free_subtitles def _get_video_info(self, video_json, slug, series_name=None): 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 []: if video_url.get('type') != 'hls': continue url = url_or_none(video_url.get('url')) - formats.extend( - self._extract_m3u8_formats( - url, video_id, 'mp4', 'm3u8_native', - m3u8_id='hls', fatal=False)) + + fmts, subs = self._extract_m3u8_formats_and_subtitles( + url, video_id, 'mp4', 'm3u8_native', 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 = { 'id': video_id, - 'formats': self._to_ad_free_formats(video_id, formats), + 'formats': formats, + 'subtitles': subtitles, 'title': video_json.get('name'), 'description': video_json.get('description'), 'duration': float_or_none(video_json.get('duration'), scale=1000),