mirror of
https://github.com/unshackle-dl/unshackle.git
synced 2026-11-25 02:15:08 +00:00
fix(remote): match re-parsed manifest tracks by ID before attributes
Match once after every server manifest is parsed, and require range and bitrate in the video fallback, so a per-range ISM ladder no longer hands an HDR10 track the SDR quality level. Pass -xerror to the bsf ffmpeg calls so a failed rewrite keeps the original file instead of a near-empty one.
This commit is contained in:
@@ -321,6 +321,7 @@ def resolve_manifest_data(tracks: Tracks, manifests: list) -> None:
|
||||
|
||||
log_m = logging.getLogger("remote_service")
|
||||
all_tracks = list(tracks.videos) + list(tracks.audio) + list(tracks.subtitles)
|
||||
local_all: list = []
|
||||
|
||||
for manifest_info in manifests:
|
||||
m_type = manifest_info.get("type")
|
||||
@@ -351,20 +352,20 @@ def resolve_manifest_data(tracks: Tracks, manifests: list) -> None:
|
||||
else:
|
||||
continue
|
||||
|
||||
local_all = list(local_tracks.videos) + list(local_tracks.audio) + list(local_tracks.subtitles)
|
||||
for remote_track in all_tracks:
|
||||
if remote_track.data.get(m_type):
|
||||
continue
|
||||
matched = match_track(remote_track, local_all)
|
||||
if matched and matched.data.get(m_type):
|
||||
remote_track.data.update(matched.data)
|
||||
remote_track.descriptor = matched.descriptor
|
||||
if matched.drm and not remote_track.drm:
|
||||
remote_track.drm = matched.drm
|
||||
|
||||
local_all += list(local_tracks.videos) + list(local_tracks.audio) + list(local_tracks.subtitles)
|
||||
except Exception as e:
|
||||
log_m.warning("Failed to re-parse %s manifest from %s: %s", m_type, m_url, e)
|
||||
|
||||
for remote_track in all_tracks:
|
||||
if any(remote_track.data.get(key) for key in ("dash", "ism")):
|
||||
continue
|
||||
matched = match_track(remote_track, local_all)
|
||||
if matched and any(matched.data.get(key) for key in ("dash", "ism")):
|
||||
remote_track.data.update(matched.data)
|
||||
remote_track.descriptor = matched.descriptor
|
||||
if matched.drm and not remote_track.drm:
|
||||
remote_track.drm = matched.drm
|
||||
|
||||
|
||||
def same_bitrate(local: Optional[int], remote: Optional[int]) -> bool:
|
||||
"""Equal to the nearest kb/s. A server that predates ``bitrate_bps`` rounds to kb/s in transit."""
|
||||
@@ -386,7 +387,12 @@ def match_track(remote_track: Track, local_tracks: list) -> Optional[Track]:
|
||||
if lt.codec != remote_track.codec or str(lt.language) != str(remote_track.language):
|
||||
continue
|
||||
if hasattr(lt, "width") and hasattr(remote_track, "width"):
|
||||
if lt.width == remote_track.width and lt.height == remote_track.height:
|
||||
if (
|
||||
lt.width == remote_track.width
|
||||
and lt.height == remote_track.height
|
||||
and lt.range == remote_track.range
|
||||
and same_bitrate(lt.bitrate, remote_track.bitrate)
|
||||
):
|
||||
return lt
|
||||
elif hasattr(lt, "channels") and hasattr(remote_track, "channels"):
|
||||
if same_bitrate(lt.bitrate, remote_track.bitrate):
|
||||
|
||||
@@ -1016,7 +1016,8 @@ class Track:
|
||||
]
|
||||
)
|
||||
if bsf:
|
||||
args.extend(["-bsf:v", bsf])
|
||||
# ffmpeg exits 0 after dropping packets the bsf cannot parse
|
||||
args.extend(["-bsf:v", bsf, "-xerror"])
|
||||
args.append(str(output_path))
|
||||
|
||||
subprocess.run(
|
||||
|
||||
@@ -497,6 +497,8 @@ class Video(Track):
|
||||
"-hide_banner",
|
||||
"-loglevel",
|
||||
"error",
|
||||
# ffmpeg exits 0 after dropping packets the bsf cannot parse
|
||||
"-xerror",
|
||||
"-i",
|
||||
str(original_path),
|
||||
"-codec",
|
||||
|
||||
Reference in New Issue
Block a user