# Class e.c.m.MediaManager(manager.Manager):

Part of elisa.core.media_manager View In Hierarchy

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:

- explicitely in the application's config
- if any dependency (pysqlite for instance) is unmet

In a such case, the media_scanner instance variable is set to None.

Instance Variables | media_scanner | the component which scans media sources and keep the database up to date (type: `elisa.core.media_scanner.MediaScanner` )

Line # | Kind | Name | Docs
--- | --- | --- | ---
155 | Method | __init__ | Initialize media_providers instance variable and try to
166 | Method | start | Load all enabled MediaProvider components using the
178 | Method | stop | Stop the media_scanner if it's running and clean all
187 | Method | register_component | Register a new Component
200 | Method | unregister_component | Unregister a component from the Manager
212 | Method | get_metadata | just a proxy to the metadata_manager.get_metadata
247 | Method | is_scannable | Undocumented
274 | Method | get_media_type | Try to guess the maximum information from the media located
293 | Method | blocking_get_media_type | Undocumented
296 | Method | is_directory | return True if a directory
306 | Method | blocking_is_directory | Undocumented
309 | Method | has_children_with_types | Detect whether the given uri has children for given media
323 | Method | blocking_has_children_with_types | Undocumented
327 | Method | get_direct_children | Scan the data located at given uri and return a deferred.
349 | Method | blocking_get_direct_children | Undocumented
353 | Method | open | Open an uri and return MediaFile file if the block keyword
368 | Method | blocking_open | Undocumented
371 | Method | next_location | Return the uri just next to given uri and record it to history
398 | Method | blocking_next_location | Undocumented
410 | Method | previous_location | Return the uri found before given uri
421 | Method | blocking_previous_location | Undocumented
424 | Method | monitor_uri | Start monitoring given uri for modification and call a
443 | Method | unmonitor_uri | Stop monitoring given uri.
452 | Method | uri_is_monitorable | Check if the uri is monitorable for modification
463 | Method | uri_is_monitored | Check if the uri is currently monitored for modification
475 | Method | copy | Copy one location to another. If both URIs represent a
495 | Method | move | Move data located at given URI to another URI. If orig_uri
512 | Method | delete | Delete a resource located at given URI. If that URI represents
529 | Method | get_real_uri | Returns the original uri (reachable) from a virtual

Inherited from Manager:

Line # | Kind | Name | Docs
--- | --- | --- | ---
63 | Method | load_components | Load a list of components in sequence.

def __init__(self, metadata_manager):
overrides elisa.core.manager.Manager.__init__
Initialize media_providers instance variable and try to load the media_scanner.

Parameters | metadata_manager | The MetadataManager to use to create the MediaScanner (type: `elisa.core.metadata_manager.MetadataManager` )

def start(self, seconds=0, resume_scan=False):
overrides elisa.core.manager.Manager.start
Load all enabled MediaProvider components using the PluginRegistry and eventually start the media_scanner

Parameters | seconds | time in seconds to wait before starting the scanner (type: int )
| resume_scan | should the media_scanner resume interrupted scan at startup? (type: bool )

def stop(self):
overrides elisa.core.manager.Manager.stop
Stop the media_scanner if it's running and clean all registered media_providers.

def register_component(self, component):
overrides elisa.core.manager.Manager.register_component

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.

Parameters | component | the Component to register (type: `elisa.core.component.Component` )
Raises | AlreadyRegistered | when the component has already been registered
| TypeError | when the given `component` is *not* of the type `supported_components`

def unregister_component(self, component):
overrides elisa.core.manager.Manager.unregister_component

Unregister a component from the Manager

Remove the Component instance from our components list if it's there. Returns the result of the operation.

Parameters | component | the Component to register (type: `elisa.core.component.Component` )
Raises | CannotUnregister | raised when the component cannot be removed

def get_metadata(self, metadata, low_priority=False):
just a proxy to the metadata_manager.get_metadata

def is_scannable(self, uri):
Undocumented
def get_media_type(self, uri):
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 | uri | the URI to analyze (type: `elisa.core.media_uri.MediaUri` )
Returns | (type: `twisted.internet.defer.Deferred` )

