Port to QStringLiteral operator

This commit is contained in:
Jonas Kvinge
2024-10-20 06:38:55 +02:00
parent 722035913e
commit ef9ef63f02
202 changed files with 2036 additions and 1889 deletions

View File

@@ -29,6 +29,8 @@
#include "lyricssearchrequest.h"
#include "azlyricscomlyricsprovider.h"
using namespace Qt::Literals::StringLiterals;
namespace {
constexpr char kUrl[] = "https://www.azlyrics.com/lyrics/";
constexpr char kStartTag[] = "<div>";
@@ -37,11 +39,11 @@ constexpr char kLyricsStart[] = "<!-- Usage of azlyrics.com content by any third
} // namespace
AzLyricsComLyricsProvider::AzLyricsComLyricsProvider(SharedPtr<NetworkAccessManager> network, QObject *parent)
: HtmlLyricsProvider(QStringLiteral("azlyrics.com"), true, QLatin1String(kStartTag), QLatin1String(kEndTag), QLatin1String(kLyricsStart), false, network, parent) {}
: HtmlLyricsProvider(u"azlyrics.com"_s, true, QLatin1String(kStartTag), QLatin1String(kEndTag), QLatin1String(kLyricsStart), false, network, parent) {}
QUrl AzLyricsComLyricsProvider::Url(const LyricsSearchRequest &request) {
return QUrl(QLatin1String(kUrl) + StringFixup(request.artist) + QLatin1Char('/') + StringFixup(request.title) + QStringLiteral(".html"));
return QUrl(QLatin1String(kUrl) + StringFixup(request.artist) + QLatin1Char('/') + StringFixup(request.title) + u".html"_s);
}
@@ -49,7 +51,7 @@ QString AzLyricsComLyricsProvider::StringFixup(const QString &text) {
Q_ASSERT(QThread::currentThread() != qApp->thread());
static const QRegularExpression regex_words_numbers_and_dash(QStringLiteral("[^\\w0-9\\-]"));
static const QRegularExpression regex_words_numbers_and_dash(u"[^\\w0-9\\-]"_s);
return Utilities::Transliterate(text).remove(regex_words_numbers_and_dash).toLower();
}

View File

