Commit be669b3d authored by Camilo higuita's avatar Camilo higuita

fixing performance issues and polkishing the brain infor fetcher

parent 7c811634
......@@ -19,7 +19,7 @@ set(CMAKE_AUTORCC ON)
add_executable(vvave
qml.qrc
main.cpp
babe.cpp
# babe.cpp
vvave.cpp
# pulpo/services/geniusService.cpp
......@@ -41,7 +41,7 @@ add_executable(vvave
services/web/Spotify/spotify.cpp
db/conthread.cpp
db/collectionDB.cpp
settings/BabeSettings.cpp
# settings/BabeSettings.cpp
settings/fileloader.cpp
utils/brain.cpp
utils/babeconsole.cpp
......
......@@ -25,7 +25,22 @@
using namespace BAE;
CollectionDB::CollectionDB(QObject *parent) : QObject(parent)
{}
{
this->name = QUuid::createUuid().toString();
if(!BAE::fileExists(BAE::CollectionDBPath + BAE::DBName))
{
QDir collectionDBPath_dir(BAE::CollectionDBPath);
if (!collectionDBPath_dir.exists())
collectionDBPath_dir.mkpath(".");
this->openDB(this->name);
qDebug()<<"Collection doesn't exists, trying to create it" << BAE::CollectionDBPath + BAE::DBName;
this->prepareCollectionDB();
}else this->openDB(this->name);
}
CollectionDB::~CollectionDB()
{
......@@ -42,7 +57,6 @@ CollectionDB *CollectionDB::getInstance()
{
instance = new CollectionDB();
qDebug() << "getInstance(): First DBActions instance\n";
instance->init();
return instance;
} else
{
......@@ -51,28 +65,13 @@ CollectionDB *CollectionDB::getInstance()
}
}
void CollectionDB::init()
{
this->name = QUuid::createUuid().toString();
if(!BAE::fileExists(BAE::CollectionDBPath + BAE::DBName))
{
QDir collectionDBPath_dir(BAE::CollectionDBPath);
if (!collectionDBPath_dir.exists())
collectionDBPath_dir.mkpath(".");
this->openDB(this->name);
qDebug()<<"Collection doesn't exists, trying to create it" << BAE::CollectionDBPath + BAE::DBName;
this->prepareCollectionDB();
}else this->openDB(this->name);
}
void CollectionDB::prepareCollectionDB() const
void CollectionDB::prepareCollectionDB()
{
QSqlQuery query(this->m_db);
QFile file(":/db/script.sql");
qDebug()<< file.exists();
if (!file.exists())
{
......@@ -257,6 +256,7 @@ bool CollectionDB::addTrack(const FMH::MODEL &track)
auto artwork = track[FMH::MODEL_KEY::ARTWORK].isEmpty() ? "" : track[FMH::MODEL_KEY::ARTWORK];
auto artistTrack = track;
artistTrack[FMH::MODEL_KEY::ARTWORK] = "";
BAE::artworkCache(artistTrack, FMH::MODEL_KEY::ARTIST);
auto artistArtwork = artistTrack[FMH::MODEL_KEY::ARTWORK];
......
......@@ -36,7 +36,7 @@ class CollectionDB : public QObject
bool execQuery(const QString &queryTxt);
/*basic public actions*/
void prepareCollectionDB() const;
void prepareCollectionDB();
bool check_existance(const QString &tableName, const QString &searchId, const QString &search);
/* usefull actions */
......@@ -116,7 +116,6 @@ private:
QSqlDatabase m_db;
explicit CollectionDB( QObject *parent = nullptr);
~CollectionDB() override;
void init();
public slots:
......
......@@ -7,7 +7,7 @@
#include <QStyleHints>
#include <QQuickStyle>
#include <QCommandLineParser>
#include "babe.h"
#include "vvave.h"
#include "services/local/player.h"
#ifdef STATIC_KIRIGAMI
......@@ -71,7 +71,7 @@ int main(int argc, char *argv[])
if(!args.isEmpty())
urls = args;
Babe bae;
vvave vvave;
/* Services */
YouTube youtube;
......@@ -84,13 +84,13 @@ int main(int argc, char *argv[])
QObject::connect(&engine, &QQmlApplicationEngine::objectCreated, [&]()
{
qDebug()<<"FINISHED LOADING QML APP";
bae.refreshCollection();
if(!urls.isEmpty())
bae.openUrls(urls);
vvave.postActions();
// if(!urls.isEmpty())
// bae.openUrls(urls);
});
auto context = engine.rootContext();
context->setContextProperty("bae", &bae);
context->setContextProperty("vvave", &vvave);
context->setContextProperty("youtube", &youtube);
// context->setContextProperty("spotify", &spotify);
// context->setContextProperty("link", &bae.link);
......
......@@ -7,19 +7,18 @@ import QtQuick.Controls.Material 2.1
import "utils"
import "widgets"
import "widgets/MyBeatView"
import "widgets/PlaylistsView"
import "widgets/MainPlaylist"
import "widgets/SettingsView"
import "widgets/SearchView"
import "widgets/CloudView"
//import "widgets/CloudView"
import "view_models"
import "view_models/BabeTable"
import "services/local"
import "services/web"
import "services/web/Spotify"
//import "services/web/Spotify"
import "view_models/BabeGrid"
......@@ -59,7 +58,7 @@ Maui.ApplicationWindow
/*************************************************/
property bool isShuffle: Maui.FM.loadSettings("SHUFFLE","PLAYBACK", false)
property var currentTrack: ({
babe: "0",
fav: "0",
stars: "0"
})
......@@ -113,7 +112,7 @@ Maui.ApplicationWindow
/***************************************************/
/******************** UI COLORS *******************/
/*************************************************/
readonly property color babeColor: bae.babeColor() //"#140032"
readonly property color babeColor: "#f84172"
/*SIGNALS*/
signal missingAlert(var track)
......@@ -127,7 +126,7 @@ Maui.ApplicationWindow
var messageBody = "Do you want to remove it from your collection?"
notify("alert", message, messageBody, function ()
{
bae.removeTrack(currentTrack.url) //todo
// bae.removeTrack(currentTrack.url) //todo
mainPlaylist.table.model.remove(mainPlaylist.table.currentIndex)
})
}
......@@ -157,7 +156,7 @@ Maui.ApplicationWindow
altToolBars: false
accentColor: babeColor
headBarFGColor: altColorText
headBarBGColor: /*currentView === viewsIndex.vvave ? "#7e57c2" :*/ "#212121"
headBarBGColor: "#212121"
altColorText: darkTextColor
floatingBar: false
......@@ -166,14 +165,13 @@ Maui.ApplicationWindow
headBar.middleContent : [
Maui.ToolButton
{
iconName: "view-media-track"
iconName: "view-media-track"
active: currentView === viewsIndex.tracks
showIndicator: true
iconColor: active ? babeColor : altColorText
onClicked: currentView = viewsIndex.tracks
text: qsTr("Tracks")
tooltipText: pageStack.wideMode ? "" : text
colorScheme.highlightColor: babeColor
Layout.fillHeight: true
},
......@@ -184,11 +182,8 @@ Maui.ApplicationWindow
iconName: /*"album"*/ "view-media-album-cover"
iconColor: currentView === viewsIndex.albums ? babeColor : altColorText
onClicked: currentView = viewsIndex.albums
tooltipText: pageStack.wideMode ? "" : text
colorScheme.highlightColor: babeColor
Layout.fillHeight: true
showIndicator: true
},
Maui.ToolButton
......@@ -198,11 +193,8 @@ Maui.ApplicationWindow
iconName: "view-media-artist"
iconColor: currentView === viewsIndex.artists ? babeColor : altColorText
onClicked: currentView = viewsIndex.artists
tooltipText: pageStack.wideMode ? "" : text
colorScheme.highlightColor: babeColor
Layout.fillHeight: true
showIndicator: true
},
Maui.ToolButton
......@@ -212,10 +204,9 @@ Maui.ApplicationWindow
iconName: "view-media-playlist"
iconColor: currentView === viewsIndex.playlists ? babeColor : altColorText
onClicked: currentView = viewsIndex.playlists
tooltipText: pageStack.wideMode ? "" : text
colorScheme.highlightColor: babeColor
showIndicator: true
Layout.fillHeight: true
}
]
......@@ -285,15 +276,15 @@ Maui.ApplicationWindow
Layout.fillHeight: true
Layout.fillWidth: true
// leftContent: Maui.ToolButton
// {
// iconName: "headphones"
// visible: _drawer.modal
// iconColor: _drawer.visible ? babeColor : textColor
// onClicked: _drawer.visible = !_drawer.visible
// colorScheme.highlightColor: babeColor
// // text: qsTr("Now")
// }
// leftContent: Maui.ToolButton
// {
// iconName: "headphones"
// visible: _drawer.modal
// iconColor: _drawer.visible ? babeColor : textColor
// onClicked: _drawer.visible = !_drawer.visible
// colorScheme.highlightColor: babeColor
// // text: qsTr("Now")
// }
middleContent: [
......@@ -994,12 +985,12 @@ Maui.ApplicationWindow
Connections
{
target: bae
target: vvave
onRefreshTables: H.refreshCollection(size)
// onRefreshTracks: H.refreshTracks()
onRefreshAlbums: H.refreshAlbums()
// onRefreshArtists: H.refreshArtists()
onRefreshTracks: H.refreshTracks()
onRefreshAlbums: H.refreshAlbums()
onRefreshArtists: H.refreshArtists()
onCoverReady:
{
......
......@@ -153,7 +153,7 @@ struct REQUEST
QList<PULPO::INFO> info;
QList<PULPO::SERVICES> services;
std::function<void(REQUEST request, RESPONSES responses)> callback;
std::function<void(REQUEST request, RESPONSES responses)> callback = nullptr;
};
......
......@@ -71,6 +71,8 @@ void Pulpo::start()
lastfm->set(this->req);
break;
}
default: continue;
}
}
......
......@@ -34,38 +34,38 @@ void lastfm::set(const PULPO::REQUEST &request)
switch(this->request.ontology)
{
case PULPO::ONTOLOGY::ARTIST:
{
url.append("?method=artist.getinfo");
url.append(KEY);
url.append("&artist=" + encodedArtist.toString());
break;
}
case PULPO::ONTOLOGY::ARTIST:
{
url.append("?method=artist.getinfo");
url.append(KEY);
url.append("&artist=" + encodedArtist.toString());
break;
}
case PULPO::ONTOLOGY::ALBUM:
{
QUrl encodedAlbum(this->request.track[FMH::MODEL_KEY::ALBUM]);
encodedAlbum.toEncoded(QUrl::FullyEncoded);
url.append("?method=album.getinfo");
url.append(KEY);
url.append("&artist=" + encodedArtist.toString());
url.append("&album=" + encodedAlbum.toString());
break;
}
case PULPO::ONTOLOGY::ALBUM:
{
QUrl encodedAlbum(this->request.track[FMH::MODEL_KEY::ALBUM]);
encodedAlbum.toEncoded(QUrl::FullyEncoded);
url.append("?method=album.getinfo");
url.append(KEY);
url.append("&artist=" + encodedArtist.toString());
url.append("&album=" + encodedAlbum.toString());
break;
}
case PULPO::ONTOLOGY::TRACK:
{
QUrl encodedTrack(this->request.track[FMH::MODEL_KEY::TITLE]);
encodedTrack.toEncoded(QUrl::FullyEncoded);
url.append("?method=track.getinfo");
url.append(KEY);
url.append("&artist=" + encodedArtist.toString());
url.append("&track=" + encodedTrack.toString());
url.append("&format=json");
break;
}
case PULPO::ONTOLOGY::TRACK:
{
QUrl encodedTrack(this->request.track[FMH::MODEL_KEY::TITLE]);
encodedTrack.toEncoded(QUrl::FullyEncoded);
url.append("?method=track.getinfo");
url.append(KEY);
url.append("&artist=" + encodedArtist.toString());
url.append("&track=" + encodedTrack.toString());
url.append("&format=json");
break;
}
}
qDebug()<< "[lastfm service]: "<< url;
......@@ -74,142 +74,159 @@ void lastfm::set(const PULPO::REQUEST &request)
}
//void lastfm::parseArtist(const QByteArray &array)
//{
// QString xmlData(array);
// QDomDocument doc;
void lastfm::parseArtist(const QByteArray &array)
{
QString xmlData(array);
QDomDocument doc;
// if (!doc.setContent(xmlData)) return false;
if (!doc.setContent(xmlData))
{
qDebug()<< "LASTFM XML FAILED 1" << this->request.track;
emit this->responseReady(this->request, this->responses);
return;
}
if (doc.documentElement().toElement().attributes().namedItem("status").nodeValue()!="ok")
{
qDebug()<< "LASTFM XML FAILED 2" << this->request.track;
emit this->responseReady(this->request, this->responses);
return;
}
// QStringList artistTags;
// QByteArray artistSimilarArt;
// QStringList artistSimilar;
// QStringList artistStats;
// if (doc.documentElement().toElement().attributes().namedItem("status").nodeValue()!="ok")
// return;
QStringList artistTags;
QByteArray artistSimilarArt;
QStringList artistSimilar;
QStringList artistStats;
const QDomNodeList nodeList = doc.documentElement().namedItem("artist").childNodes();
for (int i = 0; i < nodeList.count(); i++)
{
QDomNode n = nodeList.item(i);
// const QDomNodeList nodeList = doc.documentElement().namedItem("artist").childNodes();
if (n.isElement())
{
//Here retrieve the artist image
if(n.nodeName() == "image" && n.hasAttributes())
{
if(this->request.info.contains(INFO::ARTWORK))
{
auto imgSize = n.attributes().namedItem("size").nodeValue();
// for (int i = 0; i < nodeList.count(); i++)
// {
// QDomNode n = nodeList.item(i);
if (imgSize == "large" && n.isElement())
{
auto artistArt_url = n.toElement().text();
this->responses << PULPO::RESPONSE {CONTEXT::IMAGE, artistArt_url};
// if (n.isElement())
// {
// //Here retrieve the artist image
// if(this->info == INFO::ARTWORK || this->info == INFO::ALL)
// {
// if(n.nodeName() == "image" && n.hasAttributes())
// {
// auto imgSize = n.attributes().namedItem("size").nodeValue();
if(this->request.info.size() == 1) break;
else continue;
// if (imgSize == "medium" && n.isElement())
// {
// auto artistArt_url = n.toElement().text();
}else continue;
// emit this->infoReady(this->track,this->packResponse(ONTOLOGY::ARTIST, INFO::ARTWORK,CONTEXT::IMAGE,startConnection(artistArt_url)));
}else continue;
}
}
}
// if(this->info == INFO::ARTWORK) return true;
// else continue;
// }else if(this->info == INFO::ARTWORK) continue;
// }
// }
// //Here retrieve the artist wiki (bio)
// if(this->info == INFO::WIKI || this->info == INFO::ALL)
// {
// if (n.nodeName() == "bio")
// {
// auto artistWiki = n.childNodes().item(2).toElement().text();
// //qDebug()<<"Fetching ArtistWiki LastFm[]";
// //Here retrieve the artist wiki (bio)
// if(this->info == INFO::WIKI || this->info == INFO::ALL)
// {
// if (n.nodeName() == "bio")
// {
// auto artistWiki = n.childNodes().item(2).toElement().text();
// //qDebug()<<"Fetching ArtistWiki LastFm[]";
// emit this->infoReady(this->track, this->packResponse(ONTOLOGY::ARTIST, INFO::WIKI,CONTEXT::WIKI,artistWiki));
// emit this->infoReady(this->track, this->packResponse(ONTOLOGY::ARTIST, INFO::WIKI,CONTEXT::WIKI,artistWiki));
// if(this->info == INFO::WIKI) return true;
// else continue;
// }else if(this->info == INFO::WIKI) continue;
// }
// if(this->info == INFO::WIKI) return true;
// else continue;
// }else if(this->info == INFO::WIKI) continue;
// }
// //Here retrieve the artist similar artists
// if(this->info == INFO::TAGS || this->info == INFO::ALL)
// {
// if(n.nodeName() == "similar")
// {
// auto similarList = n.toElement().childNodes();
// //Here retrieve the artist similar artists
// if(this->info == INFO::TAGS || this->info == INFO::ALL)
// {
// if(n.nodeName() == "similar")
// {
// auto similarList = n.toElement().childNodes();
// for(int i=0; i<similarList.count(); i++)
// {
// QDomNode m = similarList.item(i);
// for(int i=0; i<similarList.count(); i++)
// {
// QDomNode m = similarList.item(i);
// auto artistSimilarName = m.childNodes().item(0).toElement().text();
// artistSimilar<<artistSimilarName;
// }
// auto artistSimilarName = m.childNodes().item(0).toElement().text();
// artistSimilar<<artistSimilarName;
// }
// emit this->infoReady(this->track,this->packResponse(ONTOLOGY::ARTIST, INFO::TAGS,CONTEXT::ARTIST_SIMILAR,artistSimilar));
// emit this->infoReady(this->track,this->packResponse(ONTOLOGY::ARTIST, INFO::TAGS,CONTEXT::ARTIST_SIMILAR,artistSimilar));
// }else if(n.nodeName() == "tags")
// {
// auto tagsList = n.toElement().childNodes();
// //qDebug()<<"Fetching ArtistTags LastFm[]";
// }else if(n.nodeName() == "tags")
// {
// auto tagsList = n.toElement().childNodes();
// //qDebug()<<"Fetching ArtistTags LastFm[]";
// for(int i=0; i<tagsList.count(); i++)
// {
// QDomNode m = tagsList.item(i);
// artistTags<<m.childNodes().item(0).toElement().text();
// }
// for(int i=0; i<tagsList.count(); i++)
// {
// QDomNode m = tagsList.item(i);
// artistTags<<m.childNodes().item(0).toElement().text();
// }
// emit this->infoReady(this->track,this->packResponse(ONTOLOGY::ARTIST, INFO::TAGS,CONTEXT::TAG,artistTags));
// emit this->infoReady(this->track,this->packResponse(ONTOLOGY::ARTIST, INFO::TAGS,CONTEXT::TAG,artistTags));
// }else if(n.nodeName() == "stats")
// {
// QVariant stat;
// auto stats = n.toElement().childNodes();
// //qDebug()<<"Fetching ArtistTags LastFm[]";
// }else if(n.nodeName() == "stats")
// {
// QVariant stat;
// auto stats = n.toElement().childNodes();
// //qDebug()<<"Fetching ArtistTags LastFm[]";
// for(int i=0; i<stats.count(); i++)
// {
// QDomNode m = stats.item(i);
// artistStats<<m.toElement().text();
// }
// for(int i=0; i<stats.count(); i++)
// {
// QDomNode m = stats.item(i);
// artistStats<<m.toElement().text();
// }
// emit this->infoReady(this->track,this->packResponse(ONTOLOGY::ARTIST, INFO::TAGS, CONTEXT::ARTIST_STAT,artistStats));
// emit this->infoReady(this->track,this->packResponse(ONTOLOGY::ARTIST, INFO::TAGS, CONTEXT::ARTIST_STAT,artistStats));
// }else if(this->info == INFO::TAGS) continue;
// }
// }else if(this->info == INFO::TAGS) continue;
// }
// }
// }
// }
// }
// /*********NOW WE WANT TO PARSE SIMILAR ARTISTS***********/
// if(this->info == INFO::TAGS || this->info == INFO::ALL)
// {
// auto url = this->API;
// QUrl encodedTrack(this->track[FMH::MODEL_KEY::TITLE]);
// encodedTrack.toEncoded(QUrl::FullyEncoded);
// QUrl encodedArtist(this->track[FMH::MODEL_KEY::ARTIST]);
// encodedArtist.toEncoded(QUrl::FullyEncoded);
// url.append("?method=artist.getSimilar");
// url.append(KEY);
// url.append("&artist=" + encodedArtist.toString());
// url.append("&format=json");
// /*********NOW WE WANT TO PARSE SIMILAR ARTISTS***********/
// if(this->info == INFO::TAGS || this->info == INFO::ALL)
// {
// auto url = this->API;
// QUrl encodedTrack(this->track[FMH::MODEL_KEY::TITLE]);
// encodedTrack.toEncoded(QUrl::FullyEncoded);
// QUrl encodedArtist(this->track[FMH::MODEL_KEY::ARTIST]);
// encodedArtist.toEncoded(QUrl::FullyEncoded);
// url.append("?method=artist.getSimilar");
// url.append(KEY);
// url.append("&artist=" + encodedArtist.toString());
// url.append("&format=json");
// qDebug()<< "[lastfm service]: "<< url;
// qDebug()<< "[lastfm service]: "<< url;
// this->array = this->startConnection(url);
// this->array = this->startConnection(url);
// if(!this->array.isEmpty())
// this->parseSimilar();
// }
// if(!this->array.isEmpty())
// this->parseSimilar();
// }
// return true;
emit this->responseReady(this->request, this->responses);
// return true;
//}
}
void lastfm::parseAlbum(const QByteArray &array)
{
......
......@@ -22,7 +22,7 @@ public:
void set(const PULPO::REQUEST &request) override final;
protected:
// virtual void parseArtist(const QByteArray &array);
virtual void parseArtist(const QByteArray &array) override final;
virtual void parseAlbum(const QByteArray &array) override final;
// virtual void parseTrack(const QByteArray &array);