From 3cf4b91dc5ecc8e936e75204afe62b2884c55362 Mon Sep 17 00:00:00 2001 From: ChillingPepper <90042155+ChillingPepper@users.noreply.github.com> Date: Mon, 27 Sep 2021 23:00:41 +0200 Subject: [PATCH] [SovietsCloset] Add duration from m3u8 (#908) Authored by: ChillingPepper --- yt_dlp/extractor/common.py | 19 +++++++++++++++++++ yt_dlp/extractor/sovietscloset.py | 9 +++++++++ 2 files changed, 28 insertions(+) diff --git a/yt_dlp/extractor/common.py b/yt_dlp/extractor/common.py index 4797e8e2d..114b1faaf 100644 --- a/yt_dlp/extractor/common.py +++ b/yt_dlp/extractor/common.py @@ -2219,6 +2219,25 @@ def build_stream_name(): last_stream_inf = {} return formats, subtitles + def _extract_m3u8_vod_duration( + self, m3u8_vod_url, video_id, note=None, errnote=None, data=None, headers={}, query={}): + + m3u8_vod = self._download_webpage( + m3u8_vod_url, video_id, + note='Downloading m3u8 VOD manifest' if note is None else note, + errnote='Failed to download VOD manifest' if errnote is None else errnote, + fatal=False, data=data, headers=headers, query=query) + + return self._parse_m3u8_vod_duration(m3u8_vod or '', video_id) + + def _parse_m3u8_vod_duration(self, m3u8_vod, video_id): + if '#EXT-X-PLAYLIST-TYPE:VOD' not in m3u8_vod: + return None + + return int(sum( + float(line[len('#EXTINF:'):].split(',')[0]) + for line in m3u8_vod.splitlines() if line.startswith('#EXTINF:'))) or None + @staticmethod def _xpath_ns(path, namespace=None): if not namespace: diff --git a/yt_dlp/extractor/sovietscloset.py b/yt_dlp/extractor/sovietscloset.py index 64201c88c..7df23759a 100644 --- a/yt_dlp/extractor/sovietscloset.py +++ b/yt_dlp/extractor/sovietscloset.py @@ -72,6 +72,7 @@ class SovietsClosetIE(SovietsClosetBaseIE): 'upload_date': '20170413', 'uploader_id': 'SovietWomble', 'uploader_url': 'https://www.twitch.tv/SovietWomble', + 'duration': 7007, 'was_live': True, 'availability': 'public', 'series': 'The Witcher', @@ -96,6 +97,7 @@ class SovietsClosetIE(SovietsClosetBaseIE): 'upload_date': '20160420', 'uploader_id': 'SovietWomble', 'uploader_url': 'https://www.twitch.tv/SovietWomble', + 'duration': 8804, 'was_live': True, 'availability': 'public', 'series': 'Arma 3', @@ -116,9 +118,16 @@ def _extract_bunnycdn_iframe(self, video_id, bunnycdn_id): m3u8_formats = self._extract_m3u8_formats(m3u8_url, video_id, headers=self.MEDIADELIVERY_REFERER) self._sort_formats(m3u8_formats) + if not m3u8_formats: + duration = None + else: + duration = self._extract_m3u8_vod_duration( + m3u8_formats[0]['url'], video_id, headers=self.MEDIADELIVERY_REFERER) + return { 'formats': m3u8_formats, 'thumbnail': thumbnail_url, + 'duration': duration, } def _real_extract(self, url):