Last active
September 28, 2015 00:08
-
-
Save lifning/1354062 to your computer and use it in GitHub Desktop.
xchat lastfm now-playing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
# a last.fm now playing script originally written by Brandon Sutton | |
# some modifications by lifning | |
__module_name__ = "last.fm" | |
__module_version__ = "1.0" | |
__module_description__ = "/np for last.fm" | |
try: | |
import hexchat as xchat | |
except ImportError: | |
import xchat | |
import urllib2 | |
username = 'your lastfm username here' | |
api = 'b25b959554ed76058ac220b7b2e0a026' | |
def lastfm_get(word,word_eol,userdata): | |
# uncomment the next two lines if you want to use your irc nick or a passed argument as the lastfm username | |
#username = xchat.get_info('nick') | |
#if len(word) >= 2: username = word[1] | |
x = urllib2.urlopen( 'http://ws.audioscrobbler.com/2.0/?method=user.getrecenttracks&user={}&api_key={}'.format(username, api) ) | |
x = x.read().replace('&','&') | |
artist = x.split('</artist>')[0].split('>')[-1] | |
song = x.split('</name>')[0].split('<name>')[1] | |
album = x.split('</album>')[0].split('>')[-1] | |
if album != "": album = "["+album+"]" | |
xchat.command('me np: {} - {} {}'.format(artist, song, album)) | |
return xchat.EAT_ALL | |
xchat.hook_command("np", lastfm_get, help="/np displays your now playing from last.fm") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I'm having issues with this script. Getting this error on '/np':
File "C:\Users\fin\AppData\Roaming\HexChat\addons\now-playing.py", line 25, in lastfm_get
song = x.split('')[0].split('')[1]
IndexError: list index out of range