...
 
Commits (44)
......@@ -2,4 +2,4 @@
*.pro.user
*.pro.user.*
*.autosave
geniusapi_secret.h
src/geniusapi_secret.h
[main]
host = https://www.transifex.com
[harbour-Lyrics.harbour-lyricsts]
file_filter = translations/harbour-lyrics-<lang>.ts
source_file = translations/harbour-lyrics.ts
source_lang = en
type = QT
......@@ -2,13 +2,17 @@ TARGET = harbour-lyrics
CONFIG += sailfishapp
QT += dbus
DBUS_INTERFACES += org.mpris.MediaPlayer2.Player.xml
SOURCES += \
src/main.cpp \
src/lyricsmanager.cpp \
src/lyric.cpp \
src/mediaplayerscanner.cpp \
src/chartlyricsapi.cpp \
src/geniusapi.cpp \
src/lyricswikiapi.cpp \
src/provider.cpp \
src/lyricsmaniaapi.cpp
......@@ -16,10 +20,10 @@ HEADERS += \
src/lyricsmanager.h \
src/lyric_p.h \
src/lyric.h \
src/mediaplayerscanner.h \
src/chartlyricsapi.h \
src/geniusapi.h \
src/geniusapi_secret.h \
src/lyricswikiapi.h \
src/provider.h \
src/lyricsmaniaapi.h
......@@ -32,16 +36,26 @@ OTHER_FILES += \
rpm/harbour-lyrics.changes \
rpm/harbour-lyrics.spec \
rpm/harbour-lyrics.yaml \
org.mpris.MediaPlayer2.Player.xml \
translations/*.ts
CONFIG += sailfishapp_i18n
TRANSLATIONS += translations/harbour-lyrics-it.ts \
TRANSLATIONS += \
translations/harbour-lyrics-ar.ts \
translations/harbour-lyrics-ca.ts \
translations/harbour-lyrics-cs.ts \
translations/harbour-lyrics-de.ts \
translations/harbour-lyrics-el.ts \
translations/harbour-lyrics-es.ts \
translations/harbour-lyrics-fi.ts \
translations/harbour-lyrics-fr_FR.ts
translations/harbour-lyrics-fr_FR.ts \
translations/harbour-lyrics-it.ts \
translations/harbour-lyrics-nl.ts \
translations/harbour-lyrics-ru.ts \
translations/harbour-lyrics-sr.ts \
translations/harbour-lyrics-sv.ts
# LyricsWiki, Genius, LyricsMania
# Genius, LyricsMania
QT += webkitwidgets
# ChartLyrics
......
# harbour-Lyrics
# Lyrics
A music lyrics application for [Sailfish OS](https://sailfishos.org).
......@@ -6,10 +6,19 @@ Currently it supports:
* [ChartLyrics](http://chartlyrics.com)
* [Genius](http://genius.com)
* [LyricsMania](http://www.lyricsmania.com)
* [LyricsWiki](http://lyrics.wikia.com)
[![Flattr this git repo](http://api.flattr.com/button/flattr-badge-large.png)](https://flattr.com/submit/auto?user_id=ascarpino&url=https://gitlab.com/ascarpino/harbour-Lyrics&title=harbour-Lyrics&language=&tags=jolla&category=software)
[Build status](https://build.merproject.org/package/live_build_log/home:ilpianista/harbour-lyrics/sailfish_latest_armv7hl/armv8el)
Translations via [Transifex](https://www.transifex.com/organization/ascarpino-harbour/dashboard/harbour-Lyrics), thank you!
## Translations
[Build status](https://build.merproject.org/package/live_build_log/home:ilpianista/harbour-lyrics/sailfish_latest_armv7hl/armv8el)
[![Translation status](https://hosted.weblate.org/widgets/harbour-lyrics/-/svg-badge.svg)](https://hosted.weblate.org/engage/harbour-lyrics/?utm_source=widget)
Translations via [Weblate](https://hosted.weblate.org/projects/harbour-lyrics/), thank you!
## Donate
Donations via [Liberapay](https://liberapay.com/ilpianista) or Bitcoin (1Ph3hFEoQaD4PK6MhL3kBNNh9FZFBfisEH) are always welcomed, _thank you_!
## License
MIT
<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN" "http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
<node>
<interface name="org.mpris.MediaPlayer2.Player">
<method name="Next"/>
<method name="Previous"/>
<method name="Pause"/>
<method name="PlayPause"/>
<method name="Stop"/>
<method name="Play"/>
<method name="Seek">
<arg direction="in" type="x" name="Offset"/>
</method>
<method name="SetPosition">
<arg direction="in" type="o" name="TrackId"/>
<arg direction="in" type="x" name="Position"/>
</method>
<method name="OpenUri">
<arg direction="in" type="s" name="Uri"/>
<annotation value="QUrl" name="org.qtproject.QtDBus.QtTypeName.In0"/>
</method>
<signal name="Seeked">
<arg direction="out" type="x" name="Position"/>
</signal>
<property access="read" type="s" name="PlaybackStatus"/>
<property access="readwrite" type="s" name="LoopStatus"/>
<property access="readwrite" type="d" name="Rate"/>
<property access="readwrite" type="b" name="Shuffle"/>
<property access="read" type="a{sv}" name="Metadata">
<annotation value="QVariantMap" name="org.qtproject.QtDBus.QtTypeName"/>
</property>
<property access="readwrite" type="d" name="Volume"/>
<property access="read" type="x" name="Position">
<annotation value="false" name="org.freedesktop.DBus.Property.EmitsChangedSignal"/>
</property>
<property access="read" type="d" name="MinimumRate"/>
<property access="read" type="d" name="MaximumRate"/>
<property access="read" type="b" name="CanGoNext"/>
<property access="read" type="b" name="CanGoPrevious"/>
<property access="read" type="b" name="CanPlay"/>
<property access="read" type="b" name="CanPause"/>
<property access="read" type="b" name="CanSeek"/>
<property access="read" type="b" name="CanControl">
<annotation value="false" name="org.freedesktop.DBus.Property.EmitsChangedSignal"/>
</property>
</interface>
</node>
......@@ -27,8 +27,47 @@ import Sailfish.Silica 1.0
CoverBackground {
Connections {
target: manager
onSearchResult: {
placeholder.visible = !found;
if (found) {
title.text = lyric.artist + " - " + lyric.song;
songText.text = lyric.text;
}
songInfo.visible = found;
}
}
CoverPlaceholder {
id: placeholder
text: "Lyrics"
icon.source: "/usr/share/icons/hicolor/86x86/apps/harbour-lyrics.png"
}
Column {
id: songInfo
anchors.centerIn: parent
x: Theme.paddingSmall
width: parent.width - Theme.paddingSmall * 2
Label {
id: title
width: parent.width
wrapMode: Text.Wrap
font.pixelSize: Theme.fontSizeMedium
horizontalAlignment: Text.AlignHCenter
}
Label {
id: songText
width: parent.width
wrapMode: Text.Wrap
maximumLineCount: 10
elide: Text.ElideRight
font.pixelSize: Theme.fontSizeExtraSmall
}
}
}
/*
The MIT License (MIT)
Copyright (c) 2014-2015 Andrea Scarpino <me@andreascarpino.it>
Copyright (c) 2014-2016 Andrea Scarpino <me@andreascarpino.it>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
......@@ -29,6 +29,8 @@ Page {
allowedOrientations: Orientation.All
property bool userTyping: false;
Connections {
target: manager
......@@ -42,10 +44,20 @@ Page {
if (found) {
songText.text = lyric.text;
copy.enabled = true;
} else {
songText.text = "Not found :-("
}
}
onMediaPlayerInfo: {
console.log("Fetched song informations from Media Player");
if (!userTyping) {
artist.text = songArtist;
song.text = songTitle;
searchLyric();
}
}
}
SilicaFlickable {
......@@ -68,6 +80,17 @@ Page {
artist.forceActiveFocus();
song.text = "";
songText.text = "";
copy.enabled = false;
}
}
MenuItem {
id: copy
text: qsTr("Copy to clipboard")
enabled: songText.text.length > 0
onClicked: {
Clipboard.text = songText.text;
}
}
}
......@@ -76,6 +99,7 @@ Page {
id: column
x: Theme.horizontalPageMargin
width: parent.width - Theme.horizontalPageMargin * 2
spacing: Theme.paddingMedium
PageHeader {
title: "Lyrics"
......@@ -94,6 +118,9 @@ Page {
focus: true
placeholderText: qsTr("Artist")
onTextChanged: search.enabled = (text.length > 0 && song.text.length > 0)
onActiveFocusChanged: userTyping = artist.activeFocus
EnterKey.enabled: text.length > 0 && song.text.length > 0
EnterKey.onClicked: searchLyric();
}
......@@ -103,6 +130,9 @@ Page {
width: parent.width
placeholderText: qsTr("Song")
onTextChanged: search.enabled = (text.length > 0 && artist.text.length > 0)
onActiveFocusChanged: userTyping = song.activeFocus
EnterKey.enabled: text.length > 0 && artist.text.length > 0
EnterKey.onClicked: searchLyric();
}
......@@ -117,12 +147,9 @@ Page {
id: search
text: qsTr("Search")
anchors.horizontalCenter: parent.horizontalCenter
enabled: false
onClicked: {
if (artist.text.length > 0 && song.text.length > 0) {
searchLyric();
}
}
onClicked: searchLyric()
}
Text {
......@@ -130,6 +157,7 @@ Page {
width: parent.width
color: Theme.secondaryColor
wrapMode: Text.Wrap
font.pixelSize: Theme.fontSizeMedium
}
}
......@@ -143,7 +171,7 @@ Page {
busy.visible = true;
busy.running = true;
search.enabled = false;
manager.search(artist.text, song.text);
manager.search(artist.text.trim(), song.text.trim());
}
onStatusChanged: {
......
......@@ -26,11 +26,14 @@ import QtQuick 2.0
import Sailfish.Silica 1.0
Page {
id: page
allowedOrientations: Orientation.All
Column {
width: parent.width
x: Theme.horizontalPageMargin
width: parent.width - Theme.horizontalPageMargin * 2
spacing: Theme.paddingMedium
PageHeader {
title: qsTr("Settings")
......@@ -38,7 +41,7 @@ Page {
ComboBox {
id: provider
width: parent.width
width: page.width
label: qsTr("Provider")
menu: ContextMenu {
......@@ -54,12 +57,27 @@ Page {
MenuItem {
text: "LyricsMania"
}
}
}
MenuItem {
text: "LyricsWiki"
}
TextSwitch {
id: scanner
width: page.width
text: qsTr("Enable Media Player scanner")
description: qsTr("Checks Media Player to get song info. Do not focus any field to allow text substitution.")
checked: true
onCheckedChanged: {
manager.setMediaPlayerScanner(checked);
}
}
Button {
text: qsTr("Clear cache")
anchors.horizontalCenter: parent.horizontalCenter
onClicked: manager.clearCache();
}
}
Component.onCompleted: {
......@@ -68,11 +86,11 @@ Page {
provider.currentIndex = 0;
} else if (api === "Genius") {
provider.currentIndex = 1;
} else if (api === "LyricsMania") {
provider.currentIndex = 2;
} else {
provider.currentIndex = 3;
provider.currentIndex = 2;
}
scanner.checked = manager.getMediaPlayerScanner();
}
onStatusChanged: {
......@@ -80,9 +98,8 @@ Page {
switch (provider.currentIndex) {
case 0: manager.setProvider("ChartLyrics"); break;
case 1: manager.setProvider("Genius"); break;
case 2: manager.setProvider("LyricsMania"); break;
case 3:
default: manager.setProvider("LyricsWiki");
case 2:
default: manager.setProvider("LyricsMania");
}
}
}
......
* Sun Jul 31 2016 Andrea Scarpino <me@andreascarpino.it> 0.5.3-1
- Show the lyric in the cover.
- Bigger font for the lyric.
* Sun Jul 30 2016 Andrea Scarpino <me@andreascarpino.it> 0.5.2-1
- Fetch artist and song title info from Media Player.
* Wed Jul 13 2016 Andrea Scarpino <me@andreascarpino.it> 0.5.1-1
- Add Serbian and Arabic translation
- Do not enable the search button if there's no text
- Fix provider combobox width and element spacing
- Enable copy when there's something to copy
* Thu Jun 02 2016 Andrea Scarpino <me@andreascarpino.it> 0.5-1
- Add copy to clipboard (#2).
- Cache lyrics (#1).
- Fix Genius.
- Drop LyricsWiki.
- Add Swedish, Finnish, Italian and Czech translations.
* Sat Jul 18 2015 Andrea Scarpino <me@andreascarpino.it> 0.4-1
- Add LyricsMania
- Add LyricsMania.
* Fri Jul 17 2015 Andrea Scarpino <me@andreascarpino.it> 0.3.1-1
- Display current provider in main window.
......
......@@ -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.4
Version: 0.5.3
Release: 1
Group: Qt/Qt
License: MIT
......@@ -27,11 +27,12 @@ BuildRequires: pkgconfig(Qt5Qml)
BuildRequires: pkgconfig(Qt5Quick)
BuildRequires: pkgconfig(Qt5WebKitWidgets)
BuildRequires: pkgconfig(Qt5Xml)
BuildRequires: pkgconfig(Qt5DBus)
BuildRequires: desktop-file-utils
%description
Music lyrics application.
It does support: ChartLyrics, LiricsWiki, Genius.
It does support: ChartLyrics, LyricsMania, Genius.
%prep
......
Name: harbour-lyrics
Summary: Music lyrics application
Version: 0.4
Version: 0.5.3
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, LiricsWiki, Genius.
It does support: ChartLyrics, LyricsMania, Genius.
Configure: none
# The qtc5 builder inserts macros to allow QtCreator to have fine
# control over qmake/make execution
......@@ -28,6 +28,7 @@ PkgConfigBR:
- Qt5Quick
- Qt5WebKitWidgets # LyricsWiki, Genius
- Qt5Xml # ChartLyrics
- Qt5DBus
# Build dependencies without a pkgconfig setup can be listed here
# PkgBR:
......@@ -35,7 +36,7 @@ PkgConfigBR:
# Runtime dependencies which are not automatically detected
Requires:
- sailfishsilica-qt5 >= 0.10.9
- sailfishsilica-qt5 >= 0.10.9
# All installed files
Files:
......
......@@ -87,10 +87,10 @@ void ChartLyricsAPI::onGetLyricResult()
const QString text = res.namedItem(QStringLiteral("Lyric")).toElement().text();
if (!text.isEmpty()) {
qDebug() << "Got lyric text";
lyric->setText(text);
found = true;
} else {
qDebug() << "Got an empty text";
}
} else {
qDebug() << "No lyric found";
......
......@@ -34,15 +34,13 @@ class QNetworkAccessManager;
class ChartLyricsAPI : public Provider
{
Q_OBJECT
Q_INTERFACES(Provider)
public:
explicit ChartLyricsAPI(QObject *parent = 0);
virtual ~ChartLyricsAPI();
void getLyric(const QString &artist, const QString &song);
Q_SIGNALS:
void lyricFetched(Lyric *lyric, const bool &found);
private:
void onGetLyricResult();
......
......@@ -148,7 +148,7 @@ void GeniusAPI::onGetLyricPageResult()
page.settings()->setAttribute(QWebSettings::JavascriptEnabled, false);
page.mainFrame()->setHtml(reply->readAll());
QWebElement lyricbox = page.mainFrame()->findFirstElement("div[class=lyrics]");
QWebElement lyricbox = page.mainFrame()->findFirstElement("lyrics[class=lyrics]");
if (lyricbox.isNull()) {
qCritical() << "Cannot find lyric text in HTML page";
......
......@@ -37,15 +37,13 @@ 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);
Q_SIGNALS:
void lyricFetched(Lyric *lyric, const bool &found);
private:
void onGetLyricResult();
void onGetLyricPageResult();
......
/*
The MIT License (MIT)
Copyright (c) 2015 Andrea Scarpino <me@andreascarpino.it>
Copyright (c) 2015-2016 Andrea Scarpino <me@andreascarpino.it>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
......@@ -26,27 +26,38 @@
#include <QCoreApplication>
#include <QDebug>
#include <QDir>
#include <QSettings>
#include <QStandardPaths>
#include "chartlyricsapi.h"
#include "geniusapi.h"
#include "lyricsmaniaapi.h"
#include "lyricswikiapi.h"
#include "mediaplayerscanner.h"
#include "provider.h"
LyricsManager::LyricsManager(QObject *parent) :
QObject(parent)
, api(0)
, mpScanner(0)
{
settings = new QSettings("it.andreascarpino", QCoreApplication::applicationName(), this);
settings = new QSettings(QCoreApplication::applicationName(), QCoreApplication::applicationName(), this);
setProvider(settings->value("Provider").toString());
setMediaPlayerScanner(settings->value("MediaPlayerScanner", true).toBool());
}
LyricsManager::~LyricsManager()
{
delete settings;
delete api;
delete mpScanner;
}
void LyricsManager::clearCache()
{
const bool ret = QDir(getLyricsDir()).removeRecursively();
qDebug() << "Cache cleared:" << ret;
}
QString LyricsManager::getProvider() const
......@@ -58,10 +69,8 @@ QString LyricsManager::getProvider() const
provider = "ChartLyrics";
} else if (className.compare(QStringLiteral("GeniusAPI")) == 0) {
provider = "Genius";
} else if (className.compare(QStringLiteral("LyricsManiaAPI")) == 0) {
provider = "LyricsMania";
} else {
provider = "LyricsWiki";
provider = "LyricsMania";
}
qDebug() << "Default provider is" << provider;
......@@ -81,22 +90,75 @@ void LyricsManager::setProvider(const QString &provider)
} else if (provider.compare(QStringLiteral("Genius")) == 0) {
api = new GeniusAPI;
p = QStringLiteral("Genius");
} else if (provider.compare(QStringLiteral("LyricsMania")) == 0) {
} else {
api = new LyricsManiaAPI;
p = QStringLiteral("LyricsMania");
} else {
api = new LyricsWikiAPI;
p = QStringLiteral("LyricsWiki");
}
connect(api, &Provider::lyricFetched, this, &LyricsManager::searchResult);
connect(api, &Provider::lyricFetched, this, &LyricsManager::storeLyric);
qDebug() << "Setting default provider to" << p;
settings->setValue("Provider", p);
}
QString LyricsManager::getLyricsDir() const
{
const QDir lyricsDir(QStandardPaths::writableLocation(QStandardPaths::CacheLocation));
if (!lyricsDir.exists()) {
if (!lyricsDir.mkpath(lyricsDir.absolutePath())) {
qCritical() << "Cannot create dir!";
}
}
return QString(lyricsDir.absolutePath() + QDir::separator());
}
void LyricsManager::storeLyric(Lyric *lyric, const bool &found)
{
if (found) {
qDebug() << "Caching lyric by" << lyric->artist() << lyric->song();
QFile f(getLyricsDir() + lyric->artist() + "_" + lyric->song() + ".txt");
f.open(QIODevice::WriteOnly);
f.write(lyric->text().toLatin1());
f.close();
}
}
void LyricsManager::search(const QString &artist, const QString &song)
{
qDebug() << "Querying" << api->metaObject()->className();
api->getLyric(artist, song);
QFile f(getLyricsDir() + artist + "_" + song + ".txt");
if (f.exists()) {
f.open(QIODevice::ReadOnly);
connect(api, &Provider::lyricFetched, this, &LyricsManager::searchResult);
Lyric* lyric = new Lyric();
lyric->setArtist(artist);
lyric->setSong(song);
lyric->setText(f.readAll());
f.close();
Q_EMIT searchResult(lyric, true);
} else {
qDebug() << "Querying" << api->metaObject()->className();
api->getLyric(artist, song);
}
}
bool LyricsManager::getMediaPlayerScanner() const
{
return settings->value("MediaPlayerScanner").toBool();
}
void LyricsManager::setMediaPlayerScanner(const bool enabled)
{
if (enabled) {
mpScanner = new MediaPlayerScanner();
connect(mpScanner, &MediaPlayerScanner::mediaPlayerInfo, this, &LyricsManager::mediaPlayerInfo);
} else if (mpScanner) {
delete mpScanner;
mpScanner = 0;
}
settings->setValue("MediaPlayerScanner", enabled);
}
......@@ -32,6 +32,7 @@
class QSettings;
class Provider;
class MediaPlayerScanner;
class LyricsManager : public QObject
{
......@@ -40,16 +41,24 @@ public:
explicit LyricsManager(QObject *parent = 0);
virtual ~LyricsManager();
Q_INVOKABLE void clearCache();
Q_INVOKABLE QString getProvider() const;
Q_INVOKABLE void search(const QString &artist, const QString &song);
Q_INVOKABLE bool getMediaPlayerScanner() const;
Q_INVOKABLE void setMediaPlayerScanner(const bool enabled);
Q_INVOKABLE void setProvider(const QString &provider);
Q_SIGNALS:
void searchResult(Lyric *lyric, const bool &found);
void mediaPlayerInfo(const QString &songArtist, const QString &songTitle);
private:
QString getLyricsDir() const;
void storeLyric(Lyric *lyric, const bool &found);
QSettings *settings;
Provider *api;
MediaPlayerScanner *mpScanner;
};
......
......@@ -32,6 +32,8 @@
#include <QWebElement>
#include <QWebFrame>
#include "lyric.h"
const static QString BASE_URL = QStringLiteral("http://www.lyricsmania.com");
LyricsManiaAPI::LyricsManiaAPI(QObject *parent) :
......
......@@ -36,15 +36,13 @@ class QNetworkReply;
class LyricsManiaAPI : public Provider
{
Q_OBJECT
Q_INTERFACES(Provider)
public:
explicit LyricsManiaAPI(QObject *parent = 0);
virtual ~LyricsManiaAPI();
void getLyric(const QString &artist, const QString &song);
Q_SIGNALS:
void lyricFetched(Lyric *lyric, const bool &found);
private:
void onGetLyricPageResult();
......
/*
The MIT License (MIT)
Copyright (c) 2015 Andrea Scarpino <me@andreascarpino.it>
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 "lyricswikiapi.h"
#include <QDebug>
#include <QJsonDocument>
#include <QJsonObject>
#include <QNetworkAccessManager>
#include <QNetworkReply>
#include <QWebElement>
#include <QWebFrame>
#include <QWebPage>
#include <QUrl>
#include <QUrlQuery>
#include "lyric.h"
const static QString API_URL = QStringLiteral("http://lyrics.wikia.com/api.php");
LyricsWikiAPI::LyricsWikiAPI(QObject *parent) :
Provider(parent)
, network(new QNetworkAccessManager(this))
{
}
LyricsWikiAPI::~LyricsWikiAPI()
{
qDeleteAll(lyrics.keys());
qDeleteAll(lyrics.values());
delete network;
}
void LyricsWikiAPI::getLyric(const QString &artist, const QString &song)
{
qDebug() << "Requesting lyric for artist" << artist << ", song" << song;
QUrl url(QStringLiteral("http://lyrics.wikia.com"));
QString artNoSpaces(artist);
artNoSpaces.replace(QChar::Space, QChar::fromLatin1('_'));
QString songNoSpaces(song);
songNoSpaces.replace(QChar::Space, QChar::fromLatin1('_'));
url.setPath(QChar::fromLatin1('/') + artNoSpaces + QChar::fromLatin1(':') + songNoSpaces);
qDebug() << "Requesting lyric page" << url;
QNetworkRequest req(url);
QNetworkReply* reply = network->get(req);
Lyric* lyric = new Lyric();
lyric->setArtist(artist);
lyric->setSong(song);
lyrics.insert(reply, lyric);
connect(reply, &QNetworkReply::finished, this, &LyricsWikiAPI::onGetLyricResult);
}
void LyricsWikiAPI::onGetLyricResult()
{
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=lyricbox]");
if (lyricbox.isNull()) {
qCritical() << "Cannot find lyric text in HTML page";
} else {
// Remove the <script> tags
Q_FOREACH (QWebElement script, lyricbox.findAll(QStringLiteral("script"))) {
script.removeFromDocument();
}
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();
}
/*
The MIT License (MIT)
Copyright (c) 2015 Andrea Scarpino <me@andreascarpino.it>
Copyright (c) 2015-2016 Andrea Scarpino <me@andreascarpino.it>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
......@@ -36,7 +36,8 @@ int main(int argc, char *argv[])
QScopedPointer<QApplication> app(new QApplication(argc, argv));
QScopedPointer<QQuickView> view(SailfishApp::createView());
QCoreApplication::setApplicationName(QStringLiteral("Lyrics"));
QCoreApplication::setApplicationName(QStringLiteral("harbour-lyrics"));
QCoreApplication::setOrganizationDomain(QStringLiteral("andreascarpino.it"));
LyricsManager manager;
view->rootContext()->setContextProperty("manager", &manager);
......
/*
The MIT License (MIT)
Copyright (c) 2016 Andrea Scarpino <me@andreascarpino.it>
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 "mediaplayerscanner.h"
#include <QTimer>
const QString MediaPlayerScanner::MP_DBUS_SERVICE(QLatin1String("org.mpris.MediaPlayer2.jolla-mediaplayer"));
const QString MediaPlayerScanner::MP_DBUS_DAEMON_PATH(QLatin1String("/org/mpris/MediaPlayer2"));
MediaPlayerScanner::MediaPlayerScanner(QObject *parent) :
QObject(parent)
, impface(MediaPlayerScanner::MP_DBUS_SERVICE, MediaPlayerScanner::MP_DBUS_DAEMON_PATH, QDBusConnection::sessionBus())
, m_timer(new QTimer())
{
fetchInfo();
m_timer->start(5 * 1000);
connect(m_timer, &QTimer::timeout, this, &MediaPlayerScanner::fetchInfo);
}
MediaPlayerScanner::~MediaPlayerScanner()
{
delete m_timer;
}
void MediaPlayerScanner::fetchInfo()
{
const QVariantMap map = impface.metadata();
const QStringList artists(map["xesam:artist"].toStringList());
const QString title(map["xesam:title"].toString());
if (!artists.isEmpty() && !title.isEmpty()) {
Q_EMIT mediaPlayerInfo(artists.at(0), title);
}
}
/*
The MIT License (MIT)
Copyright (c) 2015 Andrea Scarpino <me@andreascarpino.it>
Copyright (c) 2016 Andrea Scarpino <me@andreascarpino.it>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
......@@ -22,35 +22,33 @@
SOFTWARE.
*/
#ifndef LYRICSWIKIAPI_H
#define LYRICSWIKIAPI_H
#ifndef MEDIAPLAYERSCANNER_H
#define MEDIAPLAYERSCANNER_H
#include <QMap>
#include <QString>
#include <QObject>
#include "provider.h"
#include "player_interface.h"
class QNetworkAccessManager;
class QNetworkReply;
class QUrl;
class QTimer;
class LyricsWikiAPI : public Provider
class MediaPlayerScanner : public QObject
{
Q_OBJECT
public:
explicit LyricsWikiAPI(QObject *parent = 0);
virtual ~LyricsWikiAPI();
void getLyric(const QString &artist, const QString &song);
explicit MediaPlayerScanner(QObject *parent = 0);
virtual ~MediaPlayerScanner();
Q_SIGNALS:
void lyricFetched(Lyric *lyric, const bool &found);
void mediaPlayerInfo(const QString &songArtist, const QString &songTitle);
private:
void onGetLyricResult();
static const QString MP_DBUS_SERVICE;
static const QString MP_DBUS_DAEMON_PATH;
void fetchInfo();
QNetworkAccessManager *network;
QMap<QNetworkReply*, Lyric*> lyrics;
OrgMprisMediaPlayer2PlayerInterface impface;
QTimer* m_timer;
};
#endif // LYRICSWIKIAPI_H
#endif // MEDIAPLAYERSCANNER_H
/*
The MIT License (MIT)
Copyright (c) 2015 Andrea Scarpino <me@andreascarpino.it>
Copyright (c) 2015-2016 Andrea Scarpino <me@andreascarpino.it>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
......@@ -24,11 +24,6 @@
#include "provider.h"
#include <QDebug>
#include <QUrl>
#include "lyric.h"
Provider::Provider(QObject *parent) :
QObject(parent)
{
......
......@@ -28,7 +28,7 @@
#include <QObject>
#include <QString>
#include "lyric.h"
class Lyric;
class Provider : public QObject
{
......@@ -46,4 +46,6 @@ Q_SIGNALS:
};
Q_DECLARE_INTERFACE(Provider, "Provider")
#endif // PROVIDER_H
<?xml version="1.0" ?><!DOCTYPE TS><TS language="ar" version="2.1">
<context>
<name>MainPage</name>
<message>
<location filename="../qml/pages/MainPage.qml" line="76"/>
<source>Clear</source>
<translation>محو</translation>
</message>
<message>
<location filename="../qml/pages/MainPage.qml" line="70"/>
<source>Settings</source>
<translation>الإعدادات</translation>
</message>
<message>
<location filename="../qml/pages/MainPage.qml" line="179"/>
<source>Powered by %1</source>
<translation>مشغل بواسطة %1</translation>
</message>
<message>
<location filename="../qml/pages/MainPage.qml" line="119"/>
<source>Artist</source>
<translation>الفنان</translation>
</message>
<message>
<location filename="../qml/pages/MainPage.qml" line="89"/>
<source>Copy to clipboard</source>
<translation>انسخ إلى الحافظة</translation>
</message>
<message>
<location filename="../qml/pages/MainPage.qml" line="131"/>
<source>Song</source>
<translation>الأغنية</translation>
</message>
<message>
<location filename="../qml/pages/MainPage.qml" line="148"/>
<source>Search</source>
<translation>بحث</translation>
</message>
</context>
<context>
<name>Settings</name>
<message>
<location filename="../qml/pages/Settings.qml" line="39"/>
<source>Settings</source>
<translation>الإعدادات</translation>
</message>
<message>
<location filename="../qml/pages/Settings.qml" line="45"/>
<source>Provider</source>
<translation>موفر</translation>
</message>
<message>
<location filename="../qml/pages/Settings.qml" line="66"/>
<source>Enable Media Player scanner</source>
<translation type="unfinished"/>
</message>
<message>
<location filename="../qml/pages/Settings.qml" line="67"/>
<source>Checks Media Player to get song info. Do not focus any field to allow text substitution.</source>
<translation type="unfinished"/>
</message>
<message>
<location filename="../qml/pages/Settings.qml" line="76"/>
<source>Clear cache</source>
<translation>امسح الخابية</translation>
</message>
</context>
</TS>
\ No newline at end of file
......@@ -2,32 +2,37 @@
<context>
<name>MainPage</name>
<message>
<location filename="../qml/pages/MainPage.qml" line="64"/>
<location filename="../qml/pages/MainPage.qml" line="76"/>
<source>Clear</source>
<translation>Neteja</translation>
</message>
<message>
<location filename="../qml/pages/MainPage.qml" line="58"/>
<location filename="../qml/pages/MainPage.qml" line="70"/>
<source>Settings</source>
<translation>Configuració</translation>
</message>
<message>
<location filename="../qml/pages/MainPage.qml" line="151"/>
<location filename="../qml/pages/MainPage.qml" line="179"/>
<source>Powered by %1</source>
<translation>Impulsat per %1</translation>
</message>
<message>
<location filename="../qml/pages/MainPage.qml" line="95"/>
<location filename="../qml/pages/MainPage.qml" line="119"/>
<source>Artist</source>
<translation>Artista</translation>
</message>
<message>
<location filename="../qml/pages/MainPage.qml" line="104"/>
<location filename="../qml/pages/MainPage.qml" line="89"/>
<source>Copy to clipboard</source>
<translation>Copia al porta-retalls</translation>
</message>
<message>
<location filename="../qml/pages/MainPage.qml" line="131"/>
<source>Song</source>
<translation>Cançó</translation>
</message>
<message>
<location filename="../qml/pages/MainPage.qml" line="118"/>
<location filename="../qml/pages/MainPage.qml" line="148"/>
<source>Search</source>
<translation>Cerca</translation>
</message>
......@@ -35,14 +40,29 @@
<context>
<name>Settings</name>
<message>
<location filename="../qml/pages/Settings.qml" line="36"/>
<location filename="../qml/pages/Settings.qml" line="39"/>
<source>Settings</source>
<translation>Configuració</translation>
</message>
<message>
<location filename="../qml/pages/Settings.qml" line="42"/>
<location filename="../qml/pages/Settings.qml" line="45"/>
<source>Provider</source>
<translation>Proveïdor</translation>
</message>
<message>
<location filename="../qml/pages/Settings.qml" line="66"/>
<source>Enable Media Player scanner</source>
<translation type="unfinished"/>
</message>
<message>
<location filename="../qml/pages/Settings.qml" line="67"/>
<source>Checks Media Player to get song info. Do not focus any field to allow text substitution.</source>
<translation type="unfinished"/>
</message>
<message>
<location filename="../qml/pages/Settings.qml" line="76"/>
<source>Clear cache</source>
<translation>Neteja la memòria cau</translation>
</message>
</context>
</TS>
\ No newline at end of file
......@@ -2,32 +2,37 @@
<context>
<name>MainPage</name>
<message>
<location filename="../qml/pages/MainPage.qml" line="64"/>
<location filename="../qml/pages/MainPage.qml" line="76"/>
<source>Clear</source>
<translation>Vyprázdnit</translation>
</message>
<message>
<location filename="../qml/pages/MainPage.qml" line="58"/>
<location filename="../qml/pages/MainPage.qml" line="70"/>
<source>Settings</source>
<translation>Nastavení</translation>
</message>
<message>
<location filename="../qml/pages/MainPage.qml" line="151"/>
<location filename="../qml/pages/MainPage.qml" line="179"/>
<source>Powered by %1</source>
<translation type="unfinished"/>
<translation>Napájeno %1</translation>
</message>
<message>
<location filename="../qml/pages/MainPage.qml" line="95"/>
<location filename="../qml/pages/MainPage.qml" line="119"/>
<source>Artist</source>
<translation>Umělec</translation>
</message>
<message>
<location filename="../qml/pages/MainPage.qml" line="104"/>
<location filename="../qml/pages/MainPage.qml" line="89"/>
<source>Copy to clipboard</source>
<translation type="unfinished"/>
</message>
<message>
<location filename="../qml/pages/MainPage.qml" line="131"/>
<source>Song</source>
<translation>Píseň</translation>
</message>
<message>
<location filename="../qml/pages/MainPage.qml" line="118"/>
<location filename="../qml/pages/MainPage.qml" line="148"/>
<source>Search</source>
<translation>Hledat</translation>
</message>
......@@ -35,14 +40,29 @@
<context>
<name>Settings</name>
<message>
<location filename="../qml/pages/Settings.qml" line="36"/>
<location filename="../qml/pages/Settings.qml" line="39"/>
<source>Settings</source>
<translation>Nastavení</translation>
</message>
<message>
<location filename="../qml/pages/Settings.qml" line="42"/>
<location filename="../qml/pages/Settings.qml" line="45"/>
<source>Provider</source>
<translation>Poskytovatel</translation>
</message>
<message>
<location filename="../qml/pages/Settings.qml" line="66"/>
<source>Enable Media Player scanner</source>
<translation type="unfinished"/>
</message>
<message>
<location filename="../qml/pages/Settings.qml" line="67"/>
<source>Checks Media Player to get song info. Do not focus any field to allow text substitution.</source>
<translation type="unfinished"/>
</message>
<message>
<location filename="../qml/pages/Settings.qml" line="76"/>
<source>Clear cache</source>
<translation type="unfinished"/>
</message>
</context>
</TS>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS>
<TS language="de" version="2.1">
<context>
<name>MainPage</name>
<message>
<location filename="../qml/pages/MainPage.qml" line="76"/>
<source>Clear</source>
<translation>Leeren</translation>
</message>
<message>
<location filename="../qml/pages/MainPage.qml" line="70"/>
<source>Settings</source>
<translation>Einstellungen</translation>
</message>
<message>
<location filename="../qml/pages/MainPage.qml" line="179"/>
<source>Powered by %1</source>
<translation>Unterstützt von %1</translation>
</message>
<message>
<location filename="../qml/pages/MainPage.qml" line="119"/>
<source>Artist</source>
<translation>Künstler</translation>
</message>
<message>
<location filename="../qml/pages/MainPage.qml" line="89"/>
<source>Copy to clipboard</source>
<translation>In Zwischenablage kopieren</translation>
</message>
<message>
<location filename="../qml/pages/MainPage.qml" line="131"/>
<source>Song</source>
<translation>Lied</translation>
</message>
<message>
<location filename="../qml/pages/MainPage.qml" line="148"/>
<source>Search</source>
<translation>Suchen</translation>
</message>
</context>
<context>
<name>Settings</name>
<message>
<location filename="../qml/pages/Settings.qml" line="39"/>
<source>Settings</source>
<translation>Einstellungen</translation>
</message>
<message>
<location filename="../qml/pages/Settings.qml" line="45"/>
<source>Provider</source>
<translation>Anbieter</translation>
</message>
<message>
<location filename="../qml/pages/Settings.qml" line="66"/>
<source>Enable Media Player scanner</source>
<translation>Medienscanner aktivieren</translation>
</message>
<message>
<location filename="../qml/pages/Settings.qml" line="67"/>
<source>Checks Media Player to get song info. Do not focus any field to allow text substitution.</source>
<translation>Holt Information aus dem Mediaplayer. Lasse die Felder unfokussiert, damit der Text ersetzt werden kann.</translation>
</message>
<message>
<location filename="../qml/pages/Settings.qml" line="76"/>
<source>Clear cache</source>
<translation>Cache leeren</translation>
</message>
</context>
</TS>
<?xml version="1.0" ?><!DOCTYPE TS><TS language="el" version="2.1">
<context>
<name>MainPage</name>
<message>
<location filename="../qml/pages/MainPage.qml" line="76"/>
<source>Clear</source>
<translation type="unfinished"/>
</message>
<message>
<location filename="../qml/pages/MainPage.qml" line="70"/>
<source>Settings</source>
<translation type="unfinished"/>
</message>
<message>
<location filename="../qml/pages/MainPage.qml" line="179"/>
<source>Powered by %1</source>
<translation type="unfinished"/>
</message>
<message>
<location filename="../qml/pages/MainPage.qml" line="119"/>
<source>Artist</source>
<translation type="unfinished"/>
</message>
<message>
<location filename="../qml/pages/MainPage.qml" line="89"/>
<source>Copy to clipboard</source>
<translation type="unfinished"/>
</message>
<message>
<location filename="../qml/pages/MainPage.qml" line="131"/>
<source>Song</source>
<translation type="unfinished"/>
</message>
<message>
<location filename="../qml/pages/MainPage.qml" line="148"/>
<source>Search</source>
<translation type="unfinished"/>
</message>
</context>
<context>
<name>Settings</name>
<message>
<location filename="