~ubuntu-branches/ubuntu/hardy/emesene/hardy-proposed

« back to all changes in this revision

Viewing changes to plugins_base/currentSong/Listen.py

  • Committer: Bazaar Package Importer
  • Author(s): Emilio Pozuelo Monfort
  • Date: 2008-02-06 21:57:05 UTC
  • Revision ID: james.westby@ubuntu.com-20080206215705-d1abf07rdwcaju3p
Tags: upstream-1.0~r1013
ImportĀ upstreamĀ versionĀ 1.0~r1013

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- coding: utf-8 -*-
 
2
 
 
3
#   This file is part of emesene.
 
4
#
 
5
#    Emesene is free software; you can redistribute it and/or modify
 
6
#    it under the terms of the GNU General Public License as published by
 
7
#    the Free Software Foundation; either version 2 of the License, or
 
8
#    (at your option) any later version.
 
9
#
 
10
#    emesene is distributed in the hope that it will be useful,
 
11
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
#    GNU General Public License for more details.
 
14
#
 
15
#    You should have received a copy of the GNU General Public License
 
16
#    along with emesene; if not, write to the Free Software
 
17
#    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
18
 
 
19
# based on plugin by Tomer Haimovich
 
20
 
 
21
VERSION = '0.2'
 
22
IFACE_NAME = 'org.gnome.Listen'
 
23
IFACE_PATH = '/org/gnome/listen'
 
24
 
 
25
import CurrentSong
 
26
 
 
27
 
 
28
class Listen( CurrentSong.DbusBase ):
 
29
    '''Communicate with GNOME's Listen player'''
 
30
    
 
31
    def __init__(self):
 
32
        CurrentSong.DbusBase.__init__( self, IFACE_NAME, self.setInterface )
 
33
 
 
34
        try: self.iface
 
35
        except: self.iface = None
 
36
 
 
37
    def setInterface( self ):
 
38
        self.iface = self.bus.get_object( IFACE_NAME, IFACE_PATH )
 
39
        
 
40
    def check(self):
 
41
        if not self.iface or not self.isNameActive(IFACE_NAME):
 
42
            return
 
43
        
 
44
        message = self.iface.current_playing()
 
45
        
 
46
        # process the received string. it's built this way:
 
47
        #  <m_track> - (<m_album> - <m_artist>)
 
48
        
 
49
        if message != "":
 
50
            buf = message.split(" - (")
 
51
            title = buf[0]
 
52
            secbuf = buf[1].split(" - ")
 
53
            album = secbuf[0]
 
54
            artist = secbuf[1][0:-1]
 
55
            
 
56
            if title != self.title or \
 
57
               album != self.album or \
 
58
               artist != self.artist:
 
59
                self.title = title
 
60
                self.album = album
 
61
                self.artist = artist
 
62
                return True
 
63
            else:
 
64
                return False
 
65
            
 
66
    def isPlaying(self):
 
67
        if not self.isRunning(): return False
 
68
        if not self.iface: return False
 
69
        try:
 
70
            self.iface.current_playing()
 
71
        except:
 
72
            return False
 
73
        return True
 
74
        
 
75
    def isRunning(self):
 
76
        return self.isNameActive(IFACE_NAME)