forked from kenzuya/unshackle
fix(manifests): skip a DASH Representation or HLS variant with an unknown codec
This commit is contained in:
@@ -300,6 +300,12 @@ class DASH:
|
||||
All Track URLs will be a list of segment URLs.
|
||||
"""
|
||||
tracks = Tracks()
|
||||
skipped = 0
|
||||
codec_types: dict[str, type[Video] | type[Audio] | type[Subtitle]] = {
|
||||
"video": Video,
|
||||
"audio": Audio,
|
||||
"text": Subtitle,
|
||||
}
|
||||
|
||||
filtered_period_ids: list[str] = []
|
||||
|
||||
@@ -340,29 +346,36 @@ class DASH:
|
||||
if content_type == "application" and mime_type and "/mp4" not in mime_type:
|
||||
content_type = "text"
|
||||
|
||||
if mime_type == "application/mp4" or content_type == "application":
|
||||
# likely mp4-boxed subtitles
|
||||
# TODO: It may not actually be subtitles
|
||||
try:
|
||||
try:
|
||||
if mime_type == "application/mp4" or content_type == "application":
|
||||
# likely mp4-boxed subtitles
|
||||
# TODO: It may not actually be subtitles
|
||||
real_codec = Subtitle.Codec.from_mime(codecs or "")
|
||||
content_type = "text"
|
||||
mime_type = f"application/mp4; codecs='{real_codec.value.lower()}'"
|
||||
except ValueError:
|
||||
raise ValueError(
|
||||
f"Unsupported content type '{content_type}' with codecs of '{codecs}'"
|
||||
) from None
|
||||
|
||||
if content_type == "text" and mime_type and "/mp4" not in mime_type:
|
||||
# mimeType likely specifies the subtitle codec better than `codecs`
|
||||
codecs = mime_type.split("/")[1]
|
||||
if content_type == "text" and mime_type and "/mp4" not in mime_type:
|
||||
# mimeType likely specifies the subtitle codec better than `codecs`
|
||||
codecs = mime_type.split("/")[1]
|
||||
|
||||
codec_type = codec_types.get(content_type or "")
|
||||
track_codec: Any = (
|
||||
codec_type.Codec.from_codecs(codecs or ("vtt" if codec_type is Subtitle else ""))
|
||||
if codec_type
|
||||
else None
|
||||
)
|
||||
except ValueError:
|
||||
logging.getLogger("DASH").warning(
|
||||
f"Skipped DASH Representation '{rep.get('id')}': unsupported codec '{codecs or ''}'"
|
||||
)
|
||||
skipped += 1
|
||||
continue
|
||||
|
||||
video_args: dict[str, Any] = {}
|
||||
track_type: type[Video] | type[Audio] | type[Subtitle]
|
||||
track_codec: Any # always the Codec of track_type, a pairing mypy cannot express
|
||||
track_args: dict[str, Any]
|
||||
if content_type == "video":
|
||||
track_type = Video
|
||||
track_codec = Video.Codec.from_codecs(codecs or "")
|
||||
track_fps = get("frameRate")
|
||||
if not track_fps and segment_base is not None:
|
||||
track_fps = segment_base.get("timescale")
|
||||
@@ -388,7 +401,6 @@ class DASH:
|
||||
video_args["stereo"] = Video.is_stereo(codecs, get("supplementalCodecs"))
|
||||
elif content_type == "audio":
|
||||
track_type = Audio
|
||||
track_codec = Audio.Codec.from_codecs(codecs or "")
|
||||
track_args = dict(
|
||||
bitrate=get("bandwidth") or None,
|
||||
channels=self.get_audio_channels(adaptation_set, rep),
|
||||
@@ -397,7 +409,6 @@ class DASH:
|
||||
)
|
||||
elif content_type == "text":
|
||||
track_type = Subtitle
|
||||
track_codec = Subtitle.Codec.from_codecs(codecs or "vtt")
|
||||
track_args = dict(
|
||||
cc=self.is_closed_caption(adaptation_set),
|
||||
sdh=self.is_sdh(adaptation_set),
|
||||
@@ -455,6 +466,9 @@ class DASH:
|
||||
|
||||
break
|
||||
|
||||
if skipped and not tracks:
|
||||
raise ValueError(f"No DASH Representation has a supported codec: {skipped} skipped")
|
||||
|
||||
tracks.manifest_url = self.url
|
||||
|
||||
log_event(
|
||||
|
||||
@@ -227,6 +227,7 @@ class HLS:
|
||||
}
|
||||
)
|
||||
tracks = Tracks()
|
||||
skipped = 0
|
||||
|
||||
supplemental_codecs = self.supplemental_codecs_by_uri()
|
||||
|
||||
@@ -236,12 +237,22 @@ class HLS:
|
||||
]
|
||||
for playlist, video_layout in zip(self.manifest.playlists, video_layouts, strict=False):
|
||||
video_codec: Video.Codec | None = None
|
||||
audio_codec: Audio.Codec | None = None
|
||||
primary_track_type: type[Audio] | type[Video]
|
||||
try:
|
||||
# TODO: Any better way to figure out the primary track type?
|
||||
if playlist.stream_info.codecs:
|
||||
video_codec = Video.Codec.from_codecs(playlist.stream_info.codecs)
|
||||
except ValueError:
|
||||
with suppress(ValueError):
|
||||
audio_codec = Audio.Codec.from_codecs(playlist.stream_info.codecs)
|
||||
if audio_codec is None or playlist.stream_info.resolution:
|
||||
logging.getLogger("HLS").warning(
|
||||
f"Skipped HLS variant '{safe_display_url(playlist.uri)}': "
|
||||
f"unsupported codec '{playlist.stream_info.codecs}'"
|
||||
)
|
||||
skipped += 1
|
||||
continue
|
||||
primary_track_type = Audio
|
||||
else:
|
||||
primary_track_type = Video
|
||||
@@ -263,11 +274,7 @@ class HLS:
|
||||
primary_track_type(
|
||||
id_=hex(crc32(str(playlist).encode()))[2:],
|
||||
url=urljoin(playlist.base_uri, playlist.uri),
|
||||
codec=(
|
||||
cast(Any, primary_track_type.Codec.from_codecs(playlist.stream_info.codecs))
|
||||
if playlist.stream_info.codecs
|
||||
else None
|
||||
),
|
||||
codec=cast(Any, video_codec or audio_codec),
|
||||
language=language, # HLS manifests do not seem to have language info
|
||||
is_original_lang=True, # TODO: All we can do is assume Yes
|
||||
bitrate=playlist.stream_info.average_bandwidth or playlist.stream_info.bandwidth,
|
||||
@@ -373,6 +380,9 @@ class HLS:
|
||||
except Exception as e:
|
||||
logging.getLogger("HLS").debug(f"TS probe failed for {video.url}: {e!r}")
|
||||
|
||||
if skipped and not tracks:
|
||||
raise ValueError(f"No HLS variant has a supported codec: {skipped} skipped")
|
||||
|
||||
if self.url:
|
||||
tracks.manifest_url = self.url
|
||||
|
||||
|
||||
Reference in New Issue
Block a user