From a98d1d98acf79b8776aad6421b3fd28585a1d567 Mon Sep 17 00:00:00 2001 From: rlaphoenix Date: Sat, 10 Feb 2024 17:54:59 +0000 Subject: [PATCH] Add a new Subtitle Track Event, OnConverted This runs after a Subtitle has been converted to another format, and only if it was converted. It is passed the new subtitle format codec value. --- devine/core/tracks/subtitle.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/devine/core/tracks/subtitle.py b/devine/core/tracks/subtitle.py index 0c98f5f..bbdf28b 100644 --- a/devine/core/tracks/subtitle.py +++ b/devine/core/tracks/subtitle.py @@ -6,7 +6,7 @@ from collections import defaultdict from enum import Enum from io import BytesIO from pathlib import Path -from typing import Any, Iterable, Optional +from typing import Any, Callable, Iterable, Optional import pycaption from construct import Container @@ -134,6 +134,9 @@ class Subtitle(Track): if (self.cc or self.sdh) and self.forced: raise ValueError("A text track cannot be CC/SDH as well as Forced.") + # Called after Track has been converted to another format + self.OnConverted: Optional[Callable[[Subtitle.Codec], None]] = None + def get_track_name(self) -> Optional[str]: """Return the base Track Name.""" track_name = super().get_track_name() or "" @@ -214,6 +217,9 @@ class Subtitle(Track): self.swap(output_path) self.codec = codec + if callable(self.OnConverted): + self.OnConverted(codec) + return output_path @staticmethod