forked from kenzuya/unshackle
fix(events): emit TRACK_DOWNLOADED once per track after decryption
This commit is contained in:
@@ -871,7 +871,6 @@ class HLS:
|
||||
decrypt_output(track, ctx, session_drm, decrypt=not segment_decrypter)
|
||||
progress(downloaded="Downloaded", completed=100, total=100)
|
||||
track.path = save_path
|
||||
events.emit(events.Types.TRACK_DOWNLOADED, track=track)
|
||||
return
|
||||
|
||||
progress(total=total_segments, completed=0, downloaded="Merging")
|
||||
@@ -1162,8 +1161,6 @@ class HLS:
|
||||
if session_drm:
|
||||
track.drm = None
|
||||
|
||||
events.emit(events.Types.TRACK_DOWNLOADED, track=track)
|
||||
|
||||
@staticmethod
|
||||
def discontinuity_starts(wanted_segments: list[Any]) -> list[float]:
|
||||
"""Start in seconds of each discontinuity block, counted as download_track numbers the blocks, then the end."""
|
||||
|
||||
@@ -253,9 +253,8 @@ def remove_segment_dir(save_dir: Path) -> None:
|
||||
|
||||
|
||||
def complete_track(track: AnyTrack, ctx: DownloadContext, drm: DRM_T | None, decrypt: bool = True) -> None:
|
||||
"""Hand the merged file to the track: TRACK_DOWNLOADED, then the decryption, then the segment directory cleanup."""
|
||||
"""Hand the merged file to the track, decrypt it, and remove the segment directory."""
|
||||
track.path = ctx.save_path
|
||||
events.emit(events.Types.TRACK_DOWNLOADED, track=track)
|
||||
|
||||
if drm:
|
||||
decrypt_output(track, ctx, drm, decrypt)
|
||||
|
||||
@@ -266,7 +266,8 @@ class TitleSource(metaclass=ABCMeta):
|
||||
|
||||
def on_track_downloaded(self, track: AnyTrack) -> None:
|
||||
"""
|
||||
Called when a Track has finished downloading.
|
||||
Called once when a Track has finished downloading, after unshackle decrypted its `drm`.
|
||||
In a licence-only run the track has no file.
|
||||
|
||||
Parameters:
|
||||
track: The downloaded Track object.
|
||||
|
||||
@@ -733,7 +733,7 @@ class Track:
|
||||
track's init data and stores it on the track, so a service need not declare `drm` itself.
|
||||
"""
|
||||
from unshackle.core.manifests import DASH, HLS, ISM
|
||||
from unshackle.core.manifests.segment_pipeline import license_drm
|
||||
from unshackle.core.manifests.segment_pipeline import license_drm, licensing
|
||||
from unshackle.core.tracks.audio import Audio
|
||||
from unshackle.core.tracks.subtitle import Subtitle
|
||||
from unshackle.core.tracks.video import Video
|
||||
@@ -889,7 +889,6 @@ class Track:
|
||||
media_path.unlink()
|
||||
|
||||
self.path = save_path
|
||||
events.emit(events.Types.TRACK_DOWNLOADED, track=self)
|
||||
|
||||
if drm:
|
||||
progress(downloaded="Decrypting", completed=0, total=None)
|
||||
@@ -926,6 +925,17 @@ class Track:
|
||||
DOWNLOAD_CANCELLED.set()
|
||||
progress(downloaded="[red]FAILED")
|
||||
raise
|
||||
|
||||
if DOWNLOAD_CANCELLED.is_set():
|
||||
return
|
||||
|
||||
if not DOWNLOAD_LICENCE_ONLY.is_set():
|
||||
assert self.path is not None
|
||||
if self.path.stat().st_size <= 3: # Empty UTF-8 BOM == 3 bytes
|
||||
raise OSError("Download failed, the downloaded file is empty.")
|
||||
|
||||
with licensing(ctx):
|
||||
events.emit(events.Types.TRACK_DOWNLOADED, track=self)
|
||||
except DownloadCancelled:
|
||||
abandon()
|
||||
progress(downloaded="[yellow]SKIPPED")
|
||||
@@ -935,16 +945,6 @@ class Track:
|
||||
abandon()
|
||||
raise
|
||||
|
||||
if DOWNLOAD_CANCELLED.is_set():
|
||||
return
|
||||
|
||||
if not DOWNLOAD_LICENCE_ONLY.is_set():
|
||||
assert self.path is not None
|
||||
if self.path.stat().st_size <= 3: # Empty UTF-8 BOM == 3 bytes
|
||||
raise OSError("Download failed, the downloaded file is empty.")
|
||||
|
||||
events.emit(events.Types.TRACK_DOWNLOADED, track=self)
|
||||
|
||||
def delete(self) -> None:
|
||||
if self.path:
|
||||
self.path.unlink()
|
||||
|
||||
Reference in New Issue
Block a user