3 MPD to Gajim (via DBUS) script.
5 Copyright (c) 2007, Alexander Stanley
6 alexanderwstanley@gmail.com
9 Redistribution and use in source and binary forms, with or without modification, are permitted
10 provided that the following conditions are met:
12 * Redistributions of source code must retain the above copyright notice, this list of conditions
13 and the following disclaimer.
14 * Redistributions in binary form must reproduce the above copyright notice, this list of
15 conditions and the following disclaimer in the documentation and/or other materials provided with the
17 * Neither the name of the Orloglausa.Net nor the names of its contributors may be used to endorse
18 or promote products derived from this software without specific prior written permission.
20 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 ### Only play with this if your system is getting
33 ### flogged by the process (which is shouldn't be)
34 interval
= 1 # number of seconds between checks
54 bus
= dbus
.SessionBus()
55 obj
= bus
.get_object('org.gajim.dbus', '/org/gajim/dbus/RemoteObject')
56 myinterface
= dbus
.Interface(obj
, 'org.gajim.dbus.RemoteInterface')
58 def update(title
, artist
, track
, album
, mytime
):
65 stat_msg
= str("%s %s - %s %s %s") % (note
,artist
,title
,note
,pausestr
)
67 for account
in myinterface
.list_accounts():
68 status
= myinterface
.get_status(account
)
69 myinterface
.change_status(status
,stat_msg
,account
)
76 stat_msg
= str("Music Stopped.")
78 for account
in myinterface
.list_accounts():
79 status
= myinterface
.get_status(account
)
80 myinterface
.change_status(status
,stat_msg
,account
)
87 m
= mpdclient2
.connect()
88 if str(m
.status().state
) == str("stop"):
102 album
= str(var
['album'])
106 artist
= str(var
['artist'])
110 title
= str(var
['title'])
114 track
= str(var
['track'])
117 current
= s
.time
.split(':', 2)[0]
118 mytime
= s
.time
.split(':', 2)[1]
119 mytime
= str("[" + str(timehack(mytime
)+ "]"))
122 if str(m
.status().state
) == str("pause"):
124 update(title
,artist
,track
,album
,mytime
)
128 if str(old_t
) == str(title
) and str(old_a
) == str(artist
):
129 if tichk
> int(current
):
130 update(title
, artist
, track
, album
, mytime
)
132 update(title
, artist
, track
, album
, mytime
)
138 if (str(tmp_t
) != str(title
) and str(old_a
) != str(artist
)):
142 def timehack(vartime
):
143 valmins
= int(vartime
)/60
144 valsecs
= int(vartime
) - (valmins
* 60)
146 valsecs
= "%s%s" % (0,valsecs
)
147 valtime
= "%s:%s" % (valmins
,valsecs
)
158 if os
.fork() > 0: os
._exit
(0)
159 except OSError, error
:
160 print 'Error in fork 1 :: %d (%s)' % (error
.errno
, error
.strerror
)
170 print 'Daemonised (PID: %d)' % pid
172 except OSError, error
:
173 print 'Error in fork 2 :: %d (%s)' % (error
.errno
, error
.strerror
)