Replace QLatin1String with operator _L1
This commit is contained in:
@@ -38,6 +38,8 @@
|
||||
#include "lyricssearchresult.h"
|
||||
#include "chartlyricsprovider.h"
|
||||
|
||||
using namespace Qt::StringLiterals;
|
||||
|
||||
namespace {
|
||||
constexpr char kUrlSearch[] = "http://api.chartlyrics.com/apiv1.asmx/SearchLyricDirect";
|
||||
}
|
||||
@@ -100,21 +102,21 @@ void ChartLyricsProvider::HandleSearchReply(QNetworkReply *reply, const int id,
|
||||
QXmlStreamReader::TokenType type = reader.readNext();
|
||||
QString name = reader.name().toString();
|
||||
if (type == QXmlStreamReader::StartElement) {
|
||||
if (name == QLatin1String("GetLyricResult")) {
|
||||
if (name == "GetLyricResult"_L1) {
|
||||
result = LyricsSearchResult();
|
||||
}
|
||||
if (name == QLatin1String("LyricArtist")) {
|
||||
if (name == "LyricArtist"_L1) {
|
||||
result.artist = reader.readElementText();
|
||||
}
|
||||
else if (name == QLatin1String("LyricSong")) {
|
||||
else if (name == "LyricSong"_L1) {
|
||||
result.title = reader.readElementText();
|
||||
}
|
||||
else if (name == QLatin1String("Lyric")) {
|
||||
else if (name == "Lyric"_L1) {
|
||||
result.lyrics = reader.readElementText();
|
||||
}
|
||||
}
|
||||
else if (type == QXmlStreamReader::EndElement) {
|
||||
if (name == QLatin1String("GetLyricResult")) {
|
||||
if (name == "GetLyricResult"_L1) {
|
||||
if (!result.artist.isEmpty() && !result.title.isEmpty() && !result.lyrics.isEmpty() &&
|
||||
(result.artist.compare(request.albumartist, Qt::CaseInsensitive) == 0 ||
|
||||
result.artist.compare(request.artist, Qt::CaseInsensitive) == 0 ||
|
||||
|
||||
@@ -29,6 +29,8 @@
|
||||
#include "lyricssearchrequest.h"
|
||||
#include "elyricsnetlyricsprovider.h"
|
||||
|
||||
using namespace Qt::StringLiterals;
|
||||
|
||||
namespace {
|
||||
constexpr char kUrl[] = "https://www.elyrics.net/read/";
|
||||
constexpr char kStartTag[] = "<div[^>]*>";
|
||||
@@ -41,7 +43,7 @@ ElyricsNetLyricsProvider::ElyricsNetLyricsProvider(SharedPtr<NetworkAccessManage
|
||||
|
||||
QUrl ElyricsNetLyricsProvider::Url(const LyricsSearchRequest &request) {
|
||||
|
||||
return QUrl(QLatin1String(kUrl) + request.artist[0].toLower() + QLatin1Char('/') + StringFixup(request.artist) + QLatin1String("-lyrics/") + StringFixup(request.title) + QLatin1String("-lyrics.html"));
|
||||
return QUrl(QLatin1String(kUrl) + request.artist[0].toLower() + QLatin1Char('/') + StringFixup(request.artist) + "-lyrics/"_L1 + StringFixup(request.title) + "-lyrics.html"_L1);
|
||||
|
||||
}
|
||||
|
||||
@@ -56,7 +58,7 @@ QString ElyricsNetLyricsProvider::StringFixup(const QString &text) {
|
||||
.replace(regex_illegal_characters, QStringLiteral("_"))
|
||||
.replace(regex_duplicate_whitespaces, QStringLiteral(" "))
|
||||
.simplified()
|
||||
.replace(QLatin1Char(' '), QLatin1Char('-'))
|
||||
.replace(u' ', u'-')
|
||||
.toLower();
|
||||
|
||||
}
|
||||
|
||||
@@ -55,6 +55,7 @@
|
||||
#include "htmllyricsprovider.h"
|
||||
#include "geniuslyricsprovider.h"
|
||||
|
||||
using namespace Qt::StringLiterals;
|
||||
using std::make_shared;
|
||||
|
||||
namespace {
|
||||
@@ -128,7 +129,7 @@ void GeniusLyricsProvider::Authenticate() {
|
||||
|
||||
code_verifier_ = Utilities::CryptographicRandomString(44);
|
||||
code_challenge_ = QString::fromLatin1(QCryptographicHash::hash(code_verifier_.toUtf8(), QCryptographicHash::Sha256).toBase64(QByteArray::Base64UrlEncoding));
|
||||
if (code_challenge_.lastIndexOf(QLatin1Char('=')) == code_challenge_.length() - 1) {
|
||||
if (code_challenge_.lastIndexOf(u'=') == code_challenge_.length() - 1) {
|
||||
code_challenge_.chop(1);
|
||||
}
|
||||
|
||||
@@ -250,9 +251,9 @@ void GeniusLyricsProvider::AccessTokenRequestFinished(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.isEmpty() && json_obj.contains(QLatin1String("error")) && json_obj.contains(QLatin1String("error_description"))) {
|
||||
QString error = json_obj[QLatin1String("error")].toString();
|
||||
QString error_description = json_obj[QLatin1String("error_description")].toString();
|
||||
if (!json_obj.isEmpty() && json_obj.contains("error"_L1) && json_obj.contains("error_description"_L1)) {
|
||||
QString error = json_obj["error"_L1].toString();
|
||||
QString error_description = json_obj["error_description"_L1].toString();
|
||||
login_errors_ << QStringLiteral("Authentication failure: %1 (%2)").arg(error, error_description);
|
||||
}
|
||||
}
|
||||
@@ -295,12 +296,12 @@ void GeniusLyricsProvider::AccessTokenRequestFinished(QNetworkReply *reply) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!json_obj.contains(QLatin1String("access_token"))) {
|
||||
if (!json_obj.contains("access_token"_L1)) {
|
||||
AuthError(QStringLiteral("Authentication reply from server is missing access token."), json_obj);
|
||||
return;
|
||||
}
|
||||
|
||||
const QString access_token = json_obj[QLatin1String("access_token")].toString();
|
||||
const QString access_token = json_obj["access_token"_L1].toString();
|
||||
|
||||
set_access_token(access_token);
|
||||
|
||||
@@ -362,26 +363,26 @@ void GeniusLyricsProvider::HandleSearchReply(QNetworkReply *reply, const int id)
|
||||
return;
|
||||
}
|
||||
|
||||
if (!json_obj.contains(QLatin1String("meta"))) {
|
||||
if (!json_obj.contains("meta"_L1)) {
|
||||
Error(QStringLiteral("Json reply is missing meta object."), json_obj);
|
||||
EndSearch(search);
|
||||
return;
|
||||
}
|
||||
if (!json_obj[QLatin1String("meta")].isObject()) {
|
||||
if (!json_obj["meta"_L1].isObject()) {
|
||||
Error(QStringLiteral("Json reply meta is not an object."), json_obj);
|
||||
EndSearch(search);
|
||||
return;
|
||||
}
|
||||
QJsonObject obj_meta = json_obj[QLatin1String("meta")].toObject();
|
||||
if (!obj_meta.contains(QLatin1String("status"))) {
|
||||
QJsonObject obj_meta = json_obj["meta"_L1].toObject();
|
||||
if (!obj_meta.contains("status"_L1)) {
|
||||
Error(QStringLiteral("Json reply meta object is missing status."), obj_meta);
|
||||
EndSearch(search);
|
||||
return;
|
||||
}
|
||||
int status = obj_meta[QLatin1String("status")].toInt();
|
||||
int status = obj_meta["status"_L1].toInt();
|
||||
if (status != 200) {
|
||||
if (obj_meta.contains(QLatin1String("message"))) {
|
||||
Error(QStringLiteral("Received error %1: %2.").arg(status).arg(obj_meta[QLatin1String("message")].toString()));
|
||||
if (obj_meta.contains("message"_L1)) {
|
||||
Error(QStringLiteral("Received error %1: %2.").arg(status).arg(obj_meta["message"_L1].toString()));
|
||||
}
|
||||
else {
|
||||
Error(QStringLiteral("Received error %1.").arg(status));
|
||||
@@ -390,50 +391,50 @@ void GeniusLyricsProvider::HandleSearchReply(QNetworkReply *reply, const int id)
|
||||
return;
|
||||
}
|
||||
|
||||
if (!json_obj.contains(QLatin1String("response"))) {
|
||||
if (!json_obj.contains("response"_L1)) {
|
||||
Error(QStringLiteral("Json reply is missing response."), json_obj);
|
||||
EndSearch(search);
|
||||
return;
|
||||
}
|
||||
if (!json_obj[QLatin1String("response")].isObject()) {
|
||||
if (!json_obj["response"_L1].isObject()) {
|
||||
Error(QStringLiteral("Json response is not an object."), json_obj);
|
||||
EndSearch(search);
|
||||
return;
|
||||
}
|
||||
QJsonObject obj_response = json_obj[QLatin1String("response")].toObject();
|
||||
if (!obj_response.contains(QLatin1String("hits"))) {
|
||||
QJsonObject obj_response = json_obj["response"_L1].toObject();
|
||||
if (!obj_response.contains("hits"_L1)) {
|
||||
Error(QStringLiteral("Json response is missing hits."), obj_response);
|
||||
EndSearch(search);
|
||||
return;
|
||||
}
|
||||
if (!obj_response[QLatin1String("hits")].isArray()) {
|
||||
if (!obj_response["hits"_L1].isArray()) {
|
||||
Error(QStringLiteral("Json hits is not an array."), obj_response);
|
||||
EndSearch(search);
|
||||
return;
|
||||
}
|
||||
const QJsonArray array_hits = obj_response[QLatin1String("hits")].toArray();
|
||||
const QJsonArray array_hits = obj_response["hits"_L1].toArray();
|
||||
|
||||
for (const QJsonValue &value_hit : array_hits) {
|
||||
if (!value_hit.isObject()) {
|
||||
continue;
|
||||
}
|
||||
QJsonObject obj_hit = value_hit.toObject();
|
||||
if (!obj_hit.contains(QLatin1String("result"))) {
|
||||
if (!obj_hit.contains("result"_L1)) {
|
||||
continue;
|
||||
}
|
||||
if (!obj_hit[QLatin1String("result")].isObject()) {
|
||||
if (!obj_hit["result"_L1].isObject()) {
|
||||
continue;
|
||||
}
|
||||
QJsonObject obj_result = obj_hit[QLatin1String("result")].toObject();
|
||||
if (!obj_result.contains(QLatin1String("title")) || !obj_result.contains(QLatin1String("primary_artist")) || !obj_result.contains(QLatin1String("url")) || !obj_result[QLatin1String("primary_artist")].isObject()) {
|
||||
QJsonObject obj_result = obj_hit["result"_L1].toObject();
|
||||
if (!obj_result.contains("title"_L1) || !obj_result.contains("primary_artist"_L1) || !obj_result.contains("url"_L1) || !obj_result["primary_artist"_L1].isObject()) {
|
||||
Error(QStringLiteral("Missing one or more values in result object"), obj_result);
|
||||
continue;
|
||||
}
|
||||
QJsonObject primary_artist = obj_result[QLatin1String("primary_artist")].toObject();
|
||||
if (!primary_artist.contains(QLatin1String("name"))) continue;
|
||||
QJsonObject primary_artist = obj_result["primary_artist"_L1].toObject();
|
||||
if (!primary_artist.contains("name"_L1)) continue;
|
||||
|
||||
QString artist = primary_artist[QLatin1String("name")].toString();
|
||||
QString title = obj_result[QLatin1String("title")].toString();
|
||||
QString artist = primary_artist["name"_L1].toString();
|
||||
QString title = obj_result["title"_L1].toString();
|
||||
|
||||
// Ignore results where both the artist and title don't match.
|
||||
if (!artist.startsWith(search->request.albumartist, Qt::CaseInsensitive) &&
|
||||
@@ -442,7 +443,7 @@ void GeniusLyricsProvider::HandleSearchReply(QNetworkReply *reply, const int id)
|
||||
continue;
|
||||
}
|
||||
|
||||
QUrl url(obj_result[QLatin1String("url")].toString());
|
||||
QUrl url(obj_result["url"_L1].toString());
|
||||
if (!url.isValid()) continue;
|
||||
if (search->requests_lyric_.contains(url)) continue;
|
||||
|
||||
|
||||
@@ -36,6 +36,8 @@
|
||||
#include "htmllyricsprovider.h"
|
||||
#include "lyricssearchrequest.h"
|
||||
|
||||
using namespace Qt::StringLiterals;
|
||||
|
||||
HtmlLyricsProvider::HtmlLyricsProvider(const QString &name, const bool enabled, const QString &start_tag, const QString &end_tag, const QString &lyrics_start, const bool multiple, SharedPtr<NetworkAccessManager> network, QObject *parent)
|
||||
: LyricsProvider(name, enabled, false, network, parent), start_tag_(start_tag), end_tag_(end_tag), lyrics_start_(lyrics_start), multiple_(multiple) {}
|
||||
|
||||
@@ -110,7 +112,7 @@ void HtmlLyricsProvider::HandleLyricsReply(QNetworkReply *reply, const int id, c
|
||||
}
|
||||
|
||||
const QString lyrics = ParseLyricsFromHTML(QString::fromUtf8(data), QRegularExpression(start_tag_), QRegularExpression(end_tag_), QRegularExpression(lyrics_start_), multiple_);
|
||||
if (lyrics.isEmpty() || lyrics.contains(QLatin1String("we do not have the lyrics for"), Qt::CaseInsensitive)) {
|
||||
if (lyrics.isEmpty() || lyrics.contains("we do not have the lyrics for"_L1, Qt::CaseInsensitive)) {
|
||||
qLog(Debug) << name_ << "No lyrics for" << request.artist << request.album << request.title;
|
||||
Q_EMIT SearchFinished(id);
|
||||
return;
|
||||
@@ -165,7 +167,7 @@ QString HtmlLyricsProvider::ParseLyricsFromHTML(const QString &content, const QR
|
||||
|
||||
if (end_lyrics_idx != -1 && start_lyrics_idx < end_lyrics_idx) {
|
||||
if (!lyrics.isEmpty()) {
|
||||
lyrics.append(QLatin1Char('\n'));
|
||||
lyrics.append(u'\n');
|
||||
}
|
||||
static const QRegularExpression regex_html_tag_a(QStringLiteral("<a [^>]*>[^<]*</a>"));
|
||||
static const QRegularExpression regex_html_tag_script(QStringLiteral("<script>[^>]*</script>"));
|
||||
@@ -174,8 +176,8 @@ QString HtmlLyricsProvider::ParseLyricsFromHTML(const QString &content, const QR
|
||||
static const QRegularExpression regex_html_tag_p_close(QStringLiteral("</p>"));
|
||||
static const QRegularExpression regex_html_tags(QStringLiteral("<[^>]*>"));
|
||||
lyrics.append(content.mid(start_lyrics_idx, end_lyrics_idx - start_lyrics_idx)
|
||||
.remove(QLatin1Char('\r'))
|
||||
.remove(QLatin1Char('\n'))
|
||||
.remove(u'\r')
|
||||
.remove(u'\n')
|
||||
.remove(regex_html_tag_a)
|
||||
.remove(regex_html_tag_script)
|
||||
.remove(regex_html_tag_div)
|
||||
@@ -191,7 +193,7 @@ QString HtmlLyricsProvider::ParseLyricsFromHTML(const QString &content, const QR
|
||||
}
|
||||
while (start_idx > 0 && multiple);
|
||||
|
||||
if (lyrics.length() > 6000 || lyrics.contains(QLatin1String("there are no lyrics to"), Qt::CaseInsensitive)) {
|
||||
if (lyrics.length() > 6000 || lyrics.contains("there are no lyrics to"_L1, Qt::CaseInsensitive)) {
|
||||
return QString();
|
||||
}
|
||||
|
||||
|
||||
@@ -30,6 +30,8 @@
|
||||
#include "lyricssearchrequest.h"
|
||||
#include "letraslyricsprovider.h"
|
||||
|
||||
using namespace Qt::StringLiterals;
|
||||
|
||||
namespace {
|
||||
constexpr char kUrl[] = "https://www.letras.mus.br/winamp.php";
|
||||
constexpr char kStartTag[] = "<div[^>]*>";
|
||||
@@ -42,7 +44,7 @@ LetrasLyricsProvider::LetrasLyricsProvider(SharedPtr<NetworkAccessManager> netwo
|
||||
|
||||
QUrl LetrasLyricsProvider::Url(const LyricsSearchRequest &request) {
|
||||
|
||||
return QUrl(QLatin1String(kUrl) + QLatin1String("?musica=") + StringFixup(request.artist) + QLatin1String("&artista=") + StringFixup(request.title));
|
||||
return QUrl(QLatin1String(kUrl) + "?musica="_L1 + StringFixup(request.artist) + "&artista="_L1 + StringFixup(request.title));
|
||||
|
||||
}
|
||||
|
||||
@@ -57,7 +59,7 @@ QString LetrasLyricsProvider::StringFixup(const QString &text) {
|
||||
.replace(regex_illegal_characters, QStringLiteral("_"))
|
||||
.replace(regex_multiple_whitespaces, QStringLiteral(" "))
|
||||
.simplified()
|
||||
.replace(QLatin1Char(' '), QLatin1Char('-'))
|
||||
.replace(u' ', u'-')
|
||||
.toLower()
|
||||
));
|
||||
|
||||
|
||||
@@ -38,6 +38,8 @@
|
||||
#include "lyricssearchresult.h"
|
||||
#include "lololyricsprovider.h"
|
||||
|
||||
using namespace Qt::StringLiterals;
|
||||
|
||||
namespace {
|
||||
constexpr char kUrlSearch[] = "http://api.lololyrics.com/0.5/getLyric";
|
||||
}
|
||||
@@ -104,15 +106,15 @@ void LoloLyricsProvider::HandleSearchReply(QNetworkReply *reply, const int id, c
|
||||
QXmlStreamReader::TokenType type = reader.readNext();
|
||||
QString name = reader.name().toString();
|
||||
if (type == QXmlStreamReader::StartElement) {
|
||||
if (name == QLatin1String("result")) {
|
||||
if (name == "result"_L1) {
|
||||
status.clear();
|
||||
result = LyricsSearchResult();
|
||||
}
|
||||
else if (name == QLatin1String("status")) {
|
||||
else if (name == "status"_L1) {
|
||||
status = reader.readElementText();
|
||||
}
|
||||
else if (name == QLatin1String("response")) {
|
||||
if (status == QLatin1String("OK")) {
|
||||
else if (name == "response"_L1) {
|
||||
if (status == "OK"_L1) {
|
||||
result.lyrics = reader.readElementText();
|
||||
}
|
||||
else {
|
||||
@@ -122,7 +124,7 @@ void LoloLyricsProvider::HandleSearchReply(QNetworkReply *reply, const int id, c
|
||||
}
|
||||
}
|
||||
else if (type == QXmlStreamReader::EndElement) {
|
||||
if (name == QLatin1String("result")) {
|
||||
if (name == "result"_L1) {
|
||||
if (!result.lyrics.isEmpty()) {
|
||||
result.lyrics = Utilities::DecodeHtmlEntities(result.lyrics);
|
||||
results << result;
|
||||
|
||||
@@ -37,6 +37,8 @@
|
||||
#include "utilities/transliterate.h"
|
||||
#include "lyricfindlyricsprovider.h"
|
||||
|
||||
using namespace Qt::StringLiterals;
|
||||
|
||||
namespace {
|
||||
constexpr char kUrl[] = "https://lyrics.lyricfind.com/lyrics";
|
||||
constexpr char kLyricsStart[] = "<script id=\"__NEXT_DATA__\" type=\"application/json\">";
|
||||
@@ -73,7 +75,7 @@ QString LyricFindLyricsProvider::StringFixup(const QString &text) {
|
||||
.remove(regex_illegal_characters)
|
||||
.replace(regex_multiple_whitespaces, QStringLiteral(" "))
|
||||
.simplified()
|
||||
.replace(QLatin1Char(' '), QLatin1Char('-'))
|
||||
.replace(u' ', u'-')
|
||||
.toLower();
|
||||
|
||||
}
|
||||
@@ -151,48 +153,48 @@ void LyricFindLyricsProvider::HandleSearchReply(QNetworkReply *reply, const int
|
||||
if (obj.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
if (!obj.contains(QLatin1String("props")) || !obj[QLatin1String("props")].isObject()) {
|
||||
if (!obj.contains("props"_L1) || !obj["props"_L1].isObject()) {
|
||||
Error(QStringLiteral("Missing props."));
|
||||
return;
|
||||
}
|
||||
obj = obj[QLatin1String("props")].toObject();
|
||||
if (!obj.contains(QLatin1String("pageProps")) || !obj[QLatin1String("pageProps")].isObject()) {
|
||||
obj = obj["props"_L1].toObject();
|
||||
if (!obj.contains("pageProps"_L1) || !obj["pageProps"_L1].isObject()) {
|
||||
Error(QStringLiteral("Missing pageProps."));
|
||||
return;
|
||||
}
|
||||
obj = obj[QLatin1String("pageProps")].toObject();
|
||||
if (!obj.contains(QLatin1String("songData")) || !obj[QLatin1String("songData")].isObject()) {
|
||||
obj = obj["pageProps"_L1].toObject();
|
||||
if (!obj.contains("songData"_L1) || !obj["songData"_L1].isObject()) {
|
||||
Error(QStringLiteral("Missing songData."));
|
||||
return;
|
||||
}
|
||||
obj = obj[QLatin1String("songData")].toObject();
|
||||
obj = obj["songData"_L1].toObject();
|
||||
|
||||
if (!obj.contains(QLatin1String("response")) || !obj[QLatin1String("response")].isObject()) {
|
||||
if (!obj.contains("response"_L1) || !obj["response"_L1].isObject()) {
|
||||
Error(QStringLiteral("Missing response."));
|
||||
return;
|
||||
}
|
||||
//const QJsonObject obj_response = obj[QLatin1String("response")].toObject();
|
||||
|
||||
if (!obj.contains(QLatin1String("track")) || !obj[QLatin1String("track")].isObject()) {
|
||||
if (!obj.contains("track"_L1) || !obj["track"_L1].isObject()) {
|
||||
Error(QStringLiteral("Missing track."));
|
||||
return;
|
||||
}
|
||||
const QJsonObject obj_track = obj[QLatin1String("track")].toObject();
|
||||
const QJsonObject obj_track = obj["track"_L1].toObject();
|
||||
|
||||
if (!obj_track.contains(QLatin1String("title")) ||
|
||||
!obj_track.contains(QLatin1String("lyrics"))) {
|
||||
if (!obj_track.contains("title"_L1) ||
|
||||
!obj_track.contains("lyrics"_L1)) {
|
||||
Error(QStringLiteral("Missing title or lyrics."));
|
||||
return;
|
||||
}
|
||||
|
||||
LyricsSearchResult result;
|
||||
|
||||
const QJsonObject obj_artist = obj[QLatin1String("artist")].toObject();
|
||||
if (obj_artist.contains(QLatin1String("name"))) {
|
||||
result.artist = obj_artist[QLatin1String("name")].toString();
|
||||
const QJsonObject obj_artist = obj["artist"_L1].toObject();
|
||||
if (obj_artist.contains("name"_L1)) {
|
||||
result.artist = obj_artist["name"_L1].toString();
|
||||
}
|
||||
result.title = obj_track[QLatin1String("title")].toString();
|
||||
result.lyrics = obj_track[QLatin1String("lyrics")].toString();
|
||||
result.title = obj_track["title"_L1].toString();
|
||||
result.lyrics = obj_track["lyrics"_L1].toString();
|
||||
results << result;
|
||||
|
||||
}
|
||||
|
||||
@@ -33,6 +33,8 @@
|
||||
#include "lyricsprovider.h"
|
||||
#include "lyricsproviders.h"
|
||||
|
||||
using namespace Qt::StringLiterals;
|
||||
|
||||
namespace {
|
||||
constexpr int kSearchTimeoutMs = 3000;
|
||||
constexpr int kGoodLyricsLength = 60;
|
||||
@@ -62,7 +64,7 @@ void LyricsFetcherSearch::TerminateSearch() {
|
||||
void LyricsFetcherSearch::Start(SharedPtr<LyricsProviders> lyrics_providers) {
|
||||
|
||||
// Ignore Radio Paradise "commercial" break.
|
||||
if (request_.artist.compare(QLatin1String("commercial-free"), Qt::CaseInsensitive) == 0 && request_.title.compare(QLatin1String("listener-supported"), Qt::CaseInsensitive) == 0) {
|
||||
if (request_.artist.compare("commercial-free"_L1, Qt::CaseInsensitive) == 0 && request_.title.compare("listener-supported"_L1, Qt::CaseInsensitive) == 0) {
|
||||
TerminateSearch();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -45,6 +45,7 @@
|
||||
#include "musixmatchlyricsprovider.h"
|
||||
#include "providers/musixmatchprovider.h"
|
||||
|
||||
using namespace Qt::StringLiterals;
|
||||
using std::make_shared;
|
||||
|
||||
MusixmatchLyricsProvider::MusixmatchLyricsProvider(SharedPtr<NetworkAccessManager> network, QObject *parent) : JsonLyricsProvider(QStringLiteral("Musixmatch"), true, false, network, parent), use_api_(true) {}
|
||||
@@ -140,31 +141,31 @@ void MusixmatchLyricsProvider::HandleSearchReply(QNetworkReply *reply, LyricsSea
|
||||
return;
|
||||
}
|
||||
|
||||
if (!json_obj.contains(QLatin1String("message"))) {
|
||||
if (!json_obj.contains("message"_L1)) {
|
||||
Error(QStringLiteral("Json reply is missing message object."), json_obj);
|
||||
EndSearch(search);
|
||||
return;
|
||||
}
|
||||
if (!json_obj[QLatin1String("message")].isObject()) {
|
||||
if (!json_obj["message"_L1].isObject()) {
|
||||
Error(QStringLiteral("Json reply message is not an object."), json_obj);
|
||||
EndSearch(search);
|
||||
return;
|
||||
}
|
||||
QJsonObject obj_message = json_obj[QLatin1String("message")].toObject();
|
||||
QJsonObject obj_message = json_obj["message"_L1].toObject();
|
||||
|
||||
if (!obj_message.contains(QLatin1String("header"))) {
|
||||
if (!obj_message.contains("header"_L1)) {
|
||||
Error(QStringLiteral("Json reply message object is missing header."), obj_message);
|
||||
EndSearch(search);
|
||||
return;
|
||||
}
|
||||
if (!obj_message[QLatin1String("header")].isObject()) {
|
||||
if (!obj_message["header"_L1].isObject()) {
|
||||
Error(QStringLiteral("Json reply message header is not an object."), obj_message);
|
||||
EndSearch(search);
|
||||
return;
|
||||
}
|
||||
QJsonObject obj_header = obj_message[QLatin1String("header")].toObject();
|
||||
QJsonObject obj_header = obj_message["header"_L1].toObject();
|
||||
|
||||
int status_code = obj_header[QLatin1String("status_code")].toInt();
|
||||
int status_code = obj_header["status_code"_L1].toInt();
|
||||
if (status_code != 200) {
|
||||
Error(QStringLiteral("Received status code %1, switching to URL based lookup.").arg(status_code));
|
||||
use_api_ = false;
|
||||
@@ -172,29 +173,29 @@ void MusixmatchLyricsProvider::HandleSearchReply(QNetworkReply *reply, LyricsSea
|
||||
return;
|
||||
}
|
||||
|
||||
if (!obj_message.contains(QLatin1String("body"))) {
|
||||
if (!obj_message.contains("body"_L1)) {
|
||||
Error(QStringLiteral("Json reply is missing body."), json_obj);
|
||||
EndSearch(search);
|
||||
return;
|
||||
}
|
||||
if (!obj_message[QLatin1String("body")].isObject()) {
|
||||
if (!obj_message["body"_L1].isObject()) {
|
||||
Error(QStringLiteral("Json body is not an object."), json_obj);
|
||||
EndSearch(search);
|
||||
return;
|
||||
}
|
||||
QJsonObject obj_body = obj_message[QLatin1String("body")].toObject();
|
||||
QJsonObject obj_body = obj_message["body"_L1].toObject();
|
||||
|
||||
if (!obj_body.contains(QLatin1String("track_list"))) {
|
||||
if (!obj_body.contains("track_list"_L1)) {
|
||||
Error(QStringLiteral("Json response is missing body."), obj_body);
|
||||
EndSearch(search);
|
||||
return;
|
||||
}
|
||||
if (!obj_body[QLatin1String("track_list")].isArray()) {
|
||||
if (!obj_body["track_list"_L1].isArray()) {
|
||||
Error(QStringLiteral("Json hits is not an array."), obj_body);
|
||||
EndSearch(search);
|
||||
return;
|
||||
}
|
||||
const QJsonArray array_tracklist = obj_body[QLatin1String("track_list")].toArray();
|
||||
const QJsonArray array_tracklist = obj_body["track_list"_L1].toArray();
|
||||
|
||||
for (const QJsonValue &value_track : array_tracklist) {
|
||||
if (!value_track.isObject()) {
|
||||
@@ -202,23 +203,23 @@ void MusixmatchLyricsProvider::HandleSearchReply(QNetworkReply *reply, LyricsSea
|
||||
}
|
||||
QJsonObject obj_track = value_track.toObject();
|
||||
|
||||
if (!obj_track.contains(QLatin1String("track")) || !obj_track[QLatin1String("track")].isObject()) {
|
||||
if (!obj_track.contains("track"_L1) || !obj_track["track"_L1].isObject()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
obj_track = obj_track[QLatin1String("track")].toObject();
|
||||
if (!obj_track.contains(QLatin1String("artist_name")) ||
|
||||
!obj_track.contains(QLatin1String("album_name")) ||
|
||||
!obj_track.contains(QLatin1String("track_name")) ||
|
||||
!obj_track.contains(QLatin1String("track_share_url"))) {
|
||||
obj_track = obj_track["track"_L1].toObject();
|
||||
if (!obj_track.contains("artist_name"_L1) ||
|
||||
!obj_track.contains("album_name"_L1) ||
|
||||
!obj_track.contains("track_name"_L1) ||
|
||||
!obj_track.contains("track_share_url"_L1)) {
|
||||
Error(QStringLiteral("Missing one or more values in result object"), obj_track);
|
||||
continue;
|
||||
}
|
||||
|
||||
QString artist_name = obj_track[QLatin1String("artist_name")].toString();
|
||||
QString album_name = obj_track[QLatin1String("album_name")].toString();
|
||||
QString track_name = obj_track[QLatin1String("track_name")].toString();
|
||||
QUrl track_share_url(obj_track[QLatin1String("track_share_url")].toString());
|
||||
QString artist_name = obj_track["artist_name"_L1].toString();
|
||||
QString album_name = obj_track["album_name"_L1].toString();
|
||||
QString track_name = obj_track["track_name"_L1].toString();
|
||||
QUrl track_share_url(obj_track["track_share_url"_L1].toString());
|
||||
|
||||
// Ignore results where both the artist, album and title don't match.
|
||||
if (use_api_ &&
|
||||
@@ -304,8 +305,8 @@ void MusixmatchLyricsProvider::HandleLyricsReply(QNetworkReply *reply, LyricsSea
|
||||
}
|
||||
|
||||
const QString content = QString::fromUtf8(data);
|
||||
const QString data_begin = QLatin1String("<script id=\"__NEXT_DATA__\" type=\"application/json\">");
|
||||
const QString data_end = QLatin1String("</script>");
|
||||
const QString data_begin = "<script id=\"__NEXT_DATA__\" type=\"application/json\">"_L1;
|
||||
const QString data_end = "</script>"_L1;
|
||||
qint64 begin_idx = content.indexOf(data_begin);
|
||||
QString content_json;
|
||||
if (begin_idx > 0) {
|
||||
@@ -333,86 +334,86 @@ void MusixmatchLyricsProvider::HandleLyricsReply(QNetworkReply *reply, LyricsSea
|
||||
return;
|
||||
}
|
||||
|
||||
if (!obj_data.contains(QLatin1String("props")) || !obj_data[QLatin1String("props")].isObject()) {
|
||||
if (!obj_data.contains("props"_L1) || !obj_data["props"_L1].isObject()) {
|
||||
Error(QStringLiteral("Json reply is missing props."), obj_data);
|
||||
EndSearch(search, url);
|
||||
return;
|
||||
}
|
||||
obj_data = obj_data[QLatin1String("props")].toObject();
|
||||
obj_data = obj_data["props"_L1].toObject();
|
||||
|
||||
if (!obj_data.contains(QLatin1String("pageProps")) || !obj_data[QLatin1String("pageProps")].isObject()) {
|
||||
if (!obj_data.contains("pageProps"_L1) || !obj_data["pageProps"_L1].isObject()) {
|
||||
Error(QStringLiteral("Json props is missing pageProps."), obj_data);
|
||||
EndSearch(search, url);
|
||||
return;
|
||||
}
|
||||
obj_data = obj_data[QLatin1String("pageProps")].toObject();
|
||||
obj_data = obj_data["pageProps"_L1].toObject();
|
||||
|
||||
if (!obj_data.contains(QLatin1String("data")) || !obj_data[QLatin1String("data")].isObject()) {
|
||||
if (!obj_data.contains("data"_L1) || !obj_data["data"_L1].isObject()) {
|
||||
Error(QStringLiteral("Json pageProps is missing data."), obj_data);
|
||||
EndSearch(search, url);
|
||||
return;
|
||||
}
|
||||
obj_data = obj_data[QLatin1String("data")].toObject();
|
||||
obj_data = obj_data["data"_L1].toObject();
|
||||
|
||||
|
||||
if (!obj_data.contains(QLatin1String("trackInfo")) || !obj_data[QLatin1String("trackInfo")].isObject()) {
|
||||
if (!obj_data.contains("trackInfo"_L1) || !obj_data["trackInfo"_L1].isObject()) {
|
||||
Error(QStringLiteral("Json data is missing trackInfo."), obj_data);
|
||||
EndSearch(search, url);
|
||||
return;
|
||||
}
|
||||
obj_data = obj_data[QLatin1String("trackInfo")].toObject();
|
||||
obj_data = obj_data["trackInfo"_L1].toObject();
|
||||
|
||||
if (!obj_data.contains(QLatin1String("data")) || !obj_data[QLatin1String("data")].isObject()) {
|
||||
if (!obj_data.contains("data"_L1) || !obj_data["data"_L1].isObject()) {
|
||||
Error(QStringLiteral("Json trackInfo reply is missing data."), obj_data);
|
||||
EndSearch(search, url);
|
||||
return;
|
||||
}
|
||||
obj_data = obj_data[QLatin1String("data")].toObject();
|
||||
obj_data = obj_data["data"_L1].toObject();
|
||||
|
||||
if (!obj_data.contains(QLatin1String("track")) || !obj_data[QLatin1String("track")].isObject()) {
|
||||
if (!obj_data.contains("track"_L1) || !obj_data["track"_L1].isObject()) {
|
||||
Error(QStringLiteral("Json data is missing track."), obj_data);
|
||||
EndSearch(search, url);
|
||||
return;
|
||||
}
|
||||
|
||||
const QJsonObject obj_track = obj_data[QLatin1String("track")].toObject();
|
||||
const QJsonObject obj_track = obj_data["track"_L1].toObject();
|
||||
|
||||
if (!obj_track.contains(QLatin1String("hasLyrics")) || !obj_track[QLatin1String("hasLyrics")].isBool()) {
|
||||
if (!obj_track.contains("hasLyrics"_L1) || !obj_track["hasLyrics"_L1].isBool()) {
|
||||
Error(QStringLiteral("Json track is missing hasLyrics."), obj_track);
|
||||
EndSearch(search, url);
|
||||
return;
|
||||
}
|
||||
|
||||
const bool has_lyrics = obj_track[QLatin1String("hasLyrics")].toBool();
|
||||
const bool has_lyrics = obj_track["hasLyrics"_L1].toBool();
|
||||
if (!has_lyrics) {
|
||||
EndSearch(search, url);
|
||||
return;
|
||||
}
|
||||
|
||||
LyricsSearchResult result;
|
||||
if (obj_track.contains(QLatin1String("artistName")) && obj_track[QLatin1String("artistName")].isString()) {
|
||||
result.artist = obj_track[QLatin1String("artistName")].toString();
|
||||
if (obj_track.contains("artistName"_L1) && obj_track["artistName"_L1].isString()) {
|
||||
result.artist = obj_track["artistName"_L1].toString();
|
||||
}
|
||||
if (obj_track.contains(QLatin1String("albumName")) && obj_track[QLatin1String("albumName")].isString()) {
|
||||
result.album = obj_track[QLatin1String("albumName")].toString();
|
||||
if (obj_track.contains("albumName"_L1) && obj_track["albumName"_L1].isString()) {
|
||||
result.album = obj_track["albumName"_L1].toString();
|
||||
}
|
||||
if (obj_track.contains(QLatin1String("name")) && obj_track[QLatin1String("name")].isString()) {
|
||||
result.title = obj_track[QLatin1String("name")].toString();
|
||||
if (obj_track.contains("name"_L1) && obj_track["name"_L1].isString()) {
|
||||
result.title = obj_track["name"_L1].toString();
|
||||
}
|
||||
|
||||
if (!obj_data.contains(QLatin1String("lyrics")) || !obj_data[QLatin1String("lyrics")].isObject()) {
|
||||
if (!obj_data.contains("lyrics"_L1) || !obj_data["lyrics"_L1].isObject()) {
|
||||
Error(QStringLiteral("Json data is missing lyrics."), obj_data);
|
||||
EndSearch(search, url);
|
||||
return;
|
||||
}
|
||||
QJsonObject obj_lyrics = obj_data[QLatin1String("lyrics")].toObject();
|
||||
QJsonObject obj_lyrics = obj_data["lyrics"_L1].toObject();
|
||||
|
||||
if (!obj_lyrics.contains(QLatin1String("body")) || !obj_lyrics[QLatin1String("body")].isString()) {
|
||||
if (!obj_lyrics.contains("body"_L1) || !obj_lyrics["body"_L1].isString()) {
|
||||
Error(QStringLiteral("Json lyrics reply is missing body."), obj_lyrics);
|
||||
EndSearch(search, url);
|
||||
return;
|
||||
}
|
||||
result.lyrics = obj_lyrics[QLatin1String("body")].toString();
|
||||
result.lyrics = obj_lyrics["body"_L1].toString();
|
||||
|
||||
if (!result.lyrics.isEmpty()) {
|
||||
result.lyrics = Utilities::DecodeHtmlEntities(result.lyrics);
|
||||
|
||||
@@ -37,6 +37,8 @@
|
||||
#include "jsonlyricsprovider.h"
|
||||
#include "ovhlyricsprovider.h"
|
||||
|
||||
using namespace Qt::StringLiterals;
|
||||
|
||||
namespace {
|
||||
constexpr char kUrlSearch[] = "https://api.lyrics.ovh/v1/";
|
||||
}
|
||||
@@ -80,20 +82,20 @@ void OVHLyricsProvider::HandleSearchReply(QNetworkReply *reply, const int id, co
|
||||
return;
|
||||
}
|
||||
|
||||
if (json_obj.contains(QLatin1String("error"))) {
|
||||
Error(json_obj[QLatin1String("error")].toString());
|
||||
if (json_obj.contains("error"_L1)) {
|
||||
Error(json_obj["error"_L1].toString());
|
||||
qLog(Debug) << "OVHLyrics: No lyrics for" << request.artist << request.title;
|
||||
Q_EMIT SearchFinished(id);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!json_obj.contains(QLatin1String("lyrics"))) {
|
||||
if (!json_obj.contains("lyrics"_L1)) {
|
||||
Q_EMIT SearchFinished(id);
|
||||
return;
|
||||
}
|
||||
|
||||
LyricsSearchResult result;
|
||||
result.lyrics = json_obj[QLatin1String("lyrics")].toString();
|
||||
result.lyrics = json_obj["lyrics"_L1].toString();
|
||||
|
||||
if (result.lyrics.isEmpty()) {
|
||||
qLog(Debug) << "OVHLyrics: No lyrics for" << request.artist << request.title;
|
||||
|
||||
@@ -28,6 +28,8 @@
|
||||
#include "lyricssearchrequest.h"
|
||||
#include "songlyricscomlyricsprovider.h"
|
||||
|
||||
using namespace Qt::StringLiterals;
|
||||
|
||||
namespace {
|
||||
constexpr char kUrl[] = "https://www.songlyrics.com/";
|
||||
constexpr char kStartTag[] = "<p[^>]*>";
|
||||
@@ -40,7 +42,7 @@ SongLyricsComLyricsProvider::SongLyricsComLyricsProvider(SharedPtr<NetworkAccess
|
||||
|
||||
QUrl SongLyricsComLyricsProvider::Url(const LyricsSearchRequest &request) {
|
||||
|
||||
return QUrl(QLatin1String(kUrl) + StringFixup(request.artist) + QLatin1Char('/') + StringFixup(request.title) + QLatin1String("-lyrics/"));
|
||||
return QUrl(QLatin1String(kUrl) + StringFixup(request.artist) + QLatin1Char('/') + StringFixup(request.title) + "-lyrics/"_L1);
|
||||
|
||||
}
|
||||
|
||||
@@ -52,12 +54,12 @@ QString SongLyricsComLyricsProvider::StringFixup(QString text) {
|
||||
static const QRegularExpression regex_multiple_whitespaces(QStringLiteral(" {2,}"));
|
||||
static const QRegularExpression regex_multiple_dashes(QStringLiteral("(-)\\1+"));
|
||||
|
||||
return text.replace(QLatin1Char('/'), QLatin1Char('-'))
|
||||
.replace(QLatin1Char('\''), QLatin1Char('-'))
|
||||
return text.replace(u'/', u'-')
|
||||
.replace(u'\'', u'-')
|
||||
.remove(regex_illegal_characters)
|
||||
.replace(regex_multiple_whitespaces, QStringLiteral(" "))
|
||||
.simplified()
|
||||
.replace(QLatin1Char(' '), QLatin1Char('-'))
|
||||
.replace(u' ', u'-')
|
||||
.replace(regex_multiple_dashes, QStringLiteral("-"))
|
||||
.toLower();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user