coherence.backends.fs_storage (module) — Cohen3 0.8.0 documentation

# 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)

exception `NoThumbnailFound`

  Bases: `Exception`

  no thumbnail found

`_find_thumbnail`(filename, thumbnail_folder='.thumbs')

  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)

  Bases: `coherence.backend.BackendItem`

  `logCategory` = 'fs_item'
  `rebuild`(urlbase)
  `check_for_cover_art`()

    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`()
  `add_child`(child, update=False)
  `remove_child`(child)
  `get_children`(start=0, request_count=0)

    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`()

    Called by the CDS.

    Returns: | the number of its childs - len(childs) or a Deferred

  `get_id`()
  `get_update_id`()
  `get_path`()

    Called by the MediaServer web.

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

  `get_realpath`()
  `set_path`(path=None, extension=None)
  `get_name`()

    Called by the MediaServer web.

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

  `get_cover`()

    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`()
  `get_item`()

    Called by the CDS and the MediaServer web.

    Returns: | an UPnP ContentDirectoryServer DIDLLite object or a Deferred

  `get_xml`()

class `FSStore`(server, **kwargs)

  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': [('/home/opacam/', 'audio', 'audio'), ('/home/opacam/', 'image', 'images'), ('/home/opacam/', 'video', 'videos')], '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`()

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

  `len`()
  `get_by_id`(id)

    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='')
  `get_url_by_name`(parent='0', name='')
  `update_config`(**kwargs)
  `add_content_folder`(path)
  `remove_content_folder`(path)
  `walk`(path, parent=None, ignore_file_pattern='')
  `create`(mimetype, path, parent)
  `append`(bytes_path, parent)
  `remove`(id)
  `notify`(ignore, path, mask, parameter=None)
  `getnextID`()
  `backend_import`(item, data)
  `upnp_init`()

    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)
  `upnp_CreateObject`(*args, **kwargs)
  `hidden_upnp_DestroyObject`(*args, **kwargs)