Subsonic: Handle album id as string
This commit is contained in:
parent
c4be310081
commit
d4373aae93
|
@ -262,9 +262,9 @@ void SubsonicRequest::AlbumsReplyReceived(QNetworkReply *reply, const int offset
|
|||
continue;
|
||||
}
|
||||
|
||||
qint64 album_id = json_obj["id"].toString().toLongLong();
|
||||
if (album_id == 0) {
|
||||
album_id = json_obj["id"].toInt();
|
||||
QString album_id = json_obj["id"].toString();
|
||||
if (album_id.isEmpty()) {
|
||||
album_id = QString::number(json_obj["id"].toInt());
|
||||
}
|
||||
|
||||
QString artist = json_obj["artist"].toString();
|
||||
|
@ -300,7 +300,7 @@ void SubsonicRequest::AlbumsFinishCheck(const int offset, const int albums_recei
|
|||
|
||||
if (albums_requests_queue_.isEmpty() && albums_requests_active_ <= 0) { // Albums list is finished, get songs for all albums.
|
||||
|
||||
QHash<int, Request> ::iterator i;
|
||||
QHash<QString, Request> ::iterator i;
|
||||
for (i = album_songs_requests_pending_.begin() ; i != album_songs_requests_pending_.end() ; ++i) {
|
||||
Request request = i.value();
|
||||
AddAlbumSongsRequest(request.artist_id, request.album_id, request.album_artist);
|
||||
|
@ -319,7 +319,7 @@ void SubsonicRequest::AlbumsFinishCheck(const int offset, const int albums_recei
|
|||
|
||||
}
|
||||
|
||||
void SubsonicRequest::AddAlbumSongsRequest(const qint64 artist_id, const qint64 album_id, const QString &album_artist, const int offset) {
|
||||
void SubsonicRequest::AddAlbumSongsRequest(const qint64 artist_id, const QString &album_id, const QString &album_artist, const int offset) {
|
||||
|
||||
Request request;
|
||||
request.artist_id = artist_id;
|
||||
|
@ -338,7 +338,7 @@ void SubsonicRequest::FlushAlbumSongsRequests() {
|
|||
|
||||
Request request = album_songs_requests_queue_.dequeue();
|
||||
++album_songs_requests_active_;
|
||||
ParamList params = ParamList() << Param("id", QString::number(request.album_id));
|
||||
ParamList params = ParamList() << Param("id", request.album_id);
|
||||
QNetworkReply *reply = CreateGetRequest(QString("getAlbum"), params);
|
||||
replies_ << reply;
|
||||
NewClosure(reply, SIGNAL(finished()), this, SLOT(AlbumSongsReplyReceived(QNetworkReply*, const qint64, const qint64, const QString&)), reply, request.artist_id, request.album_id, request.album_artist);
|
||||
|
@ -486,10 +486,8 @@ int SubsonicRequest::ParseSong(Song &song, const QJsonObject &json_obj, const qi
|
|||
!json_obj.contains("id") ||
|
||||
!json_obj.contains("title") ||
|
||||
!json_obj.contains("size") ||
|
||||
!json_obj.contains("contentType") ||
|
||||
!json_obj.contains("suffix") ||
|
||||
!json_obj.contains("duration") ||
|
||||
!json_obj.contains("bitRate") ||
|
||||
!json_obj.contains("type")
|
||||
) {
|
||||
Error("Invalid Json reply, song is missing one or more values.", json_obj);
|
||||
|
@ -499,10 +497,10 @@ int SubsonicRequest::ParseSong(Song &song, const QJsonObject &json_obj, const qi
|
|||
qint64 song_id = json_obj["id"].toString().toLongLong();
|
||||
if (song_id == 0) song_id = json_obj["id"].toInt();
|
||||
|
||||
qint64 album_id = -1;
|
||||
QString album_id;
|
||||
if (json_obj.contains("albumId")) {
|
||||
album_id = json_obj["albumId"].toString().toLongLong();
|
||||
if (album_id == 0) album_id = json_obj["albumId"].toInt();
|
||||
album_id = json_obj["albumId"].toString();
|
||||
if (album_id.isEmpty()) album_id = json_obj["albumId"].toInt();
|
||||
}
|
||||
|
||||
qint64 artist_id = -1;
|
||||
|
@ -524,9 +522,17 @@ int SubsonicRequest::ParseSong(Song &song, const QJsonObject &json_obj, const qi
|
|||
}
|
||||
|
||||
int size = json_obj["size"].toInt();
|
||||
QString mimetype = json_obj["contentType"].toString();
|
||||
quint64 duration = json_obj["duration"].toInt() * kNsecPerSec;
|
||||
int bitrate = json_obj["bitRate"].toInt();
|
||||
|
||||
int bitrate = 0;
|
||||
if (json_obj.contains("bitRate")) {
|
||||
bitrate = json_obj["bitRate"].toInt();
|
||||
}
|
||||
|
||||
QString mimetype;
|
||||
if (json_obj.contains("contentType")) {
|
||||
mimetype = json_obj["contentType"].toString();
|
||||
}
|
||||
|
||||
int year = 0;
|
||||
if (json_obj.contains("year")) year = json_obj["year"].toInt();
|
||||
|
@ -543,10 +549,10 @@ int SubsonicRequest::ParseSong(Song &song, const QJsonObject &json_obj, const qi
|
|||
QString genre;
|
||||
if (json_obj.contains("genre")) genre = json_obj["genre"].toString();
|
||||
|
||||
int cover_art_id = -1;
|
||||
QString cover_art_id;
|
||||
if (json_obj.contains("coverArt")) {
|
||||
cover_art_id = json_obj["coverArt"].toString().toInt();
|
||||
if (cover_art_id == 0) cover_art_id = json_obj["coverArt"].toInt();
|
||||
cover_art_id = json_obj["coverArt"].toString();
|
||||
if (cover_art_id.isEmpty()) cover_art_id = QString::number(json_obj["coverArt"].toInt());
|
||||
}
|
||||
|
||||
QUrl url;
|
||||
|
@ -554,20 +560,21 @@ int SubsonicRequest::ParseSong(Song &song, const QJsonObject &json_obj, const qi
|
|||
url.setPath(QString::number(song_id));
|
||||
|
||||
QUrl cover_url;
|
||||
if (cover_art_id != -1) {
|
||||
const ParamList params = ParamList() << Param("id", QString::number(cover_art_id));
|
||||
cover_url = CreateUrl("getCoverArt", params);
|
||||
if (!cover_art_id.isEmpty()) {
|
||||
cover_url = CreateUrl("getCoverArt", ParamList() << Param("id", cover_art_id));
|
||||
}
|
||||
|
||||
Song::FileType filetype(Song::FileType_Stream);
|
||||
QMimeDatabase mimedb;
|
||||
for (QString suffix : mimedb.mimeTypeForName(mimetype.toUtf8()).suffixes()) {
|
||||
filetype = Song::FiletypeByExtension(suffix);
|
||||
if (filetype != Song::FileType_Unknown) break;
|
||||
}
|
||||
if (filetype == Song::FileType_Unknown) {
|
||||
qLog(Debug) << "Subsonic: Unknown mimetype" << mimetype;
|
||||
filetype = Song::FileType_Stream;
|
||||
if (!mimetype.isEmpty()) {
|
||||
QMimeDatabase mimedb;
|
||||
for (QString suffix : mimedb.mimeTypeForName(mimetype.toUtf8()).suffixes()) {
|
||||
filetype = Song::FiletypeByExtension(suffix);
|
||||
if (filetype != Song::FileType_Unknown) break;
|
||||
}
|
||||
if (filetype == Song::FileType_Unknown) {
|
||||
qLog(Debug) << "Subsonic: Unknown mimetype" << mimetype;
|
||||
filetype = Song::FileType_Stream;
|
||||
}
|
||||
}
|
||||
|
||||
song.set_source(Song::Source_Subsonic);
|
||||
|
|
|
@ -75,7 +75,7 @@ class SubsonicRequest : public SubsonicBaseRequest {
|
|||
|
||||
struct Request {
|
||||
qint64 artist_id = 0;
|
||||
qint64 album_id = 0;
|
||||
QString album_id;
|
||||
qint64 song_id = 0;
|
||||
int offset = 0;
|
||||
int size = 0;
|
||||
|
@ -94,7 +94,7 @@ class SubsonicRequest : public SubsonicBaseRequest {
|
|||
void AlbumsFinishCheck(const int offset = 0, const int albums_received = 0);
|
||||
void SongsFinishCheck();
|
||||
|
||||
void AddAlbumSongsRequest(const qint64 artist_id, const qint64 album_id, const QString &album_artist, const int offset = 0);
|
||||
void AddAlbumSongsRequest(const qint64 artist_id, const QString &album_id, const QString &album_artist, const int offset = 0);
|
||||
void FlushAlbumSongsRequests();
|
||||
|
||||
int ParseSong(Song &song, const QJsonObject &json_obj, const qint64 artist_id_requested = 0, const qint64 album_id_requested = 0, const QString &album_artist = QString());
|
||||
|
@ -124,7 +124,7 @@ class SubsonicRequest : public SubsonicBaseRequest {
|
|||
QQueue<Request> album_songs_requests_queue_;
|
||||
QQueue<AlbumCoverRequest> album_cover_requests_queue_;
|
||||
|
||||
QHash<int, Request> album_songs_requests_pending_;
|
||||
QHash<QString, Request> album_songs_requests_pending_;
|
||||
QMultiMap<QString, Song*> album_covers_requests_sent_;
|
||||
|
||||
int albums_requests_active_;
|
||||
|
|
Loading…
Reference in New Issue