From cd194e3192ccc6ce0e172945a26e254fd8120194 Mon Sep 17 00:00:00 2001 From: rlaphoenix Date: Sat, 10 Feb 2024 18:10:09 +0000 Subject: [PATCH] Add new Track Event, OnSegmentDownloaded Like OnDownloaded but called every time a DASH or HLS segment is downloaded. The path to the downloaded segment file is passed to the callable. --- devine/core/manifests/dash.py | 3 +++ devine/core/manifests/hls.py | 3 +++ devine/core/tracks/track.py | 2 ++ 3 files changed, 8 insertions(+) diff --git a/devine/core/manifests/dash.py b/devine/core/manifests/dash.py index 7189478..cf500f7 100644 --- a/devine/core/manifests/dash.py +++ b/devine/core/manifests/dash.py @@ -565,6 +565,9 @@ class DASH: segmented=True ) + if callable(track.OnSegmentDownloaded): + track.OnSegmentDownloaded(out_path) + # fix audio decryption on ATVP by fixing the sample description index # TODO: Should this be done in the video data or the init data? if isinstance(track, Audio): diff --git a/devine/core/manifests/hls.py b/devine/core/manifests/hls.py index ab50a1c..7633966 100644 --- a/devine/core/manifests/hls.py +++ b/devine/core/manifests/hls.py @@ -484,6 +484,9 @@ class HLS: segmented=True ) + if callable(track.OnSegmentDownloaded): + track.OnSegmentDownloaded(out_path) + download_size = out_path.stat().st_size # fix audio decryption on ATVP by fixing the sample description index diff --git a/devine/core/tracks/track.py b/devine/core/tracks/track.py index 2d94d0e..6880aa4 100644 --- a/devine/core/tracks/track.py +++ b/devine/core/tracks/track.py @@ -55,6 +55,8 @@ class Track: # TODO: Currently using OnFoo event naming, change to just segment_filter self.OnSegmentFilter: Optional[Callable] = None + # Called after one of the Track's segments have downloaded + self.OnSegmentDownloaded: Optional[Callable[[Path], None]] = None # Called after the Track has downloaded self.OnDownloaded: Optional[Callable] = None # Called after the Track or one of its segments have been decrypted