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
| Name | Type | Description |
|---|---|---|
code | str |
Attributes
| Name |
|---|
code |
Searchdataclass
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
| Name | Type | Default | Description |
|---|---|---|---|
content_type | ContentType | ||
media_type | MediaType | ||
parse | QueryParser | ||
factory_type | str | ||
same_work | Optional[SameWork] | None | |
localized | bool | True |
Attributes
| Name | Type |
|---|---|
content_type | ContentType |
factory_type | str |
localized | bool |
media_type | MediaType |
parse | QueryParser |
same_work | Optional[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
| Name | Type | Description |
|---|---|---|
code | str | |
service | str |
Attributes
| Name | Type |
|---|---|
code | |
others | List[SearchStopped] |
service |
Searcher
class Searcher(db: Database, config: ConfigManager, settings: Settings)Search the rows, change them, and describe them for the tabs.
Parameters
| Name | Type | Description |
|---|---|---|
db | Database | |
config | ConfigManager | |
settings | Settings |
batch_ops
def batch_ops(media_type: str) -> Any:The file operations that rename a media type.
Parameters
| Name | Type | Description |
|---|---|---|
media_type | str |
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
| Name | Type | Default | Description |
|---|---|---|---|
row_id | int | The row. | |
selected | Optional[int] | None | Index of the candidate picked. |
destination | Optional[int] | None | Index of the destination folder of its media type. |
destinations | int | 1 | How many destination folders the media type has. |
Raises
UnknownRowNo row has this id.InvalidChangeinvalid_selection or invalid_destination.
describe
def describe(row: Any) -> Dict[str, Any]:A row with its candidates and, once matched, the new names.
Parameters
| Name | Type | Description |
|---|---|---|
row | Any |
destination
def destination(row: Any) -> Optional[str]:The destination folder of a row, if its media type has one.
Parameters
| Name | Type | Description |
|---|---|---|
row | Any |
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
| Name | Type | Description |
|---|---|---|
row | Any |
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
| Name | Type | Description |
|---|---|---|
media_type | str | |
item | Any | |
files | List[str] | |
destination | Optional[str] |
row
def row(row_id: int) -> Dict[str, Any]:Parameters
| Name | Type | Description |
|---|---|---|
row_id | int |
rows
def rows(media_type: str) -> List[Dict[str, Any]]:The rows of a tab, as the interface shows them.
Parameters
| Name | Type | Description |
|---|---|---|
media_type | str |
search_pendingasync
async def search_pending( progress: Optional[Callable[[int, int], None]] = None,) -> int:Search every row not searched yet, kind by kind.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
progress | Optional[Callable[[int, int], None]] | None | Called 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.
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
| Name | Type | Default | Description |
|---|---|---|---|
row_id | int | ||
query | Optional[str] | None |
Raises
UnknownRowNo row has this id.SearchStoppedA key is missing or refused, or the quota is used.
UnknownRow
class UnknownRowBases: LookupError
No row has this id.
SourceFunctions
api_language
def api_language(language: str) -> str:The language of the results: "fr" → "fr-FR", as the desktop app asks.
Parameters
| Name | Type | Description |
|---|---|---|
language | str |
search_error
def search_error(exc: SearchStopped) -> Dict[str, Any]:{"code", "service"}, and "others" when other services stopped too.
Parameters
| Name | Type | Description |
|---|---|---|
exc | SearchStopped |
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
| Name | Type | Description |
|---|---|---|
api_name | str |
Attributes
| Name | Type | Value |
|---|---|---|
KEY_REFUSED | 'key_refused' | |
MISSING_KEY | 'missing_key' | |
OVERVIEW_LENGTH | 300 | |
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' | |
SEARCHES | Dict[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')} |
logger | logging.getLogger(__name__) |