@@ -44,7 +44,7 @@ namespace {
constexpr char kUrlSearch[] = "http://api.chartlyrics.com/apiv1.asmx/SearchLyricDirect";
}
ChartLyricsProvider::ChartLyricsProvider(SharedPtr<NetworkAccessManager> network, QObject *parent) : LyricsProvider(QStringLiteral("ChartLyrics"), false, false, network, parent) {}
ChartLyricsProvider::ChartLyricsProvider(SharedPtr<NetworkAccessManager> network, QObject *parent) : LyricsProvider(u"ChartLyrics"_s, false, false, network, parent) {}
ChartLyricsProvider::~ChartLyricsProvider() {
@@ -62,8 +62,8 @@ void ChartLyricsProvider::StartSearch(const int id, const LyricsSearchRequest &r
Q_ASSERT(QThread::currentThread() != qApp->thread());
QUrlQuery url_query;
url_query.addQueryItem(QStringLiteral("artist"), QString::fromUtf8(QUrl::toPercentEncoding(request.artist)));
url_query.addQueryItem(QStringLiteral("song"), QString::fromUtf8(QUrl::toPercentEncoding(request.title)));
url_query.addQueryItem(u"artist"_s, QString::fromUtf8(QUrl::toPercentEncoding(request.artist)));
url_query.addQueryItem(u"song"_s, QString::fromUtf8(QUrl::toPercentEncoding(request.title)));
QUrl url(QString::fromUtf8(kUrlSearch));
url.setQuery(url_query);

View File

@@ -39,7 +39,7 @@ constexpr char kLyricsStart[] = "<div id='inlyr'>";
} // namespace
ElyricsNetLyricsProvider::ElyricsNetLyricsProvider(SharedPtr<NetworkAccessManager> network, QObject *parent)
: HtmlLyricsProvider(QStringLiteral("elyrics.net"), true, QLatin1String(kStartTag), QLatin1String(kEndTag), QLatin1String(kLyricsStart), false, network, parent) {}
: HtmlLyricsProvider(u"elyrics.net"_s, true, QLatin1String(kStartTag), QLatin1String(kEndTag), QLatin1String(kLyricsStart), false, network, parent) {}
QUrl ElyricsNetLyricsProvider::Url(const LyricsSearchRequest &request) {
@@ -51,12 +51,12 @@ QString ElyricsNetLyricsProvider::StringFixup(const QString &text) {
Q_ASSERT(QThread::currentThread() != qApp->thread());
static const QRegularExpression regex_illegal_characters(QStringLiteral("[^\\w0-9_,&\\-\\(\\) ]"));
static const QRegularExpression regex_duplicate_whitespaces(QStringLiteral(" {2,}"));
static const QRegularExpression regex_illegal_characters(u"[^\\w0-9_,&\\-\\(\\) ]"_s);
static const QRegularExpression regex_duplicate_whitespaces(u" {2,}"_s);
return Utilities::Transliterate(text)
.replace(regex_illegal_characters, QStringLiteral("_"))
.replace(regex_duplicate_whitespaces, QStringLiteral(" "))
.replace(regex_illegal_characters, u"_"_s)
.replace(regex_duplicate_whitespaces, u" "_s)
.simplified()
.replace(u' ', u'-')
.toLower();

View File

@@ -68,7 +68,7 @@ constexpr char kClientIDB64[] = "RUNTNXU4U1VyMU1KUU5hdTZySEZteUxXY2hkanFiY3lfc2J
constexpr char kClientSecretB64[] = "VE9pMU9vUjNtTXZ3eFR3YVN0QVRyUjVoUlhVWDI1Ylp5X240eEt1M0ZkYlNwRG5JUnd0LXFFbHdGZkZkRWY2VzJ1S011UnQzM3c2Y3hqY0tVZ3NGN2c=";
} // namespace
GeniusLyricsProvider::GeniusLyricsProvider(SharedPtr<NetworkAccessManager> network, QObject *parent) : JsonLyricsProvider(QStringLiteral("Genius"), true, true, network, parent), server_(nullptr) {
GeniusLyricsProvider::GeniusLyricsProvider(SharedPtr<NetworkAccessManager> network, QObject *parent) : JsonLyricsProvider(u"Genius"_s, true, true, network, parent), server_(nullptr) {
Settings s;
s.beginGroup(kSettingsGroup);
@@ -134,11 +134,11 @@ void GeniusLyricsProvider::Authenticate() {
}
QUrlQuery url_query;
url_query.addQueryItem(QStringLiteral("client_id"), QString::fromLatin1(QUrl::toPercentEncoding(QString::fromLatin1(QByteArray::fromBase64(kClientIDB64)))));
url_query.addQueryItem(QStringLiteral("redirect_uri"), QString::fromLatin1(QUrl::toPercentEncoding(redirect_url.toString())));
url_query.addQueryItem(QStringLiteral("scope"), QStringLiteral("me"));
url_query.addQueryItem(QStringLiteral("state"), QString::fromLatin1(QUrl::toPercentEncoding(code_challenge_)));
url_query.addQueryItem(QStringLiteral("response_type"), QStringLiteral("code"));
url_query.addQueryItem(u"client_id"_s, QString::fromLatin1(QUrl::toPercentEncoding(QString::fromLatin1(QByteArray::fromBase64(kClientIDB64)))));
url_query.addQueryItem(u"redirect_uri"_s, QString::fromLatin1(QUrl::toPercentEncoding(redirect_url.toString())));
url_query.addQueryItem(u"scope"_s, u"me"_s);
url_query.addQueryItem(u"state"_s, QString::fromLatin1(QUrl::toPercentEncoding(code_challenge_)));
url_query.addQueryItem(u"response_type"_s, u"code"_s);
QUrl url(QString::fromLatin1(kOAuthAuthorizeUrl));
url.setQuery(url_query);
@@ -160,10 +160,10 @@ void GeniusLyricsProvider::RedirectArrived() {
QUrl url = server_->request_url();
if (url.isValid()) {
QUrlQuery url_query(url);
if (url_query.hasQueryItem(QStringLiteral("error"))) {
AuthError(QUrlQuery(url).queryItemValue(QStringLiteral("error")));
if (url_query.hasQueryItem(u"error"_s)) {
AuthError(QUrlQuery(url).queryItemValue(u"error"_s));
}
else if (url_query.hasQueryItem(QStringLiteral("code"))) {
else if (url_query.hasQueryItem(u"code"_s)) {
QUrl redirect_url(QString::fromLatin1(kOAuthRedirectUrl));
redirect_url.setPort(server_->url().port());
RequestAccessToken(url, redirect_url);
@@ -192,17 +192,17 @@ void GeniusLyricsProvider::RequestAccessToken(const QUrl &url, const QUrl &redir
QUrlQuery url_query(url);
if (url.hasQuery() && url_query.hasQueryItem(QStringLiteral("code")) && url_query.hasQueryItem(QStringLiteral("state"))) {
if (url.hasQuery() && url_query.hasQueryItem(u"code"_s) && url_query.hasQueryItem(u"state"_s)) {
const QString code = url_query.queryItemValue(QStringLiteral("code"));
const QString code = url_query.queryItemValue(u"code"_s);
QUrlQuery new_url_query;
new_url_query.addQueryItem(QStringLiteral("code"), QString::fromLatin1(QUrl::toPercentEncoding(code)));
new_url_query.addQueryItem(QStringLiteral("client_id"), QString::fromLatin1(QUrl::toPercentEncoding(QString::fromLatin1(QByteArray::fromBase64(kClientIDB64)))));
new_url_query.addQueryItem(QStringLiteral("client_secret"), QString::fromLatin1(QUrl::toPercentEncoding(QString::fromLatin1(QByteArray::fromBase64(kClientSecretB64)))));
new_url_query.addQueryItem(QStringLiteral("redirect_uri"), QString::fromLatin1(QUrl::toPercentEncoding(redirect_url.toString())));
new_url_query.addQueryItem(QStringLiteral("grant_type"), QStringLiteral("authorization_code"));
new_url_query.addQueryItem(QStringLiteral("response_type"), QStringLiteral("code"));
new_url_query.addQueryItem(u"code"_s, QString::fromLatin1(QUrl::toPercentEncoding(code)));
new_url_query.addQueryItem(u"client_id"_s, QString::fromLatin1(QUrl::toPercentEncoding(QString::fromLatin1(QByteArray::fromBase64(kClientIDB64)))));
new_url_query.addQueryItem(u"client_secret"_s, QString::fromLatin1(QUrl::toPercentEncoding(QString::fromLatin1(QByteArray::fromBase64(kClientSecretB64)))));
new_url_query.addQueryItem(u"redirect_uri"_s, QString::fromLatin1(QUrl::toPercentEncoding(redirect_url.toString())));
new_url_query.addQueryItem(u"grant_type"_s, u"authorization_code"_s);
new_url_query.addQueryItem(u"response_type"_s, u"code"_s);
QUrl new_url(QString::fromLatin1(kOAuthAccessTokenUrl));
QNetworkRequest req(new_url);
@@ -281,23 +281,23 @@ void GeniusLyricsProvider::AccessTokenRequestFinished(QNetworkReply *reply) {
}
if (json_doc.isEmpty()) {
AuthError(QStringLiteral("Authentication reply from server has empty Json document."));
AuthError(u"Authentication reply from server has empty Json document."_s);
return;
}
if (!json_doc.isObject()) {
AuthError(QStringLiteral("Authentication reply from server has Json document that is not an object."), json_doc);
AuthError(u"Authentication reply from server has Json document that is not an object."_s, json_doc);
return;
}
QJsonObject json_obj = json_doc.object();
if (json_obj.isEmpty()) {
AuthError(QStringLiteral("Authentication reply from server has empty Json object."), json_doc);
AuthError(u"Authentication reply from server has empty Json object."_s, json_doc);
return;
}
if (!json_obj.contains("access_token"_L1)) {
AuthError(QStringLiteral("Authentication reply from server is missing access token."), json_obj);
AuthError(u"Authentication reply from server is missing access token."_s, json_obj);
return;
}
@@ -332,7 +332,7 @@ void GeniusLyricsProvider::StartSearch(const int id, const LyricsSearchRequest &
}
QUrlQuery url_query;
url_query.addQueryItem(QStringLiteral("q"), QString::fromLatin1(QUrl::toPercentEncoding(QStringLiteral("%1 %2").arg(request.artist, request.title))));
url_query.addQueryItem(u"q"_s, QString::fromLatin1(QUrl::toPercentEncoding(QStringLiteral("%1 %2").arg(request.artist, request.title))));
QUrl url(QString::fromLatin1(kUrlSearch));
url.setQuery(url_query);
@@ -364,18 +364,18 @@ void GeniusLyricsProvider::HandleSearchReply(QNetworkReply *reply, const int id)
}
if (!json_obj.contains("meta"_L1)) {
Error(QStringLiteral("Json reply is missing meta object."), json_obj);
Error(u"Json reply is missing meta object."_s, json_obj);
EndSearch(search);
return;
}
if (!json_obj["meta"_L1].isObject()) {
Error(QStringLiteral("Json reply meta is not an object."), json_obj);
Error(u"Json reply meta is not an object."_s, json_obj);
EndSearch(search);
return;
}
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);
Error(u"Json reply meta object is missing status."_s, obj_meta);
EndSearch(search);
return;
}
@@ -392,23 +392,23 @@ void GeniusLyricsProvider::HandleSearchReply(QNetworkReply *reply, const int id)
}
if (!json_obj.contains("response"_L1)) {
Error(QStringLiteral("Json reply is missing response."), json_obj);
Error(u"Json reply is missing response."_s, json_obj);
EndSearch(search);
return;
}
if (!json_obj["response"_L1].isObject()) {
Error(QStringLiteral("Json response is not an object."), json_obj);
Error(u"Json response is not an object."_s, json_obj);
EndSearch(search);
return;
}
QJsonObject obj_response = json_obj["response"_L1].toObject();
if (!obj_response.contains("hits"_L1)) {
Error(QStringLiteral("Json response is missing hits."), obj_response);
Error(u"Json response is missing hits."_s, obj_response);
EndSearch(search);
return;
}
if (!obj_response["hits"_L1].isArray()) {
Error(QStringLiteral("Json hits is not an array."), obj_response);
Error(u"Json hits is not an array."_s, obj_response);
EndSearch(search);
return;
}
@@ -427,7 +427,7 @@ void GeniusLyricsProvider::HandleSearchReply(QNetworkReply *reply, const int id)
}
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);
Error(u"Missing one or more values in result object"_s, obj_result);
continue;
}
QJsonObject primary_artist = obj_result["primary_artist"_L1].toObject();
@@ -497,15 +497,15 @@ void GeniusLyricsProvider::HandleLyricReply(QNetworkReply *reply, const int sear
const QByteArray data = reply->readAll();
if (data.isEmpty()) {
Error(QStringLiteral("Empty reply received from server."));
Error(u"Empty reply received from server."_s);
EndSearch(search, lyric);
return;
}
const QString content = QString::fromUtf8(data);
QString lyrics = HtmlLyricsProvider::ParseLyricsFromHTML(content, QRegularExpression(QStringLiteral("<div[^>]*>")), QRegularExpression(QStringLiteral("<\\/div>")), QRegularExpression(QStringLiteral("<div data-lyrics-container=[^>]+>")), true);
QString lyrics = HtmlLyricsProvider::ParseLyricsFromHTML(content, QRegularExpression(u"<div[^>]*>"_s), QRegularExpression(u"<\\/div>"_s), QRegularExpression(u"<div data-lyrics-container=[^>]+>"_s), true);
if (lyrics.isEmpty()) {
lyrics = HtmlLyricsProvider::ParseLyricsFromHTML(content, QRegularExpression(QStringLiteral("<div[^>]*>")), QRegularExpression(QStringLiteral("<\\/div>")), QRegularExpression(QStringLiteral("<div class=\"lyrics\">")), true);
lyrics = HtmlLyricsProvider::ParseLyricsFromHTML(content, QRegularExpression(u"<div[^>]*>"_s), QRegularExpression(u"<\\/div>"_s), QRegularExpression(u"<div class=\"lyrics\">"_s), true);
}
if (!lyrics.isEmpty()) {

View File

@@ -69,7 +69,7 @@ void HtmlLyricsProvider::StartSearch(const int id, const LyricsSearchRequest &re
QUrl url(Url(request));
QNetworkRequest req(url);
req.setAttribute(QNetworkRequest::RedirectPolicyAttribute, QNetworkRequest::NoLessSafeRedirectPolicy);
req.setHeader(QNetworkRequest::UserAgentHeader, QStringLiteral("Mozilla/5.0 (X11; Linux x86_64; rv:122.0) Gecko/20100101 Firefox/122.0"));
req.setHeader(QNetworkRequest::UserAgentHeader, u"Mozilla/5.0 (X11; Linux x86_64; rv:122.0) Gecko/20100101 Firefox/122.0"_s);
QNetworkReply *reply = network_->get(req);
replies_ << reply;
QObject::connect(reply, &QNetworkReply::finished, this, [this, reply, id, request]() { HandleLyricsReply(reply, id, request); });
@@ -169,20 +169,20 @@ QString HtmlLyricsProvider::ParseLyricsFromHTML(const QString &content, const QR
if (!lyrics.isEmpty()) {
lyrics.append(u'\n');
}
static const QRegularExpression regex_html_tag_a(QStringLiteral("<a [^>]*>[^<]*</a>"));
static const QRegularExpression regex_html_tag_script(QStringLiteral("<script>[^>]*</script>"));
static const QRegularExpression regex_html_tag_div(QStringLiteral("<div [^>]*>×</div>"));
static const QRegularExpression regex_html_tag_br(QStringLiteral("<br[^>]*>"));
static const QRegularExpression regex_html_tag_p_close(QStringLiteral("</p>"));
static const QRegularExpression regex_html_tags(QStringLiteral("<[^>]*>"));
static const QRegularExpression regex_html_tag_a(u"<a [^>]*>[^<]*</a>"_s);
static const QRegularExpression regex_html_tag_script(u"<script>[^>]*</script>"_s);
static const QRegularExpression regex_html_tag_div(u"<div [^>]*>×</div>"_s);
static const QRegularExpression regex_html_tag_br(u"<br[^>]*>"_s);
static const QRegularExpression regex_html_tag_p_close(u"</p>"_s);
static const QRegularExpression regex_html_tags(u"<[^>]*>"_s);
lyrics.append(content.mid(start_lyrics_idx, end_lyrics_idx - start_lyrics_idx)
.remove(u'\r')
.remove(u'\n')
.remove(regex_html_tag_a)
.remove(regex_html_tag_script)
.remove(regex_html_tag_div)
.replace(regex_html_tag_br, QStringLiteral("\n"))
.replace(regex_html_tag_p_close, QStringLiteral("\n\n"))
.replace(regex_html_tag_br, u"\n"_s)
.replace(regex_html_tag_p_close, u"\n\n"_s)
.remove(regex_html_tags)
.trimmed());
}

View File

@@ -40,7 +40,7 @@ constexpr char kLyricsStart[] = "<div id=\"letra-cnt\">";
} // namespace
LetrasLyricsProvider::LetrasLyricsProvider(SharedPtr<NetworkAccessManager> network, QObject *parent)
: HtmlLyricsProvider(QStringLiteral("letras.mus.br"), true, QLatin1String(kStartTag), QLatin1String(kEndTag), QLatin1String(kLyricsStart), false, network, parent) {}
: HtmlLyricsProvider(u"letras.mus.br"_s, true, QLatin1String(kStartTag), QLatin1String(kEndTag), QLatin1String(kLyricsStart), false, network, parent) {}
QUrl LetrasLyricsProvider::Url(const LyricsSearchRequest &request) {
@@ -52,12 +52,12 @@ QString LetrasLyricsProvider::StringFixup(const QString &text) {
Q_ASSERT(QThread::currentThread() != qApp->thread());
static const QRegularExpression regex_illegal_characters(QStringLiteral("[^\\w0-9_,&\\-\\(\\) ]"));
static const QRegularExpression regex_multiple_whitespaces(QStringLiteral(" {2,}"));
static const QRegularExpression regex_illegal_characters(u"[^\\w0-9_,&\\-\\(\\) ]"_s);
static const QRegularExpression regex_multiple_whitespaces(u" {2,}"_s);
return QString::fromLatin1(QUrl::toPercentEncoding(Utilities::Transliterate(text)
.replace(regex_illegal_characters, QStringLiteral("_"))
.replace(regex_multiple_whitespaces, QStringLiteral(" "))
.replace(regex_illegal_characters, u"_"_s)
.replace(regex_multiple_whitespaces, u" "_s)
.simplified()
.replace(u' ', u'-')
.toLower()

View File

@@ -44,7 +44,7 @@ namespace {
constexpr char kUrlSearch[] = "http://api.lololyrics.com/0.5/getLyric";
}
LoloLyricsProvider::LoloLyricsProvider(SharedPtr<NetworkAccessManager> network, QObject *parent) : LyricsProvider(QStringLiteral("LoloLyrics"), true, false, network, parent) {}
LoloLyricsProvider::LoloLyricsProvider(SharedPtr<NetworkAccessManager> network, QObject *parent) : LyricsProvider(u"LoloLyrics"_s, true, false, network, parent) {}
LoloLyricsProvider::~LoloLyricsProvider() {
@@ -62,8 +62,8 @@ void LoloLyricsProvider::StartSearch(const int id, const LyricsSearchRequest &re
Q_ASSERT(QThread::currentThread() != qApp->thread());
QUrlQuery url_query;
url_query.addQueryItem(QStringLiteral("artist"), QString::fromLatin1(QUrl::toPercentEncoding(request.artist)));
url_query.addQueryItem(QStringLiteral("track"), QString::fromLatin1(QUrl::toPercentEncoding(request.title)));
url_query.addQueryItem(u"artist"_s, QString::fromLatin1(QUrl::toPercentEncoding(request.artist)));
url_query.addQueryItem(u"track"_s, QString::fromLatin1(QUrl::toPercentEncoding(request.title)));
QUrl url(QString::fromLatin1(kUrlSearch));
url.setQuery(url_query);

View File

@@ -45,7 +45,7 @@ constexpr char kLyricsStart[] = "<script id=\"__NEXT_DATA__\" type=\"application
constexpr char kLyricsEnd[] = "</script>";
} // namespace
LyricFindLyricsProvider::LyricFindLyricsProvider(SharedPtr<NetworkAccessManager> network, QObject *parent) : JsonLyricsProvider(QStringLiteral("lyricfind.com"), true, false, network, parent) {}
LyricFindLyricsProvider::LyricFindLyricsProvider(SharedPtr<NetworkAccessManager> network, QObject *parent) : JsonLyricsProvider(u"lyricfind.com"_s, true, false, network, parent) {}
LyricFindLyricsProvider::~LyricFindLyricsProvider() {
@@ -68,12 +68,12 @@ QString LyricFindLyricsProvider::StringFixup(const QString &text) {
Q_ASSERT(QThread::currentThread() != qApp->thread());
static const QRegularExpression regex_illegal_characters(QStringLiteral("[^\\w0-9_\\- ]"));
static const QRegularExpression regex_multiple_whitespaces(QStringLiteral(" {2,}"));
static const QRegularExpression regex_illegal_characters(u"[^\\w0-9_\\- ]"_s);
static const QRegularExpression regex_multiple_whitespaces(u" {2,}"_s);
return Utilities::Transliterate(text)
.remove(regex_illegal_characters)
.replace(regex_multiple_whitespaces, QStringLiteral(" "))
.replace(regex_multiple_whitespaces, u" "_s)
.simplified()
.replace(u' ', u'-')
.toLower();
@@ -87,7 +87,7 @@ void LyricFindLyricsProvider::StartSearch(const int id, const LyricsSearchReques
const QUrl url = Url(request);
QNetworkRequest req(url);
req.setAttribute(QNetworkRequest::RedirectPolicyAttribute, QNetworkRequest::NoLessSafeRedirectPolicy);
req.setHeader(QNetworkRequest::UserAgentHeader, QStringLiteral("Mozilla/5.0 (X11; Linux x86_64; rv:122.0) Gecko/20100101 Firefox/122.0"));
req.setHeader(QNetworkRequest::UserAgentHeader, u"Mozilla/5.0 (X11; Linux x86_64; rv:122.0) Gecko/20100101 Firefox/122.0"_s);
QNetworkReply *reply = network_->get(req);
replies_ << reply;
QObject::connect(reply, &QNetworkReply::finished, this, [this, reply, id, request]() { HandleSearchReply(reply, id, request); });
@@ -123,13 +123,13 @@ void LyricFindLyricsProvider::HandleSearchReply(QNetworkReply *reply, const int
const QByteArray data = reply->readAll();
if (data.isEmpty()) {
Error(QStringLiteral("Empty reply received from server."));
Error(u"Empty reply received from server."_s);
return;
}
const QString content = QString::fromUtf8(data);
if (content.isEmpty()) {
Error(QStringLiteral("Empty reply received from server."));
Error(u"Empty reply received from server."_s);
return;
}
@@ -145,7 +145,7 @@ void LyricFindLyricsProvider::HandleSearchReply(QNetworkReply *reply, const int
}
}
if (content_json.isEmpty()) {
Error(QStringLiteral("Could not parse HTML reply."));
Error(u"Could not parse HTML reply."_s);
return;
}
@@ -154,36 +154,36 @@ void LyricFindLyricsProvider::HandleSearchReply(QNetworkReply *reply, const int
return;
}
if (!obj.contains("props"_L1) || !obj["props"_L1].isObject()) {
Error(QStringLiteral("Missing props."));
Error(u"Missing props."_s);
return;
}
obj = obj["props"_L1].toObject();
if (!obj.contains("pageProps"_L1) || !obj["pageProps"_L1].isObject()) {
Error(QStringLiteral("Missing pageProps."));
Error(u"Missing pageProps."_s);
return;
}
obj = obj["pageProps"_L1].toObject();
if (!obj.contains("songData"_L1) || !obj["songData"_L1].isObject()) {
Error(QStringLiteral("Missing songData."));
Error(u"Missing songData."_s);
return;
}
obj = obj["songData"_L1].toObject();
if (!obj.contains("response"_L1) || !obj["response"_L1].isObject()) {
Error(QStringLiteral("Missing response."));
Error(u"Missing response."_s);
return;
}
//const QJsonObject obj_response = obj[QLatin1String("response")].toObject();
if (!obj.contains("track"_L1) || !obj["track"_L1].isObject()) {
Error(QStringLiteral("Missing track."));
Error(u"Missing track."_s);
return;
}
const QJsonObject obj_track = obj["track"_L1].toObject();
if (!obj_track.contains("title"_L1) ||
!obj_track.contains("lyrics"_L1)) {
Error(QStringLiteral("Missing title or lyrics."));
Error(u"Missing title or lyrics."_s);
return;
}

View File

@@ -48,7 +48,7 @@
using namespace Qt::Literals::StringLiterals;
using std::make_shared;
MusixmatchLyricsProvider::MusixmatchLyricsProvider(SharedPtr<NetworkAccessManager> network, QObject *parent) : JsonLyricsProvider(QStringLiteral("Musixmatch"), true, false, network, parent), use_api_(true) {}
MusixmatchLyricsProvider::MusixmatchLyricsProvider(SharedPtr<NetworkAccessManager> network, QObject *parent) : JsonLyricsProvider(u"Musixmatch"_s, true, false, network, parent), use_api_(true) {}
MusixmatchLyricsProvider::~MusixmatchLyricsProvider() {
@@ -82,12 +82,12 @@ void MusixmatchLyricsProvider::StartSearch(const int id, const LyricsSearchReque
bool MusixmatchLyricsProvider::SendSearchRequest(LyricsSearchContextPtr search) {
QUrlQuery url_query;
url_query.addQueryItem(QStringLiteral("apikey"), QString::fromLatin1(QByteArray::fromBase64(kApiKey)));
url_query.addQueryItem(QStringLiteral("q_artist"), QString::fromLatin1(QUrl::toPercentEncoding(search->request.artist)));
url_query.addQueryItem(QStringLiteral("q_track"), QString::fromLatin1(QUrl::toPercentEncoding(search->request.title)));
url_query.addQueryItem(QStringLiteral("f_has_lyrics"), QStringLiteral("1"));
url_query.addQueryItem(u"apikey"_s, QString::fromLatin1(QByteArray::fromBase64(kApiKey)));
url_query.addQueryItem(u"q_artist"_s, QString::fromLatin1(QUrl::toPercentEncoding(search->request.artist)));
url_query.addQueryItem(u"q_track"_s, QString::fromLatin1(QUrl::toPercentEncoding(search->request.title)));
url_query.addQueryItem(u"f_has_lyrics"_s, u"1"_s);
QUrl url(QString::fromLatin1(kApiUrl) + QStringLiteral("/track.search"));
QUrl url(QString::fromLatin1(kApiUrl) + u"/track.search"_s);
url.setQuery(url_query);
QNetworkRequest req(url);
req.setAttribute(QNetworkRequest::RedirectPolicyAttribute, QNetworkRequest::NoLessSafeRedirectPolicy);
@@ -142,24 +142,24 @@ void MusixmatchLyricsProvider::HandleSearchReply(QNetworkReply *reply, LyricsSea
}
if (!json_obj.contains("message"_L1)) {
Error(QStringLiteral("Json reply is missing message object."), json_obj);
Error(u"Json reply is missing message object."_s, json_obj);
EndSearch(search);
return;
}
if (!json_obj["message"_L1].isObject()) {
Error(QStringLiteral("Json reply message is not an object."), json_obj);
Error(u"Json reply message is not an object."_s, json_obj);
EndSearch(search);
return;
}
QJsonObject obj_message = json_obj["message"_L1].toObject();
if (!obj_message.contains("header"_L1)) {
Error(QStringLiteral("Json reply message object is missing header."), obj_message);
Error(u"Json reply message object is missing header."_s, obj_message);
EndSearch(search);
return;
}
if (!obj_message["header"_L1].isObject()) {
Error(QStringLiteral("Json reply message header is not an object."), obj_message);
Error(u"Json reply message header is not an object."_s, obj_message);
EndSearch(search);
return;
}
@@ -174,24 +174,24 @@ void MusixmatchLyricsProvider::HandleSearchReply(QNetworkReply *reply, LyricsSea
}
if (!obj_message.contains("body"_L1)) {
Error(QStringLiteral("Json reply is missing body."), json_obj);
Error(u"Json reply is missing body."_s, json_obj);
EndSearch(search);
return;
}
if (!obj_message["body"_L1].isObject()) {
Error(QStringLiteral("Json body is not an object."), json_obj);
Error(u"Json body is not an object."_s, json_obj);
EndSearch(search);
return;
}
QJsonObject obj_body = obj_message["body"_L1].toObject();
if (!obj_body.contains("track_list"_L1)) {
Error(QStringLiteral("Json response is missing body."), obj_body);
Error(u"Json response is missing body."_s, obj_body);
EndSearch(search);
return;
}
if (!obj_body["track_list"_L1].isArray()) {
Error(QStringLiteral("Json hits is not an array."), obj_body);
Error(u"Json hits is not an array."_s, obj_body);
EndSearch(search);
return;
}
@@ -212,7 +212,7 @@ void MusixmatchLyricsProvider::HandleSearchReply(QNetworkReply *reply, LyricsSea
!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);
Error(u"Missing one or more values in result object"_s, obj_track);
continue;
}
@@ -299,7 +299,7 @@ void MusixmatchLyricsProvider::HandleLyricsReply(QNetworkReply *reply, LyricsSea
const QByteArray data = reply->readAll();
if (data.isEmpty()) {
Error(QStringLiteral("Empty reply received from server."));
Error(u"Empty reply received from server."_s);
EndSearch(search, url);
return;
}
@@ -322,7 +322,7 @@ void MusixmatchLyricsProvider::HandleLyricsReply(QNetworkReply *reply, LyricsSea
return;
}
static const QRegularExpression regex_html_tag(QStringLiteral("<[^>]*>"));
static const QRegularExpression regex_html_tag(u"<[^>]*>"_s);
if (content_json.contains(regex_html_tag)) { // Make sure it's not HTML code.
EndSearch(search, url);
return;
@@ -335,21 +335,21 @@ void MusixmatchLyricsProvider::HandleLyricsReply(QNetworkReply *reply, LyricsSea
}
if (!obj_data.contains("props"_L1) || !obj_data["props"_L1].isObject()) {
Error(QStringLiteral("Json reply is missing props."), obj_data);
Error(u"Json reply is missing props."_s, obj_data);
EndSearch(search, url);
return;
}
obj_data = obj_data["props"_L1].toObject();
if (!obj_data.contains("pageProps"_L1) || !obj_data["pageProps"_L1].isObject()) {
Error(QStringLiteral("Json props is missing pageProps."), obj_data);
Error(u"Json props is missing pageProps."_s, obj_data);
EndSearch(search, url);
return;
}
obj_data = obj_data["pageProps"_L1].toObject();
if (!obj_data.contains("data"_L1) || !obj_data["data"_L1].isObject()) {
Error(QStringLiteral("Json pageProps is missing data."), obj_data);
Error(u"Json pageProps is missing data."_s, obj_data);
EndSearch(search, url);
return;
}
@@ -357,21 +357,21 @@ void MusixmatchLyricsProvider::HandleLyricsReply(QNetworkReply *reply, LyricsSea
if (!obj_data.contains("trackInfo"_L1) || !obj_data["trackInfo"_L1].isObject()) {
Error(QStringLiteral("Json data is missing trackInfo."), obj_data);
Error(u"Json data is missing trackInfo."_s, obj_data);
EndSearch(search, url);
return;
}
obj_data = obj_data["trackInfo"_L1].toObject();
if (!obj_data.contains("data"_L1) || !obj_data["data"_L1].isObject()) {
Error(QStringLiteral("Json trackInfo reply is missing data."), obj_data);
Error(u"Json trackInfo reply is missing data."_s, obj_data);
EndSearch(search, url);
return;
}
obj_data = obj_data["data"_L1].toObject();
if (!obj_data.contains("track"_L1) || !obj_data["track"_L1].isObject()) {
Error(QStringLiteral("Json data is missing track."), obj_data);
Error(u"Json data is missing track."_s, obj_data);
EndSearch(search, url);
return;
}
@@ -379,7 +379,7 @@ void MusixmatchLyricsProvider::HandleLyricsReply(QNetworkReply *reply, LyricsSea
const QJsonObject obj_track = obj_data["track"_L1].toObject();
if (!obj_track.contains("hasLyrics"_L1) || !obj_track["hasLyrics"_L1].isBool()) {
Error(QStringLiteral("Json track is missing hasLyrics."), obj_track);
Error(u"Json track is missing hasLyrics."_s, obj_track);
EndSearch(search, url);
return;
}
@@ -402,14 +402,14 @@ void MusixmatchLyricsProvider::HandleLyricsReply(QNetworkReply *reply, LyricsSea
}
if (!obj_data.contains("lyrics"_L1) || !obj_data["lyrics"_L1].isObject()) {
Error(QStringLiteral("Json data is missing lyrics."), obj_data);
Error(u"Json data is missing lyrics."_s, obj_data);
EndSearch(search, url);
return;
}
QJsonObject obj_lyrics = obj_data["lyrics"_L1].toObject();
if (!obj_lyrics.contains("body"_L1) || !obj_lyrics["body"_L1].isString()) {
Error(QStringLiteral("Json lyrics reply is missing body."), obj_lyrics);
Error(u"Json lyrics reply is missing body."_s, obj_lyrics);
EndSearch(search, url);
return;
}

View File

@@ -43,7 +43,7 @@ namespace {
constexpr char kUrlSearch[] = "https://api.lyrics.ovh/v1/";
}
OVHLyricsProvider::OVHLyricsProvider(SharedPtr<NetworkAccessManager> network, QObject *parent) : JsonLyricsProvider(QStringLiteral("Lyrics.ovh"), true, false, network, parent) {}
OVHLyricsProvider::OVHLyricsProvider(SharedPtr<NetworkAccessManager> network, QObject *parent) : JsonLyricsProvider(u"Lyrics.ovh"_s, true, false, network, parent) {}
OVHLyricsProvider::~OVHLyricsProvider() {

View File

@@ -38,7 +38,7 @@ constexpr char kLyricsStart[] = "<p id=\"songLyricsDiv\"[^>]+>";
} // namespace
SongLyricsComLyricsProvider::SongLyricsComLyricsProvider(SharedPtr<NetworkAccessManager> network, QObject *parent)
: HtmlLyricsProvider(QStringLiteral("songlyrics.com"), true, QLatin1String(kStartTag), QLatin1String(kEndTag), QLatin1String(kLyricsStart), false, network, parent) {}
: HtmlLyricsProvider(u"songlyrics.com"_s, true, QLatin1String(kStartTag), QLatin1String(kEndTag), QLatin1String(kLyricsStart), false, network, parent) {}
QUrl SongLyricsComLyricsProvider::Url(const LyricsSearchRequest &request) {
@@ -50,17 +50,17 @@ QString SongLyricsComLyricsProvider::StringFixup(QString text) {
Q_ASSERT(QThread::currentThread() != qApp->thread());
static const QRegularExpression regex_illegal_characters(QStringLiteral("[^\\w0-9\\- ]"));
static const QRegularExpression regex_multiple_whitespaces(QStringLiteral(" {2,}"));
static const QRegularExpression regex_multiple_dashes(QStringLiteral("(-)\\1+"));
static const QRegularExpression regex_illegal_characters(u"[^\\w0-9\\- ]"_s);
static const QRegularExpression regex_multiple_whitespaces(u" {2,}"_s);
static const QRegularExpression regex_multiple_dashes(u"(-)\\1+"_s);
return text.replace(u'/', u'-')
.replace(u'\'', u'-')
.remove(regex_illegal_characters)
.replace(regex_multiple_whitespaces, QStringLiteral(" "))
.replace(regex_multiple_whitespaces, u" "_s)
.simplified()
.replace(u' ', u'-')
.replace(regex_multiple_dashes, QStringLiteral("-"))
.replace(regex_multiple_dashes, u"-"_s)
.toLower();
}