mirror of
https://github.com/unshackle-dl/unshackle.git
synced 2026-11-27 03:15:08 +00:00
Merge branch 'dev' into feat/downloader-speed
# Conflicts: # unshackle/core/downloaders/requests.py # unshackle/core/manifests/dash.py
This commit is contained in:
@@ -382,11 +382,11 @@ class Track:
|
||||
events.emit(events.Types.TRACK_DOWNLOADED, track=self)
|
||||
|
||||
if drm:
|
||||
progress(downloaded="Decrypting", completed=0, total=100)
|
||||
progress(downloaded="Decrypting", completed=0, total=None)
|
||||
drm.decrypt(save_path)
|
||||
self.drm = None
|
||||
events.emit(events.Types.TRACK_DECRYPTED, track=self, drm=drm, segment=None)
|
||||
progress(downloaded="Decrypted", completed=100)
|
||||
progress(downloaded="Decrypted", completed=100, total=100)
|
||||
|
||||
if track_type == "Subtitle" and self.codec.name not in ("fVTT", "fTTML"):
|
||||
track_data = self.path.read_bytes()
|
||||
@@ -576,7 +576,7 @@ class Track:
|
||||
Load DRM information for this track if it was deferred during parsing.
|
||||
|
||||
Args:
|
||||
service: Service instance that can fetch track-specific DRM info
|
||||
service (Service | None): Service instance that can fetch track-specific DRM info
|
||||
|
||||
Returns:
|
||||
True if DRM was loaded or already present, False if failed
|
||||
@@ -731,7 +731,16 @@ class Track:
|
||||
|
||||
return init_data
|
||||
|
||||
def repackage(self) -> None:
|
||||
def repackage(self, bsf_v: Optional[str] = None) -> bool:
|
||||
"""Remux the track with ffmpeg ``-c copy``.
|
||||
|
||||
When ``bsf_v`` is given it is folded into the same pass as ``-bsf:v`` (used to
|
||||
normalize video VUI colour metadata without a second full-file remux). Repackaging
|
||||
is mandatory; the bitstream filter is best-effort. If the combined run fails (and it
|
||||
isn't the AAC-retry case) it is retried once without ``bsf_v`` so the remux still
|
||||
succeeds. Returns True if the requested ``bsf_v`` was applied (always False when
|
||||
``bsf_v`` is None, since nothing was requested).
|
||||
"""
|
||||
if not self.path or not self.path.exists():
|
||||
raise ValueError("Cannot repackage a Track that has not been downloaded.")
|
||||
|
||||
@@ -741,7 +750,7 @@ class Track:
|
||||
original_path = self.path
|
||||
output_path = original_path.with_stem(f"{original_path.stem}_repack")
|
||||
|
||||
def _ffmpeg(extra_args: list[str] = None):
|
||||
def _ffmpeg(extra_args: list[str] = None, bsf: Optional[str] = None):
|
||||
args = [
|
||||
binaries.FFMPEG,
|
||||
"-hide_banner",
|
||||
@@ -775,9 +784,11 @@ class Track:
|
||||
"bitexact", # only have minimal tag data, reproducible mux
|
||||
"-codec",
|
||||
"copy",
|
||||
str(output_path),
|
||||
]
|
||||
)
|
||||
if bsf:
|
||||
args.extend(["-bsf:v", bsf])
|
||||
args.append(str(output_path))
|
||||
|
||||
subprocess.run(
|
||||
args,
|
||||
@@ -793,12 +804,20 @@ class Track:
|
||||
context={"track_type": self.__class__.__name__, "id": self.id, "file": original_path.name},
|
||||
)
|
||||
|
||||
bsf_applied = False
|
||||
try:
|
||||
_ffmpeg()
|
||||
_ffmpeg(bsf=bsf_v)
|
||||
bsf_applied = bsf_v is not None
|
||||
except subprocess.CalledProcessError as e:
|
||||
if b"Malformed AAC bitstream detected" in e.stderr:
|
||||
# e.g., TruTV's dodgy encodes
|
||||
_ffmpeg(["-y", "-bsf:a", "aac_adtstoasc"])
|
||||
_ffmpeg(["-y", "-bsf:a", "aac_adtstoasc"], bsf=bsf_v)
|
||||
bsf_applied = bsf_v is not None
|
||||
elif bsf_v is not None:
|
||||
# Repack is mandatory, the VUI bitstream filter is best-effort: retry
|
||||
# without it so the remux still succeeds; caller falls back to normalize_vui.
|
||||
output_path.unlink(missing_ok=True)
|
||||
_ffmpeg()
|
||||
else:
|
||||
raise
|
||||
|
||||
@@ -816,6 +835,7 @@ class Track:
|
||||
"output_size": output_path.stat().st_size if output_path.exists() else 0,
|
||||
},
|
||||
)
|
||||
return bsf_applied
|
||||
|
||||
|
||||
__all__ = ("Track", "DownloadContext")
|
||||
|
||||
Reference in New Issue
Block a user