diff options
author | ChillingPepper <90042155+ChillingPepper@users.noreply.github.com> | 2021-09-27 23:00:41 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-09-28 02:30:41 +0530 |
commit | 3cf4b91dc5ecc8e936e75204afe62b2884c55362 (patch) | |
tree | 524ee02b0418cbbabf5f3293d7430117c8e20a97 /yt_dlp/extractor/common.py | |
parent | fecb20a503720e03349391752c17afd7194856e6 (diff) | |
download | hypervideo-pre-3cf4b91dc5ecc8e936e75204afe62b2884c55362.tar.lz hypervideo-pre-3cf4b91dc5ecc8e936e75204afe62b2884c55362.tar.xz hypervideo-pre-3cf4b91dc5ecc8e936e75204afe62b2884c55362.zip |
[SovietsCloset] Add duration from m3u8 (#908)
Authored by: ChillingPepper
Diffstat (limited to 'yt_dlp/extractor/common.py')
-rw-r--r-- | yt_dlp/extractor/common.py | 19 |
1 files changed, 19 insertions, 0 deletions
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 @@ class InfoExtractor(object): 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: |