aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authortrialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38>2013-01-29 12:05:15 +0000
committertrialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38>2013-01-29 12:05:15 +0000
commitf24e948ba5117ec92a148b78222269d4905916bc (patch)
treee0afa36248cac6c4946bb99e3202b8cd809e07c7 /src
parent0d00fa7582627e1de763115122d92f2b2712b7f6 (diff)
downloadqmmp-f24e948ba5117ec92a148b78222269d4905916bc.tar.gz
qmmp-f24e948ba5117ec92a148b78222269d4905916bc.tar.bz2
qmmp-f24e948ba5117ec92a148b78222269d4905916bc.zip
removed registration code from main last.fm scrobbler class
git-svn-id: http://svn.code.sf.net/p/qmmp-dev/code/trunk/qmmp@3193 90c681e8-e032-0410-971d-27865f9a5e38
Diffstat (limited to 'src')
-rw-r--r--src/plugins/General/scrobbler/lastfmscrobbler.cpp116
-rw-r--r--src/plugins/General/scrobbler/lastfmscrobbler.h5
2 files changed, 5 insertions, 116 deletions
diff --git a/src/plugins/General/scrobbler/lastfmscrobbler.cpp b/src/plugins/General/scrobbler/lastfmscrobbler.cpp
index fe4ae2ff4..be327ae0a 100644
--- a/src/plugins/General/scrobbler/lastfmscrobbler.cpp
+++ b/src/plugins/General/scrobbler/lastfmscrobbler.cpp
@@ -82,8 +82,6 @@ void LastfmResponse::parse(QIODevice *device)
LastfmScrobbler::LastfmScrobbler(QObject *parent) : QObject(parent)
{
- m_getTokenReply = 0;
- m_getSessionReply = 0;
m_notificationReply = 0;
m_submitedSongs = 0;
m_submitReply = 0;
@@ -104,9 +102,7 @@ LastfmScrobbler::LastfmScrobbler(QObject *parent) : QObject(parent)
setupProxy();
m_cachedSongs = m_cache->load();
- if(m_session.isEmpty())
- getToken();
- else
+ if(!m_session.isEmpty())
{
submit();
if(m_core->state() == Qmmp::Playing)
@@ -193,66 +189,7 @@ void LastfmScrobbler::processResponse(QNetworkReply *reply)
qWarning("LastfmScrobbler: invalid content");
}
- if (reply == m_getTokenReply)
- {
- m_getTokenReply = 0;
- if(response.status == "ok")
- {
- m_token = response.token;
- qDebug("LastfmScrobbler: token: %s", qPrintable(m_token));
- QDesktopServices::openUrl("http://www.last.fm/api/auth/?api_key="API_KEY"&token="+m_token);
- QTimer::singleShot(120000, this, SLOT(getSession())); //2 minutes
- }
- else if(error_code == "8" || error_code == "7" || error_code == "11" || error_code.isEmpty())
- {
- m_token.clear();
- QTimer::singleShot(120000, this, SLOT(getToken())); // wait 2 minutes and try again
- }
- else
- {
- m_token.clear();
- qWarning("LastfmScrobbler: service returned unrecoverable error, scrobbling disabled");
- }
- }
- else if(reply == m_getSessionReply)
- {
- m_getSessionReply = 0;
- m_session.clear();
- if(response.status == "ok")
- {
- m_session = response.key;
- qDebug("LastfmScrobbler: name: %s", qPrintable(response.name));
- qDebug("LastfmScrobbler: key: %s", qPrintable(m_session));
- qDebug("LastfmScrobbler: subscriber: %s", qPrintable(response.subscriber));
- QSettings settings(Qmmp::configFile(), QSettings::IniFormat);
- settings.setValue("Scrobbler/lastfm_session", m_session);
- submit();
- }
- else if(error_code == "4" || error_code == "15") //invalid token
- {
- m_token.clear();
- getToken();
- }
- else if(error_code == "11") //service offline
- {
- QTimer::singleShot(120000, this, SLOT(getSession()));
- }
- else if(error_code == "14") // unauthorized token
- {
- QDesktopServices::openUrl("http://www.last.fm/api/auth/?api_key="API_KEY"&token="+m_token);
- QTimer::singleShot(120000, this, SLOT(getSession())); //2 minutes
- }
- else if (error_code.isEmpty()) //network error
- {
- QTimer::singleShot(120000, this, SLOT(getSession()));
- }
- else
- {
- m_token.clear();
- qWarning("LastfmScrobbler: service returned unrecoverable error, scrobbling disabled");
- }
- }
- else if (reply == m_submitReply)
+ if (reply == m_submitReply)
{
m_submitReply = 0;
if (response.status == "ok")
@@ -276,7 +213,7 @@ void LastfmScrobbler::processResponse(QNetworkReply *reply)
else if(error_code == "9") //invalid session key
{
m_session.clear();
- getToken();
+ qWarning("LastfmScrobbler: invalid session key, scrobbling disabled");
}
else if(error_code == "11" || error_code == "16" || error_code.isEmpty()) //unavailable
{
@@ -298,7 +235,7 @@ void LastfmScrobbler::processResponse(QNetworkReply *reply)
else if(error_code == "9") //invalid session key
{
m_session.clear();
- getToken();
+ qWarning("LastfmScrobbler: invalid session key, scrobbling disabled");
}
}
reply->deleteLater();
@@ -321,51 +258,6 @@ void LastfmScrobbler::setupProxy()
m_http->setProxy(QNetworkProxy::NoProxy);
}
-void LastfmScrobbler::getToken()
-{
- qDebug("LastfmScrobbler: new token request");
- m_session.clear();
- QUrl url(QString(SCROBBLER_LASTFM_URL) + "?");
- url.setPort(80);
- url.addQueryItem("method", "auth.getToken");
- url.addQueryItem("api_key", API_KEY);
-
- QByteArray data;
- data.append("api_key"API_KEY);
- data.append("methodauth.getToken");
- data.append(SECRET);
- url.addQueryItem("api_sig", QCryptographicHash::hash(data,QCryptographicHash::Md5).toHex());
-
- QNetworkRequest request(url);
- request.setRawHeader("User-Agent", m_ua);
- request.setRawHeader("Host",url.host().toAscii());
- request.setRawHeader("Accept", "*/*");
- m_getTokenReply = m_http->get(request);
-}
-
-void LastfmScrobbler::getSession()
-{
- qDebug("LastfmScrobbler: new session request");
- QUrl url(QString(SCROBBLER_LASTFM_URL) + "?");
- url.setPort(80);
- url.addQueryItem("api_key", API_KEY);
- url.addQueryItem("method", "auth.getSession");
- url.addQueryItem("token", m_token);
-
- QByteArray data;
- data.append("api_key"API_KEY);
- data.append("methodauth.getSession");
- data.append("token" + m_token.toUtf8());
- data.append(SECRET);
- url.addQueryItem("api_sig", QCryptographicHash::hash(data, QCryptographicHash::Md5).toHex());
-
- QNetworkRequest request(url);
- request.setRawHeader("User-Agent", m_ua);
- request.setRawHeader("Host",url.host().toAscii());
- request.setRawHeader("Accept", "*/*");
- m_getSessionReply = m_http->get(request);
-}
-
void LastfmScrobbler::submit()
{
if (m_cachedSongs.isEmpty() || m_session.isEmpty() || m_submitReply)
diff --git a/src/plugins/General/scrobbler/lastfmscrobbler.h b/src/plugins/General/scrobbler/lastfmscrobbler.h
index d6e97c8c0..cf0c2609e 100644
--- a/src/plugins/General/scrobbler/lastfmscrobbler.h
+++ b/src/plugins/General/scrobbler/lastfmscrobbler.h
@@ -64,8 +64,6 @@ private slots:
void updateMetaData();
void processResponse(QNetworkReply *reply);
void setupProxy();
- void getToken();
- void getSession();
void submit();
private:
@@ -78,10 +76,9 @@ private:
QList <SongInfo> m_cachedSongs;
QByteArray m_ua;
int m_submitedSongs;
- QString m_token, m_session;
+ QString m_session;
QNetworkAccessManager *m_http;
SoundCore *m_core;
- QNetworkReply *m_getTokenReply, *m_getSessionReply;
QNetworkReply *m_submitReply, *m_notificationReply;
QTime *m_time;
ScrobblerCache *m_cache;