-
-
Save MikeN123/3f0fc168e6cef8709850 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
# a last.fm now playing script originally written by Brandon Sutton | |
# some modifications by lifning | |
# and more modifications by praseodym | |
import urllib2 | |
import sys | |
# change me | |
me = 'praseodymium' | |
def lastfm_get(username): | |
print("/debug /lastfm called, it might take a few seconds to fetch the track list...") | |
xml = urllib2.urlopen("http://ws.audioscrobbler.com/2.0/user/" + username + "/recenttracks.xml?limit=1") | |
xml = xml.read().replace('&','&') | |
username = xml.split('" page="')[0].split('<recenttracks user="')[1] | |
artist = xml.split('</artist>')[0].split('>')[-1] | |
song = xml.split('</name>')[0].split('<name>')[1] | |
album = xml.split('</album>')[0].split('>')[-1] | |
if album != "": | |
albumtext = " from the album " + album + "" | |
else: | |
albumtext = "" | |
if xml.find("<track nowplaying=\"true\">") == -1: | |
nowplaying = " last listened" | |
else: | |
nowplaying = " is listening" | |
prefix = "/me" if username == me else username | |
print(prefix + nowplaying + " to " + song + " by " + artist + albumtext) | |
username = sys.argv[1] if len(sys.argv) == 2 and sys.argv[1] != '' else me | |
lastfm_get(username) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment