Database managment module

SQlite database library

class sima.lib.simadb.SimaDB(db_path=None)[source]

SQLite management

add_history(track, date=None)[source]

Record last play date of track (ie. not a real play history).

Parameters
create_db()[source]

Set up a database

delete_bl(track=None, album=None, artist=None)[source]
drop_all()[source]
fetch_albums_history(needle=None, duration=720)[source]
Parameters
  • needle (sima.lib.meta.Artist) – When specified, returns albums history for this artist.

  • duration (int) – How long ago to fetch history from (in hours)

fetch_artists_history(needle=None, duration=720)[source]

Returns a list of Artist objects

Parameters
  • needle (sima.lib.meta.Artist or sima.lib.meta.MetaContainer) – When specified, returns history for these artists only

  • duration (int) – How long ago to fetch history from (in hours)

fetch_genres_history(duration=720, limit=20)[source]

Returns genre history

Parameters
  • duration (int) – How long ago to fetch history from (in hours)

  • limit (int) – number of genre to fetch

fetch_history(artist=None, duration=720)[source]

Fetches tracks history, more recent first

Parameters
  • artist (sima.lib.meta.Artist) – limit history to this artist

  • duration (int) – How long ago to fetch history from (in hours)

get_album(album, with_connection=None, add=True)[source]

get album information from the database. if not in database insert new entry.

Parameters
get_albumartist(artist, with_connection=None, add=True)[source]

get albumartist information from the database. if not in database insert new entry.

Parameters
get_artist(artist, with_connection=None, add=True)[source]

get artist information from the database. if not in database insert new entry.

Parameters
get_bl_album(album, with_connection=None, add=True)[source]

Add an album to blocklist

Parameters
  • sima.lib.meta.Album – Album object to add to blocklist

  • with_connection (sqlite3.Connection) – sqlite3.Connection to reuse, else create a new one

  • add (bool) – Default is to add a new record, set to False to fetch associated record

get_bl_artist(artist, with_connection=None, add=True)[source]

Add an artist to blocklist

Parameters
  • sima.lib.meta.Artist – Artist object to add to blocklist

  • with_connection (sqlite3.Connection) – sqlite3.Connection to reuse, else create a new one

  • add (bool) – Default is to add a new record, set to False to fetch associated record

get_bl_track(track, with_connection=None, add=True)[source]

Add a track to blocklist

Parameters
  • track (sima.lib.track.Track) – Track object to add to blocklist

  • with_connection (sqlite3.Connection) – sqlite3.Connection to reuse, else create a new one

  • add (bool) – Default is to add a new record, set to False to fetch associated record

get_database_connection()[source]

get database reference

get_genre(genre, with_connection=None, add=True)[source]

get genre from the database. if not in database insert new entry.

Parameters
get_info()[source]
get_track(track, with_connection=None, add=True)[source]

Get a track id from Tracks table, add if not existing,

Parameters
purge_history(duration=720)[source]

Remove old entries in history

Parameters

duration (int) – Purge history record older than duration in hours

view_bl()[source]
exception sima.lib.simadb.SimaDBError[source]

Exceptions.

sima.lib.simadb.__HIST_DURATION__ = 720

Default history duration for both request and purge in hours