Skip to content

Commit

Permalink
migrate to the last mpris2 python interface
Browse files Browse the repository at this point in the history
  • Loading branch information
pat1 committed Sep 27, 2021
1 parent d78bcb8 commit 1122a2b
Show file tree
Hide file tree
Showing 38 changed files with 1,330 additions and 630 deletions.
25 changes: 15 additions & 10 deletions autoplayergui
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,11 @@ class Main(object):


if position is not None:
id = self.play.Metadata.get(u'mpris:trackid',None)
try:
id = self.play.Metadata.get(u'mpris:trackid',None)
except:
id = None

if id is not None:
length=self.tl.GetTracksMetadata((id,))[0].get(u'mpris:length',None)
if position <= length and length != 0:
Expand All @@ -97,7 +101,8 @@ class Main(object):

#Connect to player
DBusGMainLoop(set_as_default=True)
uris = get_players_uri(pattern=".",busaddress=busaddress)
#uris = get_players_uri(pattern=".",busaddress=busaddress)
uris = list(get_players_uri(pattern="."))

if len(uris) >0 :
uri=uris[0]
Expand Down Expand Up @@ -136,18 +141,18 @@ class Main(object):
self.connected = True

# Create the GUI
self.win = gtk.Window(gtk.WINDOW_TOPLEVEL)
self.win = gtk.Window(type=gtk.WINDOW_TOPLEVEL)

self.win.set_size_request(400, 600)
self.win.set_title("AutoPlayer gui")
self.win.connect("delete_event", self.delete_event)
vbox = gtk.VBox(False, 0)
hbox = gtk.HBox(False, 0)
self.load_file = gtk.FileChooserButton("Choose Audio File")
self.play_button = gtk.ToolButton( gtk.STOCK_MEDIA_PLAY)
self.pause_button = gtk.ToolButton( gtk.STOCK_MEDIA_PAUSE)
self.stop_button = gtk.ToolButton( gtk.STOCK_MEDIA_STOP)
self.delete_button = gtk.Button('Delete')
vbox = gtk.VBox(homogeneous=False,spacing=0)
hbox = gtk.HBox(homogeneous=False,spacing=0)
self.load_file = gtk.FileChooserButton(homogeneous="Choose Audio File")
self.play_button = gtk.ToolButton( stock_id=gtk.STOCK_MEDIA_PLAY)
self.pause_button = gtk.ToolButton( stock_id=gtk.STOCK_MEDIA_PAUSE)
self.stop_button = gtk.ToolButton( stock_id=gtk.STOCK_MEDIA_STOP)
self.delete_button = gtk.Button(label='Delete')
self.delete_button.connect('clicked', self.on_delete_button_clicked)
self.load_file.connect("selection-changed",self.on_file_selected)
self.play_button.connect("clicked", self.on_play_clicked)
Expand Down
57 changes: 28 additions & 29 deletions autoradio/mpris2/__init__.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
#!/usr/bin/python
# -*- coding: UTF8 -*
'''
This is mprisV2.1 documentation
This is a copy of mprisV2.2 documentation
http://www.mpris.org/2.1/spec/index.html
http://specifications.freedesktop.org/mpris-spec/latest/
Also works as python lib.
That also works as python lib.
Version 2.1
Version 2.2
===========
Copyright © 2006-2010 the VideoLAN team(Mirsal Ennaime, Rafaël Carré, Jean-Paul Saman)
Copyright © 2005-2008 Milosz Derezynski
Copyright © 2008 Nick Welch
Copyright © 2010 Alex Merry
Copyright © 2010-2012 Alex Merry
This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.
Expand All @@ -37,8 +37,18 @@
Changes
=======
Changes (Permalink)
From 2.1 to 2.2:
* Added the optional Fullscreen and CanSetFullscreen properties to the org.mpris.MediaPlayer2 interface.
* The path /org/mpris/MediaPlayer2/TrackList/NoTrack now represents "no track" where required in the org.mpris.MediaPlayer2.TrackList interface (since empty paths are not allowed by D-Bus).
* The suggested unique instance identifier no longer violates the D-Bus specification by begining with a digit.
From 2.0 to 2.1:
Added the optional org.mpris.MediaPlayer2.Playlists interface.
* Added the optional org.mpris.MediaPlayer2.Playlists interface.
Expand All @@ -53,21 +63,22 @@
This allows clients to list available media players (either already running or which can be started via D-Bus activation)
In the case where the media player allows multiple instances running simultaneously, each additional instance should request a unique bus name, adding a dot and a unique identifier (such as a UNIX process id) to its usual bus name. For example, this could be
In the case where the media player allows multiple instances running simultaneously, each additional instance should request a unique bus name, adding a dot and a unique identifier to its usual bus name, such as one based on a UNIX process id. For example, this could be:
* org.mpris.MediaPlayer2.vlc.7389
Note: According to the D-Bus specification, the unique identifier "must only contain the ASCII characters '[A-Z][a-z][0-9]_-'" and "must not begin with a digit".
Entry point
===========
The media player *must* expose the */org/mpris/MediaPlayer2* object path, which *must* implement the following interfaces:
* org.mpris.MediaPlayer2
* org.mpris.MediaPlayer2.Player
* :doc:`org.mpris.MediaPlayer2<../mpris2.mediaplayer2>`
* :doc:`org.mpris.MediaPlayer2.Player<../mpris2.player>`
The */org/mpris/MediaPlayer2* object may implement the *org.mpris.MediaPlayer2.TrackList* interface.
The */org/mpris/MediaPlayer2* object may implement the :doc:`org.mpris.MediaPlayer2.TrackList<../mpris2.tracklist>` interface.
The */org/mpris/MediaPlayer2* object may implement the *org.mpris.MediaPlayer2.Playlists* interface.
The */org/mpris/MediaPlayer2* object may implement the :doc:`org.mpris.MediaPlayer2.Playlists<../mpris2.playlists>` interface.
The PropertiesChanged signal
Expand All @@ -84,30 +95,18 @@
Interfaces
==========
* org.mpris.MediaPlayer2
* org.mpris.MediaPlayer2.TrackList
* org.mpris.MediaPlayer2.Player
* org.mpris.MediaPlayer2.Playlists
* :doc:`org.mpris.MediaPlayer2<../mpris2.mediaplayer2>`
* :doc:`org.mpris.MediaPlayer2.Player<../mpris2.player>`
* :doc:`org.mpris.MediaPlayer2.Playlists<../mpris2.playlists>`
* :doc:`org.mpris.MediaPlayer2.TrackList<../mpris2.tracklist>`
'''
from __future__ import print_function
from __future__ import absolute_import

