Skip to content

sok.server.search

The search of the rows of S.O.K Server, and what the tabs show of them.

The batch engine of the desktop app (BatchMatcher) searches each row, as the batch pages of the desktop app do: a movie, a track, a book or a game by its file name, a series by its title, an album by its tags or its folder. A series that is Ready, or picked by hand, gets its details and the titles of its episodes, which name the episodes, and the folder it already has in a TV destination (refresh_folders): one folder found is used as it is, several wait for a choice (rows.folder_pending). A missing key or a used quota stops the search (SearchStopped); the rows keep what they had.

InvalidChange

class InvalidChange(code: str)

Bases: ValueError

A change of a row that cannot be: invalid_selection, invalid_destination, invalid_folder.

Parameters

NameTypeDescription
codestr
Source

Attributes

Name
code
class Search(
content_type: ContentType,
media_type: MediaType,
parse: QueryParser,
factory_type: str,
same_work: Optional[SameWork] = None,
localized: bool = True,
)

How the rows of one kind are searched and named.

Parameters

NameTypeDefaultDescription
content_typeContentType
media_typeMediaType
parseQueryParser
factory_typestr
same_workOptional[SameWork]None
localizedboolTrue
Source

Attributes

NameType
content_typeContentType
factory_typestr
localizedbool
media_typeMediaType
parseQueryParser
same_workOptional[SameWork]

SearchStopped

class SearchStopped(code: str, service: str)

Bases: Exception

A search that cannot go on: a missing or refused key, a used quota.

After a search of several kinds, others lists the services that stopped after this one.

Parameters

NameTypeDescription
codestr
servicestr
Source

Attributes

NameType
code
othersList[SearchStopped]
service

Searcher

class Searcher(db: Database, config: ConfigManager, settings: Settings)

Search the rows, change them, and describe them for the tabs.

Parameters

NameTypeDescription
dbDatabase
configConfigManager
settingsSettings
Source

batch_ops

def batch_ops(media_type: str) -> Any:

The file operations that rename a media type.

Parameters

NameTypeDescription
media_typestr
Source

changeasync

async def change(
row_id: int,
selected: Optional[int] = None,
destination: Optional[int] = None,
destinations: int = 1,
folder: Optional[Union[int, str]] = None,
track_language: Optional[Dict[str, Any]] = None,
languages_forced: Optional[bool] = None,
) -> None:

Pick a candidate (the row is then Ready), a destination folder, the folder of a series that has several, or the language of a track.

Parameters

NameTypeDefaultDescription
row_idintThe row.
selectedOptional[int]NoneIndex of the candidate picked.
destinationOptional[int]NoneIndex of the destination folder of its media type.
destinationsint1How many destination folders the media type has.
folderOptional[Union[int, str]]NoneIndex of the existing folder of the series picked, or NEW_FOLDER for a new one.
track_languageOptional[Dict[str, Any]]None{"kind", "position", "language"}: the language of a track of its videos (None: back to automatic), for all its files.
languages_forcedOptional[bool]NoneTrue sorts the row without the languages it waits for (unsure_languages); False makes it wait again.

Raises

  • UnknownRowNo row has this id.
  • InvalidChangeinvalid_selection, invalid_destination, invalid_folder or invalid_track_language.
Source

chosen_folderstaticmethod

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

The existing folder a row's series goes into, or None for a new one (also when another destination was picked since).

Parameters

NameTypeDescription
rowAny
Source

describe

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

A row with its candidates and, once matched, the new names.

Parameters

NameTypeDescription
rowAny
Source

destination

def destination(row: Any) -> Optional[str]:

The destination folder of a row, if its media type has one.

Parameters

NameTypeDescription
rowAny
Source

known_folders

def known_folders(ids: Dict[str, str]) -> List[str]:

The folders S.O.K put a series in before, from its ids.

Parameters

NameTypeDescription
idsDict[str, str]
Source

media_item

def media_item(row: Any) -> Any:

The media item of the candidate picked for a row, or None before a match.

A series gets the titles of its episodes and the folders of its seasons ("Season 2 - The Name", in the language of the settings).

Parameters

NameTypeDescription
rowAny
Source

movie_detailsasync

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

The details of the movie picked for a row, with its credits: the director and the genres a rename writes into the file (write_metadata). None when they fail: the file then gets what the search result gives.

Parameters

NameTypeDescription
rowAny
Source

new_names

def new_names(
media_type: str,
item: Any,
files: List[str],
destination: Optional[str],
) -> List[str]:

The new path of each file of a row under its destination.

