Skip to content

Commit

Permalink
Move Track OnDownloaded event before decryption
Browse files Browse the repository at this point in the history
  • Loading branch information
rlaphoenix committed Feb 10, 2024
1 parent a98d1d9 commit 87779f4
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 6 deletions.
5 changes: 2 additions & 3 deletions devine/commands/dl.py
Original file line number Diff line number Diff line change
Expand Up @@ -893,6 +893,8 @@ def cleanup():
)

track.path = save_path
if callable(track.OnDownloaded):
track.OnDownloaded()

if drm:
progress(downloaded="Decrypting", completed=0, total=100)
Expand Down Expand Up @@ -930,9 +932,6 @@ def cleanup():
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."""
Expand Down
5 changes: 4 additions & 1 deletion devine/core/manifests/dash.py
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,10 @@ def download_track(
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)
Expand All @@ -510,7 +514,6 @@ def download_track(
track.OnDecrypted(drm)
progress(downloaded="Decrypted", completed=100)

track.path = save_path
save_dir.rmdir()

progress(downloaded="Downloaded")
Expand Down
2 changes: 2 additions & 0 deletions devine/core/manifests/hls.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,8 @@ def download_track(
progress(downloaded="Downloaded")

track.path = save_path
if callable(track.OnDownloaded):
track.OnDownloaded()

@staticmethod
def download_segment(
Expand Down
3 changes: 1 addition & 2 deletions devine/core/tracks/track.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@ def __init__(
# 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
Expand Down

0 comments on commit 87779f4

Please sign in to comment.