mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-03-19 07:19:42 +01:00
Small changes in groovesharkparser
This commit is contained in:
parent
e989bc1652
commit
2e25337cc1
@ -1,5 +1,7 @@
|
||||
/* === 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>
|
||||
*
|
||||
* 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_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 )
|
||||
lookupUrl( url );
|
||||
}
|
||||
@ -80,57 +90,48 @@ void
|
||||
GroovesharkParser::lookupGroovesharkPlaylist( const QString& linkRaw )
|
||||
{
|
||||
tLog() << "Parsing Grooveshark Playlist URI:" << linkRaw;
|
||||
QString browseUri = linkRaw;
|
||||
|
||||
QStringList urlParts = linkRaw.split("/");
|
||||
QStringList urlParts = linkRaw.split( "/" );
|
||||
bool ok;
|
||||
int playlistID = urlParts.last().toInt(&ok, 10);
|
||||
int playlistID = urlParts.last().toInt( &ok, 10 );
|
||||
if (!ok)
|
||||
{
|
||||
tDebug() << "incorrect grooveshark url";
|
||||
return;
|
||||
}
|
||||
|
||||
m_title = urlParts.at(urlParts.size()-2);
|
||||
m_title = urlParts.at( urlParts.size()-2 );
|
||||
|
||||
tDebug() << "should get playlist " << playlistID;
|
||||
|
||||
DropJob::DropType type;
|
||||
|
||||
if ( browseUri.contains( "playlist" ) )
|
||||
if ( linkRaw.contains( "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(QString("hmac(md5)"),key);
|
||||
tDebug() << "created hmac object";
|
||||
QCA::MessageAuthenticationCode hmac( "hmac(md5)", m_apiKey );
|
||||
|
||||
QCA::SecureArray secdata( data );
|
||||
tDebug() << "before creating hmac";
|
||||
hmac.update(secdata);
|
||||
QCA::SecureArray resultArray = hmac.final();
|
||||
|
||||
QString hash = QCA::arrayToHex(resultArray.toByteArray());
|
||||
QUrl url = QUrl(base_url + hash);
|
||||
QString hash = QCA::arrayToHex( resultArray.toByteArray() );
|
||||
QUrl url = QUrl( base_url + hash );
|
||||
|
||||
tDebug() << "Looking up URL..." << url.toString();
|
||||
|
||||
QNetworkReply* reply = TomahawkUtils::nam()->post( QNetworkRequest( url ), data );
|
||||
connect( reply, SIGNAL( finished() ), this, SLOT( groovesharkLookupFinished() ) );
|
||||
|
||||
//m_browseJob = new DropJobNotifier( pixmap(), "Grooveshark", type, reply );
|
||||
//JobStatusView::instance()->model()->addJob( m_browseJob );
|
||||
m_browseJob = new DropJobNotifier( pixmap(), "Grooveshark", type, reply );
|
||||
JobStatusView::instance()->model()->addJob( m_browseJob );
|
||||
|
||||
m_queries.insert( reply );
|
||||
}
|
||||
@ -157,13 +158,10 @@ GroovesharkParser::groovesharkLookupFinished()
|
||||
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)
|
||||
{
|
||||
QVariantMap trackResult = var.toMap();
|
||||
//tDebug() << map;
|
||||
|
||||
QString title, artist, album;
|
||||
|
||||
@ -173,7 +171,7 @@ GroovesharkParser::groovesharkLookupFinished()
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@ -190,11 +188,11 @@ GroovesharkParser::groovesharkLookupFinished()
|
||||
if ( m_trackMode )
|
||||
checkTrackFinished();
|
||||
else
|
||||
checkBrowseFinished();
|
||||
checkPlaylistFinished();
|
||||
}
|
||||
|
||||
void
|
||||
GroovesharkParser::checkBrowseFinished()
|
||||
GroovesharkParser::checkPlaylistFinished()
|
||||
{
|
||||
tDebug() << "Checking for grooveshark batch playlist job finished" << m_queries.isEmpty() << m_createNewPlaylist;
|
||||
if ( m_queries.isEmpty() ) // we're done
|
||||
@ -252,7 +250,7 @@ QPixmap
|
||||
GroovesharkParser::pixmap() const
|
||||
{
|
||||
if ( !s_pixmap )
|
||||
s_pixmap = new QPixmap( RESPATH "images/spotify-logo.png" );
|
||||
s_pixmap = new QPixmap( RESPATH "images/grooveshark.png" );
|
||||
|
||||
return *s_pixmap;
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,8 @@
|
||||
/* === 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
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@ -24,6 +26,8 @@
|
||||
#include "query.h"
|
||||
#include "jobview/JobStatusItem.h"
|
||||
|
||||
#include <qca_basic.h>
|
||||
|
||||
#include <QObject>
|
||||
#include <QSet>
|
||||
#include <QtCore/QStringList>
|
||||
@ -62,7 +66,7 @@ private:
|
||||
void lookupUrl( const QString& url );
|
||||
void lookupGroovesharkPlaylist( const QString& playlist );
|
||||
void checkTrackFinished();
|
||||
void checkBrowseFinished();
|
||||
void checkPlaylistFinished();
|
||||
int m_limit;
|
||||
bool m_trackMode;
|
||||
bool m_createNewPlaylist;
|
||||
@ -72,6 +76,8 @@ private:
|
||||
Tomahawk::playlist_ptr m_playlist;
|
||||
DropJobNotifier* m_browseJob;
|
||||
|
||||
QCA::SymmetricKey m_apiKey;
|
||||
|
||||
static QPixmap* s_pixmap;
|
||||
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user