Skip to content

Commit 28b6caa

Browse files
committed
Initial additional lyrics providers work
1 parent dc5a0ce commit 28b6caa

11 files changed

+869
-641
lines changed

CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,8 @@ target_sources(
453453
widgets/volumecontrol.cpp
454454
context/lyricsettings.cpp
455455
context/ultimatelyricsprovider.cpp
456+
context/ultimatelyricshttpprovider.cpp
457+
context/ultimatelyricscommandprovider.cpp
456458
context/ultimatelyrics.cpp
457459
context/lyricsdialog.cpp
458460
context/contextwidget.cpp

context/lyrics_providers.xml

Lines changed: 33 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<lyricproviders>
3-
<provider name="azlyrics.com" charset="utf-8" url="https://www.azlyrics.com/lyrics/{artist}/{title}.html">
3+
<provider type="http" name="azlyrics.com" charset="utf-8" url="https://www.azlyrics.com/lyrics/{artist}/{title}.html">
44
<urlFormat replace=" ._@,;&amp;\/()'&quot;-?" with=""/>
55
<extract>
66
<item begin="&lt;!-- END OF RINGTONE 1 --&gt;" end="&lt;!-- RINGTONE 2 --&gt;"/>
@@ -15,22 +15,22 @@
1515
</exclude>
1616
<invalidIndicator value="&lt;h1&gt;Welcome to AZLyrics!&lt;/h1&gt;"/>
1717
</provider>
18-
<provider name="bollywoodlyrics.com (Bollywood songs)" charset="utf-8" url="https://www.bollywoodlyrics.com/lyric/{Title}">
18+
<provider type="http" name="bollywoodlyrics.com (Bollywood songs)" charset="utf-8" url="https://www.bollywoodlyrics.com/lyric/{Title}">
1919
<urlFormat replace=" _@;\/&quot;'()[]" with="-"/>
2020
<urlFormat replace="?" with=""/>
2121
<extract>
2222
<item begin="&lt;div class=&quot;entry-content&quot;&gt;" end="&lt;/div&gt;"/>
2323
</extract>
2424
<invalidIndicator value="Couldn't find that page."/>
2525
</provider>
26-
<provider name="chartlyrics.com" charset="utf-8" url="http://api.chartlyrics.com/apiv1.asmx/SearchLyricDirect?artist={artist}&amp;song={title}">
26+
<provider type="http" name="chartlyrics.com" charset="utf-8" url="http://api.chartlyrics.com/apiv1.asmx/SearchLyricDirect?artist={artist}&amp;song={title}">
2727
<urlFormat replace="_@,;&amp;\/&quot;#" with="_"/>
2828
<extract>
2929
<item tag="&lt;Lyric&gt;"/>
3030
</extract>
3131
<invalidIndicator value="ERROR"/>
3232
</provider>
33-
<provider name="darklyrics.com" charset="utf-8" url="http://www.darklyrics.com/lyrics/{artist2}/{album2}.html">
33+
<provider type="http" name="darklyrics.com" charset="utf-8" url="http://www.darklyrics.com/lyrics/{artist2}/{album2}.html">
3434
<extract> <!-- modified -->
3535
<item begin="&lt;h3&gt;&lt;a name=&quot;{track}&quot;&gt;{track}. {Title}&lt;/a&gt;&lt;/h3&gt;&lt;br/&gt;" end="&lt;h3&gt;"/>
3636
</extract>
@@ -42,7 +42,7 @@
4242
</extract>
4343
<invalidIndicator value="The page you requested was not found on DarkLyrics.com."/>
4444
</provider>
45-
<provider name="directlyrics.com" charset="utf-8" url="http://www.directlyrics.com/{artist}-{title}-lyrics.html"> <!-- was iso-8859-1 -->
45+
<provider type="http" name="directlyrics.com" charset="utf-8" url="http://www.directlyrics.com/{artist}-{title}-lyrics.html"> <!-- was iso-8859-1 -->
4646
<urlFormat replace=" _@,;&amp;\/'&quot;" with="-"/>
4747
<urlFormat replace="." with=""/>
4848
<extract>
@@ -59,7 +59,7 @@
5959
<item begin="&lt;script async src=&quot;" end="&lt;/script&gt;&lt;br&gt;"/>
6060
</exclude>
6161
</provider>
62-
<provider name="elyrics.net" charset="iso-8859-1" url="https://www.elyrics.net/read/{a}/{artist}-lyrics/{title}-lyrics.html">
62+
<provider type="http" name="elyrics.net" charset="iso-8859-1" url="https://www.elyrics.net/read/{a}/{artist}-lyrics/{title}-lyrics.html">
6363
<urlFormat replace=" _@;&amp;\/&quot;" with="-"/>
6464
<urlFormat replace="'" with="_"/>
6565
<extract> <!-- new -->
@@ -77,7 +77,7 @@
7777
</exclude>
7878
<invalidIndicator value="Page not Found"/>
7979
</provider>
80-
<provider name="hindilyrics.net (Bollywood songs)" charset="utf-8" url="http://www.hindilyrics.net/lyrics/of-{Title}.html">
80+
<provider type="http" name="hindilyrics.net (Bollywood songs)" charset="utf-8" url="http://www.hindilyrics.net/lyrics/of-{Title}.html">
8181
<urlFormat replace=" _@;\/&quot;'()[]" with="%20"/>
8282
<urlFormat replace="?" with=""/>
8383
<extract>
@@ -89,7 +89,7 @@
8989
<invalidIndicator value="Couldn't find that page."/>
9090
</provider>
9191
<!-- Issue #1571
92-
<provider name="Encyclopaedia Metallum" charset="utf-8" url="https://www.metal-archives.com/search/ajax-advanced/searching/songs/?songTitle={title}&amp;bandName={artist}&amp;ExactBandMatch=1">
92+
<provider type="http" name="Encyclopaedia Metallum" charset="utf-8" url="https://www.metal-archives.com/search/ajax-advanced/searching/songs/?songTitle={title}&amp;bandName={artist}&amp;ExactBandMatch=1">
9393
<extract>
9494
<item url="http://www.metal-archives.com/release/ajax-view-lyrics/id/{id}"/>
9595
<item begin="id=\&quot;lyricsLink_" end="&quot;"/>
@@ -98,7 +98,7 @@
9898
<invalidIndicator value="lyrics not available"/>
9999
</provider>
100100
-->
101-
<provider name="letras.mus.br" charset="utf-8" url="https://www.letras.mus.br/winamp.php?musica={title}&amp;artista={artist}">
101+
<provider type="http" name="letras.mus.br" charset="utf-8" url="https://www.letras.mus.br/winamp.php?musica={title}&amp;artista={artist}">
102102
<urlFormat replace="_@,;&amp;\/&quot;" with="_"/>
103103
<urlFormat replace=" " with="+"/>
104104
<extract> <!-- new -->
@@ -109,7 +109,7 @@
109109
</extract>
110110
<invalidIndicator value="Verifique se o nome do seu arquivo e sua"/>
111111
</provider>
112-
<provider name="genius.com" charset="utf-8" url="https://www.genius.com/{artist}-{title}-lyrics">
112+
<provider type="http" name="genius.com" charset="utf-8" url="https://www.genius.com/{artist}-{title}-lyrics">
113113
<urlFormat replace=",._@!#%^*+;\/&quot;'()[]?" with=""/>
114114
<urlFormat replace=" :" with="-"/>
115115
<!-- When $ is used as the dollar sign it is ommitted from the url
@@ -137,14 +137,14 @@
137137
<item begin="&lt;/a" end="&gt;"/>
138138
</exclude>
139139
</provider>
140-
<provider name="lololyrics.com" charset="utf-8" url="http://api.lololyrics.com/0.5/getLyric?artist={artist}&amp;track={title}">
140+
<provider type="http" name="lololyrics.com" charset="utf-8" url="http://api.lololyrics.com/0.5/getLyric?artist={artist}&amp;track={title}">
141141
<urlFormat replace="_@,;&amp;\/&quot;#" with="_"/>
142142
<extract>
143143
<item tag="&lt;response&gt;"/>
144144
</extract>
145145
<invalidIndicator value="ERROR"/>
146146
</provider>
147-
<provider name="loudson.gs" charset="utf-8" url="http://www.loudson.gs/{a}/{artist}/{album}/{title}">
147+
<provider type="http" name="loudson.gs" charset="utf-8" url="http://www.loudson.gs/{a}/{artist}/{album}/{title}">
148148
<urlFormat replace=" _@,;&amp;\/&quot;" with="-"/>
149149
<urlFormat replace="." with=""/>
150150
<extract>
@@ -154,7 +154,7 @@
154154
<item tag="&lt;div class=&quot;middle_col_TracksLyrics&quot;&gt;"/>
155155
</extract>
156156
</provider>
157-
<provider name="lyrics.com" charset="utf-8" url="https://www.lyrics.com/lyrics/{artist}/{title}.html">
157+
<provider type="http" name="lyrics.com" charset="utf-8" url="https://www.lyrics.com/lyrics/{artist}/{title}.html">
158158
<urlFormat replace=" _@,;&amp;\/&quot;" with="-"/>
159159
<urlFormat replace="'." with=""/>
160160
<extract> <!-- new -->
@@ -170,7 +170,7 @@
170170
<invalidIndicator value="we do not have the lyric for this song"/>
171171
<invalidIndicator value="Your name will be printed as part of the credit when your lyric is approved"/>
172172
</provider>
173-
<provider name="lyrics.wikia.com" charset="utf-8" url="https://lyrics.wikia.com/api.php">
173+
<provider type="http" name="lyrics.wikia.com" charset="utf-8" url="https://lyrics.wikia.com/api.php">
174174
<!-- These are not used, as mediawiki API is used instead...
175175
<urlFormat replace=" _@;\&quot;" with="_"/>
176176
<urlFormat replace="?" with="%3F"/>
@@ -183,15 +183,15 @@
183183
</exclude>
184184
-->
185185
</provider>
186-
<provider name="lyricsdownload.com" charset="utf-8" url="http://www.lyricsdownload.com/{artist}-{title}-lyrics.html">
186+
<provider type="http" name="lyricsdownload.com" charset="utf-8" url="http://www.lyricsdownload.com/{artist}-{title}-lyrics.html">
187187
<urlFormat replace=" _@,;&amp;\/&quot;" with="-"/>
188188
<urlFormat replace="." with=""/>
189189
<extract>
190190
<item tag="&lt;div id=&quot;div_customCSS&quot;&gt;"/>
191191
</extract>
192192
<invalidIndicator value="We haven't lyrics of this song"/>
193193
</provider>
194-
<provider name="lyricsmania.com" charset="iso-8859-1" url="https://www.lyricsmania.com/{title}_lyrics_{artist}.html">
194+
<provider type="http" name="lyricsmania.com" charset="iso-8859-1" url="https://www.lyricsmania.com/{title}_lyrics_{artist}.html">
195195
<urlFormat replace=" _@;&amp;\/&quot;'." with="_"/>
196196
<extract> <!-- new -->
197197
<item tag="&lt;div id='songlyrics_h' class='dn'&gt;"/>
@@ -202,7 +202,7 @@
202202
</extract>
203203
<invalidIndicator value="The lyrics you requested is not in our archive yet,"/>
204204
</provider>
205-
<provider name="lyricsmode.com" charset="iso-8859-1" url="http://www.lyricsmode.com/lyrics/{a}/{artist}/{title}.html">
205+
<provider type="http" name="lyricsmode.com" charset="iso-8859-1" url="http://www.lyricsmode.com/lyrics/{a}/{artist}/{title}.html">
206206
<urlFormat replace=" ._@,;&amp;\/&quot;" with="_"/>
207207
<extract>
208208
<item tag="&lt;div id='songlyrics_h' class='dn'&gt;"/>
@@ -212,7 +212,7 @@
212212
</extract>
213213
<invalidIndicator value="Sorry, we have no"/>
214214
</provider>
215-
<provider name="lyricsreg.com" charset="iso-8859-1" url="https://www.lyricsreg.com/lyrics/{artist}/{title}/">
215+
<provider type="http" name="lyricsreg.com" charset="iso-8859-1" url="https://www.lyricsreg.com/lyrics/{artist}/{title}/">
216216
<urlFormat replace=" _@,;&amp;\/&quot;" with="+"/>
217217
<urlFormat replace="'." with=""/>
218218
<extract>
@@ -225,7 +225,7 @@
225225
</extract>
226226
<invalidIndicator value="Page not Found"/>
227227
</provider>
228-
<provider name="lyriki.com" charset="utf-8" url="http://www.lyriki.com/{artist}:{title}">
228+
<provider type="http" name="lyriki.com" charset="utf-8" url="http://www.lyriki.com/{artist}:{title}">
229229
<urlFormat replace=" _@,;&amp;\/&quot;" with="_"/>
230230
<urlFormat replace="." with=""/>
231231
<extract>
@@ -234,7 +234,7 @@
234234
</extract>
235235
</provider>
236236
<!-- broken
237-
<provider name="metrolyrics.com" charset="utf-8" url="http://www.metrolyrics.com/{title}-lyrics-{artist}.html">
237+
<provider type="http" name="metrolyrics.com" charset="utf-8" url="http://www.metrolyrics.com/{title}-lyrics-{artist}.html">
238238
<urlFormat replace=" _@,;&amp;\/&quot;" with="-"/>
239239
<urlFormat replace="'." with=""/>
240240
<extract>
@@ -252,7 +252,7 @@
252252
<invalidIndicator value="These lyrics are missing"/>
253253
</provider>
254254
-->
255-
<provider name="mp3lyrics.org" charset="utf-8" url="http://www.mp3lyrics.org/{a}/{artist}/{title}/">
255+
<provider type="http" name="mp3lyrics.org" charset="utf-8" url="http://www.mp3lyrics.org/{a}/{artist}/{title}/">
256256
<urlFormat replace=" _@,;&amp;\/&quot;" with="-"/>
257257
<urlFormat replace="'." with=""/>
258258
<extract>
@@ -271,7 +271,7 @@
271271
</exclude>
272272
<invalidIndicator value="Something went wrong"/>
273273
</provider>
274-
<provider name="musixmatch.com" charset="utf-8" url="https://www.musixmatch.com/lyrics/{Artist}/{Title}">
274+
<provider type="http" name="musixmatch.com" charset="utf-8" url="https://www.musixmatch.com/lyrics/{Artist}/{Title}">
275275
<urlFormat replace=" _@;\/&quot;'()[]" with="-"/>
276276
<urlFormat replace="?" with=""/>
277277
<extract>
@@ -282,7 +282,7 @@
282282
</exclude>
283283
<invalidIndicator value="We couldn't find that page."/>
284284
</provider>
285-
<provider name="songlyrics.com" charset="utf-8" url="https://www.songlyrics.com/{artist}/{title}-lyrics/">
285+
<provider type="http" name="songlyrics.com" charset="utf-8" url="https://www.songlyrics.com/{artist}/{title}-lyrics/">
286286
<urlFormat replace=" ._@,;&amp;\/&quot;" with="-"/>
287287
<urlFormat replace="'" with="_"/>
288288
<extract>
@@ -297,7 +297,7 @@
297297
<invalidIndicator value="Sorry, we have no"/>
298298
<invalidIndicator value="This is an upcoming album and we do not have the"/>
299299
</provider>
300-
<provider name="tekstowo.pl (Original lyric language)" charset="utf-8" url="http://www.tekstowo.pl/piosenka,{artist},{title}.html">
300+
<provider type="http" name="tekstowo.pl (Original lyric language)" charset="utf-8" url="http://www.tekstowo.pl/piosenka,{artist},{title}.html">
301301
<urlFormat replace=" _@,;&amp;\/'&quot;." with="_"/>
302302
<extract>
303303
<item begin="&lt;div class=&quot;song-text&quot;&gt;" end="&lt;a href=&quot;javascript:;&quot;"/>
@@ -309,7 +309,7 @@
309309
<item begin="&lt;h2&gt;" end="&lt;/h2&gt;&lt;br /&gt;"/>
310310
</exclude>
311311
</provider>
312-
<provider name="tekstowo.pl (Translated to Polish)" charset="utf-8" url="http://www.tekstowo.pl/piosenka,{artist},{title}.html">
312+
<provider type="http" name="tekstowo.pl (Translated to Polish)" charset="utf-8" url="http://www.tekstowo.pl/piosenka,{artist},{title}.html">
313313
<urlFormat replace=" _@,;&amp;\/'&quot;." with="_"/>
314314
<extract>
315315
<item begin="&lt;div id=&quot;translation&quot; class=" end="&lt;a href="/>
@@ -318,14 +318,14 @@
318318
<item begin="&quot;id-" end="&quot;&gt;"/>
319319
</exclude>
320320
</provider>
321-
<provider name="teksty.org" title="{artist} - {title} - tekst" charset="utf-8" url="http://teksty.org/{artist},{title},tekst-piosenki">
321+
<provider type="http" name="teksty.org" title="{artist} - {title} - tekst" charset="utf-8" url="http://teksty.org/{artist},{title},tekst-piosenki">
322322
<urlFormat replace=" _@,;&amp;\/&quot;'" with="-"/>
323323
<urlFormat replace="." with=""/>
324324
<extract>
325325
<item begin="&lt;div class=&quot;songText&quot; id=&quot;songContent&quot;&gt;" end="&lt;/div&gt;"/>
326326
</extract>
327327
</provider>
328-
<provider name="vagalume.com.br" charset="iso-8859-1" url="http://vagalume.com.br/{artist}/{title}.html">
328+
<provider type="http" name="vagalume.com.br" charset="iso-8859-1" url="http://vagalume.com.br/{artist}/{title}.html">
329329
<urlFormat replace=" _@,;&amp;\/'&quot;." with="-"/>
330330
<extract>
331331
<item tag="&lt;span class=&quot;editable_area&quot;&gt;"/>
@@ -334,7 +334,7 @@
334334
<item tag="&lt;div itemprop=description&gt;"/>
335335
</extract>
336336
</provider>
337-
<provider name="vagalume.com.br (PORTUGUESE)" charset="iso-8859-1" url="https://www.vagalume.com.br/{artist}/{title}-traducao.html">
337+
<provider type="http" name="vagalume.com.br (PORTUGUESE)" charset="iso-8859-1" url="https://www.vagalume.com.br/{artist}/{title}-traducao.html">
338338
<urlFormat replace=" _@,;&amp;\/'&quot;." with="-"/>
339339
<extract>
340340
<item tag="&lt;div class=&quot;tab_traducao sideBySide lyricArea tab_tra_pt&quot;&gt;"/>
@@ -344,4 +344,9 @@
344344
<item begin="&lt;div&gt;" end="null"/>
345345
</extract>
346346
</provider>
347+
<provider type="command" name="lrclib.net" executable="lrclib.sh">
348+
<argument value="{Title}"/>
349+
<argument value="{Artist}"/>
350+
<argument value="{duration}"/>
351+
</provider>
347352
</lyricproviders>

context/ultimatelyrics.cpp

Lines changed: 18 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,19 @@
2222
*/
2323

2424
#include "ultimatelyrics.h"
25+
2526
#include "gui/settings.h"
2627
#include "support/globalstatic.h"
28+
#include "ultimatelyricscommandprovider.h"
29+
#include "ultimatelyricshttpprovider.h"
2730
#include "ultimatelyricsprovider.h"
2831
#include <QDir>
2932
#include <QFile>
3033
#include <QFileInfoList>
3134
#include <QSet>
3235
#include <QXmlStreamReader>
3336
#include <algorithm>
37+
#include <unistd.h>
3438

3539
GLOBAL_STATIC(UltimateLyrics, instance)
3640

@@ -39,78 +43,6 @@ static bool compareLyricProviders(const UltimateLyricsProvider* a, const Ultimat
3943
return a->getRelevance() < b->getRelevance();
4044
}
4145

42-
static QString parseInvalidIndicator(QXmlStreamReader* reader)
43-
{
44-
QString ret = reader->attributes().value("value").toString();
45-
reader->skipCurrentElement();
46-
return ret;
47-
}
48-
49-
static UltimateLyricsProvider::Rule parseRule(QXmlStreamReader* reader)
50-
{
51-
UltimateLyricsProvider::Rule ret;
52-
53-
while (!reader->atEnd()) {
54-
reader->readNext();
55-
56-
if (QXmlStreamReader::EndElement == reader->tokenType()) {
57-
break;
58-
}
59-
60-
if (QXmlStreamReader::StartElement == reader->tokenType()) {
61-
if (QLatin1String("item") == reader->name()) {
62-
QXmlStreamAttributes attr = reader->attributes();
63-
if (attr.hasAttribute("tag")) {
64-
ret << UltimateLyricsProvider::RuleItem(attr.value("tag").toString(), QString());
65-
}
66-
else if (attr.hasAttribute("begin")) {
67-
ret << UltimateLyricsProvider::RuleItem(attr.value("begin").toString(), attr.value("end").toString());
68-
}
69-
}
70-
reader->skipCurrentElement();
71-
}
72-
}
73-
return ret;
74-
}
75-
76-
static UltimateLyricsProvider* parseProvider(QXmlStreamReader* reader)
77-
{
78-
QXmlStreamAttributes attributes = reader->attributes();
79-
80-
UltimateLyricsProvider* scraper = new UltimateLyricsProvider;
81-
scraper->setName(attributes.value("name").toString());
82-
scraper->setCharset(attributes.value("charset").toString());
83-
scraper->setUrl(attributes.value("url").toString());
84-
85-
while (!reader->atEnd()) {
86-
reader->readNext();
87-
88-
if (QXmlStreamReader::EndElement == reader->tokenType()) {
89-
break;
90-
}
91-
92-
if (QXmlStreamReader::StartElement == reader->tokenType()) {
93-
if (QLatin1String("extract") == reader->name()) {
94-
scraper->addExtractRule(parseRule(reader));
95-
}
96-
else if (QLatin1String("exclude") == reader->name()) {
97-
scraper->addExcludeRule(parseRule(reader));
98-
}
99-
else if (QLatin1String("invalidIndicator") == reader->name()) {
100-
scraper->addInvalidIndicator(parseInvalidIndicator(reader));
101-
}
102-
else if (QLatin1String("urlFormat") == reader->name()) {
103-
scraper->addUrlFormat(reader->attributes().value("replace").toString(), reader->attributes().value("with").toString());
104-
reader->skipCurrentElement();
105-
}
106-
else {
107-
reader->skipCurrentElement();
108-
}
109-
}
110-
}
111-
return scraper;
112-
}
113-
11446
void UltimateLyrics::release()
11547
{
11648
for (UltimateLyricsProvider* provider : providers) {
@@ -178,10 +110,22 @@ void UltimateLyrics::load()
178110
reader.readNext();
179111

180112
if (QLatin1String("provider") == reader.name()) {
181-
QString name = reader.attributes().value("name").toString();
113+
auto attributes = reader.attributes();
114+
QString name = attributes.value("name").toString();
115+
QString type = attributes.value("type").toString();
182116

183117
if (!providerNames.contains(name)) {
184-
UltimateLyricsProvider* provider = parseProvider(&reader);
118+
UltimateLyricsProvider* provider;
119+
120+
if (type == QString("http")) {
121+
provider = UltimateLyricsHttpProvider::parseProvider(&reader);
122+
} else if (type == QString("command")) {
123+
provider = UltimateLyricsCommandProvider::parseProvider(&reader);
124+
} else {
125+
// TODO: Throw exception
126+
__builtin_unreachable();
127+
}
128+
185129
if (provider) {
186130
providers << provider;
187131
connect(provider, SIGNAL(lyricsReady(int, QString)), this, SIGNAL(lyricsReady(int, QString)));

0 commit comments

Comments
 (0)