Package elisa :: Package core :: Module media_manager :: Class MediaManager
[hide private]
[frames] | no frames]

Class MediaManager

source code


Provides access to files through the use of MediaProvider components which allows to handle different file I/O protocols using URIs. It also handles caching in a database and the monitoring of files via the elisa.core.media_scanner.MediaScanner.

Database caching can be disabled: In a such case, the media_scanner instance variable is set to None.

Nested Classes [hide private]

Inherited from manager.Manager: __metaclass__

Instance Methods [hide private]
 
__init__(self, metadata_manager)
Initialize media_providers instance variable and try to load the media_scanner.
source code
 
media_db__get(self)
MediaDB instance accessor.
source code
 
_get_db_options(self) source code
 
enabled__get(self) source code
 
start(self, seconds=0, resume_scan=True)
Load all enabled MediaProvider components using the PluginRegistry and eventually start the media_scanner
source code
twisted.internet.defer.DeferredList
stop(self)
Stop the media_scanner if it's running and clean all registered media_providers.
source code
 
register_component(self, component)
Register a new Component
source code
 
unregister_component(self, component)
Unregister a component from the Manager
source code
 
get_metadata(self, metadata, low_priority=True)
just a proxy to the metadata_manager.get_metadata
source code
 
add_source(self, source_uri, media_types='frontend')
Add a new source in DB.
source code
 
remove_source(self, source_uri)
Mark a source as unavailable in the db and stop monitoring it
source code
 
update_source(self, source_uri)
Schedule a new scan of the source located at given uri.
source code
elisa.extern.db_row.DBRow
get_source_for_uri(self, uri)
Fetch the source located at given uri, by retrieving its information in the media database.
source code
 
handle_notify_event(self, uri, event, media_types) source code
elisa.extern.db_row.DBRow
get_media_information(self, uri, extended=True, media_type='frontend')
Fetch the media located at given uri, by retrieving its information in the media database.
source code
elisa.base_components.media_provider.MediaProvider
_get_media_provider(self, uri)
Retrieve the MediaProvider supporting the scheme of the given URI.
source code
 
_proxy(self, method_name, fallback_result, uri, *args, **kw) source code
 
is_scannable(self, uri) source code
 
_guess_source_for_uri(self, uri) source code
twisted.internet.defer.Deferred
get_media_type(self, uri)
Try to guess the maximum information from the media located at given uri by looking at eventual file extension.
source code
 
blocking_get_media_type(self, uri) source code
bool
is_directory(self, uri)
return True if a directory
source code
 
blocking_is_directory(self, uri) source code
twisted.internet.defer.Deferred
has_children_with_types(self, uri, media_types)
Detect whether the given uri has children for given media types which can be one of media_provider.media_types.
source code
 
blocking_has_children_with_types(self, uri, media_types) source code
 
get_direct_children(self, uri, children_with_info)
Scan the data located at given uri and return a deferred.
source code
 
blocking_get_direct_children(self, children_with_info) source code
elisa.core.media_file.MediaFile
open(self, uri, mode='r')
Open an uri and return MediaFile file if the block keyword parameter is True.
source code
 
blocking_open(self, uri, mode='r') source code
elisa.core.media_uri.MediaUri
next_location(self, uri, root='frontend')
Return the uri just next to given uri and record it to history
source code
 
blocking_next_location(self, uri, root='frontend') source code
elisa.core.media_uri.MediaUri
previous_location(self, uri)
Return the uri found before given uri
source code
 
blocking_previous_location(self, uri) source code
 
monitor_uri(self, uri, callback, *extra_args)
Start monitoring given uri for modification and call a function in case of any change happening on `uri` Raises UriNotMonitorable(uri) if uri can't be monitored
source code
 
unmonitor_uri(self, uri)
Stop monitoring given uri.
source code
bool
uri_is_monitorable(self, uri)
Check if the uri is monitorable for modification
source code
bool
uri_is_monitored(self, uri)
Check if the uri is currently monitored for modification
source code
bool
copy(self, orig_uri, dest_uri, recursive=True)
Copy one location to another.
source code
bool
move(self, orig_uri, dest_uri)
Move data located at given URI to another URI.
source code
bool
delete(self, uri, recursive=True)
Delete a resource located at given URI.
source code
elisa.core.media_uri.MediaUri
get_real_uri(self, uri)
Returns the original uri (reachable) from a virtual uri representation.
source code

Inherited from manager.Manager: component_registered, initialize

Inherited from manager.Manager (private): _load_providers

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__

Static Methods [hide private]

Inherited from manager.Manager: __classinit__

Class Variables [hide private]
  name = 'media_manager'

Inherited from extern.log.log.Loggable: logCategory

Instance Variables [hide private]
elisa.core.media_scanner.MediaScanner media_scanner
the component which scans media sources and keep the database up to date

Inherited from manager.Manager (private): _components

Properties [hide private]
  enabled
  media_db
MediaDB instance accessor.

Inherited from object: __class__

Method Details [hide private]

__init__(self, metadata_manager)
(Constructor)

source code 
Initialize media_providers instance variable and try to load the media_scanner.
Parameters:
Overrides: manager.Manager.__init__

start(self, seconds=0, resume_scan=True)

source code 
Load all enabled MediaProvider components using the PluginRegistry and eventually start the media_scanner
Parameters:
  • seconds (int) - time in seconds to wait before starting the scanner
  • resume_scan (bool) - should the media_scanner resume interrupted scan at startup?
Overrides: manager.Manager.start

stop(self)

source code 
Stop the media_scanner if it's running and clean all registered media_providers.
Returns: twisted.internet.defer.DeferredList
Overrides: manager.Manager.stop

register_component(self, component)

