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
| Name | Type | Default | Description |
|---|---|---|---|
path | str | The folder. | |
root | int | Index of the destination folder that holds it. | |
how | str | BY_ID, BY_HISTORY or BY_TITLE. | |
source | Optional[str] | None | The service of the id (BY_ID), or "nfo" when a tvshow.nfo gave it: "tvdb", "nfo". |
title | Optional[str] | None | The title the name matched (BY_TITLE). |
seasons | List[int] | list() | The seasons it already has, from its season folders. |
episodes | int | 0 | The video files it already has. |
Attributes
| Name | Type | Description |
|---|---|---|
episodes | int | The video files it already has. |
how | str | BY_ID, BY_HISTORY or BY_TITLE. |
path | str | The folder. |
root | int | Index of the destination folder that holds it. |
seasons | List[int] | The seasons it already has, from its season folders. |
source | Optional[str] | The service of the id (BY_ID), or "nfo" when a tvshow.nfo gave it: "tvdb", "nfo". |
title | Optional[str] | The title the name matched (BY_TITLE). |
to_dict
def to_dict() -> Dict[str, Any]: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
| Name | Type | Default | Description |
|---|---|---|---|
title | str | The title of the series, as S.O.K names its folder. | |
year | Optional[int] | None | The year of its first episode, if known. |
titles | List[str] | list() | Every name of the series: title, original, translated. |
ids | Dict[str, str] | dict() | Service → id ("tmdb", "tvdb", "imdb"), as text. |
Attributes
| Name | Type | Description |
|---|---|---|
ids | Dict[str, str] | Service → id ("tmdb", "tvdb", "imdb"), as text. |
title | str | The title of the series, as S.O.K names its folder. |
titles | List[str] | Every name of the series: title, original, translated. |
year | Optional[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
| Name | Type | Description |
|---|---|---|
api | Any | The video API of the series; it needs get_tv_episodes (TMDB). |
series_id | str | The id of the series in that API. |
number_of_seasons | int | From the details of the series. |
language | str | Language of the titles, such as "fr-FR". |
Returns
Dict[str, str]Episode code ("S01E01") → title; empty if the API has no episodes.
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
| Name | Type | Default | Description |
|---|---|---|---|
identity | SeriesIdentity | The series. | |
roots | List[str] | The destination folders of the series, in order. | |
known | Iterable[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; emptyList[FolderMatch]when the series has no folder yet.
folder_content
def folder_content(folder: str) -> tuple:(seasons, episodes) a series folder already has.
Parameters
| Name | Type | Description |
|---|---|---|
folder | str |
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
| Name | Type | Description |
|---|---|---|
name | str |
nfo_ids
def nfo_ids(folder: str) -> Dict[str, str]:The ids of the tvshow.nfo of a folder (Kodi, Jellyfin, Emby).
Parameters
| Name | Type | Description |
|---|---|---|
folder | str |
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
| Name | Type | Description |
|---|---|---|
details | Dict[str, Any] | Details of the series, with number_of_seasons and seasons. |
season_word | str | "Season" in the language of the interface. |
Returns
Dict[str, int]Folder name → season number, for seasons 1 to number_of_seasons.
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
| Name | Type | Description |
|---|---|---|
candidate | Dict[str, Any] | The search result picked. |
details | Optional[Dict[str, Any]] | Its details; TMDB ones may carry alternative_titles and external_ids, TVDB ones aliases and remote_ids. |
service | str | The service of the candidate's id: "tmdb" or "tvdb". |
Attributes
| Name | Value |
|---|---|
BY_HISTORY | 'history' |
BY_ID | 'id' |
BY_TITLE | 'title' |
ID_SERVICES | ('tmdb', 'tvdb', 'imdb') |
logger | logging.getLogger(__name__) |