upsies.jobs.webdb

Query online databases like IMDb

Classes

class upsies.jobs.webdb.WebDbSearchJob(*, home_directory=None, cache_directory=None, cache_id='', ignore_cache=False, no_output_is_ok=False, hidden=False, autostart=True, guaranteed=False, precondition=None, prejobs=(), callbacks={}, **kwargs)[source]

Bases: JobBase

Ask user to select a specific search result from an internet database

This job adds the following signals to signal:

search_results

Emitted after new search results are available. Registered callbacks get a sequence of SearchResult instances as a positional argument.

searching_status

Emitted when a new search is started and when new results are available. Registered callbacks get True for “search started” or False for “search ended” as a positional argument.

info_updating

Emitted when an attempt to fetch additional information is made. Registered callbacks get the name of an attribute of a SearchResult object that returns a coroutine function as a positional argument.

info_updated

Emitted when additional information is available. Registered callbacks are called for each piece of information and get key and value as positional arguments. key is an attribute of a SearchResult object that returns a coroutine function. value is the return value of that coroutine function.

query_updated

Emitted after the query changed. Registered callbacks get the new query as a positional argument.

selected

Emitted when result_selected() is called. Registered callbacks get a dict with the keys id, title, type, url and year.

property name

Internal name (e.g. for the cache file name)

property label

User-facing name

property db

WebDbApiBase instance

property query

Query instance

property no_id_ok

Whether this job will finish gracefully if no ID is selected

property show_poster

Whether to display a poster of the focused search result

property is_searching

Whether a search request is currently being made

initialize(*, db, query, autodetect=None, no_id_ok=False, show_poster=True)[source]

Set internal state

Parameters:
  • db (WebDbApiBase) – Return value of utils.webdbs.webdb()

  • query – Path of the release (doesn’t have to exist) or Query instance

  • autodetect

    Coroutine function that takes no arguments and returns an ID or None

    If autodetect returns a valid ID it is automatically selected and the job is finished with no user interaction. Otherwise, the returned ID is inserted into the usual prompt and it’s up to the user to fix it.

  • no_id_ok – Whether this job may finish without error if no ID is selected

  • show_poster – Whether to display a poster of the focused search result

async run()[source]

Do the work

This method is called by start(). Its coroutine is passed to add_task().

Any keyword arguments passed to initialize() are available via kwargs.

The job is_finished when all added tasks are done or cancelled. (See also finalize() and finalization().)

This method may call add_task() if more tasks are required.

search(query)[source]

Make new search request

Any currently ongoing search is cancelled.

Parameters:

query (str) – Query that is first passed through from_any() and then sanitize_query()

result_focused(result)[source]

Must be called by the UI when the user focuses a different search result

Parameters:

result (SearchResult) – Focused search result or None if there are no results

result_selected(result)[source]

Must be called by the UI when the user accepts a search result

Parameters:

result (SearchResult) – Focused search result or None if there are no results and the user accepted that (see no_id_ok)

property selected

Some more information about the selected search result

This is a dict that is empty before result_selected() is called. After result_selected() is called, it contains the following keys:

  • id

  • title

  • type

  • url

  • year

property exit_code

0 if job was successful, > 0 otherwise, None while job is not finished