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.
Find the answer to your Linux question:
New to Linux Forums? Register here for free!
    Linux Forums > GNU Linux Zone > Gaming / Games / Multimedia / Entertainment > Missing lyrics in Amarok

Forgot Password?
 Gaming / Games / Multimedia / Entertainment   General discussion about Games, video, sound, multimedia, DVD's in Linux

Site Navigation
Linux Articles
Linux Forums
Linux Downloads
Linux Hosting
Free Magazines
Job Board
IRC Chat
RSS Feeds


Linux Forum Topics
Linux Forums
Your Distro
Linux Resources
GNU Linux Zone
The Community
Reply
 
Thread Tools Display Modes
Old 10-17-2009   #1 (permalink)
Just Joined!
 
Join Date: Nov 2007
Posts: 1
Missing lyrics in Amarok

Hi,

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 );
debianized is offline  


Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Free Magazines
Run Your Own Web Server Using Linux & Apache - Free 191 Page Preview
Learn about everything you'll need to build and maintain your Linux servers, and to deploy Web applications to them.
subscribe
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



All times are GMT. The time now is 09:32 AM.






© 2000 - 2009 - All Rights Reserved - Property of  MAS Media

Content Relevant URLs by vBSEO 3.3.0 RC2