~francesco-marella/specto/blacklist-plugins

« back to all changes in this revision

Viewing changes to spectlib/plugins/watch_music_rhythmbox.py

  • Committer: Jean-François Fortin Tam
  • Date: 2009-12-29 21:02:37 UTC
  • mfrom: (98.3.84 specto-woutc)
  • Revision ID: nekohayo@gmail.com-20091229210237-pt7k7v2shsun2z49
Merge Wout's fixes and new features
- DBUS watches (including Pidgin, Evolution, Rhythmbox, and a bunch of others)
- Integration with Ubuntu's indicator applet
- Use GStreamer for playing sounds (fixes issue 289)
- Fix the Google Reader watch (issue 283)
- Various other enhancements

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- coding: UTF8 -*-
 
2
 
 
3
# Specto , Unobtrusive event notifier
 
4
#
 
5
#       watch_music_rhythmbox.py
 
6
#
 
7
# See the AUTHORS file for copyright ownership information
 
8
 
 
9
# This program is free software; you can redistribute it and/or
 
10
# modify it under the terms of the GNU General Public
 
11
# License as published by the Free Software Foundation; either
 
12
# version 2.1 of the License, or (at your option) any later version.
 
13
#
 
14
# This program is distributed in the hope that it will be useful,
 
15
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
16
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 
17
# General Public License for more details.
 
18
#
 
19
# You should have received a copy of the GNU General Public
 
20
# License along with this program; if not, write to the
 
21
# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 
22
# Boston, MA 02111-1307, USA.
 
23
 
 
24
from spectlib.watch import Watch
 
25
from spectlib.i18n import _
 
26
import dbus
 
27
 
 
28
type = "Watch_music_rhythmbox"
 
29
type_desc = _("Rhythmbox")
 
30
icon = 'rhythmbox'
 
31
category = _("Music")
 
32
dbus_watch = True
 
33
 
 
34
 
 
35
class Watch_music_rhythmbox(Watch):
 
36
    """
 
37
    Watch class that will check if a song has changed in rhythmbox.
 
38
    """
 
39
 
 
40
    def __init__(self, specto, id, values):
 
41
 
 
42
        watch_values = []
 
43
        self.icon = icon
 
44
        self.current_song = ""
 
45
        self.standard_open_command = 'rhythmbox'
 
46
        self.type_desc = type_desc
 
47
 
 
48
        #Init the superclass and set some specto values
 
49
        Watch.__init__(self, specto, id, values, watch_values)
 
50
        
 
51
        self.dbus = True
 
52
        self.message = ""
 
53
        self.extra_info = ""
 
54
        # Use the dbus interface we saw in dbus-notify
 
55
        self.dbus_interface = "org.gnome.Rhythmbox.Player"
 
56
        self.dbus_path = "/org/gnome/Rhythmbox/Player"
 
57
        self.dbus_name = "org.gnome.Rhythmbox"
 
58
 
 
59
        self.signals = {"playingUriChanged": self.playingUriChanged}
 
60
        
 
61
        
 
62
    def playingUriChanged(self, uri):
 
63
        metadata = {}
 
64
        info = ["artist", "album", "title", "track-number"]
 
65
 
 
66
        shell = self.get_rhythmbox_interface()
 
67
        if uri:
 
68
            data = shell.getSongProperties(uri)
 
69
            for key in data:
 
70
                if key in info:
 
71
                    metadata[key] = data[key]
 
72
 
 
73
            header = metadata["title"]
 
74
            self.message = "%s - %s\nTrack: %d" %(metadata["artist"],metadata["title"],metadata["track-number"])
 
75
            self.current_song = "%s - %s" % (metadata["artist"], metadata["title"])
 
76
            self.watch_changed()
 
77
    
 
78
    def get_balloon_text(self):
 
79
        """ create the text for the balloon """
 
80
        return self.message
 
81
 
 
82
    def get_gui_info(self):
 
83
        return [(_('Name'), self.name),
 
84
                (_('Last changed'), self.last_changed),
 
85
                (_('Current track'), self.current_song)]
 
86
                
 
87
    def get_rhythmbox_interface(self):
 
88
        rhythmbox_object = self.session_bus.get_object("org.gnome.Rhythmbox", "/org/gnome/Rhythmbox/Shell")
 
89
        return dbus.Interface(rhythmbox_object, "org.gnome.Rhythmbox.Shell")