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.
This commit is contained in:
rlaphoenix 2024-02-10 18:10:09 +00:00
parent 87779f4e7d
commit cd194e3192
3 changed files with 8 additions and 0 deletions

View File

@ -565,6 +565,9 @@ class DASH:
segmented=True segmented=True
) )
if callable(track.OnSegmentDownloaded):
track.OnSegmentDownloaded(out_path)
# fix audio decryption on ATVP by fixing the sample description index # fix audio decryption on ATVP by fixing the sample description index
# TODO: Should this be done in the video data or the init data? # TODO: Should this be done in the video data or the init data?
if isinstance(track, Audio): if isinstance(track, Audio):

View File

@ -484,6 +484,9 @@ class HLS:
segmented=True segmented=True
) )
if callable(track.OnSegmentDownloaded):
track.OnSegmentDownloaded(out_path)
download_size = out_path.stat().st_size download_size = out_path.stat().st_size
# fix audio decryption on ATVP by fixing the sample description index # fix audio decryption on ATVP by fixing the sample description index

View File

@ -55,6 +55,8 @@ class Track:
# TODO: Currently using OnFoo event naming, change to just segment_filter # TODO: Currently using OnFoo event naming, change to just segment_filter
self.OnSegmentFilter: Optional[Callable] = None 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 # Called after the Track has downloaded
self.OnDownloaded: Optional[Callable] = None self.OnDownloaded: Optional[Callable] = None
# Called after the Track or one of its segments have been decrypted # Called after the Track or one of its segments have been decrypted