Commit dc1771c4 authored by Camilo Higuita's avatar Camilo Higuita

fixes and get lyrics async/signal

parent 6823eb7c
......@@ -31,25 +31,19 @@ QVariantList Babe::get(const QString &queryTxt)
for(auto key : data.keys())
map[BAE::KEYMAP[key]] = data[key];
res<<map;
res << map;
}
return res;
}
QString Babe::trackLyrics(const QString &url)
void Babe::trackLyrics(const QString &url)
{
auto track = this->con->getDBData(QString("SELECT * FROM %1 WHERE %2 = \"%3\"").arg(TABLEMAP[TABLE::TRACKS],
KEYMAP[KEY::URL], url));
KEYMAP[KEY::URL], url));
if(track.isEmpty()) return "ERROR";
auto lyrics = track.first()[KEY::LYRICS];
if(!lyrics.isEmpty())
return lyrics;
return this->fetchTrackLyrics(track.first());
if(track.isEmpty()) return;
this->fetchTrackLyrics(track.first());
}
bool Babe::trackBabe(const QString &path)
......@@ -104,21 +98,13 @@ QString Babe::albumArt(const QString &album, const QString &artist)
return "";
}
QString Babe::fetchTrackLyrics(DB &song)
void Babe::fetchTrackLyrics(DB &song)
{
Pulpo pulpo;
pulpo.registerServices({SERVICES::LyricWikia, SERVICES::Genius});
pulpo.setOntology(PULPO::ONTOLOGY::TRACK);
pulpo.setInfo(PULPO::INFO::LYRICS);
QEventLoop loop;
QTimer timer;
timer.setSingleShot(true);
timer.setInterval(1000);
connect(&timer, &QTimer::timeout, &loop, &QEventLoop::quit);
connect(&pulpo, &Pulpo::infoReady, [&](const BAE::DB &track, const PULPO::RESPONSE &res)
{
if(!res[PULPO::ONTOLOGY::TRACK][PULPO::INFO::LYRICS].isEmpty())
......@@ -126,18 +112,13 @@ QString Babe::fetchTrackLyrics(DB &song)
auto lyrics = res[PULPO::ONTOLOGY::TRACK][PULPO::INFO::LYRICS][PULPO::CONTEXT::LYRIC].toString();
this->con->lyricsTrack(track, lyrics);
song.insert(KEY::LYRICS, lyrics);
emit this->trackLyricsReady(song[KEY::LYRICS], song[KEY::URL]);
}
loop.quit();
});
pulpo.feed(song, PULPO::RECURSIVE::OFF);
timer.start();
loop.exec();
timer.stop();
return song[KEY::LYRICS];
}
QString Babe::albumWiki(const QString &album, const QString &artist)
......
......@@ -22,7 +22,7 @@ public:
/* DATABASE INTERFACES */
Q_INVOKABLE QVariantList get(const QString &queryTxt);
Q_INVOKABLE QString trackLyrics(const QString &url);
Q_INVOKABLE void trackLyrics(const QString &url);
Q_INVOKABLE bool trackBabe(const QString &path);
Q_INVOKABLE QString artistArt(const QString &artist);
Q_INVOKABLE QString albumArt(const QString &album, const QString &artist);
......@@ -64,10 +64,11 @@ private:
QString fetchCoverArt(DB &song);
QString fetchTrackLyrics(DB &song);
void fetchTrackLyrics(DB &song);
signals:
void refreshTables(QVariantMap tables);
void trackLyricsReady(QString lyrics, QString url);
public slots:
};
......
......@@ -65,6 +65,12 @@ ApplicationWindow
albumsView.populate()
artistsView.populate()
}
onTrackLyricsReady:
{
if(url === root.mainPlaylist.currentTrack.url)
root.mainPlaylist.infoView.lyrics = lyrics
}
}
header: BabeBar
......@@ -161,26 +167,40 @@ ApplicationWindow
TracksView
{
id: tracksView
onRowClicked: Player.appendTrack(model.get(index))
onQuickPlayTrack: Player.quickPlay(model.get(index))
Connections
{
target: tracksView
onRowClicked: Player.addTrack(tracksView.model.get(index))
onQuickPlayTrack: Player.quickPlay(tracksView.model.get(index))
}
}
AlbumsView
{
id: albumsView
onRowClicked: Player.appendTrack(track)
onPlayAlbum: Player.playAlbum(tracks)
onAppendAlbum: Player.appendAlbum(tracks)
onPlayTrack: Player.quickPlay(track)
Connections
{
target: albumsView
onRowClicked: Player.addTrack(track)
onPlayAlbum: Player.playAlbum(tracks)
onAppendAlbum: Player.appendAlbum(tracks)
onPlayTrack: Player.quickPlay(track)
}
}
ArtistsView
{
id: artistsView
onRowClicked: Player.appendTrack(track)
onPlayAlbum: Player.playAlbum(tracks)
onAppendAlbum: Player.appendAlbum(tracks)
onPlayTrack: Player.quickPlay(track)
Connections
{
target: artistsView
onRowClicked: Player.addTrack(track)
onPlayAlbum: Player.playAlbum(tracks)
onAppendAlbum: Player.appendAlbum(tracks)
onPlayTrack: Player.quickPlay(track)
}
}
PlaylistsView {}
......
......@@ -12,21 +12,22 @@ function playTrack(track)
root.mainPlaylist.playIcon.text = Icon.pause
if(bae.trackBabe(root.mainPlaylist.currentTrack.url))
root.mainPlaylist.babeBtnIcon.color = "#E91E63"
root.mainPlaylist.babeBtnIcon.color = bae.babeColor()
else
root.mainPlaylist.babeBtnIcon.color = root.mainPlaylist.babeBtnIcon.defaultColor
root.mainPlaylist.infoView.lyrics = ""
root.mainPlaylist.infoView.wikiAlbum = ""
root.mainPlaylist.infoView.wikiArtist = ""
root.mainPlaylist.infoView.lyrics = bae.trackLyrics(root.mainPlaylist.currentTrack.url)
root.mainPlaylist.infoView.wikiAlbum = bae.albumWiki(root.mainPlaylist.currentTrack.album,root.mainPlaylist.currentTrack.artist)
root.mainPlaylist.infoView.wikiArtist = bae.artistWiki(root.mainPlaylist.currentTrack.artist)
// root.mainPlaylist.infoView.artistHead = bae.artistArt(root.mainPlaylist.currentTrack.artist)
var lyrics = root.mainPlaylist.currentTrack.lyrics
if(!lyrics)
bae.trackLyrics(root.mainPlaylist.currentTrack.url)
else
root.mainPlaylist.infoView.lyrics = lyrics
// root.mainPlaylist.infoView.wikiAlbum = bae.albumWiki(root.mainPlaylist.currentTrack.album,root.mainPlaylist.currentTrack.artist)
// root.mainPlaylist.infoView.wikiArtist = bae.artistWiki(root.mainPlaylist.currentTrack.artist)
// // root.mainPlaylist.infoView.artistHead = bae.artistArt(root.mainPlaylist.currentTrack.artist)
}
function stop()
{
player.stop()
......@@ -88,13 +89,14 @@ function quickPlay(track)
root.currentView = 0
appendTrack(track)
playAt(root.mainPlaylist.list.count-1)
root.mainPlaylist.list.positionViewAtEnd()
}
function appendTrack(track)
{
var empty = root.mainPlaylist.list.count
root.mainPlaylist.list.model.append(track)
root.mainPlaylist.list.positionViewAtEnd()
if(empty === 0 && root.mainPlaylist.list.count>0)
{
......@@ -103,10 +105,17 @@ function appendTrack(track)
}
}
function addTrack(track)
{
appendTrack(track)
root.mainPlaylist.list.positionViewAtEnd()
}
function appendAlbum(tracks)
{
for(var i in tracks)
appendTrack(tracks[i])
root.mainPlaylist.list.positionViewAtEnd()
}
function savePlaylist()
......@@ -148,12 +157,13 @@ function playAlbum(tracks)
root.mainPlaylist.list.clearTable()
root.currentView = 0
for(var i in tracks)
for(var i = 0; i< tracks.length; i++)
appendTrack(tracks[i])
root.mainPlaylist.list.currentIndex = 0
playTrack(root.mainPlaylist.list.model.get(0))
// root.mainPlaylist.list.currentIndex = 0
// playTrack(root.mainPlaylist.list.model.get(0))
root.mainPlaylist.list.positionViewAtBeginning()
}
......
......@@ -95,12 +95,11 @@ Pane
var artist = grid.model.get(index).artist
albumCoverClicked(album, artist)
grid.currentIndex = index
console.log("current index is: ", grid.currentIndex)
}
}
}
ScrollBar.vertical: ScrollBar{ visible: !(Qt.platform.os === android)}
ScrollBar.vertical: ScrollBar{ visible: !(Qt.platform.os === "android")}
}
}
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