Use QStringLiteral
This commit is contained in:
@@ -142,7 +142,7 @@ QByteArray LastFMImport::GetReplyData(QNetworkReply *reply) {
|
||||
else {
|
||||
if (reply->error() != QNetworkReply::NoError && reply->error() < 200) {
|
||||
// This is a network error, there is nothing more to do.
|
||||
Error(QString("%1 (%2)").arg(reply->errorString()).arg(reply->error()));
|
||||
Error(QStringLiteral("%1 (%2)").arg(reply->errorString()).arg(reply->error()));
|
||||
}
|
||||
else {
|
||||
QString error;
|
||||
@@ -152,18 +152,18 @@ QByteArray LastFMImport::GetReplyData(QNetworkReply *reply) {
|
||||
QJsonDocument json_doc = QJsonDocument::fromJson(data, &json_error);
|
||||
if (json_error.error == QJsonParseError::NoError && !json_doc.isEmpty() && json_doc.isObject()) {
|
||||
QJsonObject json_obj = json_doc.object();
|
||||
if (json_obj.contains("error") && json_obj.contains("message")) {
|
||||
int error_code = json_obj["error"].toInt();
|
||||
QString error_message = json_obj["message"].toString();
|
||||
error = QString("%1 (%2)").arg(error_message).arg(error_code);
|
||||
if (json_obj.contains(QStringLiteral("error")) && json_obj.contains(QStringLiteral("message"))) {
|
||||
int error_code = json_obj[QStringLiteral("error")].toInt();
|
||||
QString error_message = json_obj[QStringLiteral("message")].toString();
|
||||
error = QStringLiteral("%1 (%2)").arg(error_message).arg(error_code);
|
||||
}
|
||||
}
|
||||
if (error.isEmpty()) {
|
||||
if (reply->error() != QNetworkReply::NoError) {
|
||||
error = QString("%1 (%2)").arg(reply->errorString()).arg(reply->error());
|
||||
error = QStringLiteral("%1 (%2)").arg(reply->errorString()).arg(reply->error());
|
||||
}
|
||||
else {
|
||||
error = QString("Received HTTP code %1").arg(reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt());
|
||||
error = QStringLiteral("Received HTTP code %1").arg(reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt());
|
||||
}
|
||||
}
|
||||
Error(error);
|
||||
@@ -181,20 +181,20 @@ QJsonObject LastFMImport::ExtractJsonObj(const QByteArray &data) {
|
||||
QJsonDocument json_doc = QJsonDocument::fromJson(data, &error);
|
||||
|
||||
if (error.error != QJsonParseError::NoError) {
|
||||
Error("Reply from server missing Json data.", data);
|
||||
Error(QStringLiteral("Reply from server missing Json data."), data);
|
||||
return QJsonObject();
|
||||
}
|
||||
if (json_doc.isEmpty()) {
|
||||
Error("Received empty Json document.", json_doc);
|
||||
Error(QStringLiteral("Received empty Json document."), json_doc);
|
||||
return QJsonObject();
|
||||
}
|
||||
if (!json_doc.isObject()) {
|
||||
Error("Json document is not an object.", json_doc);
|
||||
Error(QStringLiteral("Json document is not an object."), json_doc);
|
||||
return QJsonObject();
|
||||
}
|
||||
QJsonObject json_obj = json_doc.object();
|
||||
if (json_obj.isEmpty()) {
|
||||
Error("Received empty Json object.", json_doc);
|
||||
Error(QStringLiteral("Received empty Json object."), json_doc);
|
||||
return QJsonObject();
|
||||
}
|
||||
|
||||
@@ -284,62 +284,62 @@ void LastFMImport::GetRecentTracksRequestFinished(QNetworkReply *reply, const in
|
||||
return;
|
||||
}
|
||||
|
||||
if (json_obj.contains("error") && json_obj.contains("message")) {
|
||||
int error_code = json_obj["error"].toInt();
|
||||
QString error_message = json_obj["message"].toString();
|
||||
QString error_reason = QString("%1 (%2)").arg(error_message).arg(error_code);
|
||||
if (json_obj.contains(QStringLiteral("error")) && json_obj.contains(QStringLiteral("message"))) {
|
||||
int error_code = json_obj[QStringLiteral("error")].toInt();
|
||||
QString error_message = json_obj[QStringLiteral("message")].toString();
|
||||
QString error_reason = QStringLiteral("%1 (%2)").arg(error_message).arg(error_code);
|
||||
Error(error_reason);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!json_obj.contains("recenttracks")) {
|
||||
Error("JSON reply from server is missing recenttracks.", json_obj);
|
||||
if (!json_obj.contains(QStringLiteral("recenttracks"))) {
|
||||
Error(QStringLiteral("JSON reply from server is missing recenttracks."), json_obj);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!json_obj["recenttracks"].isObject()) {
|
||||
Error("Failed to parse JSON: recenttracks is not an object!", json_obj);
|
||||
if (!json_obj[QStringLiteral("recenttracks")].isObject()) {
|
||||
Error(QStringLiteral("Failed to parse JSON: recenttracks is not an object!"), json_obj);
|
||||
return;
|
||||
}
|
||||
json_obj = json_obj["recenttracks"].toObject();
|
||||
json_obj = json_obj[QStringLiteral("recenttracks")].toObject();
|
||||
|
||||
if (!json_obj.contains("@attr")) {
|
||||
Error("JSON reply from server is missing @attr.", json_obj);
|
||||
if (!json_obj.contains(QStringLiteral("@attr"))) {
|
||||
Error(QStringLiteral("JSON reply from server is missing @attr."), json_obj);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!json_obj.contains("track")) {
|
||||
Error("JSON reply from server is missing track.", json_obj);
|
||||
if (!json_obj.contains(QStringLiteral("track"))) {
|
||||
Error(QStringLiteral("JSON reply from server is missing track."), json_obj);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!json_obj["@attr"].isObject()) {
|
||||
Error("Failed to parse JSON: @attr is not an object.", json_obj);
|
||||
if (!json_obj[QStringLiteral("@attr")].isObject()) {
|
||||
Error(QStringLiteral("Failed to parse JSON: @attr is not an object."), json_obj);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!json_obj["track"].isArray()) {
|
||||
Error("Failed to parse JSON: track is not an object.", json_obj);
|
||||
if (!json_obj[QStringLiteral("track")].isArray()) {
|
||||
Error(QStringLiteral("Failed to parse JSON: track is not an object."), json_obj);
|
||||
return;
|
||||
}
|
||||
|
||||
QJsonObject obj_attr = json_obj["@attr"].toObject();
|
||||
QJsonObject obj_attr = json_obj[QStringLiteral("@attr")].toObject();
|
||||
|
||||
if (!obj_attr.contains("page")) {
|
||||
Error("Failed to parse JSON: attr object is missing page.", json_obj);
|
||||
if (!obj_attr.contains(QStringLiteral("page"))) {
|
||||
Error(QStringLiteral("Failed to parse JSON: attr object is missing page."), json_obj);
|
||||
return;
|
||||
}
|
||||
if (!obj_attr.contains("totalPages")) {
|
||||
Error("Failed to parse JSON: attr object is missing totalPages.", json_obj);
|
||||
if (!obj_attr.contains(QStringLiteral("totalPages"))) {
|
||||
Error(QStringLiteral("Failed to parse JSON: attr object is missing totalPages."), json_obj);
|
||||
return;
|
||||
}
|
||||
if (!obj_attr.contains("total")) {
|
||||
Error("Failed to parse JSON: attr object is missing total.", json_obj);
|
||||
if (!obj_attr.contains(QStringLiteral("total"))) {
|
||||
Error(QStringLiteral("Failed to parse JSON: attr object is missing total."), json_obj);
|
||||
return;
|
||||
}
|
||||
|
||||
int total = obj_attr["total"].toString().toInt();
|
||||
int pages = obj_attr["totalPages"].toString().toInt();
|
||||
int total = obj_attr[QStringLiteral("total")].toString().toInt();
|
||||
int pages = obj_attr[QStringLiteral("totalPages")].toString().toInt();
|
||||
|
||||
if (page == 0) {
|
||||
lastplayed_total_ = total;
|
||||
@@ -348,7 +348,7 @@ void LastFMImport::GetRecentTracksRequestFinished(QNetworkReply *reply, const in
|
||||
}
|
||||
else {
|
||||
|
||||
QJsonArray array_track = json_obj["track"].toArray();
|
||||
QJsonArray array_track = json_obj[QStringLiteral("track")].toArray();
|
||||
|
||||
for (const QJsonValueRef value_track : array_track) {
|
||||
|
||||
@@ -358,30 +358,30 @@ void LastFMImport::GetRecentTracksRequestFinished(QNetworkReply *reply, const in
|
||||
continue;
|
||||
}
|
||||
QJsonObject obj_track = value_track.toObject();
|
||||
if (!obj_track.contains("artist") ||
|
||||
!obj_track.contains("album") ||
|
||||
!obj_track.contains("name") ||
|
||||
!obj_track.contains("date") ||
|
||||
!obj_track["artist"].isObject() ||
|
||||
!obj_track["album"].isObject() ||
|
||||
!obj_track["date"].isObject()
|
||||
if (!obj_track.contains(QStringLiteral("artist")) ||
|
||||
!obj_track.contains(QStringLiteral("album")) ||
|
||||
!obj_track.contains(QStringLiteral("name")) ||
|
||||
!obj_track.contains(QStringLiteral("date")) ||
|
||||
!obj_track[QStringLiteral("artist")].isObject() ||
|
||||
!obj_track[QStringLiteral("album")].isObject() ||
|
||||
!obj_track[QStringLiteral("date")].isObject()
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
|
||||
QJsonObject obj_artist = obj_track["artist"].toObject();
|
||||
QJsonObject obj_album = obj_track["album"].toObject();
|
||||
QJsonObject obj_date = obj_track["date"].toObject();
|
||||
QJsonObject obj_artist = obj_track[QStringLiteral("artist")].toObject();
|
||||
QJsonObject obj_album = obj_track[QStringLiteral("album")].toObject();
|
||||
QJsonObject obj_date = obj_track[QStringLiteral("date")].toObject();
|
||||
|
||||
if (!obj_artist.contains("#text") || !obj_album.contains("#text") || !obj_date.contains("#text")) {
|
||||
if (!obj_artist.contains(QStringLiteral("#text")) || !obj_album.contains(QStringLiteral("#text")) || !obj_date.contains(QStringLiteral("#text"))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
QString artist = obj_artist["#text"].toString();
|
||||
QString album = obj_album["#text"].toString();
|
||||
QString date = obj_date["#text"].toString();
|
||||
QString title = obj_track["name"].toString();
|
||||
QDateTime datetime = QDateTime::fromString(date, "dd MMM yyyy, hh:mm");
|
||||
QString artist = obj_artist[QStringLiteral("#text")].toString();
|
||||
QString album = obj_album[QStringLiteral("#text")].toString();
|
||||
QString date = obj_date[QStringLiteral("#text")].toString();
|
||||
QString title = obj_track[QStringLiteral("name")].toString();
|
||||
QDateTime datetime = QDateTime::fromString(date, QStringLiteral("dd MMM yyyy, hh:mm"));
|
||||
if (datetime.isValid()) {
|
||||
emit UpdateLastPlayed(artist, album, title, datetime.toSecsSinceEpoch());
|
||||
}
|
||||
@@ -447,62 +447,62 @@ void LastFMImport::GetTopTracksRequestFinished(QNetworkReply *reply, const int p
|
||||
return;
|
||||
}
|
||||
|
||||
if (json_obj.contains("error") && json_obj.contains("message")) {
|
||||
int error_code = json_obj["error"].toInt();
|
||||
QString error_message = json_obj["message"].toString();
|
||||
QString error_reason = QString("%1 (%2)").arg(error_message).arg(error_code);
|
||||
if (json_obj.contains(QStringLiteral("error")) && json_obj.contains(QStringLiteral("message"))) {
|
||||
int error_code = json_obj[QStringLiteral("error")].toInt();
|
||||
QString error_message = json_obj[QStringLiteral("message")].toString();
|
||||
QString error_reason = QStringLiteral("%1 (%2)").arg(error_message).arg(error_code);
|
||||
Error(error_reason);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!json_obj.contains("toptracks")) {
|
||||
Error("JSON reply from server is missing toptracks.", json_obj);
|
||||
if (!json_obj.contains(QStringLiteral("toptracks"))) {
|
||||
Error(QStringLiteral("JSON reply from server is missing toptracks."), json_obj);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!json_obj["toptracks"].isObject()) {
|
||||
Error("Failed to parse JSON: toptracks is not an object!", json_obj);
|
||||
if (!json_obj[QStringLiteral("toptracks")].isObject()) {
|
||||
Error(QStringLiteral("Failed to parse JSON: toptracks is not an object!"), json_obj);
|
||||
return;
|
||||
}
|
||||
json_obj = json_obj["toptracks"].toObject();
|
||||
json_obj = json_obj[QStringLiteral("toptracks")].toObject();
|
||||
|
||||
if (!json_obj.contains("@attr")) {
|
||||
Error("JSON reply from server is missing @attr.", json_obj);
|
||||
if (!json_obj.contains(QStringLiteral("@attr"))) {
|
||||
Error(QStringLiteral("JSON reply from server is missing @attr."), json_obj);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!json_obj.contains("track")) {
|
||||
Error("JSON reply from server is missing track.", json_obj);
|
||||
if (!json_obj.contains(QStringLiteral("track"))) {
|
||||
Error(QStringLiteral("JSON reply from server is missing track."), json_obj);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!json_obj["@attr"].isObject()) {
|
||||
Error("Failed to parse JSON: @attr is not an object.", json_obj);
|
||||
if (!json_obj[QStringLiteral("@attr")].isObject()) {
|
||||
Error(QStringLiteral("Failed to parse JSON: @attr is not an object."), json_obj);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!json_obj["track"].isArray()) {
|
||||
Error("Failed to parse JSON: track is not an object.", json_obj);
|
||||
if (!json_obj[QStringLiteral("track")].isArray()) {
|
||||
Error(QStringLiteral("Failed to parse JSON: track is not an object."), json_obj);
|
||||
return;
|
||||
}
|
||||
|
||||
QJsonObject obj_attr = json_obj["@attr"].toObject();
|
||||
QJsonObject obj_attr = json_obj[QStringLiteral("@attr")].toObject();
|
||||
|
||||
if (!obj_attr.contains("page")) {
|
||||
Error("Failed to parse JSON: attr object is missing page.", json_obj);
|
||||
if (!obj_attr.contains(QStringLiteral("page"))) {
|
||||
Error(QStringLiteral("Failed to parse JSON: attr object is missing page."), json_obj);
|
||||
return;
|
||||
}
|
||||
if (!obj_attr.contains("totalPages")) {
|
||||
Error("Failed to parse JSON: attr object is missing page.", json_obj);
|
||||
if (!obj_attr.contains(QStringLiteral("totalPages"))) {
|
||||
Error(QStringLiteral("Failed to parse JSON: attr object is missing page."), json_obj);
|
||||
return;
|
||||
}
|
||||
if (!obj_attr.contains("total")) {
|
||||
Error("Failed to parse JSON: attr object is missing total.", json_obj);
|
||||
if (!obj_attr.contains(QStringLiteral("total"))) {
|
||||
Error(QStringLiteral("Failed to parse JSON: attr object is missing total."), json_obj);
|
||||
return;
|
||||
}
|
||||
|
||||
int pages = obj_attr["totalPages"].toString().toInt();
|
||||
int total = obj_attr["total"].toString().toInt();
|
||||
int pages = obj_attr[QStringLiteral("totalPages")].toString().toInt();
|
||||
int total = obj_attr[QStringLiteral("total")].toString().toInt();
|
||||
|
||||
if (page == 0) {
|
||||
playcount_total_ = total;
|
||||
@@ -511,7 +511,7 @@ void LastFMImport::GetTopTracksRequestFinished(QNetworkReply *reply, const int p
|
||||
}
|
||||
else {
|
||||
|
||||
QJsonArray array_track = json_obj["track"].toArray();
|
||||
QJsonArray array_track = json_obj[QStringLiteral("track")].toArray();
|
||||
for (QJsonArray::iterator it = array_track.begin(); it != array_track.end(); ++it) {
|
||||
|
||||
const QJsonValue &value_track = *it;
|
||||
@@ -523,22 +523,22 @@ void LastFMImport::GetTopTracksRequestFinished(QNetworkReply *reply, const int p
|
||||
}
|
||||
|
||||
QJsonObject obj_track = value_track.toObject();
|
||||
if (!obj_track.contains("artist") ||
|
||||
!obj_track.contains("name") ||
|
||||
!obj_track.contains("playcount") ||
|
||||
!obj_track["artist"].isObject()
|
||||
if (!obj_track.contains(QStringLiteral("artist")) ||
|
||||
!obj_track.contains(QStringLiteral("name")) ||
|
||||
!obj_track.contains(QStringLiteral("playcount")) ||
|
||||
!obj_track[QStringLiteral("artist")].isObject()
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
|
||||
QJsonObject obj_artist = obj_track["artist"].toObject();
|
||||
if (!obj_artist.contains("name")) {
|
||||
QJsonObject obj_artist = obj_track[QStringLiteral("artist")].toObject();
|
||||
if (!obj_artist.contains(QStringLiteral("name"))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
QString artist = obj_artist["name"].toString();
|
||||
QString title = obj_track["name"].toString();
|
||||
int playcount = obj_track["playcount"].toString().toInt();
|
||||
QString artist = obj_artist[QStringLiteral("name")].toString();
|
||||
QString title = obj_track[QStringLiteral("name")].toString();
|
||||
int playcount = obj_track[QStringLiteral("playcount")].toString().toInt();
|
||||
|
||||
if (playcount <= 0) continue;
|
||||
|
||||
|
||||
@@ -177,16 +177,16 @@ void ListenBrainzScrobbler::Authenticate() {
|
||||
redirect_url.setPort(server_->url().port());
|
||||
|
||||
QUrlQuery url_query;
|
||||
url_query.addQueryItem("response_type", "code");
|
||||
url_query.addQueryItem("client_id", QByteArray::fromBase64(kClientIDB64));
|
||||
url_query.addQueryItem("redirect_uri", redirect_url.toString());
|
||||
url_query.addQueryItem("scope", "profile;email;tag;rating;collection;submit_isrc;submit_barcode");
|
||||
url_query.addQueryItem(QStringLiteral("response_type"), QStringLiteral("code"));
|
||||
url_query.addQueryItem(QStringLiteral("client_id"), QByteArray::fromBase64(kClientIDB64));
|
||||
url_query.addQueryItem(QStringLiteral("redirect_uri"), redirect_url.toString());
|
||||
url_query.addQueryItem(QStringLiteral("scope"), QStringLiteral("profile;email;tag;rating;collection;submit_isrc;submit_barcode"));
|
||||
QUrl url(kOAuthAuthorizeUrl);
|
||||
url.setQuery(url_query);
|
||||
|
||||
bool result = QDesktopServices::openUrl(url);
|
||||
if (!result) {
|
||||
QMessageBox messagebox(QMessageBox::Information, tr("ListenBrainz Authentication"), tr("Please open this URL in your browser") + QString(":<br /><a href=\"%1\">%1</a>").arg(url.toString()), QMessageBox::Ok);
|
||||
QMessageBox messagebox(QMessageBox::Information, tr("ListenBrainz Authentication"), tr("Please open this URL in your browser") + QStringLiteral(":<br /><a href=\"%1\">%1</a>").arg(url.toString()), QMessageBox::Ok);
|
||||
messagebox.setTextFormat(Qt::RichText);
|
||||
messagebox.exec();
|
||||
}
|
||||
@@ -201,11 +201,11 @@ void ListenBrainzScrobbler::RedirectArrived() {
|
||||
QUrl url = server_->request_url();
|
||||
if (url.isValid()) {
|
||||
QUrlQuery url_query(url);
|
||||
if (url_query.hasQueryItem("error")) {
|
||||
AuthError(QUrlQuery(url).queryItemValue("error"));
|
||||
if (url_query.hasQueryItem(QStringLiteral("error"))) {
|
||||
AuthError(QUrlQuery(url).queryItemValue(QStringLiteral("error")));
|
||||
}
|
||||
else if (url_query.hasQueryItem("code")) {
|
||||
RequestAccessToken(url, url_query.queryItemValue("code"));
|
||||
else if (url_query.hasQueryItem(QStringLiteral("code"))) {
|
||||
RequestAccessToken(url, url_query.queryItemValue(QStringLiteral("code")));
|
||||
}
|
||||
else {
|
||||
AuthError(tr("Redirect missing token code!"));
|
||||
@@ -234,23 +234,23 @@ ListenBrainzScrobbler::ReplyResult ListenBrainzScrobbler::GetJsonObject(QNetwork
|
||||
reply_error_type = ReplyResult::Success;
|
||||
}
|
||||
else {
|
||||
error_description = QString("Received HTTP code %1").arg(reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt());
|
||||
error_description = QStringLiteral("Received HTTP code %1").arg(reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt());
|
||||
}
|
||||
}
|
||||
else {
|
||||
error_description = QString("%1 (%2)").arg(reply->errorString()).arg(reply->error());
|
||||
error_description = QStringLiteral("%1 (%2)").arg(reply->errorString()).arg(reply->error());
|
||||
}
|
||||
|
||||
// See if there is Json data containing "error" and "error_description" or "code" and "error" - then use that instead.
|
||||
if (reply->error() == QNetworkReply::NoError || reply->error() >= 200) {
|
||||
const QByteArray data = reply->readAll();
|
||||
if (!data.isEmpty() && ExtractJsonObj(data, json_obj, error_description)) {
|
||||
if (json_obj.contains("error") && json_obj.contains("error_description")) {
|
||||
error_description = json_obj["error_description"].toString();
|
||||
if (json_obj.contains(QStringLiteral("error")) && json_obj.contains(QStringLiteral("error_description"))) {
|
||||
error_description = json_obj[QStringLiteral("error_description")].toString();
|
||||
reply_error_type = ReplyResult::APIError;
|
||||
}
|
||||
else if (json_obj.contains("code") && json_obj.contains("error")) {
|
||||
error_description = QString("%1 (%2)").arg(json_obj["error"].toString()).arg(json_obj["code"].toInt());
|
||||
else if (json_obj.contains(QStringLiteral("code")) && json_obj.contains(QStringLiteral("error"))) {
|
||||
error_description = QStringLiteral("%1 (%2)").arg(json_obj[QStringLiteral("error")].toString()).arg(json_obj[QStringLiteral("code")].toInt());
|
||||
reply_error_type = ReplyResult::APIError;
|
||||
}
|
||||
}
|
||||
@@ -315,16 +315,16 @@ void ListenBrainzScrobbler::AuthenticateReplyFinished(QNetworkReply *reply) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!json_obj.contains("access_token") || !json_obj.contains("expires_in") || !json_obj.contains("token_type")) {
|
||||
AuthError("Json access_token, expires_in or token_type is missing.");
|
||||
if (!json_obj.contains(QStringLiteral("access_token")) || !json_obj.contains(QStringLiteral("expires_in")) || !json_obj.contains(QStringLiteral("token_type"))) {
|
||||
AuthError(QStringLiteral("Json access_token, expires_in or token_type is missing."));
|
||||
return;
|
||||
}
|
||||
|
||||
access_token_ = json_obj["access_token"].toString();
|
||||
expires_in_ = json_obj["expires_in"].toInt();
|
||||
token_type_ = json_obj["token_type"].toString();
|
||||
if (json_obj.contains("refresh_token")) {
|
||||
refresh_token_ = json_obj["refresh_token"].toString();
|
||||
access_token_ = json_obj[QStringLiteral("access_token")].toString();
|
||||
expires_in_ = json_obj[QStringLiteral("expires_in")].toInt();
|
||||
token_type_ = json_obj[QStringLiteral("token_type")].toString();
|
||||
if (json_obj.contains(QStringLiteral("refresh_token"))) {
|
||||
refresh_token_ = json_obj[QStringLiteral("refresh_token")].toString();
|
||||
}
|
||||
login_time_ = QDateTime::currentDateTime().toSecsSinceEpoch();
|
||||
|
||||
@@ -355,7 +355,7 @@ QNetworkReply *ListenBrainzScrobbler::CreateRequest(const QUrl &url, const QJson
|
||||
QNetworkRequest req(url);
|
||||
req.setAttribute(QNetworkRequest::RedirectPolicyAttribute, QNetworkRequest::NoLessSafeRedirectPolicy);
|
||||
req.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
|
||||
req.setRawHeader("Authorization", QString("Token %1").arg(user_token_).toUtf8());
|
||||
req.setRawHeader("Authorization", QStringLiteral("Token %1").arg(user_token_).toUtf8());
|
||||
QNetworkReply *reply = network_->post(req, json_doc.toJson());
|
||||
replies_ << reply;
|
||||
|
||||
@@ -369,32 +369,32 @@ QJsonObject ListenBrainzScrobbler::JsonTrackMetadata(const ScrobbleMetadata &met
|
||||
|
||||
QJsonObject object_track_metadata;
|
||||
if (prefer_albumartist_) {
|
||||
object_track_metadata.insert("artist_name", QJsonValue::fromVariant(metadata.effective_albumartist()));
|
||||
object_track_metadata.insert(QStringLiteral("artist_name"), QJsonValue::fromVariant(metadata.effective_albumartist()));
|
||||
}
|
||||
else {
|
||||
object_track_metadata.insert("artist_name", QJsonValue::fromVariant(metadata.artist));
|
||||
object_track_metadata.insert(QStringLiteral("artist_name"), QJsonValue::fromVariant(metadata.artist));
|
||||
}
|
||||
|
||||
if (!metadata.album.isEmpty()) {
|
||||
object_track_metadata.insert("release_name", QJsonValue::fromVariant(StripAlbum(metadata.album)));
|
||||
object_track_metadata.insert(QStringLiteral("release_name"), QJsonValue::fromVariant(StripAlbum(metadata.album)));
|
||||
}
|
||||
|
||||
object_track_metadata.insert("track_name", QJsonValue::fromVariant(StripTitle(metadata.title)));
|
||||
object_track_metadata.insert(QStringLiteral("track_name"), QJsonValue::fromVariant(StripTitle(metadata.title)));
|
||||
|
||||
QJsonObject object_additional_info;
|
||||
|
||||
if (metadata.length_nanosec > 0) {
|
||||
object_additional_info.insert("duration_ms", metadata.length_nanosec / kNsecPerMsec);
|
||||
object_additional_info.insert(QStringLiteral("duration_ms"), metadata.length_nanosec / kNsecPerMsec);
|
||||
}
|
||||
|
||||
if (metadata.track > 0) {
|
||||
object_additional_info.insert("tracknumber", metadata.track);
|
||||
object_additional_info.insert(QStringLiteral("tracknumber"), metadata.track);
|
||||
}
|
||||
|
||||
object_additional_info.insert("media_player", QCoreApplication::applicationName());
|
||||
object_additional_info.insert("media_player_version", QCoreApplication::applicationVersion());
|
||||
object_additional_info.insert("submission_client", QCoreApplication::applicationName());
|
||||
object_additional_info.insert("submission_client_version", QCoreApplication::applicationVersion());
|
||||
object_additional_info.insert(QStringLiteral("media_player"), QCoreApplication::applicationName());
|
||||
object_additional_info.insert(QStringLiteral("media_player_version"), QCoreApplication::applicationVersion());
|
||||
object_additional_info.insert(QStringLiteral("submission_client"), QCoreApplication::applicationName());
|
||||
object_additional_info.insert(QStringLiteral("submission_client_version"), QCoreApplication::applicationVersion());
|
||||
|
||||
QStringList artist_mbids_list;
|
||||
if (!metadata.musicbrainz_album_artist_id.isEmpty()) {
|
||||
@@ -414,28 +414,28 @@ QJsonObject ListenBrainzScrobbler::JsonTrackMetadata(const ScrobbleMetadata &met
|
||||
}
|
||||
}
|
||||
if (!artist_mbids_array.isEmpty()) {
|
||||
object_additional_info.insert("artist_mbids", artist_mbids_array);
|
||||
object_additional_info.insert(QStringLiteral("artist_mbids"), artist_mbids_array);
|
||||
}
|
||||
}
|
||||
|
||||
if (!metadata.musicbrainz_album_id.isEmpty()) {
|
||||
object_additional_info.insert("release_mbid", metadata.musicbrainz_album_id);
|
||||
object_additional_info.insert(QStringLiteral("release_mbid"), metadata.musicbrainz_album_id);
|
||||
}
|
||||
else if (!metadata.musicbrainz_original_album_id.isEmpty()) {
|
||||
object_additional_info.insert("release_mbid", metadata.musicbrainz_original_album_id);
|
||||
object_additional_info.insert(QStringLiteral("release_mbid"), metadata.musicbrainz_original_album_id);
|
||||
}
|
||||
|
||||
if (!metadata.musicbrainz_recording_id.isEmpty()) {
|
||||
object_additional_info.insert("recording_mbid", metadata.musicbrainz_recording_id);
|
||||
object_additional_info.insert(QStringLiteral("recording_mbid"), metadata.musicbrainz_recording_id);
|
||||
}
|
||||
if (!metadata.musicbrainz_track_id.isEmpty()) {
|
||||
object_additional_info.insert("track_mbid", metadata.musicbrainz_track_id);
|
||||
object_additional_info.insert(QStringLiteral("track_mbid"), metadata.musicbrainz_track_id);
|
||||
}
|
||||
if (!metadata.musicbrainz_work_id.isEmpty()) {
|
||||
object_additional_info.insert("work_mbids", QJsonArray() << metadata.musicbrainz_work_id);
|
||||
object_additional_info.insert(QStringLiteral("work_mbids"), QJsonArray() << metadata.musicbrainz_work_id);
|
||||
}
|
||||
|
||||
object_track_metadata.insert("additional_info", object_additional_info);
|
||||
object_track_metadata.insert(QStringLiteral("additional_info"), object_additional_info);
|
||||
|
||||
return object_track_metadata;
|
||||
|
||||
@@ -452,15 +452,15 @@ void ListenBrainzScrobbler::UpdateNowPlaying(const Song &song) {
|
||||
if (!song.is_metadata_good() || !authenticated() || settings_->offline()) return;
|
||||
|
||||
QJsonObject object_listen;
|
||||
object_listen.insert("track_metadata", JsonTrackMetadata(ScrobbleMetadata(song)));
|
||||
object_listen.insert(QStringLiteral("track_metadata"), JsonTrackMetadata(ScrobbleMetadata(song)));
|
||||
QJsonArray array_payload;
|
||||
array_payload.append(object_listen);
|
||||
QJsonObject object;
|
||||
object.insert("listen_type", "playing_now");
|
||||
object.insert("payload", array_payload);
|
||||
object.insert(QStringLiteral("listen_type"), "playing_now");
|
||||
object.insert(QStringLiteral("payload"), array_payload);
|
||||
QJsonDocument doc(object);
|
||||
|
||||
QUrl url(QString("%1/1/submit-listens").arg(kApiUrl));
|
||||
QUrl url(QStringLiteral("%1/1/submit-listens").arg(kApiUrl));
|
||||
QNetworkReply *reply = CreateRequest(url, doc);
|
||||
QObject::connect(reply, &QNetworkReply::finished, this, [this, reply]() { UpdateNowPlayingRequestFinished(reply); });
|
||||
|
||||
@@ -480,14 +480,14 @@ void ListenBrainzScrobbler::UpdateNowPlayingRequestFinished(QNetworkReply *reply
|
||||
return;
|
||||
}
|
||||
|
||||
if (!json_obj.contains("status")) {
|
||||
Error("Now playing request is missing status from server.");
|
||||
if (!json_obj.contains(QStringLiteral("status"))) {
|
||||
Error(QStringLiteral("Now playing request is missing status from server."));
|
||||
return;
|
||||
}
|
||||
|
||||
QString status = json_obj["status"].toString();
|
||||
if (status.compare("ok", Qt::CaseInsensitive) != 0) {
|
||||
Error(QString("Received %1 status for now playing.").arg(status));
|
||||
QString status = json_obj[QStringLiteral("status")].toString();
|
||||
if (status.compare(QLatin1String("ok"), Qt::CaseInsensitive) != 0) {
|
||||
Error(QStringLiteral("Received %1 status for now playing.").arg(status));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -548,8 +548,8 @@ void ListenBrainzScrobbler::Submit() {
|
||||
cache_item->sent = true;
|
||||
cache_items_sent << cache_item;
|
||||
QJsonObject object_listen;
|
||||
object_listen.insert("listened_at", QJsonValue::fromVariant(cache_item->timestamp));
|
||||
object_listen.insert("track_metadata", JsonTrackMetadata(cache_item->metadata));
|
||||
object_listen.insert(QStringLiteral("listened_at"), QJsonValue::fromVariant(cache_item->timestamp));
|
||||
object_listen.insert(QStringLiteral("track_metadata"), JsonTrackMetadata(cache_item->metadata));
|
||||
array.append(QJsonValue::fromVariant(object_listen));
|
||||
if (cache_items_sent.count() >= kScrobblesPerRequest || cache_item->error) break;
|
||||
}
|
||||
@@ -559,11 +559,11 @@ void ListenBrainzScrobbler::Submit() {
|
||||
submitted_ = true;
|
||||
|
||||
QJsonObject object;
|
||||
object.insert("listen_type", "import");
|
||||
object.insert("payload", array);
|
||||
object.insert(QStringLiteral("listen_type"), "import");
|
||||
object.insert(QStringLiteral("payload"), array);
|
||||
QJsonDocument doc(object);
|
||||
|
||||
QUrl url(QString("%1/1/submit-listens").arg(kApiUrl));
|
||||
QUrl url(QStringLiteral("%1/1/submit-listens").arg(kApiUrl));
|
||||
QNetworkReply *reply = CreateRequest(url, doc);
|
||||
QObject::connect(reply, &QNetworkReply::finished, this, [this, reply, cache_items_sent]() { ScrobbleRequestFinished(reply, cache_items_sent); });
|
||||
|
||||
@@ -582,8 +582,8 @@ void ListenBrainzScrobbler::ScrobbleRequestFinished(QNetworkReply *reply, Scrobb
|
||||
QString error_message;
|
||||
const ReplyResult reply_result = GetJsonObject(reply, json_obj, error_message);
|
||||
if (reply_result == ReplyResult::Success) {
|
||||
if (json_obj.contains("status")) {
|
||||
QString status = json_obj["status"].toString();
|
||||
if (json_obj.contains(QStringLiteral("status"))) {
|
||||
QString status = json_obj[QStringLiteral("status")].toString();
|
||||
qLog(Debug) << "ListenBrainz: Received scrobble status:" << status;
|
||||
}
|
||||
else {
|
||||
@@ -630,10 +630,10 @@ void ListenBrainzScrobbler::Love() {
|
||||
qLog(Debug) << "ListenBrainz: Sending love for song" << song_playing_.artist() << song_playing_.album() << song_playing_.title();
|
||||
|
||||
QJsonObject object;
|
||||
object.insert("recording_mbid", song_playing_.musicbrainz_recording_id());
|
||||
object.insert("score", 1);
|
||||
object.insert(QStringLiteral("recording_mbid"), song_playing_.musicbrainz_recording_id());
|
||||
object.insert(QStringLiteral("score"), 1);
|
||||
|
||||
QUrl url(QString("%1/1/feedback/recording-feedback").arg(kApiUrl));
|
||||
QUrl url(QStringLiteral("%1/1/feedback/recording-feedback").arg(kApiUrl));
|
||||
QNetworkReply *reply = CreateRequest(url, QJsonDocument(object));
|
||||
QObject::connect(reply, &QNetworkReply::finished, this, [this, reply]() { LoveRequestFinished(reply); });
|
||||
|
||||
@@ -653,8 +653,8 @@ void ListenBrainzScrobbler::LoveRequestFinished(QNetworkReply *reply) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (json_obj.contains("status")) {
|
||||
qLog(Debug) << "ListenBrainz: Received recording-feedback status:" << json_obj["status"].toString();
|
||||
if (json_obj.contains(QStringLiteral("status"))) {
|
||||
qLog(Debug) << "ListenBrainz: Received recording-feedback status:" << json_obj[QStringLiteral("status")].toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -99,11 +99,11 @@ void ScrobblerCache::ReadCache() {
|
||||
qLog(Error) << "Scrobbler cache has empty JSON object.";
|
||||
return;
|
||||
}
|
||||
if (!json_obj.contains("tracks")) {
|
||||
if (!json_obj.contains(QStringLiteral("tracks"))) {
|
||||
qLog(Error) << "Scrobbler cache is missing JSON tracks.";
|
||||
return;
|
||||
}
|
||||
QJsonValue json_tracks = json_obj["tracks"];
|
||||
QJsonValue json_tracks = json_obj[QStringLiteral("tracks")];
|
||||
if (!json_tracks.isArray()) {
|
||||
qLog(Error) << "Scrobbler cache JSON tracks is not an array.";
|
||||
return;
|
||||
@@ -121,13 +121,13 @@ void ScrobblerCache::ReadCache() {
|
||||
}
|
||||
QJsonObject json_obj_track = value.toObject();
|
||||
if (
|
||||
!json_obj_track.contains("timestamp") ||
|
||||
!json_obj_track.contains("artist") ||
|
||||
!json_obj_track.contains("album") ||
|
||||
!json_obj_track.contains("title") ||
|
||||
!json_obj_track.contains("track") ||
|
||||
!json_obj_track.contains("albumartist") ||
|
||||
!json_obj_track.contains("length_nanosec")
|
||||
!json_obj_track.contains(QStringLiteral("timestamp")) ||
|
||||
!json_obj_track.contains(QStringLiteral("artist")) ||
|
||||
!json_obj_track.contains(QStringLiteral("album")) ||
|
||||
!json_obj_track.contains(QStringLiteral("title")) ||
|
||||
!json_obj_track.contains(QStringLiteral("track")) ||
|
||||
!json_obj_track.contains(QStringLiteral("albumartist")) ||
|
||||
!json_obj_track.contains(QStringLiteral("length_nanosec"))
|
||||
) {
|
||||
qLog(Error) << "Scrobbler cache JSON tracks array value is missing data.";
|
||||
qLog(Debug) << value;
|
||||
@@ -135,52 +135,52 @@ void ScrobblerCache::ReadCache() {
|
||||
}
|
||||
|
||||
ScrobbleMetadata metadata;
|
||||
quint64 timestamp = json_obj_track["timestamp"].toVariant().toULongLong();
|
||||
metadata.artist = json_obj_track["artist"].toString();
|
||||
metadata.album = json_obj_track["album"].toString();
|
||||
metadata.title = json_obj_track["title"].toString();
|
||||
metadata.track = json_obj_track["track"].toInt();
|
||||
metadata.albumartist = json_obj_track["albumartist"].toString();
|
||||
metadata.length_nanosec = json_obj_track["length_nanosec"].toVariant().toLongLong();
|
||||
quint64 timestamp = json_obj_track[QStringLiteral("timestamp")].toVariant().toULongLong();
|
||||
metadata.artist = json_obj_track[QStringLiteral("artist")].toString();
|
||||
metadata.album = json_obj_track[QStringLiteral("album")].toString();
|
||||
metadata.title = json_obj_track[QStringLiteral("title")].toString();
|
||||
metadata.track = json_obj_track[QStringLiteral("track")].toInt();
|
||||
metadata.albumartist = json_obj_track[QStringLiteral("albumartist")].toString();
|
||||
metadata.length_nanosec = json_obj_track[QStringLiteral("length_nanosec")].toVariant().toLongLong();
|
||||
|
||||
if (timestamp == 0 || metadata.artist.isEmpty() || metadata.title.isEmpty() || metadata.length_nanosec <= 0) {
|
||||
qLog(Error) << "Invalid cache data" << "for song" << metadata.title;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (json_obj_track.contains("grouping")) {
|
||||
metadata.grouping = json_obj_track["grouping"].toString();
|
||||
if (json_obj_track.contains(QStringLiteral("grouping"))) {
|
||||
metadata.grouping = json_obj_track[QStringLiteral("grouping")].toString();
|
||||
}
|
||||
|
||||
if (json_obj_track.contains("musicbrainz_album_artist_id")) {
|
||||
metadata.musicbrainz_album_artist_id = json_obj_track["musicbrainz_album_artist_id"].toString();
|
||||
if (json_obj_track.contains(QStringLiteral("musicbrainz_album_artist_id"))) {
|
||||
metadata.musicbrainz_album_artist_id = json_obj_track[QStringLiteral("musicbrainz_album_artist_id")].toString();
|
||||
}
|
||||
if (json_obj_track.contains("musicbrainz_artist_id")) {
|
||||
metadata.musicbrainz_artist_id = json_obj_track["musicbrainz_artist_id"].toString();
|
||||
if (json_obj_track.contains(QStringLiteral("musicbrainz_artist_id"))) {
|
||||
metadata.musicbrainz_artist_id = json_obj_track[QStringLiteral("musicbrainz_artist_id")].toString();
|
||||
}
|
||||
if (json_obj_track.contains("musicbrainz_original_artist_id")) {
|
||||
metadata.musicbrainz_original_artist_id = json_obj_track["musicbrainz_original_artist_id"].toString();
|
||||
if (json_obj_track.contains(QStringLiteral("musicbrainz_original_artist_id"))) {
|
||||
metadata.musicbrainz_original_artist_id = json_obj_track[QStringLiteral("musicbrainz_original_artist_id")].toString();
|
||||
}
|
||||
if (json_obj_track.contains("musicbrainz_album_id")) {
|
||||
metadata.musicbrainz_album_id = json_obj_track["musicbrainz_album_id"].toString();
|
||||
if (json_obj_track.contains(QStringLiteral("musicbrainz_album_id"))) {
|
||||
metadata.musicbrainz_album_id = json_obj_track[QStringLiteral("musicbrainz_album_id")].toString();
|
||||
}
|
||||
if (json_obj_track.contains("musicbrainz_original_album_id")) {
|
||||
metadata.musicbrainz_original_album_id = json_obj_track["musicbrainz_original_album_id"].toString();
|
||||
if (json_obj_track.contains(QStringLiteral("musicbrainz_original_album_id"))) {
|
||||
metadata.musicbrainz_original_album_id = json_obj_track[QStringLiteral("musicbrainz_original_album_id")].toString();
|
||||
}
|
||||
if (json_obj_track.contains("musicbrainz_recording_id")) {
|
||||
metadata.musicbrainz_recording_id = json_obj_track["musicbrainz_recording_id"].toString();
|
||||
if (json_obj_track.contains(QStringLiteral("musicbrainz_recording_id"))) {
|
||||
metadata.musicbrainz_recording_id = json_obj_track[QStringLiteral("musicbrainz_recording_id")].toString();
|
||||
}
|
||||
if (json_obj_track.contains("musicbrainz_track_id")) {
|
||||
metadata.musicbrainz_track_id = json_obj_track["musicbrainz_track_id"].toString();
|
||||
if (json_obj_track.contains(QStringLiteral("musicbrainz_track_id"))) {
|
||||
metadata.musicbrainz_track_id = json_obj_track[QStringLiteral("musicbrainz_track_id")].toString();
|
||||
}
|
||||
if (json_obj_track.contains("musicbrainz_disc_id")) {
|
||||
metadata.musicbrainz_disc_id = json_obj_track["musicbrainz_disc_id"].toString();
|
||||
if (json_obj_track.contains(QStringLiteral("musicbrainz_disc_id"))) {
|
||||
metadata.musicbrainz_disc_id = json_obj_track[QStringLiteral("musicbrainz_disc_id")].toString();
|
||||
}
|
||||
if (json_obj_track.contains("musicbrainz_release_group_id")) {
|
||||
metadata.musicbrainz_release_group_id = json_obj_track["musicbrainz_release_group_id"].toString();
|
||||
if (json_obj_track.contains(QStringLiteral("musicbrainz_release_group_id"))) {
|
||||
metadata.musicbrainz_release_group_id = json_obj_track[QStringLiteral("musicbrainz_release_group_id")].toString();
|
||||
}
|
||||
if (json_obj_track.contains("musicbrainz_work_id")) {
|
||||
metadata.musicbrainz_work_id = json_obj_track["musicbrainz_work_id"].toString();
|
||||
if (json_obj_track.contains(QStringLiteral("musicbrainz_work_id"))) {
|
||||
metadata.musicbrainz_work_id = json_obj_track[QStringLiteral("musicbrainz_work_id")].toString();
|
||||
}
|
||||
|
||||
ScrobblerCacheItemPtr cache_item = make_shared<ScrobblerCacheItem>(metadata, timestamp);
|
||||
@@ -205,29 +205,29 @@ void ScrobblerCache::WriteCache() {
|
||||
QJsonArray array;
|
||||
for (ScrobblerCacheItemPtr cache_item : scrobbler_cache_) {
|
||||
QJsonObject object;
|
||||
object.insert("timestamp", QJsonValue::fromVariant(cache_item->timestamp));
|
||||
object.insert("artist", QJsonValue::fromVariant(cache_item->metadata.artist));
|
||||
object.insert("album", QJsonValue::fromVariant(cache_item->metadata.album));
|
||||
object.insert("title", QJsonValue::fromVariant(cache_item->metadata.title));
|
||||
object.insert("track", QJsonValue::fromVariant(cache_item->metadata.track));
|
||||
object.insert("albumartist", QJsonValue::fromVariant(cache_item->metadata.albumartist));
|
||||
object.insert("grouping", QJsonValue::fromVariant(cache_item->metadata.grouping));
|
||||
object.insert("musicbrainz_album_artist_id", QJsonValue::fromVariant(cache_item->metadata.musicbrainz_album_artist_id));
|
||||
object.insert("musicbrainz_artist_id", QJsonValue::fromVariant(cache_item->metadata.musicbrainz_artist_id));
|
||||
object.insert("musicbrainz_original_artist_id", QJsonValue::fromVariant(cache_item->metadata.musicbrainz_original_artist_id));
|
||||
object.insert("musicbrainz_album_id", QJsonValue::fromVariant(cache_item->metadata.musicbrainz_album_id));
|
||||
object.insert("musicbrainz_original_album_id", QJsonValue::fromVariant(cache_item->metadata.musicbrainz_original_album_id));
|
||||
object.insert("musicbrainz_recording_id", QJsonValue::fromVariant(cache_item->metadata.musicbrainz_recording_id));
|
||||
object.insert("musicbrainz_track_id", QJsonValue::fromVariant(cache_item->metadata.musicbrainz_track_id));
|
||||
object.insert("musicbrainz_disc_id", QJsonValue::fromVariant(cache_item->metadata.musicbrainz_disc_id));
|
||||
object.insert("musicbrainz_release_group_id", QJsonValue::fromVariant(cache_item->metadata.musicbrainz_release_group_id));
|
||||
object.insert("musicbrainz_work_id", QJsonValue::fromVariant(cache_item->metadata.musicbrainz_work_id));
|
||||
object.insert("length_nanosec", QJsonValue::fromVariant(cache_item->metadata.length_nanosec));
|
||||
object.insert(QStringLiteral("timestamp"), QJsonValue::fromVariant(cache_item->timestamp));
|
||||
object.insert(QStringLiteral("artist"), QJsonValue::fromVariant(cache_item->metadata.artist));
|
||||
object.insert(QStringLiteral("album"), QJsonValue::fromVariant(cache_item->metadata.album));
|
||||
object.insert(QStringLiteral("title"), QJsonValue::fromVariant(cache_item->metadata.title));
|
||||
object.insert(QStringLiteral("track"), QJsonValue::fromVariant(cache_item->metadata.track));
|
||||
object.insert(QStringLiteral("albumartist"), QJsonValue::fromVariant(cache_item->metadata.albumartist));
|
||||
object.insert(QStringLiteral("grouping"), QJsonValue::fromVariant(cache_item->metadata.grouping));
|
||||
object.insert(QStringLiteral("musicbrainz_album_artist_id"), QJsonValue::fromVariant(cache_item->metadata.musicbrainz_album_artist_id));
|
||||
object.insert(QStringLiteral("musicbrainz_artist_id"), QJsonValue::fromVariant(cache_item->metadata.musicbrainz_artist_id));
|
||||
object.insert(QStringLiteral("musicbrainz_original_artist_id"), QJsonValue::fromVariant(cache_item->metadata.musicbrainz_original_artist_id));
|
||||
object.insert(QStringLiteral("musicbrainz_album_id"), QJsonValue::fromVariant(cache_item->metadata.musicbrainz_album_id));
|
||||
object.insert(QStringLiteral("musicbrainz_original_album_id"), QJsonValue::fromVariant(cache_item->metadata.musicbrainz_original_album_id));
|
||||
object.insert(QStringLiteral("musicbrainz_recording_id"), QJsonValue::fromVariant(cache_item->metadata.musicbrainz_recording_id));
|
||||
object.insert(QStringLiteral("musicbrainz_track_id"), QJsonValue::fromVariant(cache_item->metadata.musicbrainz_track_id));
|
||||
object.insert(QStringLiteral("musicbrainz_disc_id"), QJsonValue::fromVariant(cache_item->metadata.musicbrainz_disc_id));
|
||||
object.insert(QStringLiteral("musicbrainz_release_group_id"), QJsonValue::fromVariant(cache_item->metadata.musicbrainz_release_group_id));
|
||||
object.insert(QStringLiteral("musicbrainz_work_id"), QJsonValue::fromVariant(cache_item->metadata.musicbrainz_work_id));
|
||||
object.insert(QStringLiteral("length_nanosec"), QJsonValue::fromVariant(cache_item->metadata.length_nanosec));
|
||||
array.append(QJsonValue::fromVariant(object));
|
||||
}
|
||||
|
||||
QJsonObject object;
|
||||
object.insert("tracks", array);
|
||||
object.insert(QStringLiteral("tracks"), array);
|
||||
QJsonDocument doc(object);
|
||||
|
||||
QFile file(filename_);
|
||||
|
||||
@@ -155,21 +155,21 @@ ScrobblingAPI20::ReplyResult ScrobblingAPI20::GetJsonObject(QNetworkReply *reply
|
||||
reply_error_type = ReplyResult::Success;
|
||||
}
|
||||
else {
|
||||
error_description = QString("Received HTTP code %1").arg(reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt());
|
||||
error_description = QStringLiteral("Received HTTP code %1").arg(reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt());
|
||||
}
|
||||
}
|
||||
else {
|
||||
error_description = QString("%1 (%2)").arg(reply->errorString()).arg(reply->error());
|
||||
error_description = QStringLiteral("%1 (%2)").arg(reply->errorString()).arg(reply->error());
|
||||
}
|
||||
|
||||
// See if there is Json data containing "error" and "message" - then use that instead.
|
||||
if (reply->error() == QNetworkReply::NoError || reply->error() >= 200) {
|
||||
const QByteArray data = reply->readAll();
|
||||
int error_code = 0;
|
||||
if (!data.isEmpty() && ExtractJsonObj(data, json_obj, error_description) && json_obj.contains("error") && json_obj.contains("message")) {
|
||||
error_code = json_obj["error"].toInt();
|
||||
QString error_message = json_obj["message"].toString();
|
||||
error_description = QString("%1 (%2)").arg(error_message).arg(error_code);
|
||||
if (!data.isEmpty() && ExtractJsonObj(data, json_obj, error_description) && json_obj.contains(QStringLiteral("error")) && json_obj.contains(QStringLiteral("message"))) {
|
||||
error_code = json_obj[QStringLiteral("error")].toInt();
|
||||
QString error_message = json_obj[QStringLiteral("message")].toString();
|
||||
error_description = QStringLiteral("%1 (%2)").arg(error_message).arg(error_code);
|
||||
reply_error_type = ReplyResult::APIError;
|
||||
}
|
||||
const ScrobbleErrorCode lastfm_error_code = static_cast<ScrobbleErrorCode>(error_code);
|
||||
@@ -202,12 +202,12 @@ void ScrobblingAPI20::Authenticate() {
|
||||
}
|
||||
|
||||
QUrlQuery url_query;
|
||||
url_query.addQueryItem("api_key", kApiKey);
|
||||
url_query.addQueryItem("cb", server_->url().toString());
|
||||
url_query.addQueryItem(QStringLiteral("api_key"), kApiKey);
|
||||
url_query.addQueryItem(QStringLiteral("cb"), server_->url().toString());
|
||||
QUrl url(auth_url_);
|
||||
url.setQuery(url_query);
|
||||
|
||||
QMessageBox messagebox(QMessageBox::Information, tr("%1 Scrobbler Authentication").arg(name_), tr("Open URL in web browser?") + QString("<br /><a href=\"%1\">%1</a><br />").arg(url.toString()) + tr("Press \"Save\" to copy the URL to clipboard and manually open it in a web browser."), QMessageBox::Open|QMessageBox::Save|QMessageBox::Cancel);
|
||||
QMessageBox messagebox(QMessageBox::Information, tr("%1 Scrobbler Authentication").arg(name_), tr("Open URL in web browser?") + QStringLiteral("<br /><a href=\"%1\">%1</a><br />").arg(url.toString()) + tr("Press \"Save\" to copy the URL to clipboard and manually open it in a web browser."), QMessageBox::Open|QMessageBox::Save|QMessageBox::Cancel);
|
||||
messagebox.setTextFormat(Qt::RichText);
|
||||
int result = messagebox.exec();
|
||||
switch (result) {
|
||||
@@ -216,7 +216,7 @@ void ScrobblingAPI20::Authenticate() {
|
||||
if (openurl_result) {
|
||||
break;
|
||||
}
|
||||
QMessageBox messagebox_error(QMessageBox::Warning, tr("%1 Scrobbler Authentication").arg(name_), tr("Could not open URL. Please open this URL in your browser") + QString(":<br /><a href=\"%1\">%1</a>").arg(url.toString()), QMessageBox::Ok);
|
||||
QMessageBox messagebox_error(QMessageBox::Warning, tr("%1 Scrobbler Authentication").arg(name_), tr("Could not open URL. Please open this URL in your browser") + QStringLiteral(":<br /><a href=\"%1\">%1</a>").arg(url.toString()), QMessageBox::Ok);
|
||||
messagebox_error.setTextFormat(Qt::RichText);
|
||||
messagebox_error.exec();
|
||||
}
|
||||
@@ -245,8 +245,8 @@ void ScrobblingAPI20::RedirectArrived() {
|
||||
QUrl url = server_->request_url();
|
||||
if (url.isValid()) {
|
||||
QUrlQuery url_query(url);
|
||||
if (url_query.hasQueryItem("token")) {
|
||||
QString token = url_query.queryItemValue("token").toUtf8();
|
||||
if (url_query.hasQueryItem(QStringLiteral("token"))) {
|
||||
QString token = url_query.queryItemValue(QStringLiteral("token")).toUtf8();
|
||||
RequestSession(token);
|
||||
}
|
||||
else {
|
||||
@@ -271,9 +271,9 @@ void ScrobblingAPI20::RequestSession(const QString &token) {
|
||||
|
||||
QUrl session_url(api_url_);
|
||||
QUrlQuery session_url_query;
|
||||
session_url_query.addQueryItem("api_key", kApiKey);
|
||||
session_url_query.addQueryItem("method", "auth.getSession");
|
||||
session_url_query.addQueryItem("token", token);
|
||||
session_url_query.addQueryItem(QStringLiteral("api_key"), kApiKey);
|
||||
session_url_query.addQueryItem(QStringLiteral("method"), QStringLiteral("auth.getSession"));
|
||||
session_url_query.addQueryItem(QStringLiteral("token"), token);
|
||||
QString data_to_sign;
|
||||
for (const Param ¶m : session_url_query.queryItems()) {
|
||||
data_to_sign += param.first + param.second;
|
||||
@@ -281,8 +281,8 @@ void ScrobblingAPI20::RequestSession(const QString &token) {
|
||||
data_to_sign += kSecret;
|
||||
QByteArray const digest = QCryptographicHash::hash(data_to_sign.toUtf8(), QCryptographicHash::Md5);
|
||||
QString signature = QString::fromLatin1(digest.toHex()).rightJustified(32, '0').toLower();
|
||||
session_url_query.addQueryItem("api_sig", signature);
|
||||
session_url_query.addQueryItem(QUrl::toPercentEncoding("format"), QUrl::toPercentEncoding("json"));
|
||||
session_url_query.addQueryItem(QStringLiteral("api_sig"), signature);
|
||||
session_url_query.addQueryItem(QUrl::toPercentEncoding(QStringLiteral("format")), QUrl::toPercentEncoding(QStringLiteral("json")));
|
||||
session_url.setQuery(session_url_query);
|
||||
|
||||
QNetworkRequest req(session_url);
|
||||
@@ -307,29 +307,29 @@ void ScrobblingAPI20::AuthenticateReplyFinished(QNetworkReply *reply) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!json_obj.contains("session")) {
|
||||
AuthError("Json reply from server is missing session.");
|
||||
if (!json_obj.contains(QStringLiteral("session"))) {
|
||||
AuthError(QStringLiteral("Json reply from server is missing session."));
|
||||
return;
|
||||
}
|
||||
|
||||
QJsonValue json_session = json_obj["session"];
|
||||
QJsonValue json_session = json_obj[QStringLiteral("session")];
|
||||
if (!json_session.isObject()) {
|
||||
AuthError("Json session is not an object.");
|
||||
AuthError(QStringLiteral("Json session is not an object."));
|
||||
return;
|
||||
}
|
||||
json_obj = json_session.toObject();
|
||||
if (json_obj.isEmpty()) {
|
||||
AuthError("Json session object is empty.");
|
||||
AuthError(QStringLiteral("Json session object is empty."));
|
||||
return;
|
||||
}
|
||||
if (!json_obj.contains("subscriber") || !json_obj.contains("name") || !json_obj.contains("key")) {
|
||||
AuthError("Json session object is missing values.");
|
||||
if (!json_obj.contains(QStringLiteral("subscriber")) || !json_obj.contains(QStringLiteral("name")) || !json_obj.contains(QStringLiteral("key"))) {
|
||||
AuthError(QStringLiteral("Json session object is missing values."));
|
||||
return;
|
||||
}
|
||||
|
||||
subscriber_ = json_obj["subscriber"].toBool();
|
||||
username_ = json_obj["name"].toString();
|
||||
session_key_ = json_obj["key"].toString();
|
||||
subscriber_ = json_obj[QStringLiteral("subscriber")].toBool();
|
||||
username_ = json_obj[QStringLiteral("name")].toString();
|
||||
session_key_ = json_obj[QStringLiteral("key")].toString();
|
||||
|
||||
QSettings s;
|
||||
s.beginGroup(settings_group_);
|
||||
@@ -366,8 +366,8 @@ QNetworkReply *ScrobblingAPI20::CreateRequest(const ParamList &request_params) {
|
||||
QByteArray const digest = QCryptographicHash::hash(data_to_sign.toUtf8(), QCryptographicHash::Md5);
|
||||
QString signature = QString::fromLatin1(digest.toHex()).rightJustified(32, '0').toLower();
|
||||
|
||||
url_query.addQueryItem("api_sig", QUrl::toPercentEncoding(signature));
|
||||
url_query.addQueryItem("format", QUrl::toPercentEncoding("json"));
|
||||
url_query.addQueryItem(QStringLiteral("api_sig"), QUrl::toPercentEncoding(signature));
|
||||
url_query.addQueryItem(QStringLiteral("format"), QUrl::toPercentEncoding(QStringLiteral("json")));
|
||||
|
||||
QUrl url(api_url_);
|
||||
QNetworkRequest req(url);
|
||||
@@ -425,8 +425,8 @@ void ScrobblingAPI20::UpdateNowPlayingRequestFinished(QNetworkReply *reply) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!json_obj.contains("nowplaying")) {
|
||||
Error("Json reply from server is missing nowplaying.", json_obj);
|
||||
if (!json_obj.contains(QStringLiteral("nowplaying"))) {
|
||||
Error(QStringLiteral("Json reply from server is missing nowplaying."), json_obj);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -499,18 +499,18 @@ void ScrobblingAPI20::Submit() {
|
||||
continue;
|
||||
}
|
||||
cache_items_sent << cache_item;
|
||||
params << Param(QString("%1[%2]").arg("artist").arg(i), prefer_albumartist_ ? cache_item->metadata.effective_albumartist() : cache_item->metadata.artist);
|
||||
params << Param(QString("%1[%2]").arg("track").arg(i), StripTitle(cache_item->metadata.title));
|
||||
params << Param(QString("%1[%2]").arg("timestamp").arg(i), QString::number(cache_item->timestamp));
|
||||
params << Param(QString("%1[%2]").arg("duration").arg(i), QString::number(cache_item->metadata.length_nanosec / kNsecPerSec));
|
||||
params << Param(QStringLiteral("%1[%2]").arg(QStringLiteral("artist")).arg(i), prefer_albumartist_ ? cache_item->metadata.effective_albumartist() : cache_item->metadata.artist);
|
||||
params << Param(QStringLiteral("%1[%2]").arg(QStringLiteral("track")).arg(i), StripTitle(cache_item->metadata.title));
|
||||
params << Param(QStringLiteral("%1[%2]").arg(QStringLiteral("timestamp")).arg(i), QString::number(cache_item->timestamp));
|
||||
params << Param(QStringLiteral("%1[%2]").arg(QStringLiteral("duration")).arg(i), QString::number(cache_item->metadata.length_nanosec / kNsecPerSec));
|
||||
if (!cache_item->metadata.album.isEmpty()) {
|
||||
params << Param(QString("%1[%2]").arg("album").arg(i), StripAlbum(cache_item->metadata.album));
|
||||
params << Param(QStringLiteral("%1[%2]").arg(QStringLiteral("album")).arg(i), StripAlbum(cache_item->metadata.album));
|
||||
}
|
||||
if (!prefer_albumartist_ && !cache_item->metadata.albumartist.isEmpty()) {
|
||||
params << Param(QString("%1[%2]").arg("albumArtist").arg(i), cache_item->metadata.albumartist);
|
||||
params << Param(QStringLiteral("%1[%2]").arg(QStringLiteral("albumArtist")).arg(i), cache_item->metadata.albumartist);
|
||||
}
|
||||
if (cache_item->metadata.track > 0) {
|
||||
params << Param(QString("%1[%2]").arg("trackNumber").arg(i), QString::number(cache_item->metadata.track));
|
||||
params << Param(QStringLiteral("%1[%2]").arg(QStringLiteral("trackNumber")).arg(i), QString::number(cache_item->metadata.track));
|
||||
}
|
||||
++i;
|
||||
if (cache_items_sent.count() >= kScrobblesPerRequest) break;
|
||||
@@ -547,59 +547,59 @@ void ScrobblingAPI20::ScrobbleRequestFinished(QNetworkReply *reply, ScrobblerCac
|
||||
cache_->Flush(cache_items);
|
||||
submit_error_ = false;
|
||||
|
||||
if (!json_obj.contains("scrobbles")) {
|
||||
Error("Json reply from server is missing scrobbles.", json_obj);
|
||||
if (!json_obj.contains(QStringLiteral("scrobbles"))) {
|
||||
Error(QStringLiteral("Json reply from server is missing scrobbles."), json_obj);
|
||||
StartSubmit();
|
||||
return;
|
||||
}
|
||||
|
||||
QJsonValue value_scrobbles = json_obj["scrobbles"];
|
||||
QJsonValue value_scrobbles = json_obj[QStringLiteral("scrobbles")];
|
||||
if (!value_scrobbles.isObject()) {
|
||||
Error("Json scrobbles is not an object.", json_obj);
|
||||
Error(QStringLiteral("Json scrobbles is not an object."), json_obj);
|
||||
StartSubmit();
|
||||
return;
|
||||
}
|
||||
json_obj = value_scrobbles.toObject();
|
||||
if (json_obj.isEmpty()) {
|
||||
Error("Json scrobbles object is empty.", value_scrobbles);
|
||||
Error(QStringLiteral("Json scrobbles object is empty."), value_scrobbles);
|
||||
StartSubmit();
|
||||
return;
|
||||
}
|
||||
if (!json_obj.contains("@attr") || !json_obj.contains("scrobble")) {
|
||||
Error("Json scrobbles object is missing values.", json_obj);
|
||||
if (!json_obj.contains(QStringLiteral("@attr")) || !json_obj.contains(QStringLiteral("scrobble"))) {
|
||||
Error(QStringLiteral("Json scrobbles object is missing values."), json_obj);
|
||||
StartSubmit();
|
||||
return;
|
||||
}
|
||||
|
||||
QJsonValue value_attr = json_obj["@attr"];
|
||||
QJsonValue value_attr = json_obj[QStringLiteral("@attr")];
|
||||
if (!value_attr.isObject()) {
|
||||
Error("Json scrobbles attr is not an object.", value_attr);
|
||||
Error(QStringLiteral("Json scrobbles attr is not an object."), value_attr);
|
||||
StartSubmit();
|
||||
return;
|
||||
}
|
||||
QJsonObject obj_attr = value_attr.toObject();
|
||||
if (obj_attr.isEmpty()) {
|
||||
Error("Json scrobbles attr is empty.", value_attr);
|
||||
Error(QStringLiteral("Json scrobbles attr is empty."), value_attr);
|
||||
StartSubmit();
|
||||
return;
|
||||
}
|
||||
if (!obj_attr.contains("accepted") || !obj_attr.contains("ignored")) {
|
||||
Error("Json scrobbles attr is missing values.", obj_attr);
|
||||
if (!obj_attr.contains(QStringLiteral("accepted")) || !obj_attr.contains(QStringLiteral("ignored"))) {
|
||||
Error(QStringLiteral("Json scrobbles attr is missing values."), obj_attr);
|
||||
StartSubmit();
|
||||
return;
|
||||
}
|
||||
int accepted = obj_attr["accepted"].toInt();
|
||||
int ignored = obj_attr["ignored"].toInt();
|
||||
int accepted = obj_attr[QStringLiteral("accepted")].toInt();
|
||||
int ignored = obj_attr[QStringLiteral("ignored")].toInt();
|
||||
|
||||
qLog(Debug) << name_ << "Scrobbles accepted:" << accepted << "ignored:" << ignored;
|
||||
|
||||
QJsonArray array_scrobble;
|
||||
|
||||
QJsonValue value_scrobble = json_obj["scrobble"];
|
||||
QJsonValue value_scrobble = json_obj[QStringLiteral("scrobble")];
|
||||
if (value_scrobble.isObject()) {
|
||||
QJsonObject obj_scrobble = value_scrobble.toObject();
|
||||
if (obj_scrobble.isEmpty()) {
|
||||
Error("Json scrobbles scrobble object is empty.", obj_scrobble);
|
||||
Error(QStringLiteral("Json scrobbles scrobble object is empty."), obj_scrobble);
|
||||
StartSubmit();
|
||||
return;
|
||||
}
|
||||
@@ -608,13 +608,13 @@ void ScrobblingAPI20::ScrobbleRequestFinished(QNetworkReply *reply, ScrobblerCac
|
||||
else if (value_scrobble.isArray()) {
|
||||
array_scrobble = value_scrobble.toArray();
|
||||
if (array_scrobble.isEmpty()) {
|
||||
Error("Json scrobbles scrobble array is empty.", value_scrobble);
|
||||
Error(QStringLiteral("Json scrobbles scrobble array is empty."), value_scrobble);
|
||||
StartSubmit();
|
||||
return;
|
||||
}
|
||||
}
|
||||
else {
|
||||
Error("Json scrobbles scrobble is not an object or array.", value_scrobble);
|
||||
Error(QStringLiteral("Json scrobbles scrobble is not an object or array."), value_scrobble);
|
||||
StartSubmit();
|
||||
return;
|
||||
}
|
||||
@@ -622,7 +622,7 @@ void ScrobblingAPI20::ScrobbleRequestFinished(QNetworkReply *reply, ScrobblerCac
|
||||
for (const QJsonValueRef value : array_scrobble) {
|
||||
|
||||
if (!value.isObject()) {
|
||||
Error("Json scrobbles scrobble array value is not an object.");
|
||||
Error(QStringLiteral("Json scrobbles scrobble array value is not an object."));
|
||||
continue;
|
||||
}
|
||||
QJsonObject json_track = value.toObject();
|
||||
@@ -630,25 +630,25 @@ void ScrobblingAPI20::ScrobbleRequestFinished(QNetworkReply *reply, ScrobblerCac
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!json_track.contains("artist") ||
|
||||
!json_track.contains("album") ||
|
||||
!json_track.contains("albumArtist") ||
|
||||
!json_track.contains("track") ||
|
||||
!json_track.contains("timestamp") ||
|
||||
!json_track.contains("ignoredMessage")
|
||||
if (!json_track.contains(QStringLiteral("artist")) ||
|
||||
!json_track.contains(QStringLiteral("album")) ||
|
||||
!json_track.contains(QStringLiteral("albumArtist")) ||
|
||||
!json_track.contains(QStringLiteral("track")) ||
|
||||
!json_track.contains(QStringLiteral("timestamp")) ||
|
||||
!json_track.contains(QStringLiteral("ignoredMessage"))
|
||||
) {
|
||||
Error("Json scrobbles scrobble is missing values.", json_track);
|
||||
Error(QStringLiteral("Json scrobbles scrobble is missing values."), json_track);
|
||||
continue;
|
||||
}
|
||||
|
||||
QJsonValue value_artist = json_track["artist"];
|
||||
QJsonValue value_album = json_track["album"];
|
||||
QJsonValue value_song = json_track["track"];
|
||||
QJsonValue value_ignoredmessage = json_track["ignoredMessage"];
|
||||
QJsonValue value_artist = json_track[QStringLiteral("artist")];
|
||||
QJsonValue value_album = json_track[QStringLiteral("album")];
|
||||
QJsonValue value_song = json_track[QStringLiteral("track")];
|
||||
QJsonValue value_ignoredmessage = json_track[QStringLiteral("ignoredMessage")];
|
||||
//quint64 timestamp = json_track["timestamp"].toVariant().toULongLong();
|
||||
|
||||
if (!value_artist.isObject() || !value_album.isObject() || !value_song.isObject() || !value_ignoredmessage.isObject()) {
|
||||
Error("Json scrobbles scrobble values are not objects.", json_track);
|
||||
Error(QStringLiteral("Json scrobbles scrobble values are not objects."), json_track);
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -658,22 +658,22 @@ void ScrobblingAPI20::ScrobbleRequestFinished(QNetworkReply *reply, ScrobblerCac
|
||||
QJsonObject obj_ignoredmessage = value_ignoredmessage.toObject();
|
||||
|
||||
if (obj_artist.isEmpty() || obj_album.isEmpty() || obj_song.isEmpty() || obj_ignoredmessage.isEmpty()) {
|
||||
Error("Json scrobbles scrobble values objects are empty.", json_track);
|
||||
Error(QStringLiteral("Json scrobbles scrobble values objects are empty."), json_track);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!obj_artist.contains("#text") || !obj_album.contains("#text") || !obj_song.contains("#text")) {
|
||||
if (!obj_artist.contains(QStringLiteral("#text")) || !obj_album.contains(QStringLiteral("#text")) || !obj_song.contains(QStringLiteral("#text"))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
//QString artist = obj_artist["#text"].toString();
|
||||
//QString album = obj_album["#text"].toString();
|
||||
QString song = obj_song["#text"].toString();
|
||||
bool ignoredmessage = obj_ignoredmessage["code"].toVariant().toBool();
|
||||
QString ignoredmessage_text = obj_ignoredmessage["#text"].toString();
|
||||
QString song = obj_song[QStringLiteral("#text")].toString();
|
||||
bool ignoredmessage = obj_ignoredmessage[QStringLiteral("code")].toVariant().toBool();
|
||||
QString ignoredmessage_text = obj_ignoredmessage[QStringLiteral("#text")].toString();
|
||||
|
||||
if (ignoredmessage) {
|
||||
Error(QString("Scrobble for \"%1\" ignored: %2").arg(song, ignoredmessage_text));
|
||||
Error(QStringLiteral("Scrobble for \"%1\" ignored: %2").arg(song, ignoredmessage_text));
|
||||
}
|
||||
else {
|
||||
qLog(Debug) << name_ << "Scrobble for" << song << "accepted";
|
||||
@@ -724,67 +724,67 @@ void ScrobblingAPI20::SingleScrobbleRequestFinished(QNetworkReply *reply, Scrobb
|
||||
return;
|
||||
}
|
||||
|
||||
if (!json_obj.contains("scrobbles")) {
|
||||
Error("Json reply from server is missing scrobbles.", json_obj);
|
||||
if (!json_obj.contains(QStringLiteral("scrobbles"))) {
|
||||
Error(QStringLiteral("Json reply from server is missing scrobbles."), json_obj);
|
||||
cache_item->sent = false;
|
||||
return;
|
||||
}
|
||||
|
||||
cache_->Remove(cache_item);
|
||||
|
||||
QJsonValue value_scrobbles = json_obj["scrobbles"];
|
||||
QJsonValue value_scrobbles = json_obj[QStringLiteral("scrobbles")];
|
||||
if (!value_scrobbles.isObject()) {
|
||||
Error("Json scrobbles is not an object.", json_obj);
|
||||
Error(QStringLiteral("Json scrobbles is not an object."), json_obj);
|
||||
return;
|
||||
}
|
||||
json_obj = value_scrobbles.toObject();
|
||||
if (json_obj.isEmpty()) {
|
||||
Error("Json scrobbles object is empty.", value_scrobbles);
|
||||
Error(QStringLiteral("Json scrobbles object is empty."), value_scrobbles);
|
||||
return;
|
||||
}
|
||||
if (!json_obj.contains("@attr") || !json_obj.contains("scrobble")) {
|
||||
Error("Json scrobbles object is missing values.", json_obj);
|
||||
if (!json_obj.contains(QStringLiteral("@attr")) || !json_obj.contains(QStringLiteral("scrobble"))) {
|
||||
Error(QStringLiteral("Json scrobbles object is missing values."), json_obj);
|
||||
return;
|
||||
}
|
||||
|
||||
QJsonValue value_attr = json_obj["@attr"];
|
||||
QJsonValue value_attr = json_obj[QStringLiteral("@attr")];
|
||||
if (!value_attr.isObject()) {
|
||||
Error("Json scrobbles attr is not an object.", value_attr);
|
||||
Error(QStringLiteral("Json scrobbles attr is not an object."), value_attr);
|
||||
return;
|
||||
}
|
||||
QJsonObject obj_attr = value_attr.toObject();
|
||||
if (obj_attr.isEmpty()) {
|
||||
Error("Json scrobbles attr is empty.", value_attr);
|
||||
Error(QStringLiteral("Json scrobbles attr is empty."), value_attr);
|
||||
return;
|
||||
}
|
||||
|
||||
QJsonValue value_scrobble = json_obj["scrobble"];
|
||||
QJsonValue value_scrobble = json_obj[QStringLiteral("scrobble")];
|
||||
if (!value_scrobble.isObject()) {
|
||||
Error("Json scrobbles scrobble is not an object.", value_scrobble);
|
||||
Error(QStringLiteral("Json scrobbles scrobble is not an object."), value_scrobble);
|
||||
return;
|
||||
}
|
||||
QJsonObject json_obj_scrobble = value_scrobble.toObject();
|
||||
if (json_obj_scrobble.isEmpty()) {
|
||||
Error("Json scrobbles scrobble is empty.", value_scrobble);
|
||||
Error(QStringLiteral("Json scrobbles scrobble is empty."), value_scrobble);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!obj_attr.contains("accepted") || !obj_attr.contains("ignored")) {
|
||||
Error("Json scrobbles attr is missing values.", obj_attr);
|
||||
if (!obj_attr.contains(QStringLiteral("accepted")) || !obj_attr.contains(QStringLiteral("ignored"))) {
|
||||
Error(QStringLiteral("Json scrobbles attr is missing values."), obj_attr);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!json_obj_scrobble.contains("artist") || !json_obj_scrobble.contains("album") || !json_obj_scrobble.contains("albumArtist") || !json_obj_scrobble.contains("track") || !json_obj_scrobble.contains("timestamp")) {
|
||||
Error("Json scrobbles scrobble is missing values.", json_obj_scrobble);
|
||||
if (!json_obj_scrobble.contains(QStringLiteral("artist")) || !json_obj_scrobble.contains(QStringLiteral("album")) || !json_obj_scrobble.contains(QStringLiteral("albumArtist")) || !json_obj_scrobble.contains(QStringLiteral("track")) || !json_obj_scrobble.contains(QStringLiteral("timestamp"))) {
|
||||
Error(QStringLiteral("Json scrobbles scrobble is missing values."), json_obj_scrobble);
|
||||
return;
|
||||
}
|
||||
|
||||
QJsonValue json_value_artist = json_obj_scrobble["artist"];
|
||||
QJsonValue json_value_album = json_obj_scrobble["album"];
|
||||
QJsonValue json_value_song = json_obj_scrobble["track"];
|
||||
QJsonValue json_value_artist = json_obj_scrobble[QStringLiteral("artist")];
|
||||
QJsonValue json_value_album = json_obj_scrobble[QStringLiteral("album")];
|
||||
QJsonValue json_value_song = json_obj_scrobble[QStringLiteral("track")];
|
||||
|
||||
if (!json_value_artist.isObject() || !json_value_album.isObject() || !json_value_song.isObject()) {
|
||||
Error("Json scrobbles scrobble values are not objects.", json_obj_scrobble);
|
||||
Error(QStringLiteral("Json scrobbles scrobble values are not objects."), json_obj_scrobble);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -793,25 +793,25 @@ void ScrobblingAPI20::SingleScrobbleRequestFinished(QNetworkReply *reply, Scrobb
|
||||
QJsonObject json_obj_song = json_value_song.toObject();
|
||||
|
||||
if (json_obj_artist.isEmpty() || json_obj_album.isEmpty() || json_obj_song.isEmpty()) {
|
||||
Error("Json scrobbles scrobble values objects are empty.", json_obj_scrobble);
|
||||
Error(QStringLiteral("Json scrobbles scrobble values objects are empty."), json_obj_scrobble);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!json_obj_artist.contains("#text") || !json_obj_album.contains("#text") || !json_obj_song.contains("#text")) {
|
||||
Error("Json scrobbles scrobble values objects are missing #text.", json_obj_artist);
|
||||
if (!json_obj_artist.contains(QStringLiteral("#text")) || !json_obj_album.contains(QStringLiteral("#text")) || !json_obj_song.contains(QStringLiteral("#text"))) {
|
||||
Error(QStringLiteral("Json scrobbles scrobble values objects are missing #text."), json_obj_artist);
|
||||
return;
|
||||
}
|
||||
|
||||
//QString artist = json_obj_artist["#text"].toString();
|
||||
//QString album = json_obj_album["#text"].toString();
|
||||
QString song = json_obj_song["#text"].toString();
|
||||
QString song = json_obj_song[QStringLiteral("#text")].toString();
|
||||
|
||||
int accepted = obj_attr["accepted"].toVariant().toInt();
|
||||
int accepted = obj_attr[QStringLiteral("accepted")].toVariant().toInt();
|
||||
if (accepted == 1) {
|
||||
qLog(Debug) << name_ << "Scrobble for" << song << "accepted";
|
||||
}
|
||||
else {
|
||||
Error(QString("Scrobble for \"%1\" not accepted").arg(song));
|
||||
Error(QStringLiteral("Scrobble for \"%1\" not accepted").arg(song));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -856,32 +856,32 @@ void ScrobblingAPI20::LoveRequestFinished(QNetworkReply *reply) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (json_obj.contains("error")) {
|
||||
QJsonValue json_value = json_obj["error"];
|
||||
if (json_obj.contains(QStringLiteral("error"))) {
|
||||
QJsonValue json_value = json_obj[QStringLiteral("error")];
|
||||
if (!json_value.isObject()) {
|
||||
Error("Error is not on object.");
|
||||
Error(QStringLiteral("Error is not on object."));
|
||||
return;
|
||||
}
|
||||
QJsonObject json_obj_error = json_value.toObject();
|
||||
if (json_obj_error.isEmpty()) {
|
||||
Error("Received empty json error object.", json_obj);
|
||||
Error(QStringLiteral("Received empty json error object."), json_obj);
|
||||
return;
|
||||
}
|
||||
if (json_obj_error.contains("code") && json_obj_error.contains("#text")) {
|
||||
int code = json_obj_error["code"].toInt();
|
||||
QString text = json_obj_error["#text"].toString();
|
||||
QString error_reason = QString("%1 (%2)").arg(text).arg(code);
|
||||
if (json_obj_error.contains(QStringLiteral("code")) && json_obj_error.contains(QStringLiteral("#text"))) {
|
||||
int code = json_obj_error[QStringLiteral("code")].toInt();
|
||||
QString text = json_obj_error[QStringLiteral("#text")].toString();
|
||||
QString error_reason = QStringLiteral("%1 (%2)").arg(text).arg(code);
|
||||
Error(error_reason);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (json_obj.contains("lfm")) {
|
||||
QJsonValue json_value = json_obj["lfm"];
|
||||
if (json_obj.contains(QStringLiteral("lfm"))) {
|
||||
QJsonValue json_value = json_obj[QStringLiteral("lfm")];
|
||||
if (json_value.isObject()) {
|
||||
QJsonObject json_obj_lfm = json_value.toObject();
|
||||
if (json_obj_lfm.contains("status")) {
|
||||
QString status = json_obj_lfm["status"].toString();
|
||||
if (json_obj_lfm.contains(QStringLiteral("status"))) {
|
||||
QString status = json_obj_lfm[QStringLiteral("status")].toString();
|
||||
qLog(Debug) << name_ << "Received love status:" << status;
|
||||
return;
|
||||
}
|
||||
@@ -911,64 +911,64 @@ QString ScrobblingAPI20::ErrorString(const ScrobbleErrorCode error) {
|
||||
|
||||
switch (error) {
|
||||
case ScrobbleErrorCode::NoError:
|
||||
return QString("This error does not exist.");
|
||||
return QStringLiteral("This error does not exist.");
|
||||
case ScrobbleErrorCode::InvalidService:
|
||||
return QString("Invalid service - This service does not exist.");
|
||||
return QStringLiteral("Invalid service - This service does not exist.");
|
||||
case ScrobbleErrorCode::InvalidMethod:
|
||||
return QString("Invalid Method - No method with that name in this package.");
|
||||
return QStringLiteral("Invalid Method - No method with that name in this package.");
|
||||
case ScrobbleErrorCode::AuthenticationFailed:
|
||||
return QString("Authentication Failed - You do not have permissions to access the service.");
|
||||
return QStringLiteral("Authentication Failed - You do not have permissions to access the service.");
|
||||
case ScrobbleErrorCode::InvalidFormat:
|
||||
return QString("Invalid format - This service doesn't exist in that format.");
|
||||
return QStringLiteral("Invalid format - This service doesn't exist in that format.");
|
||||
case ScrobbleErrorCode::InvalidParameters:
|
||||
return QString("Invalid parameters - Your request is missing a required parameter.");
|
||||
return QStringLiteral("Invalid parameters - Your request is missing a required parameter.");
|
||||
case ScrobbleErrorCode::InvalidResourceSpecified:
|
||||
return QString("Invalid resource specified");
|
||||
return QStringLiteral("Invalid resource specified");
|
||||
case ScrobbleErrorCode::OperationFailed:
|
||||
return QString("Operation failed - Most likely the backend service failed. Please try again.");
|
||||
return QStringLiteral("Operation failed - Most likely the backend service failed. Please try again.");
|
||||
case ScrobbleErrorCode::InvalidSessionKey:
|
||||
return QString("Invalid session key - Please re-authenticate.");
|
||||
return QStringLiteral("Invalid session key - Please re-authenticate.");
|
||||
case ScrobbleErrorCode::InvalidApiKey:
|
||||
return QString("Invalid API key - You must be granted a valid key by last.fm.");
|
||||
return QStringLiteral("Invalid API key - You must be granted a valid key by last.fm.");
|
||||
case ScrobbleErrorCode::ServiceOffline:
|
||||
return QString("Service Offline - This service is temporarily offline. Try again later.");
|
||||
return QStringLiteral("Service Offline - This service is temporarily offline. Try again later.");
|
||||
case ScrobbleErrorCode::SubscribersOnly:
|
||||
return QString("Subscribers Only - This station is only available to paid last.fm subscribers.");
|
||||
return QStringLiteral("Subscribers Only - This station is only available to paid last.fm subscribers.");
|
||||
case ScrobbleErrorCode::InvalidMethodSignature:
|
||||
return QString("Invalid method signature supplied.");
|
||||
return QStringLiteral("Invalid method signature supplied.");
|
||||
case ScrobbleErrorCode::UnauthorizedToken:
|
||||
return QString("Unauthorized Token - This token has not been authorized.");
|
||||
return QStringLiteral("Unauthorized Token - This token has not been authorized.");
|
||||
case ScrobbleErrorCode::ItemUnavailable:
|
||||
return QString("This item is not available for streaming.");
|
||||
return QStringLiteral("This item is not available for streaming.");
|
||||
case ScrobbleErrorCode::TemporarilyUnavailable:
|
||||
return QString("The service is temporarily unavailable, please try again.");
|
||||
return QStringLiteral("The service is temporarily unavailable, please try again.");
|
||||
case ScrobbleErrorCode::LoginRequired:
|
||||
return QString("Login: User requires to be logged in.");
|
||||
return QStringLiteral("Login: User requires to be logged in.");
|
||||
case ScrobbleErrorCode::TrialExpired:
|
||||
return QString("Trial Expired - This user has no free radio plays left. Subscription required.");
|
||||
return QStringLiteral("Trial Expired - This user has no free radio plays left. Subscription required.");
|
||||
case ScrobbleErrorCode::ErrorDoesNotExist:
|
||||
return QString("This error does not exist.");
|
||||
return QStringLiteral("This error does not exist.");
|
||||
case ScrobbleErrorCode::NotEnoughContent:
|
||||
return QString("Not Enough Content - There is not enough content to play this station.");
|
||||
return QStringLiteral("Not Enough Content - There is not enough content to play this station.");
|
||||
case ScrobbleErrorCode::NotEnoughMembers:
|
||||
return QString("Not Enough Members - This group does not have enough members for radio.");
|
||||
return QStringLiteral("Not Enough Members - This group does not have enough members for radio.");
|
||||
case ScrobbleErrorCode::NotEnoughFans:
|
||||
return QString("Not Enough Fans - This artist does not have enough fans for for radio.");
|
||||
return QStringLiteral("Not Enough Fans - This artist does not have enough fans for for radio.");
|
||||
case ScrobbleErrorCode::NotEnoughNeighbours:
|
||||
return QString("Not Enough Neighbours - There are not enough neighbours for radio.");
|
||||
return QStringLiteral("Not Enough Neighbours - There are not enough neighbours for radio.");
|
||||
case ScrobbleErrorCode::NoPeakRadio:
|
||||
return QString("No Peak Radio - This user is not allowed to listen to radio during peak usage.");
|
||||
return QStringLiteral("No Peak Radio - This user is not allowed to listen to radio during peak usage.");
|
||||
case ScrobbleErrorCode::RadioNotFound:
|
||||
return QString("Radio Not Found - Radio station not found.");
|
||||
return QStringLiteral("Radio Not Found - Radio station not found.");
|
||||
case ScrobbleErrorCode::APIKeySuspended:
|
||||
return QString("Suspended API key - Access for your account has been suspended, please contact Last.fm");
|
||||
return QStringLiteral("Suspended API key - Access for your account has been suspended, please contact Last.fm");
|
||||
case ScrobbleErrorCode::Deprecated:
|
||||
return QString("Deprecated - This type of request is no longer supported.");
|
||||
return QStringLiteral("Deprecated - This type of request is no longer supported.");
|
||||
case ScrobbleErrorCode::RateLimitExceeded:
|
||||
return QString("Rate limit exceeded - Your IP has made too many requests in a short period.");
|
||||
return QStringLiteral("Rate limit exceeded - Your IP has made too many requests in a short period.");
|
||||
}
|
||||
|
||||
return QString("Unknown error.");
|
||||
return QStringLiteral("Unknown error.");
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user