A movie gets its file name, an episode its series and season folders (an existing season folder of the destination first), the other kinds the folders and the name the desktop batches give them (batch_target): the artist and album folder of a track, the author folder of a book, the platform folder of a game. A video converted to MKV (convert_to_mkv) gets .mkv.

Parameters

NameTypeDescription
media_typestr
itemAny
filesList[str]
destinationOptional[str]
Source

refresh_folders

def refresh_folders(row_ids: Optional[Iterable[int]] = None) -> None:

Look again for the folder each series already has.

One folder found is chosen (and its destination with it); several wait for a choice. A choice made by hand stays while the same folders are found.

Parameters

NameTypeDefaultDescription
row_idsOptional[Iterable[int]]NoneThese rows only; every episode row when None.
Source

refresh_languages

def refresh_languages(
row_ids: Optional[Iterable[int]] = None,
release: bool = False,
) -> None:

Say again which video rows wait for the languages of their tracks (language_pending, the unsure_languages setting): after an analysis, a choice, a search, or a change of the settings.

Parameters

NameTypeDefaultDescription
row_idsOptional[Iterable[int]]NoneThese rows only; every video row when None.
releaseboolFalseA change of the user (the settings): a row that waited and no longer does is released for the automatic sorting.
Source

remember_folder

def remember_folder(row: Any, folder: str, date: str) -> None:

Keep the folder a series was put in, for its next episodes.

Parameters

NameTypeDescription
rowAny
folderstr
datestr
Source

row

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

Parameters

NameTypeDescription
row_idint
Source

rows

def rows(media_type: str) -> List[Dict[str, Any]]:

The rows of a tab, as the interface shows them.

Parameters

NameTypeDescription
media_typestr
Source

search_pendingasync

async def search_pending(
progress: Optional[Callable[[int, int], None]] = None,
) -> int:

Search every row not searched yet, kind by kind.

Parameters

NameTypeDefaultDescription
progressOptional[Callable[[int, int], None]]NoneCalled with (done, total) after each row.

Returns

  • intThe number of rows searched.

Raises

  • SearchStoppedA key is missing or refused, or the quota is used. The kinds of the other services are searched first: a used quota of Google Books does not keep the games from their search.
Source

search_rowasync

async def search_row(row_id: int, query: Optional[str] = None) -> None:

Search one row again, with the text typed or its own text.

Parameters

NameTypeDefaultDescription
row_idint
queryOptional[str]None

Raises

Source

UnknownRow

class UnknownRow

Bases: LookupError

No row has this id.

Source

Functions

api_language

def api_language(language: str) -> str:

The language of the results: "fr" → "fr-FR", as the desktop app asks.

Parameters

NameTypeDescription
languagestr
Source

poster_of

def poster_of(row: Any) -> Optional[str]:

The poster of the result picked for a row, if it has one.

Parameters

NameTypeDescription
rowAny
Source

search_error

def search_error(exc: SearchStopped) -> Dict[str, Any]:

{"code", "service"}, and "others" when other services stopped too.

Parameters

NameTypeDescription
excSearchStopped
Source

service_id

def service_id(api_name: str) -> str:

The id of a service from the name of its API class: GoogleBooks → google_books.

Parameters

NameTypeDescription
api_namestr
Source

Attributes

NameTypeValue
KEY_REFUSED'key_refused'
MISSING_KEY'missing_key'
NEW_FOLDER'new'
OVERVIEW_LENGTH300
PREFERRED_API{MediaType.VIDEO: ('preferred_api_video', 'tmdb'), MediaType.MUSIC: ('preferred_api_music', 'deezer'), MediaType.BOOK: ('preferred_api_books', 'google_books'), MediaType.GAME: ('preferred_api_games', 'igdb')}
RATE_LIMITED'rate_limited'
SEARCHESDict[str, Search]{'movie': Search(ContentType.MOVIE, MediaType.VIDEO, parse_movie, 'movie'), 'episode': Search(ContentType.TV_SERIES, MediaType.VIDEO, parse_series, 'tv'), 'album': Search(ContentType.ALBUM, MediaType.MUSIC, parse_album, 'album', same_album, False), 'track': Search(ContentType.TRACK, MediaType.MUSIC, parse_track, 'track', same_track, False), 'book': Search(ContentType.BOOK, MediaType.BOOK, parse_book, 'book', same_book, False), 'game': Search(ContentType.GAME, MediaType.GAME, parse_game, 'game')}
loggerlogging.getLogger(__name__)
Built with Kiln