Updated NP script for Clementine [X-Chat]

By ronnocoenahs on Apr 26, 2013

Seen a few versions of this floating around didn't really like the simplicity of the spammer so I added: Album Year, Track # & Sample Rate. Bitrate is also included though I just used that addition from another script that was floating around on last.fm forums

Spammer Example:
@ShaneO playing on Clementine :: 311:: Track #10 :: You Wouldn't Believe :: Greatest Hits '93 - '03 :: 2004 :: 1020kbps :: 44100KHz

__module_name__ = "xchat-clementine"
__module_version__ = "3.0"
__module_description__ = "Get NP information from Clementine"

# Added Album Year, Track # & Sample Rate

from dbus import Bus, DBusException
import xchat
bus = Bus(Bus.TYPE_SESSION)

def get_clem():
    try:
        return bus.get_object('org.mpris.clementine', '/Player')
    except DBusException:
        print "\x02Either Clementine is not running or you have something wrong with your D-Bus setup."
        return None

def command_np(word, word_eol, userdata):
    clem = get_clem()
    clemp =  bus.get_object('org.mpris.clementine', '/Player')
    clemmd = clemp.GetMetadata()
    metadata = clemp.GetMetadata()
    if clem:
        pos = clem.PositionGet()
        bitrate = unicode(clemmd['audio-bitrate']).encode('utf-8')  + "kbps"
        bitrate = ''

        xchat.command("me playing on Clementine" + " :: " + unicode(metadata['artist']).encode('utf-8') + "::" + " Track #" + unicode(metadata['tracknumber']).encode('utf-8') + " :: " + unicode(metadata['title']).encode('utf-8') + " " + ":: " + unicode(metadata['album']).encode('utf-8') + " :: " + unicode(metadata['year']).encode('utf-8') + " :: " + unicode(metadata['audio-bitrate']).encode('utf-8') + bitrate  + "kbps" " :: " + unicode(metadata['audio-samplerate']).encode('utf-8') + "KHz")

xchat.hook_command("np",    command_np,                 help="Displays current playing song.")
print "xchat-clementine 3.0 plugin loaded"

Comments

Sign in to comment.
Hawkee   -  Apr 26, 2013

Great to see some Python code. Welcome to the site!

ronnocoenahs  -  Apr 26, 2013

Thank you glad to be here

Jordyk19  -  Apr 29, 2013

Looks nice.

pehden  -  Oct 06, 2013

xchat.command("me playing on Clementine" + " :: " + unicode(metadata['artist']).encode('utf-8') + "::" + " Track #" + unicode(metadata['tracknumber']).encode('utf-8') + " :: " + unicode(metadata['title']).encode('utf-8') + " " + ":: " + unicode(metadata['album']).encode('utf-8') + " :: " + unicode(metadata['year']).encode('utf-8') + " :: " + unicode(metadata['audio-bitrate']).encode('utf-8') + bitrate + "kbps" " :: " + unicode(metadata['audio-samplerate']).encode('utf-8') + "KHz")

This is error with python3,
needs to be

xchat.command("me playing on Clementine" + " :: " + metadata['artist'] + "::" + " Track #" + ['tracknumber'] + " :: " + metadata['title']+ " " + ":: " + metadata['album'] + " :: " + metadata['year'] + " :: " + metadata['audio-bitrate'] + bitrate + "kbps" " :: " + metadata['audio-samplerate'] + "KHz")

Sign in to comment

Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.