def blocking_get_media_type(self, uri):
Undocumented
def is_directory(self, uri):
return True if a directory

Parameters | uri | the URI to analyze (type: `elisa.core.media_uri.MediaUri` )
Returns | (type: bool )

def blocking_is_directory(self, uri):
Undocumented
def 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. Implies the URI is a directory as well.

Parameters | uri | the URI to scan (type: `elisa.core.media_uri.MediaUri` )
| media_types | the media_types to look for on the directory (type: list of strings )
Returns | (type: `twisted.internet.defer.Deferred` )

def blocking_has_children_with_types(self, uri, media_types):
Undocumented
def get_direct_children(self, uri, children_with_info):

    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

def blocking_get_direct_children(self, children_with_info):
Undocumented
def open(self, uri, mode='r'):
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 | uri | the URI to open (type: `elisa.core.media_uri.MediaUri` )
| mode | how to open the file -- see manual of builtin open() (type: string or None )
Returns | (type: `elisa.core.media_file.MediaFile` )

def blocking_open(self, uri, mode='r'):
Undocumented
def next_location(self, uri, root=None):
Return the uri just next to given uri and record it to history

Parameters | uri | the URI representing the file or directory from where to move on (type: `elisa.core.media_uri.MediaUri` )
| root | root URI (type: `elisa.core.media_uri.MediaUri` )
Returns | (type: `elisa.core.media_uri.MediaUri` )

def blocking_next_location(self, uri, root=None):
Undocumented
def previous_location(self, uri):
Return the uri found before given uri

Parameters | uri | the URI representing the file or directory prior to uri (type: `elisa.core.media_uri.MediaUri` )
Returns | (type: `elisa.core.media_uri.MediaUri` )

def blocking_previous_location(self, uri):
Undocumented
def 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

Parameters | uri | URI representing the file or directory to monitor (type: `elisa.core.media_uri.MediaUri` )
| extra_args | extra positional arguments to pass to the callback (type: tuple )
| callback | a callable taking the event that occured and the uri of the file on which the event applies to prototype: callable(uri, event) type uri: `elisa.core.media_uri.MediaUri` type event: `elisa.core.components.media_provider.NotifyEvent`

def unmonitor_uri(self, uri):
Stop monitoring given uri.

Parameters | uri | the URI representing the file or directory to monitor (type: `elisa.core.media_uri.MediaUri` )

def uri_is_monitorable(self, uri):
Check if the uri is monitorable for modification

Parameters | uri | the URI representing the file or directory for which we would like to know if it is monitorable or not (type: `elisa.core.media_uri.MediaUri` )
Returns | (type: bool )

def uri_is_monitored(self, uri):
Check if the uri is currently monitored for modification

Parameters | uri | the URI representing the file or directory for which we would like to know if it is currently monitored or not (type: `elisa.core.media_uri.MediaUri` )
Returns | (type: bool )

def copy(self, orig_uri, dest_uri, recursive=False):
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 | the URI to copy, can represent either a directory or a file (type: `elisa.core.media_uri.MediaUri` )
| dest_uri | the destination URI, can represent either a directory or a file (type: `elisa.core.media_uri.MediaUri` )
| recursive | if orig_uri represents a directory, should I copy it recursively to dest_uri? (type: bool )
Returns | (type: bool )

def move(self, orig_uri, dest_uri):
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 | orig_uri | the URI to move, can represent either a directory or a file (type: `elisa.core.media_uri.MediaUri` )
| dest_uri | the destination URI, can represent either a directory or a file (type: `elisa.core.media_uri.MediaUri` )
Returns | (type: bool )

def delete(self, uri, recursive=False):
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 | the URI representing the file or directory for which we would like to know if it is currently monitored or not (type: `elisa.core.media_uri.MediaUri` )
| recursive | if orig_uri represents a directory, should I copy it recursively to dest_uri? (type: bool )
Returns | (type: bool )

def get_real_uri(self, uri):
Returns the original uri (reachable) from a virtual uri representation.

Parameters | uri | the URI to validate (type: `elisa.core.media_uri.MediaUri` )
Returns | (type: `elisa.core.media_uri.MediaUri` )