Add support for libre.fm - untested, as I dont have an account yet...
This commit is contained in:
committed by
craig.p.drummond
parent
eb3265f379
commit
bf335c1fd1
@@ -643,11 +643,11 @@ endif (X11_FOUND)
|
||||
|
||||
if (WIN32)
|
||||
install(FILES context/ultimate_providers.xml DESTINATION ${CMAKE_INSTALL_PREFIX}/lyrics/)
|
||||
install(FILES context/weblinks.xml online/podcast_directories.xml DESTINATION ${CMAKE_INSTALL_PREFIX}/config/)
|
||||
install(FILES context/weblinks.xml online/podcast_directories.xml scrobbling/scrobblers.xml DESTINATION ${CMAKE_INSTALL_PREFIX}/config/)
|
||||
install(FILES tags/fixes.xml DESTINATION ${CMAKE_INSTALL_PREFIX}/config/ RENAME tag-fixes.xml)
|
||||
elseif (NOT ENABLE_UBUNTU)
|
||||
install(FILES context/ultimate_providers.xml DESTINATION ${CMAKE_INSTALL_PREFIX}/share/${CMAKE_PROJECT_NAME}/lyrics)
|
||||
install(FILES context/weblinks.xml online/podcast_directories.xml DESTINATION ${CMAKE_INSTALL_PREFIX}/share/${CMAKE_PROJECT_NAME}/config/)
|
||||
install(FILES context/weblinks.xml online/podcast_directories.xml scrobbling/scrobblers.xml DESTINATION ${CMAKE_INSTALL_PREFIX}/share/${CMAKE_PROJECT_NAME}/config/)
|
||||
install(FILES tags/fixes.xml DESTINATION ${CMAKE_INSTALL_PREFIX}/share/${CMAKE_PROJECT_NAME}/config/ RENAME tag-fixes.xml)
|
||||
endif (WIN32)
|
||||
|
||||
|
||||
@@ -61,7 +61,6 @@ static const QLatin1String constBadSession("BADSESSION");
|
||||
static const QLatin1String constFailed("FAILED");
|
||||
static const QLatin1String constSettingsGroup("Scrobbling");
|
||||
static const QString constSecretKey=QLatin1String("0753a75ccded9b17b872744d4bb60b35");
|
||||
static const QString constUrl=QLatin1String("http://ws.audioscrobbler.com/2.0/");
|
||||
static const int constMaxBatchSize=50;
|
||||
|
||||
GLOBAL_STATIC(Scrobbler, instance)
|
||||
@@ -208,10 +207,7 @@ void Scrobbler::setActive()
|
||||
} else {
|
||||
disconnect(MPDStatus::self(), SIGNAL(updated()), this, SLOT(mpdStateUpdated()));
|
||||
disconnect(MPDConnection::self(), SIGNAL(currentSongUpdated(Song)), this, SLOT(setSong(Song)));
|
||||
songQueue.clear();
|
||||
lastScrobbledSongs.clear();
|
||||
saveCache();
|
||||
cancelJobs();
|
||||
reset();
|
||||
}
|
||||
|
||||
if (!isAuthenticated()) {
|
||||
@@ -229,21 +225,25 @@ void Scrobbler::loadSettings()
|
||||
// password=cfg.get("password", password);
|
||||
sessionKey=cfg.get("sessionKey", sessionKey);
|
||||
scrobblingEnabled=cfg.get("enabled", scrobblingEnabled);
|
||||
DBUG << userName << sessionKey << scrobblingEnabled;
|
||||
scrobbler=cfg.get("scrobbler", scrobbler);
|
||||
DBUG << scrobbler << userName << sessionKey << scrobblingEnabled;
|
||||
emit authenticated(isAuthenticated());
|
||||
emit enabled(isEnabled());
|
||||
setActive();
|
||||
}
|
||||
|
||||
void Scrobbler::setDetails(const QString &u, const QString &p)
|
||||
void Scrobbler::setDetails(const QString &s, const QString &u, const QString &p)
|
||||
{
|
||||
if (u!=userName || p!=password) {
|
||||
if (u!=scrobbler || u!=userName || p!=password) {
|
||||
DBUG << "details changed";
|
||||
Configuration cfg(constSettingsGroup);
|
||||
|
||||
scrobbler=s;
|
||||
userName=u;
|
||||
password=p;
|
||||
sessionKey=QString();
|
||||
reset();
|
||||
cfg.set("scrobbler", scrobbler);
|
||||
cfg.set("userName", userName);
|
||||
// cfg.set("password", password);
|
||||
setActive();
|
||||
@@ -334,7 +334,7 @@ void Scrobbler::scrobbleNowPlaying()
|
||||
params["sk"] = sessionKey;
|
||||
sign(params);
|
||||
DBUG << currentSong.title << currentSong.artist;
|
||||
QNetworkReply *job=NetworkAccessManager::self()->postFormData(QUrl(constUrl), format(params));
|
||||
QNetworkReply *job=NetworkAccessManager::self()->postFormData(scrobblerUrl(), format(params));
|
||||
connect(job, SIGNAL(finished()), this, SLOT(nowPlayingResp()));
|
||||
nowPlayingSent=true;
|
||||
}
|
||||
@@ -399,7 +399,7 @@ void Scrobbler::scrobbleQueued()
|
||||
}
|
||||
params["sk"] = sessionKey;
|
||||
sign(params);
|
||||
scrobbleJob=NetworkAccessManager::self()->postFormData(QUrl(constUrl), format(params));
|
||||
scrobbleJob=NetworkAccessManager::self()->postFormData(scrobblerUrl(), format(params));
|
||||
connect(scrobbleJob, SIGNAL(finished()), this, SLOT(scrobbleFinished()));
|
||||
}
|
||||
}
|
||||
@@ -454,7 +454,7 @@ void Scrobbler::authenticate()
|
||||
DBUG << "no login details";
|
||||
return;
|
||||
}
|
||||
QUrl url(constUrl);
|
||||
QUrl url=scrobblerUrl();
|
||||
QMap<QString, QString> params;
|
||||
params["method"] = "auth.getMobileSession";
|
||||
params["username"] = userName;
|
||||
@@ -659,3 +659,43 @@ void Scrobbler::cancelJobs()
|
||||
scrobbleJob=0;
|
||||
}
|
||||
}
|
||||
|
||||
void Scrobbler::reset()
|
||||
{
|
||||
songQueue.clear();
|
||||
lastScrobbledSongs.clear();
|
||||
saveCache();
|
||||
cancelJobs();
|
||||
}
|
||||
|
||||
void Scrobbler::loadScrobblers()
|
||||
{
|
||||
if (scrobblers.isEmpty()) {
|
||||
QFile f(CANTATA_SYS_CONFIG_DIR+"scrobblers.xml");
|
||||
if (f.open(QIODevice::ReadOnly)) {
|
||||
QXmlStreamReader doc(&f);
|
||||
while (!doc.atEnd()) {
|
||||
doc.readNext();
|
||||
if (doc.isStartElement() && QLatin1String("scrobbler")==doc.name()) {
|
||||
QString name=doc.attributes().value("name").toString();
|
||||
QString url=doc.attributes().value("url").toString();
|
||||
if (!name.isEmpty() && !url.isEmpty()) {
|
||||
scrobblers.insert(name, QUrl(url));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
QUrl Scrobbler::scrobblerUrl() const
|
||||
{
|
||||
if (scrobblers.isEmpty()) {
|
||||
return QString();
|
||||
}
|
||||
|
||||
if (!scrobblers.contains(scrobbler)) {
|
||||
return scrobblers.constBegin().value();
|
||||
}
|
||||
return scrobblers[scrobbler];
|
||||
}
|
||||
|
||||
@@ -29,9 +29,11 @@
|
||||
#define SCROBBLER_H
|
||||
|
||||
#include <QString>
|
||||
#include <QStringList>
|
||||
#include <QQueue>
|
||||
#include <QObject>
|
||||
#include <QUrl>
|
||||
#include <QMap>
|
||||
#include <time.h>
|
||||
|
||||
class QTimer;
|
||||
@@ -66,12 +68,14 @@ public:
|
||||
Scrobbler();
|
||||
~Scrobbler();
|
||||
|
||||
QStringList availableScrobblers() { loadScrobblers(); return scrobblers.keys(); }
|
||||
void stop();
|
||||
bool isEnabled() const { return scrobblingEnabled; }
|
||||
bool haveLoginDetails() const { return !userName.isEmpty() && !password.isEmpty(); }
|
||||
void setDetails(const QString &u, const QString &p);
|
||||
void setDetails(const QString &s, const QString &u, const QString &p);
|
||||
const QString & user() const { return userName; }
|
||||
const QString & pass() const { return password; }
|
||||
const QString & activeScrobbler() const { return scrobbler; }
|
||||
bool isAuthenticated() const { return !sessionKey.isEmpty(); }
|
||||
|
||||
Q_SIGNALS:
|
||||
@@ -102,15 +106,17 @@ private:
|
||||
void loadCache();
|
||||
void saveCache();
|
||||
void cancelJobs();
|
||||
void reset();
|
||||
void loadScrobblers();
|
||||
QUrl scrobblerUrl() const;
|
||||
|
||||
private:
|
||||
bool scrobblingEnabled;
|
||||
QMap<QString, QUrl> scrobblers;
|
||||
QString scrobbler;
|
||||
QString userName;
|
||||
QString password;
|
||||
QString sessionKey;
|
||||
QString nowPlayingUrl;
|
||||
QString scrobbleUrl;
|
||||
QQueue<Track> songQueue;
|
||||
QQueue<Track> lastScrobbledSongs;
|
||||
Track currentSong;
|
||||
|
||||
5
scrobbling/scrobblers.xml
Normal file
5
scrobbling/scrobblers.xml
Normal file
@@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<scrobblers>
|
||||
<scrobbler name="Last.fm" url="http://ws.audioscrobbler.com/2.0/"/>
|
||||
<scrobbler name="Libre.fm" url="http://turtle.libre.fm"/>
|
||||
</scrobblers>
|
||||
@@ -41,6 +41,14 @@ ScrobblingSettings::ScrobblingSettings(QWidget *parent)
|
||||
connect(enableScrobbling, SIGNAL(toggled(bool)), Scrobbler::self(), SLOT(setEnabled(bool)));
|
||||
connect(Scrobbler::self(), SIGNAL(enabled(bool)), enableScrobbling, SLOT(setChecked(bool)));
|
||||
loginButton->setEnabled(false);
|
||||
|
||||
QStringList scrobblers=Scrobbler::self()->availableScrobblers();
|
||||
scrobblers.sort();
|
||||
foreach (const QString &s, scrobblers) {
|
||||
scrobbler->addItem(s);
|
||||
}
|
||||
scrobbler->setVisible(scrobbler->count()>1);
|
||||
scrobblerLabel->setVisible(scrobbler->count()>1);
|
||||
}
|
||||
|
||||
void ScrobblingSettings::load()
|
||||
@@ -48,6 +56,13 @@ void ScrobblingSettings::load()
|
||||
showStatus(Scrobbler::self()->isAuthenticated());
|
||||
user->setText(Scrobbler::self()->user().trimmed());
|
||||
pass->setText(Scrobbler::self()->pass().trimmed());
|
||||
QString s=Scrobbler::self()->activeScrobbler();
|
||||
for (int i=0; i<scrobbler->count(); ++i) {
|
||||
if (scrobbler->itemText(i)==s) {
|
||||
scrobbler->setCurrentIndex(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
enableScrobbling->setChecked(Scrobbler::self()->isEnabled());
|
||||
controlLoginButton();
|
||||
}
|
||||
@@ -56,7 +71,7 @@ void ScrobblingSettings::save()
|
||||
{
|
||||
messageWidget->close();
|
||||
loginStatusLabel->setText(i18n("Authenticating..."));
|
||||
Scrobbler::self()->setDetails(user->text().trimmed(), pass->text().trimmed());
|
||||
Scrobbler::self()->setDetails(scrobbler->currentText(), user->text().trimmed(), pass->text().trimmed());
|
||||
}
|
||||
|
||||
void ScrobblingSettings::showStatus(bool status)
|
||||
|
||||
@@ -11,7 +11,32 @@
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QFormLayout" name="formLayout">
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item row="0" column="0">
|
||||
<widget class="BuddyLabel" name="scrobblerLabel">
|
||||
<property name="text">
|
||||
<string>Scrobble to:</string>
|
||||
</property>
|
||||
<property name="buddy">
|
||||
<cstring>scrobbler</cstring>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QComboBox" name="scrobbler"/>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="BuddyLabel" name="label_2">
|
||||
<property name="text">
|
||||
<string>Username:</string>
|
||||
@@ -21,10 +46,10 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<item row="1" column="1">
|
||||
<widget class="LineEdit" name="user"/>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<item row="2" column="0">
|
||||
<widget class="BuddyLabel" name="label_3">
|
||||
<property name="text">
|
||||
<string>Password:</string>
|
||||
@@ -34,14 +59,14 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<item row="2" column="1">
|
||||
<widget class="LineEdit" name="pass">
|
||||
<property name="echoMode">
|
||||
<enum>QLineEdit::Password</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<item row="3" column="0">
|
||||
<widget class="BuddyLabel" name="label_5">
|
||||
<property name="text">
|
||||
<string>Status:</string>
|
||||
@@ -51,7 +76,7 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<item row="3" column="1">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<widget class="QLabel" name="loginStatusLabel">
|
||||
@@ -81,7 +106,7 @@
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="3" column="0" colspan="2">
|
||||
<item row="4" column="0" colspan="2">
|
||||
<widget class="MessageWidget" name="messageWidget">
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::StyledPanel</enum>
|
||||
@@ -91,14 +116,14 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="0" colspan="2">
|
||||
<item row="5" column="0" colspan="2">
|
||||
<widget class="QCheckBox" name="enableScrobbling">
|
||||
<property name="text">
|
||||
<string>Scrobble tracks</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="5" column="0">
|
||||
<item row="6" column="0">
|
||||
<spacer name="verticalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
|
||||
Reference in New Issue
Block a user