Skip to content

sok.core.series

What a TV series needs to be organized: its season folders, the titles of its episodes, and the folder it already has in the library.

The module has no Qt dependency, so the desktop app and S.O.K Server share it.

FolderMatchdataclass

class FolderMatch(
path: str,
root: int,
how: str,
source: Optional[str] = None,
title: Optional[str] = None,
seasons: List[int] = list(),
episodes: int = 0,
)

A folder of the library that holds the series.

Parameters

NameTypeDefaultDescription
pathstrThe folder.
rootintIndex of the destination folder that holds it.
howstrBY_ID, BY_HISTORY or BY_TITLE.
sourceOptional[str]NoneThe service of the id (BY_ID), or "nfo" when a tvshow.nfo gave it: "tvdb", "nfo".
titleOptional[str]NoneThe title the name matched (BY_TITLE).
seasonsList[int]list()The seasons it already has, from its season folders.
episodesint0The video files it already has.
Source

Attributes

NameTypeDescription
episodesint

The video files it already has.

howstr

BY_ID, BY_HISTORY or BY_TITLE.

pathstr

The folder.

rootint

Index of the destination folder that holds it.

seasonsList[int]

The seasons it already has, from its season folders.

sourceOptional[str]

The service of the id (BY_ID), or "nfo" when a tvshow.nfo gave it: "tvdb", "nfo".

titleOptional[str]

The title the name matched (BY_TITLE).

to_dict

def to_dict() -> Dict[str, Any]:
Source

SeriesIdentitydataclass

class SeriesIdentity(
title: str,
year: Optional[int] = None,
titles: List[str] = list(),
ids: Dict[str, str] = dict(),
)

What tells a series apart, to find its folder.

Parameters

NameTypeDefaultDescription
titlestrThe title of the series, as S.O.K names its folder.
yearOptional[int]NoneThe year of its first episode, if known.
titlesList[str]list()Every name of the series: title, original, translated.
idsDict[str, str]dict()Service → id ("tmdb", "tvdb", "imdb"), as text.
Source

Attributes

NameTypeDescription
idsDict[str, str]

Service → id ("tmdb", "tvdb", "imdb"), as text.

titlestr

The title of the series, as S.O.K names its folder.

titlesList[str]

Every name of the series: title, original, translated.

yearOptional[int]

The year of its first episode, if known.

Functions

fetch_episode_titlesasync

async def fetch_episode_titles(
api: Any,
series_id: str,
number_of_seasons: int,
language: str,
) -> Dict[str, str]:

The title of every episode of a series, season by season.

A season that fails is left out (and logged): the episodes of the others still get their titles.

Parameters

NameTypeDescription
apiAnyThe video API of the series; it needs get_tv_episodes (TMDB).
series_idstrThe id of the series in that API.
number_of_seasonsintFrom the details of the series.
languagestrLanguage of the titles, such as "fr-FR".

Returns

  • Dict[str, str]Episode code ("S01E01") → title; empty if the API has no episodes.
Source

find_series_folders

def find_series_folders(
identity: SeriesIdentity,
roots: List[str],
known: Iterable[str] = (),
) -> List[FolderMatch]:

The folders of the library that already hold a series.

The folders right under each root are compared, the surest way first: an id in the folder name or in its tvshow.nfo, then a folder S.O.K put the series in before (known), then the name (case, accents, punctuation, the year and the tags left out) against every title of the series. A folder whose id is another series is never taken, and a folder whose year is far from the series' is not taken by its name. Only the matches of the surest way found are returned.

Parameters

NameTypeDefaultDescription
identitySeriesIdentityThe series.
rootsList[str]The destination folders of the series, in order.
knownIterable[str]()Folders where S.O.K put this series before.

Returns

  • List[FolderMatch]The matches, in the order of the roots then of the names; empty
  • List[FolderMatch]when the series has no folder yet.
Source

folder_content

def folder_content(folder: str) -> tuple:

(seasons, episodes) a series folder already has.

Parameters

NameTypeDescription
folderstr
Source

folder_name_parts

def folder_name_parts(name: str) -> tuple:

(name to compare, year, ids) of a folder name.

"Breaking Bad (2008) [tvdbid-81189]" → ("breakingbad", 2008, {"tvdb": "81189"}).

Parameters

NameTypeDescription
namestr
Source

nfo_ids

def nfo_ids(folder: str) -> Dict[str, str]:

The ids of the tvshow.nfo of a folder (Kodi, Jellyfin, Emby).

Parameters

NameTypeDescription
folderstr
Source

season_folders

def season_folders(details: Dict[str, Any], season_word: str) -> Dict[str, int]:

The folder name of each season, from the details of the series.

"Season 2", or "Season 2 - The Name" when the season has a name of its own ("Season 2" or "Saison 2" in the details is no name).

Parameters

NameTypeDescription
detailsDict[str, Any]Details of the series, with number_of_seasons and seasons.
season_wordstr"Season" in the language of the interface.

Returns

  • Dict[str, int]Folder name → season number, for seasons 1 to number_of_seasons.
Source

series_identity

def series_identity(
candidate: Dict[str, Any],
details: Optional[Dict[str, Any]],
service: str,
) -> SeriesIdentity:

The identity of a series, from its search result and its details.

Parameters

NameTypeDescription
candidateDict[str, Any]The search result picked.
detailsOptional[Dict[str, Any]]Its details; TMDB ones may carry alternative_titles and external_ids, TVDB ones aliases and remote_ids.
servicestrThe service of the candidate's id: "tmdb" or "tvdb".
Source

Attributes

NameValue
BY_HISTORY'history'
BY_ID'id'
BY_TITLE'title'
ID_SERVICES('tmdb', 'tvdb', 'imdb')
loggerlogging.getLogger(__name__)
Built with Kiln