Ticket #60: amarok-dbus.py

File amarok-dbus.py, 2.4 KB (added by eightmillion@…, 3 years ago)

amarok-dbus.py

Line 
1#  methlab - A music library application
2#  Copyright (C) 2007 Ingmar K. Steen (iksteen@gmail.com)
3#
4#  This program is free software; you can redistribute it and/or modify
5#  it under the terms of the GNU General Public License as published by
6#  the Free Software Foundation; either version 2 of the License, or
7#  (at your option) any later version.
8#
9#  This program is distributed in the hope that it will be useful,
10#  but WITHOUT ANY WARRANTY; without even the implied warranty of
11#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12#  GNU General Public License for more details.
13#
14#  You should have received a copy of the GNU General Public License
15#  along with this program; if not, write to the Free Software
16#  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17
18DRIVERS = ['AmarokDBusDriver']
19
20try:
21  from dbus import Bus, DBusException
22except ImportError:
23  DRIVERS = []
24
25from gettext import gettext as _
26import urllib
27
28class AmarokDBusDriver:
29  name = 'amarok-dbus'
30  name_tr = _('Amarok (using DBus)')
31  def __init__(self, methlab):
32    self.bus = Bus(Bus.TYPE_SESSION)
33    self.amarok = self.bus.get_object('org.kde.amarok', '/TrackList')
34
35  def play_files(self, files):
36    try:
37      for x in range(1,self.amarok.GetLength()+1): self.amarok.DelTrack(x)
38      uris = ['file://' + file for file in files]
39      for file in uris:
40        self.amarok.AddTrack(file,True)
41    except DBusException:
42      self.bus = Bus(Bus.TYPE_SESSION)
43      self.amarok = self.bus.get_object('org.kde.amarok', '/TrackList')
44      try:
45        for x in range(1,self.amarok.GetLength()+1): self.amarok.DelTrack(x)
46        uris = ['file://' + file for file in files]
47        for file in uris:
48          self.amarok.AddTrack(file,True)
49      except DBusException:
50        # FIXME: Should provide feedback on how to handle the problem
51        pass
52
53
54  def enqueue_files(self, files):
55    try:
56      uris = ['file://' + file for file in files]
57      for file in uris:
58        self.amarok.AddTrack(file,False)
59    except DBusException:
60      self.bus = Bus(Bus.TYPE_SESSION)
61      self.amarok = self.bus.get_object('org.kde.amarok', '/TrackList')
62      try:
63        uris = ['file://' + file for file in files]
64        for file in uris:
65          self.amarok.AddTrack(file,False)
66      except DBusException:
67        # FIXME: Should provide feedback on how to handle the problem
68        pass