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. 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.

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,
) -> None:

Pick a candidate (the row is then Ready) or a destination folder.

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.

Raises

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

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

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.

Parameters

NameTypeDescription
media_typestr
itemAny
filesList[str]
destinationOptional[str]
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

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'
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