1
0
mirror of https://github.com/yt-dlp/yt-dlp.git synced 2025-06-27 08:58:30 +00:00

skip invalid format

This commit is contained in:
c-basalt 2025-06-22 15:19:46 -04:00
parent 6beae46c0f
commit 2cc0e3e1f5

View File

@ -222,9 +222,13 @@ def _real_extract(self, url):
msg += f'. {self._login_hint()}' msg += f'. {self._login_hint()}'
raise ExtractorError(msg, expected=True) raise ExtractorError(msg, expected=True)
formats = self._extract_m3u8_formats(m3u8_url, video_id, headers=self.butter_header) raw_formats = self._extract_m3u8_formats(m3u8_url, video_id, headers=self.butter_header)
for fmt in formats: formats = []
m3u8_doc = self._download_webpage(fmt['url'], video_id, 'getting m3u8 contents', headers=self.butter_header) for fmt in raw_formats:
m3u8_doc = self._download_webpage(fmt['url'], video_id, f'getting m3u8 for {fmt["format_id"]}',
headers=self.butter_header, fatal=False)
if not m3u8_doc:
continue # skip invalid format
fmt['url'] = encode_data_uri(m3u8_doc.encode(), 'application/x-mpegurl') fmt['url'] = encode_data_uri(m3u8_doc.encode(), 'application/x-mpegurl')
match = re.search(r'^#EXT-X-KEY.*?URI="([^"]+)"', m3u8_doc, flags=re.M) match = re.search(r'^#EXT-X-KEY.*?URI="([^"]+)"', m3u8_doc, flags=re.M)
if match: if match:
@ -235,6 +239,7 @@ def _real_extract(self, url):
'age': random.randint(1, 4999), 'age': random.randint(1, 4999),
}) })
fmt['hls_aes'] = {'key': urlh.read().hex()} fmt['hls_aes'] = {'key': urlh.read().hex()}
formats.append(fmt)
return { return {
'id': video_id, 'id': video_id,