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".
When that name says no language, the language read from the text is added when it is sure: Movie.srt in French becomes "Dune (2021).fr.srt".
The subtitles of a "Subs" folder next to the video go with it too: Subs/2_English.srt for the only video of the folder, or Subs/
Functions
find_subs_folder
def find_subs_folder( video: Path, video_extensions: Iterable[str],) -> List[Path]:The subtitles of a video in a "Subs" folder next to it.
Subs/
Parameters
| Name | Type | Description |
|---|---|---|
video | Path | |
video_extensions | Iterable[str] |
Returns
List[Path]The subtitle files, in the order of their leading numberList[Path]("2_English.srt" before "10_French.srt").
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.
Those beside the video and those of its Subs folder go, with their language added when the name lacks it and the text says it surely (see plan_subtitles). 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.
plan_subtitles
def plan_subtitles( video: Path, new_video: str, video_extensions: Iterable[str],) -> List[Tuple[str, str]]:Where the subtitles of a video go when it goes to new_video.
Parameters
| Name | Type | Description |
|---|---|---|
video | Path | |
new_video | str | |
video_extensions | Iterable[str] |
Returns
List[Tuple[str, str]](source, target) pairs of paths; two targets never collide.
Attributes
| Name | Value |
|---|---|
SUBS_FOLDERS | ('subs', 'subtitles') |
SUBTITLE_EXTENSIONS | ('.srt', '.ass', '.ssa', '.sub', '.idx', '.vtt') |
logger | logging.getLogger(__name__) |