diff --git a/devine/commands/dl.py b/devine/commands/dl.py index 8d33417..c3718a1 100644 --- a/devine/commands/dl.py +++ b/devine/commands/dl.py @@ -893,6 +893,8 @@ class dl: ) track.path = save_path + if callable(track.OnDownloaded): + track.OnDownloaded() if drm: progress(downloaded="Decrypting", completed=0, total=100) @@ -930,9 +932,6 @@ class dl: if track.path.stat().st_size <= 3: # Empty UTF-8 BOM == 3 bytes raise IOError("Download failed, the downloaded file is empty.") - if callable(track.OnDownloaded): - track.OnDownloaded() - @staticmethod def get_profile(service: str) -> Optional[str]: """Get profile for Service from config.""" diff --git a/devine/core/manifests/dash.py b/devine/core/manifests/dash.py index 9d0946a..7189478 100644 --- a/devine/core/manifests/dash.py +++ b/devine/core/manifests/dash.py @@ -502,6 +502,10 @@ class DASH: f.write(segment_data) segment_file.unlink() + track.path = save_path + if callable(track.OnDownloaded): + track.OnDownloaded() + if drm: progress(downloaded="Decrypting", completed=0, total=100) drm.decrypt(save_path) @@ -510,7 +514,6 @@ class DASH: track.OnDecrypted(drm) progress(downloaded="Decrypted", completed=100) - track.path = save_path save_dir.rmdir() progress(downloaded="Downloaded") diff --git a/devine/core/manifests/hls.py b/devine/core/manifests/hls.py index 3a35e31..ab50a1c 100644 --- a/devine/core/manifests/hls.py +++ b/devine/core/manifests/hls.py @@ -361,6 +361,8 @@ class HLS: progress(downloaded="Downloaded") track.path = save_path + if callable(track.OnDownloaded): + track.OnDownloaded() @staticmethod def download_segment( diff --git a/devine/core/tracks/track.py b/devine/core/tracks/track.py index 36d3f6f..2d94d0e 100644 --- a/devine/core/tracks/track.py +++ b/devine/core/tracks/track.py @@ -55,8 +55,7 @@ class Track: # TODO: Currently using OnFoo event naming, change to just segment_filter self.OnSegmentFilter: Optional[Callable] = None - # TODO: This should realistically be before decryption - # Called after the Track has been fully downloaded and decrypted + # Called after the Track has downloaded self.OnDownloaded: Optional[Callable] = None # Called after the Track or one of its segments have been decrypted self.OnDecrypted: Optional[Callable[[DRM_T, Optional[m3u8.Segment]], None]] = None