1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-02 12:20:45 +02:00

Small changes in groovesharkparser

This commit is contained in:
Stefan Derkits
2011-12-22 23:59:16 +01:00
parent e989bc1652
commit 2e25337cc1
2 changed files with 36 additions and 32 deletions

View File

@@ -1,5 +1,7 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> === /* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
* *
* Copyright 2010-2011, Leo Franchi <lfranchi@kde.org>
* Copyright 2010-2011, Hugo Lindström <hugolm84@gmail.com>
* Copyright 2010-2011, Stefan Derkits <stefan@derkits.at> * Copyright 2010-2011, Stefan Derkits <stefan@derkits.at>
* *
* Tomahawk is free software: you can redistribute it and/or modify * Tomahawk is free software: you can redistribute it and/or modify
@@ -49,6 +51,14 @@ GroovesharkParser::GroovesharkParser( const QStringList& trackUrls, bool createN
, m_createNewPlaylist( createNewPlaylist ) , m_createNewPlaylist( createNewPlaylist )
, m_browseJob( 0 ) , m_browseJob( 0 )
{ {
QByteArray magic = QByteArray::fromBase64( enApiSecret );
QByteArray wand = QByteArray::fromBase64( QCoreApplication::applicationName().toLatin1() );
int length = magic.length(), n2 = wand.length();
for ( int i=0; i<length; i++ ) magic[i] = magic[i] ^ wand[i%n2];
m_apiKey = QCA::SymmetricKey( magic );
foreach ( const QString& url, trackUrls ) foreach ( const QString& url, trackUrls )
lookupUrl( url ); lookupUrl( url );
} }
@@ -80,7 +90,6 @@ void
GroovesharkParser::lookupGroovesharkPlaylist( const QString& linkRaw ) GroovesharkParser::lookupGroovesharkPlaylist( const QString& linkRaw )
{ {
tLog() << "Parsing Grooveshark Playlist URI:" << linkRaw; tLog() << "Parsing Grooveshark Playlist URI:" << linkRaw;
QString browseUri = linkRaw;
QStringList urlParts = linkRaw.split( "/" ); QStringList urlParts = linkRaw.split( "/" );
bool ok; bool ok;
@@ -97,27 +106,19 @@ GroovesharkParser::lookupGroovesharkPlaylist( const QString& linkRaw )
DropJob::DropType type; DropJob::DropType type;
if ( browseUri.contains( "playlist" ) ) if ( linkRaw.contains( "playlist" ) )
type = DropJob::Playlist; type = DropJob::Playlist;
QString base_url( "http://api.grooveshark.com/ws3.php?sig=" ); QString base_url( "http://api.grooveshark.com/ws3.php?sig=" );
QByteArray data = QString( "{\"method\":\"getPlaylistSongs\",\"parameters\":{\"playlistID\":\"%1\"},\"header\":{\"wsKey\":\"tomahawkplayer\"}}" ).arg( playlistID ).toLocal8Bit(); QByteArray data = QString( "{\"method\":\"getPlaylistSongs\",\"parameters\":{\"playlistID\":\"%1\"},\"header\":{\"wsKey\":\"tomahawkplayer\"}}" ).arg( playlistID ).toLocal8Bit();
QByteArray magic = QByteArray::fromBase64( enApiSecret );
QByteArray wand = QByteArray::fromBase64( QCoreApplication::applicationName().toLatin1() );
int length = magic.length(), n2 = wand.length();
for ( int i=0; i<length; i++ ) magic[i] = magic[i] ^ wand[i%n2];
QCA::SymmetricKey key( magic );
tDebug() << "key size: " << key.size(); QCA::MessageAuthenticationCode hmac( "hmac(md5)", m_apiKey );
QCA::MessageAuthenticationCode hmac(QString("hmac(md5)"),key);
tDebug() << "created hmac object";
QCA::SecureArray secdata( data ); QCA::SecureArray secdata( data );
tDebug() << "before creating hmac";
hmac.update(secdata); hmac.update(secdata);
QCA::SecureArray resultArray = hmac.final(); QCA::SecureArray resultArray = hmac.final();
@@ -129,8 +130,8 @@ GroovesharkParser::lookupGroovesharkPlaylist( const QString& linkRaw )
QNetworkReply* reply = TomahawkUtils::nam()->post( QNetworkRequest( url ), data ); QNetworkReply* reply = TomahawkUtils::nam()->post( QNetworkRequest( url ), data );
connect( reply, SIGNAL( finished() ), this, SLOT( groovesharkLookupFinished() ) ); connect( reply, SIGNAL( finished() ), this, SLOT( groovesharkLookupFinished() ) );
//m_browseJob = new DropJobNotifier( pixmap(), "Grooveshark", type, reply ); m_browseJob = new DropJobNotifier( pixmap(), "Grooveshark", type, reply );
//JobStatusView::instance()->model()->addJob( m_browseJob ); JobStatusView::instance()->model()->addJob( m_browseJob );
m_queries.insert( reply ); m_queries.insert( reply );
} }
@@ -157,13 +158,10 @@ GroovesharkParser::groovesharkLookupFinished()
return; return;
} }
//tDebug() << "parsed grooveshark result into a map " << res;
//tDebug() << "results " << res.value("result") << " which is of type " << res.value("result").type();
QVariantList list = res.value( "result" ).toMap().value( "songs" ).toList(); QVariantList list = res.value( "result" ).toMap().value( "songs" ).toList();
foreach (const QVariant& var, list) foreach (const QVariant& var, list)
{ {
QVariantMap trackResult = var.toMap(); QVariantMap trackResult = var.toMap();
//tDebug() << map;
QString title, artist, album; QString title, artist, album;
@@ -173,7 +171,7 @@ GroovesharkParser::groovesharkLookupFinished()
if ( title.isEmpty() && artist.isEmpty() ) // don't have enough... if ( title.isEmpty() && artist.isEmpty() ) // don't have enough...
{ {
tLog() << "Didn't get an artist and track name from spotify, not enough to build a query on. Aborting" << title << artist << album; tLog() << "Didn't get an artist and track name from grooveshark, not enough to build a query on. Aborting" << title << artist << album;
return; return;
} }
@@ -190,11 +188,11 @@ GroovesharkParser::groovesharkLookupFinished()
if ( m_trackMode ) if ( m_trackMode )
checkTrackFinished(); checkTrackFinished();
else else
checkBrowseFinished(); checkPlaylistFinished();
} }
void void
GroovesharkParser::checkBrowseFinished() GroovesharkParser::checkPlaylistFinished()
{ {
tDebug() << "Checking for grooveshark batch playlist job finished" << m_queries.isEmpty() << m_createNewPlaylist; tDebug() << "Checking for grooveshark batch playlist job finished" << m_queries.isEmpty() << m_createNewPlaylist;
if ( m_queries.isEmpty() ) // we're done if ( m_queries.isEmpty() ) // we're done
@@ -252,7 +250,7 @@ QPixmap
GroovesharkParser::pixmap() const GroovesharkParser::pixmap() const
{ {
if ( !s_pixmap ) if ( !s_pixmap )
s_pixmap = new QPixmap( RESPATH "images/spotify-logo.png" ); s_pixmap = new QPixmap( RESPATH "images/grooveshark.png" );
return *s_pixmap; return *s_pixmap;
} }

View File

@@ -1,6 +1,8 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> === /* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
* *
* Copyright 2010-2011, Stefan Derkits <stefan@derkits.at> * Copyright 2010-2011, Leo Franchi <lfranchi@kde.org>
* Copyright 2010-2011, Hugo Lindström <hugolm84@gmail.com>
* Copyright 2011, Stefan Derkits <stefan@derkits.at>
* *
* Tomahawk is free software: you can redistribute it and/or modify * Tomahawk is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@@ -24,6 +26,8 @@
#include "query.h" #include "query.h"
#include "jobview/JobStatusItem.h" #include "jobview/JobStatusItem.h"
#include <qca_basic.h>
#include <QObject> #include <QObject>
#include <QSet> #include <QSet>
#include <QtCore/QStringList> #include <QtCore/QStringList>
@@ -62,7 +66,7 @@ private:
void lookupUrl( const QString& url ); void lookupUrl( const QString& url );
void lookupGroovesharkPlaylist( const QString& playlist ); void lookupGroovesharkPlaylist( const QString& playlist );
void checkTrackFinished(); void checkTrackFinished();
void checkBrowseFinished(); void checkPlaylistFinished();
int m_limit; int m_limit;
bool m_trackMode; bool m_trackMode;
bool m_createNewPlaylist; bool m_createNewPlaylist;
@@ -72,6 +76,8 @@ private:
Tomahawk::playlist_ptr m_playlist; Tomahawk::playlist_ptr m_playlist;
DropJobNotifier* m_browseJob; DropJobNotifier* m_browseJob;
QCA::SymmetricKey m_apiKey;
static QPixmap* s_pixmap; static QPixmap* s_pixmap;
}; };