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.
This commit is contained in:
rlaphoenix 2024-02-10 17:54:59 +00:00
parent c18fe5706b
commit a98d1d98ac

View File

@ -6,7 +6,7 @@ from collections import defaultdict
from enum import Enum from enum import Enum
from io import BytesIO from io import BytesIO
from pathlib import Path from pathlib import Path
from typing import Any, Iterable, Optional from typing import Any, Callable, Iterable, Optional
import pycaption import pycaption
from construct import Container from construct import Container
@ -134,6 +134,9 @@ class Subtitle(Track):
if (self.cc or self.sdh) and self.forced: if (self.cc or self.sdh) and self.forced:
raise ValueError("A text track cannot be CC/SDH as well as 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]: def get_track_name(self) -> Optional[str]:
"""Return the base Track Name.""" """Return the base Track Name."""
track_name = super().get_track_name() or "" track_name = super().get_track_name() or ""
@ -214,6 +217,9 @@ class Subtitle(Track):
self.swap(output_path) self.swap(output_path)
self.codec = codec self.codec = codec
if callable(self.OnConverted):
self.OnConverted(codec)
return output_path return output_path
@staticmethod @staticmethod