Commit 090b980e authored by Andrea Scarpino's avatar Andrea Scarpino

Add LyricsMania

parent 6b108687
......@@ -9,7 +9,8 @@ SOURCES += \
src/chartlyricsapi.cpp \
src/geniusapi.cpp \
src/lyricswikiapi.cpp \
src/provider.cpp
src/provider.cpp \
src/lyricsmaniaapi.cpp
HEADERS += \
src/lyricsmanager.h \
......@@ -19,7 +20,8 @@ HEADERS += \
src/geniusapi.h \
src/geniusapi_secret.h \
src/lyricswikiapi.h \
src/provider.h
src/provider.h \
src/lyricsmaniaapi.h
OTHER_FILES += \
qml/cover/CoverPage.qml \
......
......@@ -51,6 +51,10 @@ Page {
text: "Genius"
}
MenuItem {
text: "LyricsMania"
}
MenuItem {
text: "LyricsWiki"
}
......@@ -64,8 +68,10 @@ Page {
provider.currentIndex = 0;
} else if (api === "Genius") {
provider.currentIndex = 1;
} else {
} else if (api === "LyricsMania") {
provider.currentIndex = 2;
} else {
provider.currentIndex = 3;
}
}
......@@ -74,7 +80,8 @@ Page {
switch (provider.currentIndex) {
case 0: manager.setProvider("ChartLyrics"); break;
case 1: manager.setProvider("Genius"); break;
case 2:
case 2: manager.setProvider("LyricsMania"); break;
case 3:
default: manager.setProvider("LyricsWiki");
}
}
......
* Sat Jul 18 2015 Andrea Scarpino <me@andreascarpino.it> 0.4-1
- Add LyricsMania
* Fri Jul 17 2015 Andrea Scarpino <me@andreascarpino.it> 0.3.1-1
- Display current provider in main window.
- Fix settings not being saved.
......
......@@ -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.3.1
Version: 0.4
Release: 1
Group: Qt/Qt
License: MIT
......
Name: harbour-lyrics
Summary: Music lyrics application
Version: 0.3.1
Version: 0.4
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
......
screenshots/screenshot_1.png

467 KB | W: | H:

screenshots/screenshot_1.png

467 KB | W: | H:

screenshots/screenshot_1.png
screenshots/screenshot_1.png
screenshots/screenshot_1.png
screenshots/screenshot_1.png
  • 2-up
  • Swipe
  • Onion skin
......@@ -30,6 +30,7 @@
#include "chartlyricsapi.h"
#include "geniusapi.h"
#include "lyricsmaniaapi.h"
#include "lyricswikiapi.h"
#include "provider.h"
......@@ -57,6 +58,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";
}
......@@ -78,6 +81,9 @@ 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) {
api = new LyricsManiaAPI;
p = QStringLiteral("LyricsMania");
} else {
api = new LyricsWikiAPI;
p = QStringLiteral("LyricsWiki");
......
/*
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 "lyricsmaniaapi.h"
#include <QDebug>
#include <QNetworkAccessManager>
#include <QNetworkReply>
#include <QUrl>
#include <QWebPage>
#include <QWebElement>
#include <QWebFrame>
const static QString BASE_URL = QStringLiteral("http://www.lyricsmania.com");
LyricsManiaAPI::LyricsManiaAPI(QObject *parent) :
Provider(parent)
, network(new QNetworkAccessManager(this))
{
}
LyricsManiaAPI::~LyricsManiaAPI()
{
qDeleteAll(lyrics.keys());
qDeleteAll(lyrics.values());
delete network;
}
void LyricsManiaAPI::getLyric(const QString &artist, const QString &song)
{
qDebug() << "Requesting lyric for artist" << artist << ", song" << song;
QString artNoSpaces(artist.toLower());
artNoSpaces.replace(QChar::Space, QChar::fromLatin1('_'));
QString songNoSpaces(song.toLower());
songNoSpaces.replace(QChar::Space, QChar::fromLatin1('_'));
QUrl url(BASE_URL + QStringLiteral("/%1_lyrics_%2.html").arg(songNoSpaces).arg(artNoSpaces));
qDebug() << 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, &LyricsManiaAPI::onGetLyricPageResult);
}
void LyricsManiaAPI::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-body]");
if (lyricbox.isNull()) {
qCritical() << "Cannot find lyric text in HTML page";
} else {
// Remove the video div
lyricbox.findFirst(QStringLiteral("div")).removeFromDocument();
// Remove the song title
lyricbox.findFirst(QStringLiteral("strong")).removeFromDocument();
lyric = lyrics.take(reply);
if (!lyric) {
qCritical() << "Got an invalid lyric object!";
} else {
lyric->setText(lyricbox.toPlainText());
found = true;
}
}
}
qDebug() << "Lyric found:" << found;
emit lyricFetched(lyric, found);
reply->deleteLater();
}
/*
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.
*/
#ifndef LYRICSMANIAAPI_H
#define LYRICSMANIAAPI_H
#include <QMap>
#include <QString>
#include "provider.h"
class QNetworkAccessManager;
class QNetworkReply;
class LyricsManiaAPI : public Provider
{
Q_OBJECT
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();
QNetworkAccessManager *network;
QMap<QNetworkReply*, Lyric*> lyrics;
};
#endif // LYRICSMANIAAPI_H
......@@ -59,9 +59,9 @@ void LyricsWikiAPI::getLyricBypassApi(const QString &artist, const QString &song
QUrl url(QStringLiteral("http://lyrics.wikia.com"));
QString artNoSpaces(artist);
artNoSpaces.replace(QChar::Space, "_");
artNoSpaces.replace(QChar::Space, QChar::fromLatin1('_'));
QString songNoSpaces(song);
songNoSpaces.replace(QChar::Space, "_");
songNoSpaces.replace(QChar::Space, QChar::fromLatin1('_'));
url.setPath(QChar::fromLatin1('/') + artNoSpaces + QChar::fromLatin1(':') + songNoSpaces);
......@@ -83,9 +83,9 @@ void LyricsWikiAPI::getLyric(const QString &artist, const QString &song)
QUrl url(API_URL);
QString artNoSpaces(artist);
artNoSpaces.replace(QChar::Space, "_");
artNoSpaces.replace(QChar::Space, QChar::fromLatin1('_'));
QString songNoSpaces(song);
songNoSpaces.replace(QChar::Space, "_");
songNoSpaces.replace(QChar::Space, QChar::fromLatin1('_'));
QUrlQuery query;
query.addQueryItem(QStringLiteral("func"), QStringLiteral("getSong"));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment