Skip to content

Instantly share code, notes, and snippets.

@shadyabhi
Created October 24, 2011 17:06
Show Gist options
  • Select an option

  • Save shadyabhi/1309527 to your computer and use it in GitHub Desktop.

Select an option

Save shadyabhi/1309527 to your computer and use it in GitHub Desktop.
For theone
#!/usr/bin/python2
import os
import pylast
MPD_LIBRARY_LOCATION = "/var/lib/mpd/music/"
API_KEY = "your api key"
API_SECRET = "your secret"
username = "shadyabhi"
#Enter the hash directly.
password_hash = pylast.md5("mysupersecret")
print "Deleting the song"
mpcProcess = os.popen("mpc -f %file%")
try:
# [:-1] to delete the trailing newline
     os.remove(MPD_LIBRARY_LOCATION+mpcProcess.readline()[:-1])
     #Deleting song from playlist
     os.popen("mpc del $(mpc -f %position% | head -n 1)")
except:
     print "Something really went wrong"
#!/usr/bin/python2
import os
import pylast
MPD_LIBRARY_LOCATION = "/var/lib/mpd/music/"
API_KEY = "your api key"
API_SECRET = "your secret"
username = "shadyabhi"
#Enter the hash directly.
password_hash = pylast.md5("mysupersecret")
print "Loving track on last.fm"
network = pylast.LastFMNetwork(api_key = API_KEY, api_secret = API_SECRET, username = username, password_hash = password_hash)
       
artist = os.popen('mpc -f "%artist%" | head -n 1').read()
title = os.popen('mpc -f "%title%" | head -n 1').read()
track = network.get_track(artist, title)
track.love()
 
#Confirming the user that the track has been loved by retrieving the last loved track from last.fm
last_loved_track = str(network.get_user(username).get_loved_tracks(limit=1)[0][0])
print "Last loved track confirmation" + last_loved_track + " is your last loved track"
@nikolavp
Copy link

Cool piece of code for sure!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment