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:
JobBaseAsk user to select a specific search result from an internet database
This job adds the following signals to
signal:search_resultsEmitted after new search results are available. Registered callbacks get a sequence of
SearchResultinstances as a positional argument.searching_statusEmitted 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_updatingEmitted when an attempt to fetch additional information is made. Registered callbacks get the name of an attribute of a
SearchResultobject that returns a coroutine function as a positional argument.info_updatedEmitted when additional information is available. Registered callbacks are called for each piece of information and get
keyandvalueas positional arguments.keyis an attribute of aSearchResultobject that returns a coroutine function.valueis the return value of that coroutine function.query_updatedEmitted after the
querychanged. Registered callbacks get the new query as a positional argument.selectedEmitted when
result_selected()is called. Registered callbacks get adictwith the keysid,title,type,urlandyear.
- property name
Internal name (e.g. for the cache file name)
- property label
User-facing name
- property db
WebDbApiBaseinstance
- 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
Queryinstanceautodetect –
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 toadd_task().Any keyword arguments passed to
initialize()are available viakwargs.The job
is_finishedwhen alladded tasksare done or cancelled. (See alsofinalize()andfinalization().)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 thensanitize_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
dictthat is empty beforeresult_selected()is called. Afterresult_selected()is called, it contains the following keys:idtitletypeurlyear
- property exit_code
0 if job was successful, > 0 otherwise, None while job is not finished