mirror of
https://github.com/clementine-player/Clementine
synced 2025-01-31 03:27:40 +01:00
Load subsonic library recursively
This commit is contained in:
parent
349231793f
commit
49d27b0bfe
@ -25,6 +25,8 @@ const char* SubsonicService::kApiClientName = "Clementine";
|
||||
const char* SubsonicService::kSongsTable = "subsonic_songs";
|
||||
const char* SubsonicService::kFtsTable = "subsonic_songs_fts";
|
||||
|
||||
const int SubsonicService::kChunkSize = 1000;
|
||||
|
||||
SubsonicService::SubsonicService(Application* app, InternetModel *parent)
|
||||
: InternetService(kServiceName, app, parent, parent),
|
||||
network_(new QNetworkAccessManager(this)),
|
||||
@ -126,6 +128,7 @@ void SubsonicService::GetIndexes()
|
||||
|
||||
void SubsonicService::GetMusicDirectory(const QString &id)
|
||||
{
|
||||
++directory_count_;
|
||||
QUrl url = BuildRequestUrl("getMusicDirectory");
|
||||
url.addQueryItem("id", id);
|
||||
Send(url, SLOT(onGetMusicDirectoryFinished()));
|
||||
@ -171,14 +174,16 @@ void SubsonicService::ReadIndex(QXmlStreamReader *reader)
|
||||
void SubsonicService::ReadArtist(QXmlStreamReader *reader)
|
||||
{
|
||||
Q_ASSERT(reader->name() == "artist");
|
||||
// TODO: recurse into directory
|
||||
QString id = reader->attributes().value("id").toString();
|
||||
GetMusicDirectory(id);
|
||||
reader->skipCurrentElement();
|
||||
}
|
||||
|
||||
void SubsonicService::ReadAlbum(QXmlStreamReader *reader)
|
||||
{
|
||||
Q_ASSERT(reader->name() == "child");
|
||||
// TODO: recurse into directory
|
||||
QString id = reader->attributes().value("id").toString();
|
||||
GetMusicDirectory(id);
|
||||
reader->skipCurrentElement();
|
||||
}
|
||||
|
||||
@ -286,10 +291,13 @@ void SubsonicService::onGetIndexesFinished()
|
||||
return;
|
||||
}
|
||||
|
||||
directory_count_ = 0;
|
||||
processed_directory_count_ = 0;
|
||||
new_songs_ = SongList();
|
||||
|
||||
reader.readNextStartElement();
|
||||
Q_ASSERT(reader.name() == "indexes");
|
||||
// TODO: start loading library data
|
||||
SongList songs;
|
||||
while (reader.readNextStartElement())
|
||||
{
|
||||
if (reader.name() == "index")
|
||||
@ -298,7 +306,7 @@ void SubsonicService::onGetIndexesFinished()
|
||||
}
|
||||
else if (reader.name() == "child" && reader.attributes().value("isVideo") == "false")
|
||||
{
|
||||
songs << ReadTrack(&reader);
|
||||
new_songs_ << ReadTrack(&reader);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -306,7 +314,10 @@ void SubsonicService::onGetIndexesFinished()
|
||||
}
|
||||
}
|
||||
|
||||
library_backend_->AddOrUpdateSongs(songs);
|
||||
if (new_songs_.size() >= kChunkSize || directory_count_ == processed_directory_count_) {
|
||||
library_backend_->AddOrUpdateSongs(new_songs_);
|
||||
new_songs_ = SongList();
|
||||
}
|
||||
}
|
||||
|
||||
void SubsonicService::onGetMusicDirectoryFinished()
|
||||
@ -316,6 +327,8 @@ void SubsonicService::onGetMusicDirectoryFinished()
|
||||
reply->deleteLater();
|
||||
QXmlStreamReader reader(reply);
|
||||
|
||||
++processed_directory_count_;
|
||||
|
||||
reader.readNextStartElement();
|
||||
Q_ASSERT(reader.name() == "subsonic-response");
|
||||
if (reader.attributes().value("status") != "ok")
|
||||
@ -335,11 +348,16 @@ void SubsonicService::onGetMusicDirectoryFinished()
|
||||
}
|
||||
else if (reader.attributes().value("isVideo") == "false")
|
||||
{
|
||||
ReadTrack(&reader);
|
||||
new_songs_ << ReadTrack(&reader);
|
||||
}
|
||||
else
|
||||
{
|
||||
reader.skipCurrentElement();
|
||||
}
|
||||
}
|
||||
|
||||
if (new_songs_.size() >= kChunkSize || directory_count_ == processed_directory_count_) {
|
||||
library_backend_->AddOrUpdateSongs(new_songs_);
|
||||
new_songs_ = SongList();
|
||||
}
|
||||
}
|
||||
|
@ -77,6 +77,8 @@ class SubsonicService : public InternetService
|
||||
static const char* kSongsTable;
|
||||
static const char* kFtsTable;
|
||||
|
||||
static const int kChunkSize;
|
||||
|
||||
signals:
|
||||
void LoginStateChanged(SubsonicService::LoginState newstate);
|
||||
|
||||
@ -107,6 +109,10 @@ class SubsonicService : public InternetService
|
||||
|
||||
LoginState login_state_;
|
||||
|
||||
int directory_count_;
|
||||
int processed_directory_count_;
|
||||
SongList new_songs_;
|
||||
|
||||
private slots:
|
||||
void onLoginStateChanged(SubsonicService::LoginState newstate);
|
||||
void onPingFinished();
|
||||
|
Loading…
x
Reference in New Issue
Block a user