The seedbox.db.api Module

Database API

Public facing database api that leverages a provided implementation to execute database operations.

class seedbox.db.api.DBApi(impl)

Bases: object

Provides API for supported database operations.

Parameters:impl (Connection) – database plugin instance
backup()

Backup database.

bulk_create_medias(medias)

Saves metadata for multiple media files.

Perform save (insert) operation on a list of instances of media.

Parameters:medias – a list of instances of media file
Returns:media file instance(s)
Return type:MediaFile
bulk_save_torrents(value_map, qfilter)

Performs save (update) operation on multiple instances.

Using the provided data map.
Parameters:
  • value_map – data attributes and values to update
  • qfilter – query filter to determine instances to update
clean_up()

Cleans up data within tables.

Periodically check for data no longer needed (fully processed, invalid, or deleted) and then remove from the database.

clear()

Clears all data from database.

delete_appstate(appstate)

Perform delete operation on an instance of appstate.

Parameters:appstate – an instance of appstate
delete_media(media)

Deletes metadata for media file.

Perform delete operation on an instance of media.

Parameters:media – an instance of media file
delete_medias(qfilter)

Deletes metadata for multiple media files.

Perform delete operation on a list of instances of media.

Parameters:qfilter – query filter to determine instances to delete
delete_torrent(torrent)

Performs delete operation on specific instance of torrent.

Parameters:torrent – an instance of torrent
delete_torrents(qfilter)

Performs delete operation on selection of torrent instances.

Parameters:qfilter – query filter to determine instances to delete.
fetch_or_create_torrent(name)

Fetch or create torrent by name.

Performs select operation using the name of torrent to fetch torrent, and if the torrent is not found, then the save (insert) operation is performed using the name of the torrent.

Parameters:name – the name of a torrent
Returns:torrent instance(s)
Return type:Torrent
get_appstate(name)

Retrieve appstate by name.

Perform select operation using name of appstate to fetch an instance of appstate.

Parameters:name – name of an appstate instance
Returns:appstate instance
Return type:AppState
get_media(media_id)

Fetch media file metadata by id.

Perform select operation using media primary key to fetch media.

Parameters:media_id – media primary key
Returns:media file instance
Return type:MediaFile
get_medias(qfilter)

Retrieves metadata for multiple media files.

Perform select operation on selection of media instances.

Parameters:qfilter – query filter to determine instances to fetch.
Returns:media file instance(s)
Return type:MediaFile
get_medias_by(torrent_id, file_path=None, compressed=None, synced=None, missing=None, skipped=None)

Retrieve media file metadata using specified criteria.

Perform select operation using a combination of the provided parameters to find specified media.

Parameters:
  • torrent_id – primary key of torrent
  • file_path – location where media exist on file system (default: None; ignore attribute)
  • compressed – flag to indicate to include or exclude compressed media (default: None; ignore attribute)
  • synced – flag to indicate to include or exclude synced media ( default: None; ignored attribute)
  • missing – flag to indicate to include or exclude missing media (default: None; ignored attribute)
  • skipped – flag to indicate to include or exclude skipped media (default: None; ignored attribute)
Returns:

media file instance(s)

Return type:

MediaFile

get_medias_by_torrent(torrent_id)

Fetch all media file metadata by torrent id.

Perform select operation using the primary key of torrent to fetch associated media.

Parameters:torrent_id – primary key of torrent
Returns:media file instance(s)
Return type:MediaFile
get_processed_medias(torrent_id)

Retrieve processed media files by torrent id.

Performed select operation using torrent primary key and pre-defined criteria for what constitutes processed media.

Parameters:torrent_id – torrent primary key
Returns:media file instance(s)
Return type:MediaFile
get_torrent(torrent_id)

Fetch torrent by id.

Perform select operation using the primary key of torrent to fetch torrent.

Parameters:torrent_id – primary key of torrent
Returns:torrent instance(s)
Return type:Torrent
get_torrent_by_name(name)

Fetch torrent by name.

Perform select operation using the name of torrent to fetch torrent.

Parameters:name – the name of torrent
Returns:torrent instance(s)
Return type:Torrent
get_torrents(qfilter)

Perform select operation on selection of torrent instances.

Parameters:qfilter – query filter to determine instances to fetch.
Returns:torrent instance(s)
Return type:Torrent
get_torrents_active()

Retrieves active torrents.

Perform select operation using a pre-defined criteria for what constitutes an active torrent.

Returns:torrent instance(s)
Return type:Torrent
get_torrents_by_state(state, failed=False)

Retrieve torrents by specified state.

Perform select operation using a pre-defined criteria to get torrents by a specific state.

Parameters:
  • state – name of the state of the torrent
  • failed – flag indicating to include failed entries or not
Returns:

torrent instance(s)

Return type:

Torrent

get_torrents_eligible_for_purging()

Retrieves eligible to purge.

Perform select operation using a pre-defined criteria for what constitutes eligible for purging.

Returns:torrent instance(s)
Return type:Torrent
get_torrents_eligible_for_removal()

Retrieve torrents eligible for removal.

Perform select operation using a pre-defined criteria for what constitutes eligible for removal.

Returns:torrent instance(s)
Return type:Torrent
save_appstate(appstate)

Perform save (insert/update) operation on an instance of appstate.

Parameters:appstate – an instance of appstate
Returns:appstate instance
Return type:AppState
save_media(media)

Saves media file metadata.

Perform save (insert/update) operation on an instance of media.

Parameters:media – an instance of media file
Returns:media file instance
Return type:MediaFile
save_torrent(torrent)

Performs save (insert/update) operation on an instance of torrent.

Parameters:torrent – an instance of a torrent
Returns:saved torrent instance
Return type:Torrent
shrink_db()

Shrink database.