from .interfaces import Interfaces
from .mediaplayer2 import MediaPlayer2
from .player import Player
from .playlists import Playlists
from .tracklist import TrackList

from . import types as types
from . import utils as utils

if __name__ == '__main__':
print(Interfaces)
print(MediaPlayer2)
print(Player)
print(Playlists)
print(TrackList)
print(types)
print(utils)
from .utils import get_players_uri
from .some_players import Some_Players as SomePlayers
13 changes: 13 additions & 0 deletions autoradio/mpris2/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from . import Interfaces
from . import MediaPlayer2
from . import Player
from . import Playlists
from . import TrackList


if __name__ == '__main__':
print(Interfaces())
print(MediaPlayer2())
print(Player())
print(Playlists())
print(TrackList())
13 changes: 13 additions & 0 deletions autoradio/mpris2/decorator/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
'''
This is not part of specification
Helper class to make it work as python lib
'''


from .attribute import DbusAttr
from .interface import DbusInterface
from .method import DbusMethod
from .signal import DbusSignal
from .utils import get_mainloop, get_uri, implements, \
list_all_interface, list_interfaces, list_paths
10 changes: 10 additions & 0 deletions autoradio/mpris2/decorator/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from . import DbusAttr
from . import DbusInterface
from . import DbusMethod
from . import DbusSignal

if __name__ == '__main__':
print(DbusAttr())
print(DbusInterface())
print(DbusMethod())
print(DbusSignal())
65 changes: 65 additions & 0 deletions autoradio/mpris2/decorator/attribute.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
'''
This is not part of specification
Helper class to make it work as python lib
'''

from .base import Decorator, ATTR_KEY


class DbusAttr(Decorator):
'''
https://docs.python.org/2/howto/descriptor.html#properties
'''

def __init__(self, meth=None, produces=lambda resp: resp):
self.attr = meth
self.produces = produces
self._update_me(meth)

def __call__(self, meth):
self.attr = meth
self._update_me(meth)
return self

def __get__(self, obj, objtype=None):
#static call
if not obj:
return self

_dbus = getattr(obj, ATTR_KEY)
props = _dbus.properties
iface = _dbus.iface
result = props.Get(iface, self.attr.__name__)
produces = self.produces
return produces(result)

def __set__(self, obj, value):
if obj:
_dbus = getattr(obj, ATTR_KEY)
props = _dbus.properties
iface = _dbus.iface
props.Set(iface, self.attr.__name__, value)
else: #static call
self.attr = value

def __delete__(self, obj):
raise AttributeError('can not delete attribute')


if __name__ == '__main__':
# examples
from .interface import DbusInterface

@DbusInterface('org.mpris.MediaPlayer2',
'/org/mpris/MediaPlayer2')
class Example(object):
@DbusAttr
def Identity(self):
pass

d = Example(
dbus_interface_info={
'dbus_uri': 'org.mpris.MediaPlayer2.vlc'})

assert d.Identity == 'VLC media player'
19 changes: 19 additions & 0 deletions autoradio/mpris2/decorator/base.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
'''
This is not part of specification
Helper class to make it work as python lib
'''

I_PROP = 'org.freedesktop.DBus.Properties'
ARG_KEY = 'dbus_interface_info'
ATTR_KEY = '_dbus_interface_info'


class Decorator(object):
def _update_me(self, target=None):
if hasattr(target, "__doc__"):
self.__doc__ = target.__doc__
if hasattr(target, "__name__"):
self.__name__ = target.__name__
if hasattr(target, "__bases__"):
self.__bases__ = target.__bases__
Loading

0 comments on commit 1122a2b

Please sign in to comment.