Hack:mpdlyricsscript
From Music Player Daemon Community Wiki
Very working MPD lyrics script. Uses python, no extra dependencies. Just mpd, mpc and python :)
#! /usr/bin/env python
# MPD lyrics script. WURKS!
# Usage "python mpdlyricsscript.py" or "./mpdlyricsscript.py" or whatever is this python file named
import os
import urllib
# Opens new gnome-terminal titled "MPD Lyrics" and executes vim in read-only mode
execin = 'gnome-terminal -t "MPD Lyrics" -x vim -R'
# Opens lyrics in gedit
# execin = 'gedit'
# Just outputs lyrics
# execin = ""
# Random stuff
splitter = '()()'
lyrstartstr = '<div id="lyrics">'
lyrendstr = '</div>'
def execute(cmd):
a = os.popen(cmd)
return a.readlines()
# get artist and title
mpcoutput = execute('mpc --format "%artist%' + splitter + '%title%"')[0].split(splitter)
# parses title and artist
title = mpcoutput[1].strip().replace(' ', '%20')
artist = mpcoutput[0].strip().replace(' ', '%20')
# ok... now lets fetch lyrics from TEH INTERNET
html = urllib.urlopen('http://www.lyricsplugin.com/winamp03/plugin/?artist=' + artist + '&title=' + title).read()
# gets start and end position of lyrics at html-file
lyrstart = html.find(lyrstartstr) + len(lyrstartstr)
lyrend = html.find(lyrendstr, lyrstart)
# finally, puts lyrics in lyrics-variable
lyrics = html[lyrstart:lyrend].strip()
# little string manipulation
lyrics = lyrics.replace('<br />', '').replace('"', '"').strip()
# if execin is "", just print lyrics
if execin == "":
print lyrics
# if execin is something else, write lyrics to file and execute command
else:
lyrfile = file("/tmp/lyrtmp", 'w')
lyrfile.write(lyrics)
lyrfile.close
os.system(execin + " /tmp/lyrtmp")
