Skip to content

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

NameTypeDescription
videoPathThe video file.
video_extensionsIterable[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's
  • List[Tuple[Path, str]]name, such as ".fr.srt".
Source

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

NameTypeDefaultDescription
videoPathWhere the video was.
new_videostrWhere the video went.
video_extensionsIterable[str]Extensions of the videos.
skip_duplicatesboolFalseLeave a subtitle in place when its new name exists.
backupboolFalseKeep a replaced subtitle as '.backup'.
modestrMOVEMOVE, LINK or COPY, like the video.
dry_runboolFalseOnly say where they would go.

Returns

  • Dict[str, List[Dict[str, Any]]]"moved", "skipped" and "errors" lists, like the organize reports.
Source

Attributes

NameValue
SUBTITLE_EXTENSIONS('.srt', '.ass', '.ssa', '.sub', '.idx', '.vtt')
loggerlogging.getLogger(__name__)
Built with Kiln