Commit a8ee20e6 authored by Camilo higuita's avatar Camilo higuita

force update

parent b39f5c15
......@@ -26,7 +26,24 @@ using namespace BAE;
Babe::Babe(QObject *parent) : CollectionDB(parent)
{
this->settings = new BabeSettings(this);
/*use another thread for the db to perfom heavy dutty actions*/
this->thread = new ConThread;
this->pulpo = new Pulpo;
connect(pulpo, &Pulpo::infoReady, [&](const BAE::DB &track, const PULPO::RESPONSE &res)
{
qDebug()<<"GOT THE LYRICS";
if(!res[PULPO::ONTOLOGY::TRACK][PULPO::INFO::LYRICS].isEmpty())
{
auto lyrics = res[PULPO::ONTOLOGY::TRACK][PULPO::INFO::LYRICS][PULPO::CONTEXT::LYRIC].toString();
lyricsTrack(track, lyrics);
emit this->trackLyricsReady(lyrics, track[KEY::URL]);
}
});
connect(settings, &BabeSettings::refreshTables, [this](int size)
{
......@@ -45,6 +62,7 @@ Babe::Babe(QObject *parent) : CollectionDB(parent)
});
/*The local streaming connection still unfinished*/
connect(&link, &Linking::parseAsk, this, &Babe::linkDecoder);
connect(&link, &Linking::bytesFrame, [this](QByteArray array)
{
......@@ -54,6 +72,7 @@ Babe::Babe(QObject *parent) : CollectionDB(parent)
connect(&link, &Linking::arrayReady, [this](QByteArray array)
{
qDebug()<<"trying to play the array";
Q_UNUSED(array);
this->player.playBuffer();
});
......@@ -135,6 +154,7 @@ void Babe::trackLyrics(const QString &url)
if(track.isEmpty()) return;
qDebug()<< "Getting lyrics for track"<< track.first()[KEY::TITLE];
if(!track.first()[KEY::LYRICS].isEmpty() && track.first()[KEY::LYRICS] != SLANG[W::NONE])
emit this->trackLyricsReady(track.first()[KEY::LYRICS], url);
else
......@@ -196,23 +216,14 @@ QString Babe::albumArt(const QString &album, const QString &artist)
void Babe::fetchTrackLyrics(DB &song)
{
Pulpo pulpo;
pulpo.registerServices({SERVICES::LyricWikia});
pulpo.setOntology(PULPO::ONTOLOGY::TRACK);
pulpo.setInfo(PULPO::INFO::LYRICS);
connect(&pulpo, &Pulpo::infoReady, [this](const BAE::DB &track, const PULPO::RESPONSE &res)
{
if(!res[PULPO::ONTOLOGY::TRACK][PULPO::INFO::LYRICS].isEmpty())
{
auto lyrics = res[PULPO::ONTOLOGY::TRACK][PULPO::INFO::LYRICS][PULPO::CONTEXT::LYRIC].toString();
pulpo->registerServices({SERVICES::LyricWikia, SERVICES::Genius});
pulpo->setOntology(PULPO::ONTOLOGY::TRACK);
pulpo->setInfo(PULPO::INFO::LYRICS);
lyricsTrack(track, lyrics);
emit this->trackLyricsReady(lyrics, track[KEY::URL]);
}
});
qDebug()<<"STARTED FETCHING LYRICS";
pulpo->feed(song, PULPO::RECURSIVE::OFF);
pulpo.feed(song, PULPO::RECURSIVE::OFF);
qDebug()<<"DONE FETCHING LYRICS";
}
void Babe::linkDecoder(QString json)
......@@ -340,13 +351,14 @@ void Babe::scanDir(const QString &url)
}
void Babe::brainz(const bool &on)
{
this->settings->checkCollectionBrainz(on);
{
qDebug()<< "Changed vvae brainz state"<< on;
this->settings->startBrainz(on);
}
bool Babe::brainzState()
{
return loadSetting("BRAINZ", "BABE", false).toBool();
return loadSetting("AUTO", "BRAINZ", false).toBool();
}
void Babe::refreshCollection()
......@@ -560,10 +572,9 @@ QString Babe::fetchCoverArt(DB &song)
if(BAE::artworkCache(song, KEY::ALBUM)) return song[KEY::ARTWORK];
if(BAE::artworkCache(song, KEY::ARTIST)) return song[KEY::ARTWORK];
Pulpo pulpo;
pulpo.registerServices({SERVICES::LastFm, SERVICES::Spotify});
pulpo.setOntology(PULPO::ONTOLOGY::ALBUM);
pulpo.setInfo(PULPO::INFO::ARTWORK);
pulpo->registerServices({SERVICES::LastFm, SERVICES::Spotify});
pulpo->setOntology(PULPO::ONTOLOGY::ALBUM);
pulpo->setInfo(PULPO::INFO::ARTWORK);
QEventLoop loop;
......@@ -573,7 +584,7 @@ QString Babe::fetchCoverArt(DB &song)
connect(&timer, &QTimer::timeout, &loop, &QEventLoop::quit);
connect(&pulpo, &Pulpo::infoReady, [&](const BAE::DB &track,const PULPO::RESPONSE &res)
connect(pulpo, &Pulpo::infoReady, [&](const BAE::DB &track,const PULPO::RESPONSE &res)
{
Q_UNUSED(track);
if(!res[PULPO::ONTOLOGY::ALBUM][PULPO::INFO::ARTWORK].isEmpty())
......@@ -584,13 +595,13 @@ QString Babe::fetchCoverArt(DB &song)
loop.quit();
});
pulpo.feed(song, PULPO::RECURSIVE::OFF);
pulpo->feed(song, PULPO::RECURSIVE::OFF);
timer.start();
loop.exec();
timer.stop();
return song[KEY::ARTWORK];
return song[KEY::ARTWORK];
}
QVariantList Babe::transformData(const DB_LIST &dbList)
......
......@@ -97,7 +97,7 @@ public:
public slots:
private:
Pulpo *pulpo;
ConThread *thread;
#if (defined (Q_OS_LINUX) && !defined (Q_OS_ANDROID))
......
......@@ -51,7 +51,6 @@ Maui.ApplicationWindow
/***************************************************/
/******************** PLAYBACK ********************/
/*************************************************/
property bool isShuffle: bae.loadSetting("SHUFFLE","PLAYBACK", false) == "true" ? true : false
property var currentTrack: ({
babe: "0",
......@@ -112,24 +111,14 @@ Maui.ApplicationWindow
property bool isLinked: false
property bool isServing: false
/***************************************************/
/******************** UI UNITS ********************/
/*************************************************/
property bool focusMode : false
property bool selectionMode : false
/***************************************************/
/******************** UI COLORS *******************/
/*************************************************/
property string babeColor: bae.babeColor()
/***************************************************/
/**************************************************/
/*************************************************/
property bool selectionMode : false
/*SIGNALS*/
signal missingAlert(var track)
......@@ -409,23 +398,24 @@ Maui.ApplicationWindow
{
text: qsTr("Settings...")
iconName: "view-media-config"
Kirigami.Action
{
text: "Brainz"
Kirigami.Action
{
id: brainzToggle
text: checked ? "Turn OFF" : "Turn ON"
checked: false
checkable: true
onToggled:
{
bae.saveSetting("BRAINZ", checked === true ? true : false, "BABE")
bae.brainz(checked === true ? true : false)
}
}
}
// Kirigami.Action
// {
// text: "Brainz"
// Kirigami.Action
// {
// id: brainzToggle
// text: checked ? "Turn OFF" : "Turn ON"
// checked: bae.brainzState()
// checkable: true
// onToggled:
// {
// checked = !checked
// bae.saveSetting("AUTO", checked, "BRAINZ")
//// bae.brainz(checked)
// }
// }
// }
Kirigami.Action
{
......@@ -644,7 +634,8 @@ Maui.ApplicationWindow
floatingBar: true
footBarOverlap: true
footBar.visible: !mainlistEmpty
footBarVisible: !mainlistEmpty
headBarVisible: !mainlistEmpty
footBar.leftContent: Label
{
......@@ -740,7 +731,27 @@ Maui.ApplicationWindow
id: swipeView
Layout.fillHeight: true
Layout.fillWidth: true
Component.onCompleted: contentItem.interactive = isMobile
interactive: isMobile
// contentItem: ListView
// {
// model: swipeView.contentModel
// interactive: swipeView.interactive
// currentIndex: swipeView.currentIndex
// spacing: swipeView.spacing
// orientation: swipeView.orientation
// snapMode: ListView.SnapOneItem
// boundsBehavior: Flickable.StopAtBounds
// highlightRangeMode: ListView.StrictlyEnforceRange
// preferredHighlightBegin: 0
// preferredHighlightEnd: 0
// highlightMoveDuration: 250
// // min:10
// maximumFlickVelocity: 10 * (swipeView.orientation ===
// Qt.Horizontal ? width : height)
// }
currentIndex: currentView
......@@ -1010,12 +1021,12 @@ Maui.ApplicationWindow
} else {
root.showMaximized();
}
}
}
Component.onCompleted:
{
if(isAndroid)
switchColorScheme(colorScheme.Dark)
// if(isAndroid)
// switchColorScheme(colorScheme.Dark)
}
......
......@@ -23,6 +23,9 @@
#include "services/musicbrainzService.h"
#include "services/deezerService.h"
//#include "qgumbodocument.h"
//#include "qgumbonode.h"
Pulpo::Pulpo(const BAE::DB &song,QObject *parent)
: QObject(parent), track(song) {}
......@@ -68,111 +71,136 @@ void Pulpo::setRecursive(const RECURSIVE &state)
this->recursive=state;
}
QStringList Pulpo::queryHtml(const QByteArray &array, const QString &className)
{
QStringList res;
// auto doc = QGumboDocument::parse(array);
// auto root = doc.rootNode();
// auto nodes = root.getElementsByTagName(HtmlTag::TITLE);
// Q_ASSERT(nodes.size() == 1);
// auto title = nodes.front();
// qDebug() << "title is: " << title.innerText();
// auto container = root.getElementsByClassName(className);
// // if(container.size() == 1)
// // return res;
// auto children = container.front().children();
// for(const auto &i : children)
// res << i.innerText();
return res;
}
void Pulpo::initServices()
{
for(auto service : this->registeredServices)
switch (service)
{
case SERVICES::LastFm:
case SERVICES::LastFm:
{
lastfm lastfm(this->track);
connect(&lastfm, &lastfm::infoReady, this, &Pulpo::passSignal);
if(lastfm.setUpService(this->ontology, this->info))
{
lastfm lastfm(this->track);
connect(&lastfm, &lastfm::infoReady, this, &Pulpo::passSignal);
if(recursive == RECURSIVE::OFF) return;
if(lastfm.setUpService(this->ontology, this->info))
{
if(recursive == RECURSIVE::OFF) return;
}else qDebug()<<"Error settingUp lastfm service";
}else qDebug()<<"Error settingUp lastfm service";
break;
}
break;
}
case SERVICES::Spotify:
{
spotify spotify(this->track);
connect(&spotify, &spotify::infoReady, this, &Pulpo::passSignal);
case SERVICES::Spotify:
if(spotify.setUpService(this->ontology,this->info))
{
spotify spotify(this->track);
connect(&spotify, &spotify::infoReady, this, &Pulpo::passSignal);
if(recursive== RECURSIVE::OFF) return;
if(spotify.setUpService(this->ontology,this->info))
{
if(recursive== RECURSIVE::OFF) return;
}else qDebug()<<"Error settingUp spotify service";
}else qDebug()<<"Error settingUp spotify service";
break;
}
case SERVICES::Genius:
{
genius genius(this->track);
connect(&genius, &genius::infoReady, this, &Pulpo::passSignal);
break;
}
case SERVICES::Genius:
if(genius.setUpService(this->ontology,this->info))
{
genius genius(this->track);
connect(&genius, &genius::infoReady, this, &Pulpo::passSignal);
if(recursive== RECURSIVE::OFF) return;
if(genius.setUpService(this->ontology,this->info))
{
if(recursive== RECURSIVE::OFF) return;
}else qDebug()<<"Error settingUp genius service";
}else qDebug()<<"Error settingUp spotify service";
break;
}
case SERVICES::MusicBrainz:
{
musicBrainz musicbrainz(this->track);
connect(&musicbrainz, &musicBrainz::infoReady, this, &Pulpo::passSignal);
break;
}
case SERVICES::MusicBrainz:
if(musicbrainz.setUpService(this->ontology,this->info))
{
musicBrainz musicbrainz(this->track);
connect(&musicbrainz, &musicBrainz::infoReady, this, &Pulpo::passSignal);
if(recursive== RECURSIVE::OFF) return;
if(musicbrainz.setUpService(this->ontology,this->info))
{
if(recursive== RECURSIVE::OFF) return;
}else qDebug()<<"Error settingUp musicBrainz service";
}else qDebug()<<"Error settingUp musicBrainz service";
break;
}
case SERVICES::iTunes:
{
break;
}
case SERVICES::WikiLyrics:
{
break;
}
case SERVICES::LyricWikia:
{
lyricWikia lyricwikia(this->track);
connect(&lyricwikia, &lyricWikia::infoReady, this, &Pulpo::passSignal);
break;
}
case SERVICES::iTunes:
{
break;
}
case SERVICES::WikiLyrics:
if(lyricwikia.setUpService(this->ontology,this->info))
{
break;
}
case SERVICES::LyricWikia:
{
lyricWikia lyricwikia(this->track);
connect(&lyricwikia, &lyricWikia::infoReady, this, &Pulpo::passSignal);
if(recursive== RECURSIVE::OFF) return;
if(lyricwikia.setUpService(this->ontology,this->info))
{
if(recursive== RECURSIVE::OFF) return;
}else qDebug()<<"Error settingUp lyricwikia service";
}else qDebug()<<"Error settingUp lyricwikia service";
break;
}
case SERVICES::Wikipedia:
{
break;
}
break;
}
case SERVICES::Wikipedia:
{
break;
}
case SERVICES::Deezer:
{
deezer deezer(this->track);
connect(&deezer, &deezer::infoReady, this, &Pulpo::passSignal);
case SERVICES::Deezer:
if(deezer.setUpService(this->ontology, this->info))
{
deezer deezer(this->track);
connect(&deezer, &deezer::infoReady, this, &Pulpo::passSignal);
if(recursive== RECURSIVE::OFF) return;
if(deezer.setUpService(this->ontology, this->info))
{
if(recursive== RECURSIVE::OFF) return;
}else qDebug()<<"Error settingUp deezer service";
}else qDebug()<<"Error settingUp deezer service";
break;
}
case SERVICES::ALL:
{
break;
}
case SERVICES::NONE:
{
break;
}
break;
}
case SERVICES::ALL:
{
break;
}
case SERVICES::NONE:
{
break;
}
}
}
......@@ -183,7 +211,7 @@ void Pulpo::passSignal(const BAE::DB &track, const PULPO::RESPONSE &response)
PULPO::RESPONSE Pulpo::packResponse(const PULPO::ONTOLOGY ontology, const PULPO::INFO &infoKey, const PULPO::CONTEXT &context, const QVariant &value)
{
return { { ontology ,{{ infoKey, {{ context, value }} }} } };
return {{ ontology, {{ infoKey, {{ context, value }} }} }};
}
PULPO::RESPONSE Pulpo::packResponse(const ONTOLOGY ontology, const PULPO::INFO &infoKey, const PULPO::VALUE &map)
......@@ -193,14 +221,16 @@ PULPO::RESPONSE Pulpo::packResponse(const ONTOLOGY ontology, const PULPO::INFO &
bool Pulpo::parseArray()
{
if(this->ontology != PULPO::ONTOLOGY::NONE)
switch(this->ontology)
{
case PULPO::ONTOLOGY::ALBUM: return this->parseAlbum();
case PULPO::ONTOLOGY::ARTIST: return this->parseArtist();
case PULPO::ONTOLOGY::TRACK: return this->parseTrack();
default: return false;
}
if(this->ontology == PULPO::ONTOLOGY::NONE)
return false;
switch(this->ontology)
{
case PULPO::ONTOLOGY::ALBUM: return this->parseAlbum();
case PULPO::ONTOLOGY::ARTIST: return this->parseArtist();
case PULPO::ONTOLOGY::TRACK: return this->parseTrack();
default: return false;
}
return false;
}
......
......@@ -37,6 +37,8 @@ class Pulpo : public QObject
PULPO::ONTOLOGY getOntology();
void setRecursive(const PULPO::RECURSIVE &state);
QStringList queryHtml(const QByteArray &array, const QString &className = QString());
private:
void initServices();
PULPO::RECURSIVE recursive = PULPO::RECURSIVE::ON;
......
QT += network
QT += xml
CONFIG += ordered
SOURCES += \
$$PWD/services/deezerService.cpp \
$$PWD/services/lastfmService.cpp \
......@@ -30,3 +33,5 @@ DEPENDPATH += \
INCLUDEPATH += \
$$PWD \
$$PWD/services \
#include($$PWD/QGumboParser/QGumboParser.pri)
......@@ -52,7 +52,7 @@ bool genius::setUpService(const PULPO::ONTOLOGY &ontology, const PULPO::INFO &in
qDebug()<< "[genius service]: "<< newUrl;
this->array = this->startConnection(newUrl,{{"Authorization", this->KEY}} );
this->array = this->startConnection(newUrl, {{"Authorization", this->KEY}} );
if(this->array.isEmpty()) return false;
return this->parseArray();
......@@ -216,7 +216,7 @@ bool genius::parseTrack()
if(this->info == INFO::TAGS) return true;
}
if(this->info == INFO::WIKI || this->info == INFO::WIKI)
if(this->info == INFO::WIKI || this->info == INFO::ALL)
{
QString wikiData;
for(auto wiki : itemMap.value("description").toMap().value("dom").toMap().value("children").toList())
......@@ -226,7 +226,8 @@ bool genius::parseTrack()
emit this->infoReady(this->track,this->packResponse(ONTOLOGY::TRACK, INFO::WIKI, CONTEXT::WIKI, wikiData));
if(wikiData.isEmpty() && this->info == INFO::WIKI) return false;
if(!wikiData.isEmpty() && this->info == INFO::WIKI) return true;
else return false;
}
if(this->info == INFO::ARTWORK || this->info == INFO::ALL)
......@@ -235,7 +236,8 @@ bool genius::parseTrack()
emit this->infoReady(this->track, this->packResponse(ONTOLOGY::TRACK, INFO::ARTWORK, CONTEXT::IMAGE,this->startConnection(image)));
if(image.isEmpty() && this->info == INFO::ARTWORK) return false;
if(!image.isEmpty() && this->info == INFO::ARTWORK) return true;
else return false;
}
if(this->info == INFO::LYRICS || this->info == INFO::ALL)
......@@ -251,7 +253,8 @@ bool genius::parseTrack()
if(!lyricsArray.isEmpty())
lyrics = this->extractLyrics(lyricsArray);
if(!lyrics && this->info == INFO::LYRICS) return false;
if(lyrics && this->info == INFO::LYRICS) return true;
else return false;
}
return false;
......@@ -316,15 +319,22 @@ bool genius::extractLyrics(const QByteArray &array)
parser.setHtml(array);
auto lyricsList = parser.parseTag("div", "class=\"lyrics\"");
// auto lyricsList = this->queryHtml(array, "lyrics");
if(!lyricsList.isEmpty())
lyrics=lyricsList.first();
lyrics = lyricsList.first();
else
return false;
qDebug()<< "THE LYRICS:"<< lyricsList;
QString text;
if(!lyrics.isEmpty())
{
text = "<h2 align='center' >" + this->track[BAE::KEY::TITLE] + "</h2>";
text += lyrics;
text.replace("\n", "<br>");
text= "<div align='center'>"+text+"</div>";
}
......
......@@ -58,7 +58,7 @@ bool lyricWikia::parseTrack()
QUrl temp_u (temp);
temp_u.toEncoded(QUrl::FullyEncoded);
temp =temp_u.toString();
temp = temp_u.toString();
temp.replace("http://lyrics.wikia.com/","http://lyrics.wikia.com/index.php?title=");
temp.append("&action=edit");
......@@ -95,10 +95,15 @@ bool lyricWikia::extractLyrics(const QByteArray &array)
content.replace("&lt;", "<");
QRegExp lyrics_regexp("<lyrics>(.*)</lyrics>");
lyrics_regexp.indexIn(content);
QString text;
QString lyrics = lyrics_regexp.cap(1);
if(lyrics.isEmpty()) return false;
lyrics = lyrics.trimmed();
lyrics.replace("\n", "<br>");
QString text;
if(!lyrics.contains("PUT LYRICS HERE")&&!lyrics.isEmpty())
{
text = "<h2 align='center' >" + this->track[BAE::KEY::TITLE] + "</h2>";
......@@ -107,8 +112,6 @@ bool lyricWikia::extractLyrics(const QByteArray &array)
text= "<div align='center'>"+text+"</div>";
}
if(text.isEmpty()) return false;
emit this->infoReady(this->track, this->packResponse(ONTOLOGY::TRACK, INFO::LYRICS,CONTEXT::LYRIC,text));
return true;
}
......@@ -25,26 +25,17 @@
BabeSettings::BabeSettings(QObject *parent) : QObject(parent)
{
this->connection = new CollectionDB(this);
this->brainDeamon = new Brain;
this->ytFetch = new youtubedl(this);
this->babeSocket = new Socket(static_cast<quint16>(BAE::BabePort.toInt()), this);
qDebug() << "Getting collectionDB info from: " << BAE::CollectionDBPath;
qDebug() << "Getting settings info from: " << BAE::SettingPath;
qDebug() << "Getting artwork files from: " << BAE::CachePath;
#if (defined (Q_OS_LINUX) && !defined (Q_OS_ANDROID))
const auto notifyDir = BAE::NotifyDir;
if(!BAE::fileExists(notifyDir+"/vvave.notifyrc"))
if(!BAE::fileExists(BAE::NotifyDir+"/vvave.notifyrc"))
{
bDebug::Instance()->msg("The Knotify file does not exists, going to create it");
QFile knotify(":/assets/vvave.notifyrc");
if(knotify.copy(notifyDir+"/vvave.notifyrc"))
if(knotify.copy(BAE::NotifyDir+"/vvave.notifyrc"))
bDebug::Instance()->msg("the knotify file got copied");
}
#endif
......@@ -80,14 +71,14 @@ BabeSettings::BabeSettings(QObject *parent) : QObject(parent)
emit this->refreshATable(type);
});
connect(&this->fileLoader, &FileLoader::finished,[this](int size)
connect(&this->fileLoader, &FileLoader::finished, [this](int size)
{
bDebug::Instance()->msg("Finished inserting into DB "+QString::number(size)+" tracks");
if(size > 0)
this->startBrainz(true, BAE::SEG::HALF);
else
this->startBrainz(BAE::loadSettings("BRAINZ", "BABE", false).toBool(), BAE::SEG::TWO);
this->startBrainz(BAE::loadSettings("AUTO", "BRAINZ", true).toBool(), BAE::SEG::TWO);
emit refreshTables(size);
});
......@@ -114,16 +105,9 @@ void BabeSettings::fetchYoutubeTrack(const QString &message)
this->ytFetch->fetch(message);
}
void BabeSettings::checkCollectionBrainz(const bool &state)
{
bDebug::Instance()->msg("BRAINZ STATE<<" + QString(state ? "true" : "false"));
this->startBrainz(state, BAE::SEG::THREE);
}
void BabeSettings::startBrainz(const bool &on, const uint &speed)
{
bDebug::Instance()->msg("Starting Brainz with interval: " + QString::number(BAE::SEG::ONEHALF));
qDebug()<< "Starting Brainz with interval: "<< speed << on;
this->brainDeamon->setInterval(speed);
if(on)
......
......@@ -28,7 +28,6 @@ class BabeSettings : public QObject
explicit BabeSettings(QObject *parent = nullptr);
~BabeSettings();
void checkCollectionBrainz(const bool &state);
void refreshCollection();
void fetchYoutubeTrack(const QString &message);
......
......@@ -15,7 +15,7 @@ function playTrack(index)
player.play()
var artwork = currentTrack.artwork
currentArtwork = artwork && artwork.length>0 && artwork !== "NONE"? artwork : bae.loadCover(currentTrack.url)
currentArtwork = artwork && artwork.length > 0 && artwork !== "NONE"? artwork : bae.loadCover(currentTrack.url)