Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
What's new
4
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Switch to GitLab Next
Sign in / Register
Toggle navigation
Menu
Open sidebar
Andrea Scarpino
harbour-Lyrics
Commits
b8db4ba8
Commit
b8db4ba8
authored
May 02, 2022
by
Andrea Scarpino
Browse files
Release 0.5.7
parent
6ae411db
Pipeline
#529653862
canceled with stages
in 7 seconds
Changes
9
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
.gitignore
View file @
b8db4ba8
...
...
@@ -2,5 +2,3 @@
*.pro.user
*.pro.user.*
*.autosave
src/geniusapi_secret.h
qml/pages/Settings.qml
View file @
b8db4ba8
...
...
@@ -53,10 +53,6 @@ Page {
text
:
"
ChartLyrics
"
}
MenuItem
{
text
:
"
Genius
"
}
MenuItem
{
text
:
"
LyricsMania
"
}
...
...
rpm/harbour-lyrics.changes
View file @
b8db4ba8
* Mon May 2 2022 Andrea Scarpino <andrea@scarpino.dev> 0.5.7-1
* Drop Genius provider
* Support SailJail
* Port to amber MPRIS library
* Add Lithuanian translation
* Fri Aug 6 2021 Andrea Scarpino <andrea@scarpino.dev> 0.5.6-1
- New icon by Jorren `jsehv` Schauwaert
- Update Greek translation
...
...
rpm/harbour-lyrics.spec
View file @
b8db4ba8
...
...
@@ -13,7 +13,7 @@ Name: harbour-lyrics
%{!?qtc_make:%define qtc_make make}
%{?qtc_builddir:%define _builddir %qtc_builddir}
Summary: Music lyrics application
Version: 0.5.
6
Version: 0.5.
7
Release: 1
Group: Qt/Qt
License: MIT
...
...
@@ -32,7 +32,7 @@ BuildRequires: desktop-file-utils
%description
Music lyrics application.
It does support: ChartLyrics
,
LyricsMania
, Genius
.
It does support:
AZLyrics,
ChartLyrics
and
LyricsMania.
%if "%{?vendor}" == "chum"
PackageName: Lyrics
...
...
rpm/harbour-lyrics.yaml
View file @
b8db4ba8
Name
:
harbour-lyrics
Summary
:
Music lyrics application
Version
:
0.5.
6
Version
:
0.5.
7
Release
:
1
# The contents of the Group field should be one of the groups listed here:
# http://gitorious.org/meego-developer-tools/spectacle/blobs/master/data/GROUPS
...
...
@@ -13,7 +13,7 @@ Sources:
-
'
%{name}-%{version}.tar.bz2'
Description
:
|
Music lyrics application.
It does support: ChartLyrics
,
LyricsMania
, Genius
.
It does support:
AZLyrics,
ChartLyrics
and
LyricsMania.
%if "%{?vendor}" == "chum"
PackageName: Lyrics
...
...
src/geniusapi.cpp
deleted
100644 → 0
View file @
6ae411db
/*
The MIT License (MIT)
Copyright (c) 2015-2021 Andrea Scarpino <andrea@scarpino.dev>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include
"geniusapi.h"
#include
"geniusapi_secret.h"
#include
<QDebug>
#include
<QJsonArray>
#include
<QJsonDocument>
#include
<QJsonObject>
#include
<QNetworkAccessManager>
#include
<QNetworkReply>
#include
<QUrl>
#include
<QUrlQuery>
#include
<QWebElement>
#include
<QWebFrame>
#include
<QWebPage>
#include
"lyric.h"
const
static
QString
API_URL
=
QStringLiteral
(
"https://api.genius.com"
);
GeniusAPI
::
GeniusAPI
(
QObject
*
parent
)
:
Provider
(
parent
)
,
network
(
new
QNetworkAccessManager
(
this
))
{
}
GeniusAPI
::~
GeniusAPI
()
{
qDeleteAll
(
lyrics
.
keyBegin
(),
lyrics
.
keyEnd
());
qDeleteAll
(
lyrics
);
delete
network
;
}
void
GeniusAPI
::
getLyric
(
const
QString
&
artist
,
const
QString
&
song
)
{
qDebug
()
<<
"Requesting lyric for artist"
<<
artist
<<
", song"
<<
song
;
QUrl
url
(
API_URL
+
"/search"
);
QUrlQuery
query
;
query
.
addQueryItem
(
QStringLiteral
(
"q"
),
artist
+
QChar
::
Space
+
song
);
url
.
setQuery
(
query
);
QNetworkRequest
req
(
url
);
if
(
CLIENT_ID
[
0
]
==
'\0'
)
{
qCritical
()
<<
"No client id set, the request will be rejected!"
;
}
req
.
setRawHeader
(
QByteArray
(
"client_id"
),
QByteArray
(
CLIENT_ID
));
if
(
CLIENT_SECRET
[
0
]
==
'\0'
)
{
qCritical
()
<<
"No client secret set, the request will be rejected!"
;
}
req
.
setRawHeader
(
QByteArray
(
"client_secret"
),
QByteArray
(
CLIENT_SECRET
));
if
(
CLIENT_ACCESS_TOKEN
[
0
]
==
'\0'
)
{
qCritical
()
<<
"No client access token set, the request will be rejected!"
;
}
req
.
setRawHeader
(
QByteArray
(
"Authorization"
),
QStringLiteral
(
"Bearer %1"
).
arg
(
CLIENT_ACCESS_TOKEN
).
toLatin1
());
QNetworkReply
*
reply
=
network
->
get
(
req
);
connect
(
reply
,
&
QNetworkReply
::
finished
,
this
,
&
GeniusAPI
::
onGetLyricResult
);
}
void
GeniusAPI
::
onGetLyricResult
()
{
QNetworkReply
*
reply
=
qobject_cast
<
QNetworkReply
*>
(
QObject
::
sender
());
bool
err
=
true
;
if
(
reply
->
error
()
!=
QNetworkReply
::
NoError
)
{
qCritical
()
<<
"Cannot fetch lyric:"
<<
reply
->
errorString
();
}
else
{
QJsonDocument
json
=
QJsonDocument
::
fromJson
(
reply
->
readAll
());
if
(
!
json
.
isNull
())
{
QJsonValue
response
=
json
.
object
().
value
(
"response"
);
if
(
!
response
.
isNull
())
{
QJsonArray
hits
=
response
.
toObject
().
value
(
"hits"
).
toArray
();
if
(
!
hits
.
isEmpty
())
{
// 'We'are lucky' like search
QJsonObject
result
=
hits
.
at
(
0
).
toObject
().
value
(
"result"
).
toObject
();
Lyric
*
lyric
=
new
Lyric
();
lyric
->
setArtist
(
result
.
value
(
"primary_artist"
).
toObject
().
value
(
"name"
).
toString
());
lyric
->
setSong
(
result
.
value
(
"title"
).
toString
());
const
QUrl
url
(
result
.
value
(
"url"
).
toString
());
getLyricText
(
url
,
lyric
);
err
=
false
;
}
else
{
qDebug
()
<<
"No results"
;
}
}
else
{
qDebug
()
<<
"No results"
;
}
}
else
{
qCritical
()
<<
"Got an invalid JSON!"
;
}
}
if
(
err
)
{
Q_EMIT
lyricFetched
(
0
,
!
err
);
}
reply
->
deleteLater
();
}
void
GeniusAPI
::
onGetLyricPageResult
()
{
QNetworkReply
*
reply
=
qobject_cast
<
QNetworkReply
*>
(
QObject
::
sender
());
bool
found
=
false
;
Lyric
*
lyric
=
0
;
if
(
reply
->
error
()
!=
QNetworkReply
::
NoError
)
{
qCritical
()
<<
"Cannot fetch lyric"
;
}
else
{
QWebPage
page
;
page
.
settings
()
->
setAttribute
(
QWebSettings
::
AutoLoadImages
,
false
);
page
.
settings
()
->
setAttribute
(
QWebSettings
::
JavascriptEnabled
,
false
);
page
.
mainFrame
()
->
setHtml
(
reply
->
readAll
());
QWebElement
lyricbox
=
page
.
mainFrame
()
->
findFirstElement
(
"div[class=lyrics]"
);
if
(
lyricbox
.
isNull
())
{
qCritical
()
<<
"Cannot find lyric text in HTML page"
;
}
else
{
lyric
=
lyrics
.
take
(
reply
);
if
(
!
lyric
)
{
qCritical
()
<<
"Got an invalid lyric object!"
;
}
else
{
lyric
->
setText
(
lyricbox
.
toPlainText
());
found
=
true
;
}
}
}
qDebug
()
<<
"Lyric found:"
<<
found
;
Q_EMIT
lyricFetched
(
lyric
,
found
);
reply
->
deleteLater
();
}
void
GeniusAPI
::
getLyricText
(
const
QUrl
&
url
,
Lyric
*
lyric
)
{
qDebug
()
<<
"Requesting lyric page"
<<
url
.
url
();
QNetworkRequest
req
(
url
);
QNetworkReply
*
reply
=
network
->
get
(
req
);
lyrics
.
insert
(
reply
,
lyric
);
connect
(
reply
,
&
QNetworkReply
::
finished
,
this
,
&
GeniusAPI
::
onGetLyricPageResult
);
}
src/geniusapi.h
deleted
100644 → 0
View file @
6ae411db
/*
The MIT License (MIT)
Copyright (c) 2015-2021 Andrea Scarpino <andrea@scarpino.dev>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#ifndef GENIUSAPI_H
#define GENIUSAPI_H
#include
<QMap>
#include
<QString>
#include
"provider.h"
class
QNetworkAccessManager
;
class
QNetworkReply
;
class
QUrl
;
class
GeniusAPI
:
public
Provider
{
Q_OBJECT
Q_INTERFACES
(
Provider
)
public:
explicit
GeniusAPI
(
QObject
*
parent
=
0
);
virtual
~
GeniusAPI
();
void
getLyric
(
const
QString
&
artist
,
const
QString
&
song
);
private:
void
onGetLyricResult
();
void
onGetLyricPageResult
();
void
getLyricText
(
const
QUrl
&
url
,
Lyric
*
lyric
);
QNetworkAccessManager
*
network
;
QMap
<
QNetworkReply
*
,
Lyric
*>
lyrics
;
};
#endif // GENIUSAPI_H
src/geniusapi_secret.h
deleted
100644 → 0
View file @
6ae411db
/*
The MIT License (MIT)
Copyright (c) 2015-2021 Andrea Scarpino <andrea@scarpino.dev>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#ifndef GENIUSAPI_SECRET_H
#define GENIUSAPI_SECRET_H
// I've not a better idea on how to provide an open source application
// and hide these at the same time. If you've a better idea please
// contact me.
const
static
char
*
CLIENT_ID
=
""
;
const
static
char
*
CLIENT_SECRET
=
""
;
const
static
char
*
CLIENT_ACCESS_TOKEN
=
""
;
#endif // GENIUSAPI_SECRET_H
src/lyricsmanager.cpp
View file @
b8db4ba8
...
...
@@ -67,8 +67,6 @@ QString LyricsManager::getProvider() const
provider
=
"AZLyrics"
;
}
else
if
(
className
.
compare
(
QStringLiteral
(
"ChartLyricsAPI"
))
==
0
)
{
provider
=
"ChartLyrics"
;
}
else
if
(
className
.
compare
(
QStringLiteral
(
"GeniusAPI"
))
==
0
)
{
provider
=
"Genius"
;
}
else
{
provider
=
"LyricsMania"
;
}
...
...
@@ -90,9 +88,6 @@ void LyricsManager::setProvider(const QString &provider)
}
else
if
(
provider
.
compare
(
QStringLiteral
(
"ChartLyrics"
))
==
0
)
{
api
=
new
ChartLyricsAPI
;
p
=
QStringLiteral
(
"ChartLyrics"
);
}
else
if
(
provider
.
compare
(
QStringLiteral
(
"Genius"
))
==
0
)
{
api
=
new
GeniusAPI
;
p
=
QStringLiteral
(
"Genius"
);
}
else
{
api
=
new
LyricsManiaAPI
;
p
=
QStringLiteral
(
"LyricsMania"
);
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment