Package elisa :: Package core :: Module media_db :: Class MediaDB
[hide private]
[frames] | no frames]

Class MediaDB

source code


Elisa Media database store

I'm keeping a cache of media source hierarchies in a database. I use the elisa.core.db_backend to communicate with supported database backends.

Media sources are basically roots of media locations, like ~/Music folder for audio content for instance. Media sources are referenced in the "source" db table.

Medias can be both files and directories. Each Media has a parent media id and a source id. Content-type specific information are stored in diferent tables for audio, video and images.

Instance Methods [hide private]
 
__init__(self, backend='frontend', first_load=True)
Initialize our _backend instance variable.
source code
 
close(self)
Disconnect the backend
source code
 
_check_schema(self) source code
 
_reset(self) source code
 
get_files_count_for_source_uri(self, source_uri)
DOCME
source code
 
prepare_source_for_update(self, source)
DOCME
source code
 
hide_un_updated_medias_for_source(self, source)
DOCME
source code
elisa.extern.db_row.DBRow
add_source(self, uri, short_name)
Add a new media source in the database
source code
bool
hide_source(self, source)
Mark a source as unavailable in the database.
source code
bool
show_source(self, source)
Mark a source as available in the database.
source code
 
is_source(self, row)
DOCME
source code
bool
add_media(self, uri, short_name, source_id, content_type, **extra)
Add a new media in the "media" table and in specialized tables
source code
bool
del_media_node(self, media, force_drop=True)
Mark a media as deleted in database.
source code
elisa.extern.db_row.DBRow
get_source_for_uri(self, uri)
Find in which media source the given uri is registered with.
source code
 
media_exists(self, uri) source code
elisa.extern.db_row.DBRow
get_media_information(self, uri, extended=True, media_type='frontend')
Find in database the media corresponding with the given URI.
source code
 
get_medias(self, source='frontend', media_type='frontend') source code
elisa.extern.db_row.DBRow
get_media_with_id(self, media_id)
Fetch the media with given id in the database
source code
 
update_media(self, media, **new_values)
Update some attributes in database of the given media
source code
 
update_media_metadata(self, media, **metadata)
DOCME
source code
 
get_next_location(self, uri, root_uri) source code
 
_parse_uri(self, uri) source code
 
_build_request(self, select_clause, path_values, start=0, item_count=-1) source code
list of tuple (string, elisa.core.media_uri.MediaUri, int)
get_uris_by_meta_uri(self, uri, children, start=0, item_count=-1)
This function can handle an URI with the elisa:// scheme.
source code
 
has_children(self, uri) source code
 
get_artist_from_album(self, album)
DOCME
source code
 
_guess_format_from_metadata(self, metadata) source code
 
_node_changed(self, node, values) source code
 
_kw_extract(self, kw) source code

Inherited from extern.log.log.Loggable: debug, doLog, error, info, log, logFunction, logObjectName, warning, warningFailure

Inherited from object: __delattr__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __str__

Class Variables [hide private]
  available_meta = {'albums': 'album', 'artists': 'artist', 'fil...

Inherited from extern.log.log.Loggable: logCategory

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, backend='frontend', first_load=True)
(Constructor)

source code 
Initialize our _backend instance variable. If backend is None we retrieve one in the Application.
Parameters:
  • backend (elisa.core.db_backend.DBBackend or None (to use application's)) - the database backend to use
  • first_load (bool) - is it the first time the db is loaded?
Overrides: log.Loggable.__init__

add_source(self, uri, short_name)

source code 

Add a new media source in the database

Add a new row in the "source" table. Source scanning is not handled by this method. See the elisa.core.media_scanner.MediaScanner for that.
Parameters:
Returns: elisa.extern.db_row.DBRow
the newly created source.

hide_source(self, source)

source code 

Mark a source as unavailable in the database.

Update the "available" flag of the given source record in the "source" table. Return True if source was correctly hidden
Parameters:
Returns: bool

show_source(self, source)

source code 

Mark a source as available in the database.

Update the "available" flag of the given source record in the "source" table. Return True if source was correctly shown
Parameters:
Returns: bool

add_media(self, uri, short_name, source_id, content_type, **extra)

source code 

Add a new media in the "media" table and in specialized tables

There's one specialized table for each content-type (audio, video, picture). The Media can be either a file or a directory.

If the media is already on database but marked as unavailable or deleted it will be marked as available and undeleted. In that case not further insert will be done.
Parameters:
  • uri (elisa.core.media_uri.MediaUri) - the URI identifying the media
  • short_name (string) - display-friendly media name
  • parent (elisa.extern.db_row.DBRow) - the source or media to register the media in
  • content_type (string) - the media content-type ('directory', 'audio', etc)
  • extra (dict) - extra row attributes
Returns: bool
True if inserted, False if updated

To Do: complete keywords list

del_media_node(self, media, force_drop=True)

source code 

Mark a media as deleted in database.

FIXME: document force_drop
Parameters:
Returns: bool

get_source_for_uri(self, uri)

source code 

Find in which media source the given uri is registered with.

The URI has to be referenced in the "source" table.
Parameters:
Returns: elisa.extern.db_row.DBRow

get_media_information(self, uri, extended=True, media_type='frontend')

source code 

Find in database the media corresponding with the given URI.

The URI has to be referenced in the "media" table.
Parameters:
Returns: elisa.extern.db_row.DBRow

get_media_with_id(self, media_id)

source code 
Fetch the media with given id in the database
Parameters:
  • media_id (int) - the identifier of the Media i have to dig in the db
Returns: elisa.extern.db_row.DBRow

update_media(self, media, **new_values)

source code 
Update some attributes in database of the given media
Parameters:
  • media (elisa.extern.db_row.DBRow) - the media I'm checking
  • new_values (dict) - attributes to update. Keys have to match "media" table column names.

To Do: document valid keys of new_values dict

get_uris_by_meta_uri(self, uri, children, start=0, item_count=-1)

source code 
This function can handle an URI with the elisa:// scheme. It returns a list of uris matching the request defined in uri's path
Parameters:
  • uri (elisa.core.media_uri.MediaUri) - uri representing an elisa:// scheme
  • children (list of tuple (uri, info)) - uri representing an elisa:// scheme
Returns: list of tuple (string, elisa.core.media_uri.MediaUri, int)

Class Variable Details [hide private]

available_meta

Value:
{'albums': 'album', 'artists': 'artist', 'files': 'uri'}