diff options
Diffstat (limited to 'src/plugins')
| -rw-r--r-- | src/plugins/General/CMakeLists.txt | 4 | ||||
| -rw-r--r-- | src/plugins/General/scrobbler/scrobbler.cpp | 25 | ||||
| -rw-r--r-- | src/plugins/General/scrobbler/scrobbler.h | 10 |
3 files changed, 20 insertions, 19 deletions
diff --git a/src/plugins/General/CMakeLists.txt b/src/plugins/General/CMakeLists.txt index bc52c5736..8b428c008 100644 --- a/src/plugins/General/CMakeLists.txt +++ b/src/plugins/General/CMakeLists.txt @@ -1,5 +1,5 @@ SET(USE_MPRIS TRUE CACHE BOOL "enable/disable mpris plugin") -#SET(USE_SCROBBLER TRUE CACHE BOOL "enable/disable scrobbler plugin") +SET(USE_SCROBBLER TRUE CACHE BOOL "enable/disable scrobbler plugin") SET(USE_STATICON TRUE CACHE BOOL "enable/disable status icon plugin") SET(USE_NOTIFIER TRUE CACHE BOOL "enable/disable notifier plugin") SET(USE_LYRICS TRUE CACHE BOOL "enable/disable lyrics version") @@ -11,7 +11,7 @@ add_subdirectory(mpris) ENDIF(USE_MPRIS) IF(USE_SCROBBLER) -#add_subdirectory(scrobbler) +add_subdirectory(scrobbler) ENDIF(USE_SCROBBLER) IF(USE_STATICON) diff --git a/src/plugins/General/scrobbler/scrobbler.cpp b/src/plugins/General/scrobbler/scrobbler.cpp index 0e740698c..2a760f0d2 100644 --- a/src/plugins/General/scrobbler/scrobbler.cpp +++ b/src/plugins/General/scrobbler/scrobbler.cpp @@ -24,6 +24,7 @@ #include <QCryptographicHash> #include <QUrl> #include <QTime> +#include <QDateTime> #include <QSettings> #include <QDir> #include <qmmp/soundcore.h> @@ -151,7 +152,7 @@ void Scrobbler::setState(Qmmp::State state) { case Qmmp::Playing: { - m_start_ts = time(NULL); + m_start_ts = QDateTime::currentDateTime().toTime_t(); m_time->restart(); if (!isReady() && m_handshakeid == 0) handshake(); @@ -163,7 +164,7 @@ void Scrobbler::setState(Qmmp::State state) } case Qmmp::Stopped: { - if ((!m_song.metaData().isEmpty()) + if (!m_song.metaData().isEmpty() && ((m_time->elapsed ()/1000 > 240) || (m_time->elapsed ()/1000 > int(m_song.length()/2))) && (m_time->elapsed ()/1000 > 60)) @@ -180,9 +181,7 @@ void Scrobbler::setState(Qmmp::State state) m_http->clearPendingRequests (); if (isReady() && m_submitid == 0) - { submit(); - } break; } } @@ -245,7 +244,8 @@ void Scrobbler::processResponse(int id, bool error) m_nowPlayingUrl = strlist[2]; m_session = strlist[1]; updateMetaData(); //send now-playing notification for already playing song - submit(); + if (!m_songCache.isEmpty()) //submit recent songs + submit(); return; } } @@ -264,7 +264,8 @@ void Scrobbler::processResponse(int id, bool error) m_submitedSongs--; m_songCache.removeFirst (); } - submit(); + if (!m_songCache.isEmpty()) //submit remaining songs + submit(); } else if (id == m_notificationid) { @@ -294,8 +295,8 @@ void Scrobbler::readResponse(const QHttpResponseHeader &header) void Scrobbler::handshake() { qDebug("Scrobbler::handshake()"); - time_t ts = time(NULL); - qDebug("Scrobbler: current time stamp %ld",ts); + uint ts = QDateTime::currentDateTime().toTime_t(); + qDebug("Scrobbler: current time stamp %d",ts); QString auth_tmp = QString("%1%2").arg(m_passw).arg(ts); QByteArray auth = QCryptographicHash::hash(auth_tmp.toAscii (), QCryptographicHash::Md5); auth = auth.toHex(); @@ -335,6 +336,7 @@ void Scrobbler::submit() .arg(info.metaData(Qmmp::TRACK)) .arg(i); } + qDebug(qPrintable(body)); QUrl url(m_submitUrl); m_http->setHost(url.host(), url.port()); QHttpRequestHeader header("POST", url.path()); @@ -393,6 +395,7 @@ SongInfo::SongInfo(const SongInfo &other) { m_metadata = other.metaData(); m_length = other.length(); + m_start_ts = other.timeStamp(); } SongInfo::~SongInfo() @@ -407,7 +410,7 @@ void SongInfo::operator=(const SongInfo &info) bool SongInfo::operator==(const SongInfo &info) { - return (m_metadata == info.metaData()) && (m_length == info.length()); + return (m_metadata == info.metaData()) && (m_length == info.length()) && (m_start_ts == info.timeStamp()); } bool SongInfo::operator!=(const SongInfo &info) @@ -451,12 +454,12 @@ void SongInfo::clear() m_length = 0; } -void SongInfo::setTimeStamp(time_t ts) +void SongInfo::setTimeStamp(uint ts) { m_start_ts = ts; } -time_t SongInfo::timeStamp() const +uint SongInfo::timeStamp() const { return m_start_ts; } diff --git a/src/plugins/General/scrobbler/scrobbler.h b/src/plugins/General/scrobbler/scrobbler.h index 5be5c569f..8e831ef7e 100644 --- a/src/plugins/General/scrobbler/scrobbler.h +++ b/src/plugins/General/scrobbler/scrobbler.h @@ -24,7 +24,6 @@ #include <QMap> #include <qmmpui/general.h> #include <qmmp/qmmp.h> -#include <time.h> class QHttp; class QTime; @@ -54,13 +53,13 @@ public: const QString metaData(Qmmp::MetaData) const; qint64 length () const; void clear(); - void setTimeStamp(time_t ts); - time_t timeStamp() const; + void setTimeStamp(uint ts); + uint timeStamp() const; private: QMap <Qmmp::MetaData, QString> m_metadata; qint64 m_length; - time_t m_start_ts; + uint m_start_ts; }; @@ -83,7 +82,7 @@ private: void submit(); void sendNotification(const SongInfo &info); bool isReady(); - time_t m_start_ts; + uint m_start_ts; SongInfo m_song; QHttp *m_http; Qmmp::State m_state; @@ -93,7 +92,6 @@ private: QString m_submitUrl; QString m_nowPlayingUrl; QString m_session; - //QList <time_t> m_timeStamps; QList <SongInfo> m_songCache; QTime* m_time; int m_submitedSongs; |
