Skip to content

sok.server.tracks

The audio and subtitle tracks of the videos of S.O.K Server.

An analysis reads the tracks of the videos of the Movies and TV tabs (track_languages.read_tracks) and keeps them in the tracks table, with the size and the date of each file: the next analyses read only the new or changed files. A row then says, per file, how many tracks have no language and, when fill_track_languages is on, those a rename would fill in from the names (the text of the subtitles is read only while renaming).

TrackCache

class TrackCache(db: Database)

The tracks read of the videos, in the tracks table.

Parameters

NameTypeDescription
dbDatabase
Source

refresh

def refresh(files: Iterable[str]) -> None:

Read the tracks of the files new or changed since their last read, and forget the files no longer analyzed. Blocks: run it in a thread.

Parameters

NameTypeDescription
filesIterable[str]
Source

tracks

def tracks(files: List[str]) -> Dict[str, List[Track]]:

The tracks read of the files that have been, by path.

Parameters

NameTypeDescription
filesList[str]
Source

Functions

choices_for

def choices_for(row: Any, path: str) -> Dict[Tuple[str, int], str]:

The choices of a row that apply to one of its files: none when the file changed since they were made.

Parameters

NameTypeDescription
rowAny
pathstr
Source

describe_tracks

def describe_tracks(
tracks: Optional[List[Track]],
path: str,
candidate: Optional[Dict[str, Any]],
fill: bool,
to_mkv: bool,
choices: Optional[Dict[Tuple[str, int], str]] = None,
writable: bool = True,
) -> Optional[Dict[str, Any]]:

What a row says of the tracks of a file, or None before a read.

{"audio": n, "subtitles": n} without a language, and "filled": the languages a rename writes, when the video is an MKV once renamed (to_mkv: converted) and the file mode is not a hard link (writable): the choices of the user, and with fill on, those S.O.K is sure of from the names.

Parameters

NameTypeDefaultDescription
tracksOptional[List[Track]]
pathstr
candidateOptional[Dict[str, Any]]
fillbool
to_mkvbool
choicesOptional[Dict[Tuple[str, int], str]]None
writableboolTrue
Source

forced_for

def forced_for(row: Any, path: str) -> bool:

Whether a file of a row goes without the languages it waits for.

Parameters

NameTypeDescription
rowAny
pathstr
Source

original_of

def original_of(candidate: Optional[Dict[str, Any]]) -> Optional[str]:

The original language of a search result, if the service gives it.

Parameters

NameTypeDescription
candidateOptional[Dict[str, Any]]
Source

read_choices

def read_choices(row: Any) -> Dict[str, Any]:

The languages the user gave the tracks of a row: {"choices": {"audio:2": "ja"}, "forced": whether it goes without the languages it waits for, "files": {path: [size, mtime_ns]}}.

Parameters

NameTypeDescription
rowAny
Source

row_tracks

def row_tracks(
row: Any,
files: List[str],
tracks: Dict[str, List[Track]],
fill: bool,
to_mkv: bool,
writable: bool,
) -> Optional[Dict[str, Any]]:

The tracks without a language of the videos of a row, for the user to give them one; None when none was read.

One entry per track kind and place ("the 2nd audio track"), for all the files of the row: "missing" in how many of the "files" read, what S.O.K does ("language" and "reason", explain_languages, from the first file that misses it; a reason without a language says why not) and the user's "choice". "blocked": why nothing can be written: "link" (hard links) or "convert" (an MP4 without the conversion to MKV), else None. "auto": whether S.O.K writes its guesses (fill_track_languages).

Parameters

NameTypeDescription
rowAny
filesList[str]
tracksDict[str, List[Track]]
fillbool
to_mkvbool
writablebool
Source

selected_candidate

def selected_candidate(row: Any) -> Optional[Dict[str, Any]]:

The search result picked for a row, or None.

Parameters

NameTypeDescription
rowAny
Source

stamp

def stamp(path: str) -> Optional[List[int]]:

[size, mtime_ns] of a file, or None when it is gone.

Parameters

NameTypeDescription
pathstr
Source

titles_of

def titles_of(candidate: Optional[Dict[str, Any]]) -> List[str]:

The titles of a search result, whose words are not tags of a release name.

Parameters

NameTypeDescription
candidateOptional[Dict[str, Any]]
Source

unsure

def unsure(
row: Any,
files: List[str],
tracks: Dict[str, List[Track]],
fill: bool,
to_mkv: bool,
writable: bool,
mode: str,
) -> bool:

Whether a row waits for the languages of its tracks (the unsure_languages setting): one of its videos has a track of a kind the setting waits for with no language once renamed, neither in the file, nor chosen, nor guessed for sure (with fill on).

Never for what cannot be written (hard links, an MP4 not converted), for a text subtitle (read while renaming), or for a file sorted without them by hand (forced_for).

Parameters

NameTypeDescription
rowAny
filesList[str]
tracksDict[str, List[Track]]
fillbool
to_mkvbool
writablebool
modestr
Source

with_choice

def with_choice(
row: Any,
files: List[str],
kind: str,
position: int,
language: Optional[str],
) -> str:

The track_choices of a row once a track gets a language (None: back to automatic), as JSON. The files of the row now are those it applies to: one changed or added later is not concerned.

Parameters

NameTypeDescription
rowAny
filesList[str]
kindstr
positionint
languageOptional[str]
Source

with_forced

def with_forced(row: Any, files: List[str], forced: bool) -> str:

The track_choices of a row sorted without the languages it waits for ("Ranger sans ces langues"), or waiting again, as JSON. Like a choice, it holds for the files of the row now, while they do not change.

Parameters

NameTypeDescription
rowAny
filesList[str]
forcedbool
Source

Attributes

NameValue
VIDEO_TYPES('movies', 'tv')
WAITED{'sort': (), 'wait_audio': (AUDIO,), 'wait_all': (AUDIO, SUBTITLES)}
loggerlogging.getLogger(__name__)
Built with Kiln