mirror of
https://github.com/unshackle-dl/unshackle.git
synced 2026-11-26 19:05:13 +00:00
fix(import): take a missing title language from the exported tracks
A title with no language now takes the language of an original-language track, else a video track, so an unlabelled MPD re-parses and -l orig works. A track that no longer matches its manifest is dropped with a warning instead of failing at download.
This commit is contained in:
@@ -102,7 +102,8 @@ def resolve_import_manifest_data(
|
||||
Exports can be without ``manifest_url`` (for example, when the service never set
|
||||
``title.tracks.manifest_url``) or carry one MPD per adaptation set. ``Track.from_dict``
|
||||
does not serialise manifest XML, so each exported track's ``url`` is re-fetched and
|
||||
matched to a locally parsed representation before download.
|
||||
matched to a locally parsed representation before download. A track that matches none is
|
||||
dropped with a warning, since without its manifest data it fails only when it downloads.
|
||||
"""
|
||||
if manifest_type not in MANIFEST_DATA_KEYS:
|
||||
return
|
||||
@@ -143,6 +144,13 @@ def resolve_import_manifest_data(
|
||||
if matched and matched.data.get(data_key):
|
||||
track.data.update(matched.data)
|
||||
|
||||
unmatched = {str(track.id) for track in pending if not track.data.get(data_key)}
|
||||
for track_id in unmatched:
|
||||
log.warning(f"Skipping exported track {track_id}: its {manifest_type} manifest no longer lists it")
|
||||
tracks.select_video(lambda t: str(t.id) not in unmatched)
|
||||
tracks.select_audio(lambda t: str(t.id) not in unmatched)
|
||||
tracks.select_subtitles(lambda t: str(t.id) not in unmatched)
|
||||
|
||||
|
||||
def parse_codec(codec: type[E], parse: Callable[[str], E], value: Any) -> Optional[E]:
|
||||
"""The codec a row names by enum name (``hevc``) or as ``parse`` reads it, else None."""
|
||||
@@ -316,7 +324,7 @@ class ImportService:
|
||||
if self.titles is not None:
|
||||
return self.titles
|
||||
titles_list = [
|
||||
build_title(entry.get("meta", {}), self.service_tag, fallback_id=title_id)
|
||||
build_title(self.title_meta(entry), self.service_tag, fallback_id=title_id)
|
||||
for title_id, entry in self.titles_data.items()
|
||||
]
|
||||
self.titles = (
|
||||
@@ -324,6 +332,23 @@ class ImportService:
|
||||
)
|
||||
return self.titles
|
||||
|
||||
@staticmethod
|
||||
def title_meta(entry: dict[str, Any]) -> dict[str, Any]:
|
||||
"""The title meta, with the language of an exported track when the title has none.
|
||||
|
||||
A service can set no title language yet label its tracks. The manifest re-parse and
|
||||
``-l orig`` need a title language, so an original-language track gives it, else a video.
|
||||
"""
|
||||
meta = entry.get("meta") or {}
|
||||
if fallback_language(meta.get("language")):
|
||||
return meta
|
||||
source = min(
|
||||
(d for d in (entry.get("tracks") or {}).values() if fallback_language(d.get("language"))),
|
||||
key=lambda d: (not d.get("is_original_lang"), d.get("type") != "Video"),
|
||||
default=None,
|
||||
)
|
||||
return {**meta, "language": source["language"]} if source else meta
|
||||
|
||||
def get_titles_cached(self, title_id: Optional[str] = None) -> Titles_T:
|
||||
"""Apply the service's title_map to titles reconstructed from the export sidecar."""
|
||||
title_map = (config.services.get(self.service_tag) or {}).get("title_map") or {}
|
||||
|
||||
Reference in New Issue
Block a user