Welcome to Linux Forums! With a comprehensive Linux Forum, information on various types of Linux software and many Linux Reviews articles, we have all the knowledge you need a click away, or accessible via our knowledgeable members.
Write an article for LinuxForums Today! Win Great Prizes!
I found annoying that Amarok is newly unable to fetch lyrics from LyricWiki. This is because of legal reasons... You can read more about it on their site (unfortunately I'm unable to include links as this is my first post, and it's restricted to users after 15th post.
So I changed the script to get the lyrics even after the API change.
You have to replace the script in /usr/share/kde4/apps/amarok/scripts/lyrics_lyricwiki/main.js with the below one. (The directory structure could vary depending on your distro).
As in the code itself there should be a link which I'm unable to write directly, please do insert a link to 'getLyrics' function. In the line where /***** REPLACE HERE ******/ is present, replace "" with "http colon forward-slash forward-slash liricwiki dot org forward-slash api dot php".
Ofcourse there can be bugs, but for me it works fine.
Enjoy!
Code:
Importer.loadQtBinding( "qt.core" );
Importer.loadQtBinding( "qt.xml" );
xml = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?><lyric artist=\"{artist}\" title=\"{title}\">{lyrics}</lyric>";
artist = "";
title = "";
function onFinishedHtml( dat )
{
doc = new QDomDocument();
doc.setContent( dat );
divelements = doc.elementsByTagName( "div" );
textdiv = "";
for(i=0; i<divelements.count(); i++)
{
//Amarok.debug("div element class: " + divelements.at(i).toElement().attribute("class"));
if ("lyricbox" == divelements.at(i).toElement().attribute("class"))
{
//Amarok.debug("found lyric element: " + divelements.at(i).toElement().text());
textdiv = divelements.at(i);
break;
}
}
if(i == divelements.count())
{
Amarok.debug( "error: getting lyricbox DIV element" );
Amarok.Lyrics.showLyricsError( "Could not retrieve lyrics: " + err );
return;
}
doc2 = new QDomDocument();
var owndiv = doc2.importNode(textdiv, true);
doc2.appendChild(owndiv);
lyricsString = doc2.toString();
newxml = xml.replace( "{artist}", Amarok.Lyrics.escape( artist ) );
newxml = newxml.replace( "{title}", Amarok.Lyrics.escape( title ) );
newxml = newxml.replace( "{lyrics}", lyricsString );
//Amarok.debug( "showing lyrics:" + newxml );
Amarok.Lyrics.showLyricsHtml( newxml );
}
function onFinishedXml( dat )
{
//Amarok.debug( "Got response: " + dat );
try
{
if( dat.length == 0 )
Amarok.Lyrics.showLyricsError( "Unable to contact server" ); // TODO: this should be i18n able
else
{
doc = new QDomDocument();
doc.setContent( dat );
url = doc.elementsByTagName("url").at(0).toElement().text();
artist = doc.elementsByTagName( "artist" ).at( 0 ).toElement().text();
title = doc.elementsByTagName( "song" ).at( 0 ).toElement().text();
var qurl = new QUrl(unescape(url));
new Downloader( qurl, onFinishedHtml );
}
}
catch( err )
{
Amarok.Lyrics.showLyricsError( "Could not retrieve lyrics: " + err );
Amarok.debug( "error: " + err );
}
}
function getLyrics( artist, title, url )
{
Amarok.debug( "Getting lyrics for " + artist + title + url );
try
{
var url = new QUrl( "" ); /***** REPLACE HERE ******/
url.addQueryItem( "func", "getSong" );
url.addQueryItem( "artist", artist );
url.addQueryItem( "song", title );
url.addQueryItem( "fmt", "xml" );
Amarok.debug( "request URL: " + url.toString() );
new Downloader( url, onFinishedXml );
}
catch( err )
{
Amarok.debug( "error: " + err );
}
}
Amarok.Lyrics.fetchLyrics.connect( getLyrics );
Open Source Security Myths Dispelled Dispel the five major myths surrounding Open Source Security and gain the tools necessary to make a truly informed decision for your IT organization subscribe
InformationWeek InformationWeek is the only newsweekly you'll need to stay on top of the latest developments in information technology. subscribe