Exaile Now Playing Xchat Script
This a Xchat script, which can send your currently playing track in Exaile, to the IRC channel you're on in Xchat. You can also control Exaile (play, pause, stop etc), or adjust the volume or the rating of the current song.
It also supports CTCP song request, so if someone sends a CTCP GETSONG to you, the currently playing track will be automatically sent through DCC, to the user who requested it.
Usage
/exaile - Prints your current playing song
/exaile play/pause/stop/next/prev - Control exaile
/exaile rating {rating 1-8} - Set the rating for the current song
/exaile volume up|down -Control the volume of exaile
/exaile send {nick} - Send the current playing song to {nick}
Download script as zip
Tags:
Python
Xchat
Exaile
It also supports CTCP song request, so if someone sends a CTCP GETSONG to you, the currently playing track will be automatically sent through DCC, to the user who requested it.
Usage
/exaile - Prints your current playing song
/exaile play/pause/stop/next/prev - Control exaile
/exaile rating {rating 1-8} - Set the rating for the current song
/exaile volume up|down -Control the volume of exaile
/exaile send {nick} - Send the current playing song to {nick}
Download script as zip
Source
- exaile_np.py
- #
- # Exaile Xchat plugin
- # This is a Xchat plugin, so place it in your ~/.xchat2 folder
- # Not in the plugin folder of exaile
- #
- # Send your current song to the channel your on
- # Written in python
- #
- # Created by Lucas van Dijk
- # www.return1.net
- #
- __module_name__ = "Exaile Xchat Plugin"
- __module_version__ = "0.2"
- __module_description__ = "Xchat plugin to show serverval exaile information"
- import xchat
- import dbus
- import math
- # Global exaile object
- exaile = None
- def init_dbus():
- bus = dbus.SessionBus()
- obj = bus.get_object('org.exaile.Exaile', '/org/exaile/Exaile')
- global exaile
- exaile = dbus.Interface(obj, 'org.exaile.Exaile')
- def check_exaile():
- global exaile
- if exaile == None:
- init_dbus()
- try:
- exaile.TestService("Test 1")
- except:
- init_dbus()
- try:
- exaile.TestService("Test 2")
- except:
- return False
- return True
- class Config:
- """
- All the config data goes here
- Alter these settings to modify the output of the /exaile command
- """
- def __init__(self):
- self.show_rating = True
- self.show_time = True
- self.show_album = False
- self.enable_downloads = True
- # Init global config object
- config = Config()
- class SongInfo:
- """Holds data about the song"""
- def __init__(self):
- self.artist = exaile.GetTrackAttr("artist")
- self.title = exaile.GetTrackAttr("title")
- self.album = exaile.GetTrackAttr("album")
- length = float(exaile.GetTrackAttr('__length'))
- length = '%d:%02d' % (length // 60, length % 60)
- self.length = length
- self.position = exaile.CurrentPosition()
- try:
- self.rating = int(exaile.GetTrackAttr("rating"))
- except:
- self.rating = 0;
- self.filename = exaile.GetTrackAttr("__loc").encode("utf-8")
- class Format:
- black = 1
- darkblue = 2
- green = 3
- red = 4
- darkred = 5
- purple = 6
- orange = 7
- yellow = 8
- lightgreen = 9
- aqua = 10
- lightblue = 11
- blue = 12
- violet = 13
- grey = 14
- lightgrey = 15
- white = 16
- def color(self, code):
- return "x03%02.f" % (code)
- def normal(self):
- return "x0F"
- def bold(self):
- return "x02"
- def reverse(self):
- return "x16"
- def underline(self):
- return "x1F"
- def exaile_on_command(word, word_eol, userdata):
- if check_exaile() == False:
- xchat.prnt("Exaile is not playing")
- return xchat.EAT_NONE;
- if len(word) == 1:
- now_playing()
- elif word[1] == 'play':
- exaile_control(word)
- elif word[1] == 'stop':
- exaile_control(word)
- elif word[1] == 'pause':
- exaile_control(word)
- elif word[1] == 'next':
- exaile_control(word)
- elif word[1] == 'previous' or word[1] == 'prev':
- exaile_control(word)
- elif word[1] == 'send' and len(word) == 3:
- send_track(word[2])
- elif word[1] == 'rating' and len(word) == 3:
- new_rating = int(word[2])
- if new_rating > 8:
- new_rating = 8
- if new_rating < 1:
- new_rating = 1
- exaile.set_rating(new_rating)
- elif word[1] == 'volume' and len(word) == 3:
- if word[2] == 'up':
- exaile.increase_volume(10)
- else:
- exaile.decrease_volume(10)
- else:
- print_help()
- return xchat.EAT_XCHAT
- def exaile_on_ctcp(word, word_eol, userdata):
- if word[0].upper() == 'GETSONG':
- if check_exaile() == False:
- xchat.command("notice %s Exaile is not playing at the moment." % word[1])
- return
- if config.enable_downloads == False:
- xchat.command("notice %s I don't want to share my songs." % word[1])
- return
- send_track(word[1])
- def now_playing():
- song = SongInfo()
- format = Format()
- string = u'me is listening to%s%s %s - %s %s' % (format.color(format.darkblue), format.bold(), song.artist, song.title, format.normal())
- if config.show_time:
- string += u'(%s/%s)' % (song.position, song.length)
- if int(song.rating) > 0 and config.show_rating:
- i = 0
- string += u" Rating: %s" % format.color(format.darkred)
- rating = float(song.rating / 2)
- while i < rating:
- string += u"u25CF"
- i += 1
- j = 0
- if song.rating % 2 > 0:
- string += u"u25D0"
- j += 1
- if (song.rating / 2) < 3.5:
- while j < (4 - rating):
- string += u"u25CB"
- j += 1
- string += u'%s' % format.normal()
- if config.show_album:
- string += u', Album:%s %s%s' % (format.color(format.green), song.album, format.normal())
- xchat.command(string.encode('utf-8'))
- def exaile_control(word):
- if word[1] == 'play':
- exaile.play()
- elif word[1] == 'pause':
- exaile.play_pause()
- elif word[1] == 'stop':
- exaile.stop()
- elif word[1] == 'next':
- exaile.next_track()
- elif word[1] == 'previous' or word[1] == 'prev':
- exaile.prev_track()
- def send_track(nickname):
- song = SongInfo()
- xchat.command('dcc send %s "%s"' % (nickname, song.filename))
- def print_help():
- xchat.prnt("Usage:")
- xchat.prnt("/exaile - Prints your current playing song")
- xchat.prnt("/exaile play/pause/stop/next/prev - Control exaile")
- xchat.prnt("/exaile rating {rating 1-8} - Set the rating for the current song")
- xchat.prnt("/exaile volume up|down - Control the volume of exaile")
- xchat.prnt("/exaile send {nick} - Send the current playing song to {nick}")
- xchat.hook_command('exaile', exaile_on_command)
- xchat.hook_print("CTCP Generic", exaile_on_ctcp)
- xchat.prnt('Loaded Exaile Xchat Plugin 0.2, created by Lucas van Dijk (http://www.return1.net)')
- try:
- check_exaile()
- except:
- pass

