Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
147 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,4 +5,4 @@ | |
.tox/ | ||
MANIFEST | ||
build/ | ||
dist/ | ||
dist/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
0.1.0 UNRELEASED | ||
0.1.0 2015-04-07 | ||
---------------- | ||
|
||
- Initial release. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
from __future__ import absolute_import, unicode_literals | ||
|
||
MANAGER_IFACE = 'com.intel.dLeynaServer.Manager' | ||
|
||
MEDIA_CONTAINER_IFACE = 'org.gnome.UPnP.MediaContainer2' | ||
|
||
MEDIA_ITEM_IFACE = 'org.gnome.UPnP.MediaItem2' | ||
|
||
SERVER_BUS_NAME = 'com.intel.dleyna-server' | ||
|
||
SERVER_ROOT_PATH = '/com/intel/dLeynaServer' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,58 +1,83 @@ | ||
from __future__ import unicode_literals | ||
|
||
import dbus | ||
import logging | ||
|
||
import dbus | ||
|
||
from mopidy import backend | ||
from mopidy.models import Ref | ||
from mopidy.models import Album, Artist, Ref, Track | ||
|
||
from .dleyna import MANAGER_IFACE, MEDIA_CONTAINER_IFACE | ||
from .dleyna import SERVER_BUS_NAME, SERVER_ROOT_PATH | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
_BROWSE_FILTER = ['DisplayName', 'Path', 'Type'] | ||
|
||
|
||
def _item_to_track(props): | ||
return Track( | ||
name=props.get('DisplayName'), | ||
uri='dleyna:'+props.get('Path'), | ||
artists=[Artist(name=props.get('Artist'))], | ||
album=Album(name=props.get('Album')), | ||
date=props.get('Date'), | ||
genre=props.get('Genre'), | ||
length=int(props.get('Duration', 0)*1000), | ||
track_no=props.get('TrackNumber') | ||
) | ||
|
||
|
||
class dLeynaLibraryProvider(backend.LibraryProvider): | ||
|
||
root_directory = Ref.directory( | ||
uri='dleyna:', | ||
name='DLNA Servers' | ||
name='DLNA Media Servers' | ||
) | ||
|
||
def __init__(self, config, backend): | ||
super(dLeynaLibraryProvider, self).__init__(backend) | ||
bus = dbus.SessionBus() | ||
self.__manager = dbus.Interface( | ||
bus.get_object( | ||
'com.intel.dleyna-server', | ||
'/com/intel/dLeynaServer' | ||
), | ||
'com.intel.dLeynaServer.Manager' | ||
) | ||
self._propsIF = dbus.Interface(bus.get_object( | ||
'com.intel.dleyna-server', | ||
'/com/intel/dLeynaServer'), | ||
'org.freedesktop.DBus.Properties') | ||
|
||
logger.info('manager %r' % self.__manager) | ||
self.__bus = dbus.SessionBus() | ||
|
||
def browse(self, uri): | ||
bus = dbus.SessionBus() | ||
_, _, path = uri.partition(':') | ||
|
||
refs = [] | ||
if uri == 'dleyna:': | ||
for path in self.__manager.GetServers(): | ||
logger.info('server: %r' % path) | ||
if path: | ||
container = self.__get_object(path, MEDIA_CONTAINER_IFACE) | ||
for obj in container.ListChildren(0, 0, _BROWSE_FILTER): | ||
name = obj.get('DisplayName', obj['Path']) | ||
uri = 'dleyna:' + obj['Path'] | ||
if obj['Type'] == 'container': | ||
# TODO: album, playlist, ... | ||
refs.append(Ref.directory(name=name, uri=uri)) | ||
else: | ||
refs.append(Ref.track(name=name, uri=uri)) | ||
else: | ||
manager = self.__get_object(SERVER_ROOT_PATH, MANAGER_IFACE) | ||
for path in manager.GetServers(): | ||
props = self.__get_object(path, dbus.PROPERTIES_IFACE) | ||
try: | ||
props = dbus.Interface( | ||
bus.get_object( | ||
'com.intel.dleyna-server', | ||
path | ||
), | ||
'org.freedesktop.DBus.Properties' | ||
) | ||
try: | ||
name = props.Get('', 'FriendlyName') | ||
except Exception: | ||
name = props.Get('', 'DisplayName') | ||
refs.append(Ref.directory(name=name, uri='dleyna:'+path)) | ||
except dbus.exceptions.DBusException as e: | ||
logger.error('error %r' % e) | ||
name = props.Get('', 'FriendlyName') | ||
except Exception: | ||
name = props.Get('', 'DisplayName') | ||
refs.append(Ref.directory(name=name, uri='dleyna:'+path)) | ||
return refs | ||
|
||
def lookup(self, uri): | ||
_, _, path = uri.partition(':') | ||
props = self.__get_object(path, dbus.PROPERTIES_IFACE) | ||
if props.Get('', 'Type') == 'music': | ||
return [_item_to_track(props.GetAll(''))] | ||
else: | ||
return [] # TODO: lookup containers, etc. | ||
|
||
def refresh(self, uri=None): | ||
self.__get_object(SERVER_ROOT_PATH, MANAGER_IFACE).Rescan() | ||
|
||
def __get_object(self, path, iface=None): | ||
obj = self.__bus.get_object(SERVER_BUS_NAME, path) | ||
if iface: | ||
return dbus.Interface(obj, iface) | ||
else: | ||
return obj |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
from __future__ import unicode_literals | ||
|
||
import dbus | ||
|
||
from mopidy import backend | ||
|
||
from .dleyna import MEDIA_ITEM_IFACE, SERVER_BUS_NAME | ||
|
||
|
||
class dLeynaPlaybackProvider(backend.PlaybackProvider): | ||
|
||
def __init__(self, audio, backend): | ||
super(dLeynaPlaybackProvider, self).__init__(audio, backend) | ||
self.__bus = dbus.SessionBus() | ||
|
||
def translate_uri(self, uri): | ||
_, _, path = uri.partition(':') | ||
obj = self.__bus.get_object(SERVER_BUS_NAME, path) | ||
props = dbus.Interface(obj, dbus.PROPERTIES_IFACE) | ||
urls = props.Get(MEDIA_ITEM_IFACE, 'URLs') | ||
return urls[0] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters