Skip to content

Commit

Permalink
Add a new Subtitle Track Event, OnConverted
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
rlaphoenix committed Feb 10, 2024
1 parent c18fe57 commit a98d1d9
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion devine/core/tracks/subtitle.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
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
Expand Down Expand Up @@ -134,6 +134,9 @@ def __init__(self, *args: Any, codec: Subtitle.Codec, cc: bool = False, sdh: boo
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 ""
Expand Down Expand Up @@ -214,6 +217,9 @@ def convert(self, codec: Subtitle.Codec) -> Path:
self.swap(output_path)
self.codec = codec

if callable(self.OnConverted):
self.OnConverted(codec)

return output_path

@staticmethod
Expand Down

0 comments on commit a98d1d9

Please sign in to comment.