coherence.backends.fs_storage (module)

FSStore - filesystem media server

FSStore exposes media files found in the directory trees defined by the ‘content’ configuration entry.

The first “.jpg” or “.png” file found inside a media directory is served as a cover image.

The plugin is configured with:

<plugin active="yes">
  <!-- The plugin identifier, mandatory -->
  <backend>FSStore</backend>
  <!-- A comma-separated list of path containing the medias to serve -->
  <content>/media/path1,/media/path2</content>
  <!-- The avertized media server name, default: "my media" -->
  <name>my media</name>
  <!-- The highest UPnP version this
  media server should support, default: 2 -->
  <version>2</version>
  <!-- A unique identifier used to reference the media server,
  autogenerated if not set explicitly. In this case, some control points
  might memorize it between runs and display the same media server more
  than once. -->
  <uuid>2f7f4096-cba3-4390-be7d-d1d07106a6f4</uuid>
</plugin>
_natural_key(s)[source]
exception NoThumbnailFound[source]

Bases: Exception

no thumbnail found

_find_thumbnail(filename, thumbnail_folder='.thumbs')[source]

looks for a thumbnail file of the same basename in a folder named ‘.thumbs’ relative to the file

returns the filename of the thumb, its mimetype and the correspondig DLNA PN string or throws an Exception otherwise

class FSItem(object_id, parent, path, mimetype, urlbase, UPnPClass, update=False, store=None)[source]

Bases: coherence.backend.BackendItem

logCategory = 'fs_item'
rebuild(urlbase)[source]
check_for_cover_art()[source]

let’s try to find in the current directory some jpg file, or png if the jpg search fails, and take the first one that comes around

remove()[source]
add_child(child, update=False)[source]
remove_child(child)[source]
get_children(start=0, request_count=0)[source]

Called by the CDS and the MediaServer web.

Parameters
  • start (int) – the start.

  • end (int) – the end.

Returns

  • a list of its childs, from start to end.

  • or a Deferred

get_child_count()[source]

Called by the CDS.

Returns

  • the number of its childs - len(childs)

  • or a Deferred

get_id()[source]
get_update_id()[source]
get_path()[source]

Called by the MediaServer web.

Returns

the filepath where to find the media file that this item does refer to.

get_realpath()[source]
set_path(path=None, extension=None)[source]
get_name()[source]

Called by the MediaServer web.

Returns

the name of the item, it is always expected to be in unicode.

get_cover()[source]

Called by the MediaServer web.

Returns

the filepath where to find the album art file

Note

only needed when we have created for that item an albumArtURI property that does point back to us.

get_parent()[source]
get_item()[source]

Called by the CDS and the MediaServer web.

Returns

  • an UPnP ContentDirectoryServer DIDLLite object

  • or a Deferred

get_xml()[source]
class FSStore(server, **kwargs)[source]

Bases: coherence.backend.BackendStore

Changed in version 0.9.0: Migrated from louie/dispatcher to EventDispatcher

logCategory = 'fs_store'
implements = ['MediaServer']
description = 'MediaServer exporting files from the file-system'
options = [{'option': 'name', 'type': 'string', 'default': 'my media', 'help': 'the name under this MediaServer shall show up with on other UPnP clients'}, {'option': 'version', 'type': 'int', 'default': 2, 'enum': (2, 1), 'help': 'the highest UPnP version this MediaServer shall support', 'level': 'advance'}, {'option': 'uuid', 'type': 'string', 'help': 'the unique (UPnP) identifier for this MediaServer, usually automatically set', 'level': 'advance'}, {'option': 'content', 'type': 'string', 'default': None, 'help': 'the path(s) this MediaServer shall export'}, {'option': 'ignore_patterns', 'type': 'string', 'help': 'list of regex patterns, matching filenames will be ignored'}, {'option': 'enable_inotify', 'type': 'string', 'default': 'yes', 'help': 'enable real-time monitoring of the content folders'}, {'option': 'enable_destroy', 'type': 'string', 'default': 'no', 'help': 'enable deleting a file via an UPnP method'}, {'option': 'import_folder', 'type': 'string', 'help': 'The path to store files imported via an UPnP method, if empty the Import method is disabled'}]
release()[source]

If anything needs to be cleaned up upon shutdown of this backend, this is the place for it. Should be overwritten in subclass.

len()[source]
get_by_id(id)[source]
Parameters

id (object) – is the id property of our DIDLLite item

Returns

  • None when no matching item for that id is found,

  • a BackendItem,

  • or a Deferred

Called by the CDS or the MediaServer web.

Note

if this MediaServer implements containers that can share their content, like ‘all tracks’, ‘album’ and ‘album_of_artist’ (they all have the same track item as content), then the id may be passed by the CDS like this:

‘id@container’ or ‘id@container@container@container…’

therefore a

if isinstance(id, basestring):
    id = id.split('@',1)
    id = id[0]

may be appropriate as the first thing to do when entering this method.

get_id_by_name(parent='0', name='')[source]
get_url_by_name(parent='0', name='')[source]
update_config(**kwargs)[source]
add_content_folder(path)[source]
remove_content_folder(path)[source]
walk(path, parent=None, ignore_file_pattern='')[source]
create(mimetype, path, parent)[source]
append(bytes_path, parent)[source]
remove(id)[source]
notify(ignore, path, mask, parameter=None)[source]
getnextID()[source]
backend_import(item, data)[source]
upnp_init()[source]

This method gets called after the device is fired, here all initializations of service related state variables should happen, as the services aren’t available before that point.

upnp_ImportResource(*args, **kwargs)[source]
upnp_CreateObject(*args, **kwargs)[source]
hidden_upnp_DestroyObject(*args, **kwargs)[source]