Bug 151748 - Scrobbler::similarArtists needs chars escaped
Summary: Scrobbler::similarArtists needs chars escaped
Status: RESOLVED FIXED
Alias: None
Product: amarok
Classification: Applications
Component: general (show other bugs)
Version: unspecified
Platform: Ubuntu Linux
: NOR normal
Target Milestone: ---
Assignee: Amarok Developers
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-11-02 16:29 UTC by Jer Johnson
Modified: 2008-08-02 17:02 UTC (History)
0 users

See Also:
Latest Commit:
Version Fixed In:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jer Johnson 2007-11-02 16:30:00 UTC
Version:           Amarok 1.4-SVN (oct 31,2007) (using KDE KDE 3.5.8)
Installed from:    Ubuntu Packages
OS:                Linux

Artists such as "Crosby, Stills, & Nash" weren't properly loading similar Artists.

I've fixed this locally by escaping "&", ",", and "?" in the artist name,
before it is added to the AS request URL.

there must be a QString routine to escape characters that are reserved for HTTP queries.

-=-=-=-=-=-=-=-= new code below . amarok/src/scrobbler.cpp line 69

void Scrobbler::similarArtists( const QString & artist )
{
    QString safeArtist = QDeepCopy<QString>( artist );
    if ( AmarokConfig::retrieveSimilarArtists() )
    {
//         Request looks like this:
//         http://ws.audioscrobbler.com/1.0/artist/Metallica/similar.xml

        m_similarArtistsBuffer = QByteArray();
        m_artist = artist;
        safeArtist.replace("?","%3F").replace("&","%26").replace(",","%2C");

        m_similarArtistsJob = KIO::get( "http://ws.audioscrobbler.com/1.0/artist/" + safeArtist + "/similar.xml", false, false );

        connect( m_similarArtistsJob, SIGNAL( result( KIO::Job* ) ),
                 this,                  SLOT( audioScrobblerSimilarArtistsResult( KIO::Job* ) ) );
        connect( m_similarArtistsJob, SIGNAL( data( KIO::Job*, const QByteArray& ) ),
                 this,                  SLOT( audioScrobblerSimilarArtistsData( KIO::Job*, const QByteArray& ) ) );
    }
}
Comment 1 Jer Johnson 2007-11-07 04:26:49 UTC
add   .replace("/","%2F"); as well
Comment 2 William Thomas 2007-11-30 22:21:13 UTC
This doesn't go far enough because of unicode characters.  I think the correct way to do this would be to use Qt::escape(), but I am not sure about that.
Comment 3 Gary Steinert 2008-08-01 18:33:38 UTC
I apologise if im talking complete bs, but im a bit of a newbie in the whole kde, amarok and general development area!

Is there a function (it may be QT::escape(), but there you go!) that will replace all characters with their escape sequence? (i.e. "/" -> "%2F") This may be overkill, but it will sort all unicode characters, and ensure there are absolutely _no_ problems with characters in requests.

Gary
Comment 4 Mark Kretschmann 2008-08-02 07:57:56 UTC
I could not find such a function in Qt. If you do, please let us know.
Comment 5 Gary Steinert 2008-08-02 15:58:32 UTC
Not managed to find a function as of yet. I know Qt::escape() wont work. I'll have a go at writing my own as soon as I get chance. Shouldn't be too hard (i hope!)

Gary
Comment 6 William Thomas 2008-08-02 16:35:10 UTC
It is in the documentation, but I am not a programmer nor do I play one on tv.

http://doc.trolltech.com/4.3/qt.html#escape
Comment 7 Mark Kretschmann 2008-08-02 17:02:20 UTC
SVN commit 841074 by markey:

Html-escape similar artists string before lookup. The code is commented out (not yet implemented in Amarok 2) but I've fixed it anyway.

BUG: 151748


 M  +1 -1      CollectionManager.cpp  


WebSVN link: http://websvn.kde.org/?view=rev&revision=841074