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
| Name | Type | Description |
|---|---|---|
db | Database |
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
| Name | Type | Description |
|---|---|---|
files | Iterable[str] |
tracks
def tracks(files: List[str]) -> Dict[str, List[Track]]:The tracks read of the files that have been, by path.
Parameters
| Name | Type | Description |
|---|---|---|
files | List[str] |
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
| Name | Type | Description |
|---|---|---|
row | Any | |
path | str |
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
| Name | Type | Default | Description |
|---|---|---|---|
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 |
forced_for
def forced_for(row: Any, path: str) -> bool:Whether a file of a row goes without the languages it waits for.
Parameters
| Name | Type | Description |
|---|---|---|
row | Any | |
path | str |
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
| Name | Type | Description |
|---|---|---|
candidate | Optional[Dict[str, Any]] |
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
| Name | Type | Description |
|---|---|---|
row | Any |
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
| Name | Type | Description |
|---|---|---|
row | Any | |
files | List[str] | |
tracks | Dict[str, List[Track]] | |
fill | bool | |
to_mkv | bool | |
writable | bool |
selected_candidate
def selected_candidate(row: Any) -> Optional[Dict[str, Any]]:The search result picked for a row, or None.
Parameters
| Name | Type | Description |
|---|---|---|
row | Any |
stamp
def stamp(path: str) -> Optional[List[int]]:[size, mtime_ns] of a file, or None when it is gone.
Parameters
| Name | Type | Description |
|---|---|---|
path | str |
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
| Name | Type | Description |
|---|---|---|
candidate | Optional[Dict[str, Any]] |
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
| Name | Type | Description |
|---|---|---|
row | Any | |
files | List[str] | |
tracks | Dict[str, List[Track]] | |
fill | bool | |
to_mkv | bool | |
writable | bool | |
mode | str |
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
| Name | Type | Description |
|---|---|---|
row | Any | |
files | List[str] | |
kind | str | |
position | int | |
language | Optional[str] |
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
| Name | Type | Description |
|---|---|---|
row | Any | |
files | List[str] | |
forced | bool |
Attributes
| Name | Value |
|---|---|
VIDEO_TYPES | ('movies', 'tv') |
WAITED | {'sort': (), 'wait_audio': (AUDIO,), 'wait_all': (AUDIO, SUBTITLES)} |
logger | logging.getLogger(__name__) |