1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
|
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
# Code based on Ingelrest François' "im status" plugin
import dbus
from gettext import gettext as _
from xl import event
import sys
##############################################################################
class Pidgin :
def __init__(self, dbusInterface) :
"""
Constructor
"""
self.purple = dbusInterface
def listAccounts(self) :
"""
Purple merges all accounts, so we return a default one
Each account is associated with:
* A boolean -> True if the status of this account was changed on the previous track change
"""
return {'GenericAccount' : False}
def setStatus(self, status, attr, value):
# this doesn't actually work, for some reason the getter always return ""
if self.purple.PurpleStatusGetAttrString(status, attr) != value:
self.purple.PurpleStatusSetAttrString(status, attr, value)
return True
return False
def setTune(self, artist, title, album) :
"""
Change the tune status
Return True if the message is successfully updated
"""
current = self.purple.PurpleSavedstatusGetCurrent()
accounts = self.purple.PurpleAccountsGetAll()
for account in accounts:
if self.purple.PurpleAccountIsConnected(account) != True:
continue
p = self.purple.PurpleAccountGetPresence(account)
status = self.purple.PurplePresenceGetStatus(p, "tune")
if status != 0:
updated = False
if len(title) + len(artist) + len(album) == 0:
if self.purple.PurpleStatusIsActive(status):
self.purple.PurpleStatusSetActive(status, False)
else:
self.purple.PurpleStatusSetActive(status, True)
updated |= self.setStatus(status, "tune_title", title);
updated |= self.setStatus(status, "tune_artist", artist);
updated |= self.setStatus(status, "tune_album", album);
if updated:
active = self.purple.PurplePresenceGetActiveStatus(p)
self.purple.PurplePrplChangeAccountStatus(account, active, status)
return True
##############################################################################
def on_begin_action(type, player, track):
client.setTune(
track.get_tag_display('artist'),
track.get_tag_display('title'),
track.get_tag_display('album')
)
def on_stop_action(type, player, track):
client.setTune("", "", "")
def on_pause_action(type, player, track):
if player.is_playing():
on_begin_action(type, player, track)
else:
on_stop_action(type, player, track)
def enable(exaile):
global client
obj = dbus.SessionBus().get_object('im.pidgin.purple.PurpleService',
'/im/pidgin/purple/PurpleObject')
purple = dbus.Interface(obj, "im.pidgin.purple.PurpleInterface")
client = Pidgin(purple)
event.add_callback(on_stop_action, 'quit_application')
event.add_callback(on_stop_action, 'playback_player_end')
event.add_callback(on_begin_action, 'playback_track_start')
event.add_callback(on_pause_action, 'playback_toggle_pause')
def disable(exaile):
event.remove_callback(on_stop_action, 'quit_application')
event.remove_callback(on_stop_action, 'playback_player_end')
event.remove_callback(on_begin_action, 'playback_track_start')
event.remove_callback(on_pause_action, 'playback_toggle_pause')
|