source code 

Register a new Component

Store a new Component in our components list. Returns the result of the operation. If the component is already registered, don't register it twice.
Overrides: manager.Manager.register_component
(inherited documentation)

unregister_component(self, component)

source code 

Unregister a component from the Manager

Remove the Component instance from our components list if it's there. Returns the result of the operation.
Overrides: manager.Manager.unregister_component
(inherited documentation)

add_source(self, source_uri, media_types='frontend')

source code 
Add a new source in DB. If it's already there, just mark it as available again (and start monitoring it).
Parameters:
  • source_uri (elisa.core.media_uri.MediaUri) - The location of the source
  • media_types (sequence) - a sequence of media types to scan on this source eg: ('audio', 'image') or None

remove_source(self, source_uri)

source code 
Mark a source as unavailable in the db and stop monitoring it
Parameters:

update_source(self, source_uri)

source code 
Schedule a new scan of the source located at given uri. The scan may not start just after calling this method.
Parameters:

get_source_for_uri(self, uri)

source code 
Fetch the source located at given uri, by retrieving its information in the media database.
Parameters:
Returns: elisa.extern.db_row.DBRow

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

source code 
Fetch the media located at given uri, by retrieving its information in the media database.
Parameters:
Returns: elisa.extern.db_row.DBRow

_get_media_provider(self, uri)

source code 
Retrieve the MediaProvider supporting the scheme of the given URI. If multiple MediaProviders support it, the first one is chosen.
Parameters:
Returns: elisa.base_components.media_provider.MediaProvider

get_media_type(self, uri)

source code 
Try to guess the maximum information from the media located at given uri by looking at eventual file extension. Will return something like:
 {'file_type': string (values: one of media_provider.media_types,
  'mime_type': string (example: 'audio/mpeg' for .mp3 uris. can be
                      empty string if unguessable)
  }
Parameters:
Returns: twisted.internet.defer.Deferred

is_directory(self, uri)

source code 
return True if a directory
Parameters:
Returns: bool

has_children_with_types(self, uri, media_types)

source code 
Detect whether the given uri has children for given media types which can be one of media_provider.media_types. Implies the URI is a directory as well.
Parameters:
Returns: twisted.internet.defer.Deferred

get_direct_children(self, uri, children_with_info)

source code 

Scan the data located at given uri and return a deferred.
Fills children_with_info. Defferred is called when the
gathering is finished with children_with_info as parameter

Typemap of filled result:

  [
     (uri : media_uri.MediaUri,
      additional info: dict),
    ...
  ]

@param uri:                     the URI to analyze
@type uri:                      L{elisa.core.media_uri.MediaUri}
@param children_with_info:      List where the children will be appended
@type children_with_info:       list
@rtype:                         twisted.internet.deferred

open(self, uri, mode='r')

source code 
Open an uri and return MediaFile file if the block keyword parameter is True. Else we return a deferred which will be trigerred when the media_file has been successfully opened.
Parameters:
Returns: elisa.core.media_file.MediaFile

next_location(self, uri, root='frontend')

source code 
Return the uri just next to given uri and record it to history
Parameters:
Returns: elisa.core.media_uri.MediaUri

previous_location(self, uri)

source code 
Return the uri found before given uri
Parameters:
Returns: elisa.core.media_uri.MediaUri

monitor_uri(self, uri, callback, *extra_args)

source code 
Start monitoring given uri for modification and call a function in case of any change happening on `uri` Raises UriNotMonitorable(uri) if uri can't be monitored
Parameters:

unmonitor_uri(self, uri)

source code 
Stop monitoring given uri.
Parameters:

uri_is_monitorable(self, uri)

source code 
Check if the uri is monitorable for modification
Parameters:
Returns: bool

uri_is_monitored(self, uri)

source code 
Check if the uri is currently monitored for modification
Parameters:
  • uri (elisa.core.media_uri.MediaUri) - the URI representing the file or directory for which we would like to know if it is currently monitored or not
Returns: bool

copy(self, orig_uri, dest_uri, recursive=True)

source code 
Copy one location to another. If both URIs represent a directory and recursive flag is set to True I will recursively copy the directory to the destination URI.
Parameters:
  • orig_uri (elisa.core.media_uri.MediaUri) - the URI to copy, can represent either a directory or a file
  • dest_uri (elisa.core.media_uri.MediaUri) - the destination URI, can represent either a directory or a file
  • recursive (bool) - if orig_uri represents a directory, should I copy it recursively to dest_uri?
Returns: bool

move(self, orig_uri, dest_uri)

source code 
Move data located at given URI to another URI. If orig_uri represents a directory it will recusively be moved to dest_uri. In the case where orig_uri is a directory, dest_uri can't be a file.
Parameters:
Returns: bool

delete(self, uri, recursive=True)

source code 
Delete a resource located at given URI. If that URI represents a directory and recursive flag is set to True I will recursively remove the directory.
Parameters:
  • uri (elisa.core.media_uri.MediaUri) - the URI representing the file or directory for which we would like to know if it is currently monitored or not
  • recursive (bool) - if orig_uri represents a directory, should I copy it recursively to dest_uri?
Returns: bool

get_real_uri(self, uri)

source code 
Returns the original uri (reachable) from a virtual uri representation.
Parameters:
Returns: elisa.core.media_uri.MediaUri

Property Details [hide private]

enabled

Get Method:
elisa.core.media_manager.MediaManager.enabled__get(self)
Set Method:
'frontend'
Delete Method:
'frontend'

media_db

MediaDB instance accessor.
Get Method:
elisa.core.media_manager.MediaManager.media_db__get(self) - MediaDB instance accessor.
Set Method:
'frontend'
Delete Method:
'frontend'