mirror of
https://github.com/clementine-player/Clementine
synced 2025-02-07 06:35:15 +01:00
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) {
|
||||
QUrl url = service->BuildRequestUrl("getAlbum");
|
||||
url.addQueryItem("id", id);
|
||||
if (service->IsAmpache()) {
|
||||
url.addQueryItem("ampache", "1");
|
||||
}
|
||||
QNetworkReply* reply = Send(network, url, usesslv3);
|
||||
WaitForSignal(reply, SIGNAL(finished()));
|
||||
reply->deleteLater();
|
||||
@ -221,6 +224,11 @@ void SubsonicDynamicPlaylist::GetAlbum(SubsonicService* service,
|
||||
song.set_mtime(0);
|
||||
song.set_ctime(0);
|
||||
|
||||
if (reader.attributes().hasAttribute("playCount")) {
|
||||
song.set_playcount(
|
||||
reader.attributes().value("playCount").toString().toInt());
|
||||
}
|
||||
|
||||
list << std::shared_ptr<PlaylistItem>(
|
||||
new InternetPlaylistItem(service, song));
|
||||
|
||||
|
@ -74,7 +74,8 @@ SubsonicService::SubsonicService(Application* app, InternetModel* parent)
|
||||
library_sort_model_(new QSortFilterProxyModel(this)),
|
||||
total_song_count_(0),
|
||||
login_state_(LoginState_OtherError),
|
||||
redirect_count_(0) {
|
||||
redirect_count_(0),
|
||||
is_ampache_(false) {
|
||||
app_->player()->RegisterUrlHandler(url_handler_);
|
||||
|
||||
connect(scanner_, SIGNAL(ScanFinished()), SLOT(ReloadDatabaseFinished()));
|
||||
@ -203,6 +204,8 @@ bool SubsonicService::IsConfigured() const {
|
||||
!password_.isEmpty();
|
||||
}
|
||||
|
||||
bool SubsonicService::IsAmpache() const { return is_ampache_; }
|
||||
|
||||
void SubsonicService::Login() {
|
||||
// Recreate fresh network state, otherwise old HTTPS settings seem to get
|
||||
// reused
|
||||
@ -324,6 +327,7 @@ void SubsonicService::OnPingFinished(QNetworkReply* reply) {
|
||||
} else {
|
||||
QXmlStreamReader reader(reply);
|
||||
reader.readNextStartElement();
|
||||
is_ampache_ = (reader.attributes().value("type") == "ampache");
|
||||
QStringRef status = reader.attributes().value("status");
|
||||
int http_status_code =
|
||||
reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
|
||||
@ -540,6 +544,12 @@ void SubsonicLibraryScanner::OnGetAlbumFinished(QNetworkReply* reply) {
|
||||
song.set_directory_id(0);
|
||||
song.set_mtime(0);
|
||||
song.set_ctime(0);
|
||||
|
||||
if (reader.attributes().hasAttribute("playCount")) {
|
||||
song.set_playcount(
|
||||
reader.attributes().value("playCount").toString().toInt());
|
||||
}
|
||||
|
||||
songs_ << song;
|
||||
reader.skipCurrentElement();
|
||||
}
|
||||
@ -569,6 +579,9 @@ void SubsonicLibraryScanner::GetAlbumList(int offset) {
|
||||
void SubsonicLibraryScanner::GetAlbum(const QString& id) {
|
||||
QUrl url = service_->BuildRequestUrl("getAlbum");
|
||||
url.addQueryItem("id", id);
|
||||
if (service_->IsAmpache()) {
|
||||
url.addQueryItem("ampache", "1");
|
||||
}
|
||||
QNetworkReply* reply = service_->Send(url);
|
||||
NewClosure(reply, SIGNAL(finished()), this,
|
||||
SLOT(OnGetAlbumFinished(QNetworkReply*)), reply);
|
||||
|
@ -87,6 +87,7 @@ class SubsonicService : public InternetService {
|
||||
typedef QMap<QString, QString> RequestOptions;
|
||||
|
||||
bool IsConfigured() const;
|
||||
bool IsAmpache() const;
|
||||
|
||||
QStandardItem* CreateRootItem();
|
||||
void LazyPopulate(QStandardItem* item);
|
||||
@ -155,6 +156,7 @@ signals:
|
||||
LoginState login_state_;
|
||||
QString working_server_; // The actual server, possibly post-redirect
|
||||
int redirect_count_;
|
||||
bool is_ampache_;
|
||||
|
||||
private slots:
|
||||
void UpdateTotalSongCount(int count);
|
||||
|
Loading…
x
Reference in New Issue
Block a user