sok.file_operations.subtitles
Subtitles that follow their video.
A subtitle whose name starts with the name of a video goes with it: Movie.srt, Movie.fr.srt and Movie.en.forced.srt follow Movie.mkv. It is renamed like the video and keeps what follows the video's name, so Movie.fr.srt becomes "Dune (2021).fr.srt" next to "Dune (2021).mkv".
Functions
find_subtitles
def find_subtitles( video: Path, video_extensions: Iterable[str],) -> List[Tuple[Path, str]]:The subtitles of a video, next to it.
When two videos of the folder can claim a subtitle (Movie.mkv and Movie.Part2.mkv for Movie.Part2.srt), the longest name wins.
Parameters
| Name | Type | Description |
|---|---|---|
video | Path | The video file. |
video_extensions | Iterable[str] | Extensions of the videos, to find the other ones. |
Returns
List[Tuple[Path, str]](subtitle, suffix) pairs; the suffix is what follows the video'sList[Tuple[Path, str]]name, such as ".fr.srt".
move_subtitles
def move_subtitles( video: Path, new_video: str, video_extensions: Iterable[str], skip_duplicates: bool = False, backup: bool = False, mode: str = MOVE, dry_run: bool = False,) -> Dict[str, List[Dict[str, Any]]]:Move the subtitles of a video next to its new place, under its new name.
The history records each subtitle as following the video, so undoing the video puts them back too.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
video | Path | Where the video was. | |
new_video | str | Where the video went. | |
video_extensions | Iterable[str] | Extensions of the videos. | |
skip_duplicates | bool | False | Leave a subtitle in place when its new name exists. |
backup | bool | False | Keep a replaced subtitle as ' |
mode | str | MOVE | MOVE, LINK or COPY, like the video. |
dry_run | bool | False | Only say where they would go. |
Returns
Dict[str, List[Dict[str, Any]]]"moved", "skipped" and "errors" lists, like the organize reports.
Attributes
| Name | Value |
|---|---|
SUBTITLE_EXTENSIONS | ('.srt', '.ass', '.ssa', '.sub', '.idx', '.vtt') |
logger | logging.getLogger(__name__) |