Add ampache=1 to getAlbum for playcounts
- Ampache recently added support for returning playcounts, if the client
reports that it knows it's talking to an ampache server:
1aaf01ae98
- This checks the type attribute on the ping request to see if
Clementine is talking to an Ampache server, and if so, it adds
ampache=1 to getAlbum requests, and uses the returned playcounts.
This commit is contained in:
parent
d47ee24962
commit
ee7c9527a0
@ -158,6 +158,9 @@ void SubsonicDynamicPlaylist::GetAlbum(SubsonicService* service,
|
|||||||
const bool usesslv3) {
|
const bool usesslv3) {
|
||||||
QUrl url = service->BuildRequestUrl("getAlbum");
|
QUrl url = service->BuildRequestUrl("getAlbum");
|
||||||
url.addQueryItem("id", id);
|
url.addQueryItem("id", id);
|
||||||
|
if (service->IsAmpache()) {
|
||||||
|
url.addQueryItem("ampache", "1");
|
||||||
|
}
|
||||||
QNetworkReply* reply = Send(network, url, usesslv3);
|
QNetworkReply* reply = Send(network, url, usesslv3);
|
||||||
WaitForSignal(reply, SIGNAL(finished()));
|
WaitForSignal(reply, SIGNAL(finished()));
|
||||||
reply->deleteLater();
|
reply->deleteLater();
|
||||||
@ -221,6 +224,11 @@ void SubsonicDynamicPlaylist::GetAlbum(SubsonicService* service,
|
|||||||
song.set_mtime(0);
|
song.set_mtime(0);
|
||||||
song.set_ctime(0);
|
song.set_ctime(0);
|
||||||
|
|
||||||
|
if (reader.attributes().hasAttribute("playCount")) {
|
||||||
|
song.set_playcount(
|
||||||
|
reader.attributes().value("playCount").toString().toInt());
|
||||||
|
}
|
||||||
|
|
||||||
list << std::shared_ptr<PlaylistItem>(
|
list << std::shared_ptr<PlaylistItem>(
|
||||||
new InternetPlaylistItem(service, song));
|
new InternetPlaylistItem(service, song));
|
||||||
|
|
||||||
|
@ -74,7 +74,8 @@ SubsonicService::SubsonicService(Application* app, InternetModel* parent)
|
|||||||
library_sort_model_(new QSortFilterProxyModel(this)),
|
library_sort_model_(new QSortFilterProxyModel(this)),
|
||||||
total_song_count_(0),
|
total_song_count_(0),
|
||||||
login_state_(LoginState_OtherError),
|
login_state_(LoginState_OtherError),
|
||||||
redirect_count_(0) {
|
redirect_count_(0),
|
||||||
|
is_ampache_(false) {
|
||||||
app_->player()->RegisterUrlHandler(url_handler_);
|
app_->player()->RegisterUrlHandler(url_handler_);
|
||||||
|
|
||||||
connect(scanner_, SIGNAL(ScanFinished()), SLOT(ReloadDatabaseFinished()));
|
connect(scanner_, SIGNAL(ScanFinished()), SLOT(ReloadDatabaseFinished()));
|
||||||
@ -203,6 +204,8 @@ bool SubsonicService::IsConfigured() const {
|
|||||||
!password_.isEmpty();
|
!password_.isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool SubsonicService::IsAmpache() const { return is_ampache_; }
|
||||||
|
|
||||||
void SubsonicService::Login() {
|
void SubsonicService::Login() {
|
||||||
// Recreate fresh network state, otherwise old HTTPS settings seem to get
|
// Recreate fresh network state, otherwise old HTTPS settings seem to get
|
||||||
// reused
|
// reused
|
||||||
@ -324,6 +327,7 @@ void SubsonicService::OnPingFinished(QNetworkReply* reply) {
|
|||||||
} else {
|
} else {
|
||||||
QXmlStreamReader reader(reply);
|
QXmlStreamReader reader(reply);
|
||||||
reader.readNextStartElement();
|
reader.readNextStartElement();
|
||||||
|
is_ampache_ = (reader.attributes().value("type") == "ampache");
|
||||||
QStringRef status = reader.attributes().value("status");
|
QStringRef status = reader.attributes().value("status");
|
||||||
int http_status_code =
|
int http_status_code =
|
||||||
reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
|
reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
|
||||||
@ -540,6 +544,12 @@ void SubsonicLibraryScanner::OnGetAlbumFinished(QNetworkReply* reply) {
|
|||||||
song.set_directory_id(0);
|
song.set_directory_id(0);
|
||||||
song.set_mtime(0);
|
song.set_mtime(0);
|
||||||
song.set_ctime(0);
|
song.set_ctime(0);
|
||||||
|
|
||||||
|
if (reader.attributes().hasAttribute("playCount")) {
|
||||||
|
song.set_playcount(
|
||||||
|
reader.attributes().value("playCount").toString().toInt());
|
||||||
|
}
|
||||||
|
|
||||||
songs_ << song;
|
songs_ << song;
|
||||||
reader.skipCurrentElement();
|
reader.skipCurrentElement();
|
||||||
}
|
}
|
||||||
@ -569,6 +579,9 @@ void SubsonicLibraryScanner::GetAlbumList(int offset) {
|
|||||||
void SubsonicLibraryScanner::GetAlbum(const QString& id) {
|
void SubsonicLibraryScanner::GetAlbum(const QString& id) {
|
||||||
QUrl url = service_->BuildRequestUrl("getAlbum");
|
QUrl url = service_->BuildRequestUrl("getAlbum");
|
||||||
url.addQueryItem("id", id);
|
url.addQueryItem("id", id);
|
||||||
|
if (service_->IsAmpache()) {
|
||||||
|
url.addQueryItem("ampache", "1");
|
||||||
|
}
|
||||||
QNetworkReply* reply = service_->Send(url);
|
QNetworkReply* reply = service_->Send(url);
|
||||||
NewClosure(reply, SIGNAL(finished()), this,
|
NewClosure(reply, SIGNAL(finished()), this,
|
||||||
SLOT(OnGetAlbumFinished(QNetworkReply*)), reply);
|
SLOT(OnGetAlbumFinished(QNetworkReply*)), reply);
|
||||||
|
@ -87,6 +87,7 @@ class SubsonicService : public InternetService {
|
|||||||
typedef QMap<QString, QString> RequestOptions;
|
typedef QMap<QString, QString> RequestOptions;
|
||||||
|
|
||||||
bool IsConfigured() const;
|
bool IsConfigured() const;
|
||||||
|
bool IsAmpache() const;
|
||||||
|
|
||||||
QStandardItem* CreateRootItem();
|
QStandardItem* CreateRootItem();
|
||||||
void LazyPopulate(QStandardItem* item);
|
void LazyPopulate(QStandardItem* item);
|
||||||
@ -155,6 +156,7 @@ signals:
|
|||||||
LoginState login_state_;
|
LoginState login_state_;
|
||||||
QString working_server_; // The actual server, possibly post-redirect
|
QString working_server_; // The actual server, possibly post-redirect
|
||||||
int redirect_count_;
|
int redirect_count_;
|
||||||
|
bool is_ampache_;
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void UpdateTotalSongCount(int count);
|
void UpdateTotalSongCount(int count);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user