Commit ec23afde authored by Camilo Higuita's avatar Camilo Higuita

return of youtube integration via socket, still missing android support

parent fdf80842
......@@ -204,7 +204,7 @@ void Babe::notify(const QString &title, const QString &body)
{
#if (defined (Q_OS_LINUX) && !defined (Q_OS_ANDROID))
Babe::nof->notify(title, body);
this->nof->notify(title, body);
#else
Q_UNUSED(title);
Q_UNUSED(body);
......@@ -217,7 +217,7 @@ void Babe::notifySong(const QString &url)
#if (defined (Q_OS_LINUX) && !defined (Q_OS_ANDROID))
auto query = QString("select t.*, al.artwork from tracks t inner join albums al on al.album = t.album and al.artist = t.artist where url = \"%1\"").arg(url);
auto track = getDBData(query);
Babe::nof->notifySong(track.first());
this->nof->notifySong(track.first());
#else
Q_UNUSED(url);
#endif
......
......@@ -20,9 +20,18 @@
#include "../../pulpo/pulpo.h"
#include "../../db/collectionDB.h"
#if (defined (Q_OS_LINUX) && !defined (Q_OS_ANDROID))
#include "kde/notify.h"
#endif
using namespace BAE;
YouTube::YouTube(QObject *parent) : QObject(parent) {}
YouTube::YouTube(QObject *parent) : QObject(parent)
{
#if (defined (Q_OS_LINUX) && !defined (Q_OS_ANDROID))
this->nof = new Notify(this);
#endif
}
YouTube::~YouTube(){}
......@@ -70,10 +79,12 @@ void YouTube::fetch(const QString &json)
process->deleteLater();
});
// BabeWindow::nof->notify("Song received!", infoMap[KEY::TITLE]+ " - "+ infoMap[KEY::ARTIST]+".\nWait a sec while the track is added to your collection :)");
#if (defined (Q_OS_LINUX) && !defined (Q_OS_ANDROID))
this->nof->notify("Song received!", infoMap[KEY::TITLE]+ " - "+ infoMap[KEY::ARTIST]+".\nWait a sec while the track is added to your collection :)");
#endif
auto command = ydl;
command = command.replace("$$$",infoMap[KEY::URL])+" "+infoMap[KEY::ID];
command = command.replace("$$$",infoMap[KEY::ID])+" "+infoMap[KEY::ID];
qDebug()<<command;
process->start(command);
}
......@@ -81,11 +92,12 @@ void YouTube::fetch(const QString &json)
void YouTube::processFinished_totally(const int &state,const DB &info,const QProcess::ExitStatus &exitStatus)
{
auto track = info;
auto doneId = track[KEY::ID];
auto file = YoutubeCachePath+track[KEY::URL]+".m4a";
auto file = YoutubeCachePath+track[KEY::ID]+".m4a";
if(!BAE::fileExists(file)) return;
ids.removeAll(doneId);
track.insert(KEY::URL,file);
......@@ -184,9 +196,10 @@ void YouTube::processFinished_totally(const int &state,const DB &info,const QPro
CollectionDB con(nullptr);
con.addTrack(trackMap);
// con.trackPlaylist(file, track[KEY::PLAYLIST]);
// con.trackPlaylist(file, track[KEY::PLAYLIST]);
if(this->ids.isEmpty()) emit this->done();
}
......
......@@ -14,7 +14,9 @@
#include "../../utils/bae.h"
#include "../local/taginfo.h"
#if (defined (Q_OS_LINUX) && !defined (Q_OS_ANDROID))
class Notify;
#endif
class YouTube : public QObject
{
Q_OBJECT
......@@ -31,6 +33,9 @@ private slots:
private:
const QString ydl="youtube-dl -f m4a --youtube-skip-dash-manifest -o \"$$$.%(ext)s\"";
#if (defined (Q_OS_LINUX) && !defined (Q_OS_ANDROID))
Notify *nof;
#endif
signals:
void done();
......
......@@ -29,11 +29,9 @@ BabeSettings::BabeSettings(QObject *parent) : QObject(parent)
this->connection = new CollectionDB(this);
this->fileLoader = new FileLoader;
this->brainDeamon = new Brain;
// connect(connection, &CollectionDB::initDB, [this] ()
// {
// this->populateDB(BAE::MusicPath);
// });
this->ytFetch = new YouTube(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;
......@@ -68,8 +66,22 @@ BabeSettings::BabeSettings(QObject *parent) : QObject(parent)
if(BAE::isMobile())
this->populateDB(QStringList()<<BAE::MusicPath<<BAE::DownloadsPath<<BAE::MusicPaths<<BAE::DownloadsPaths);
else
this->populateDB({BAE::MusicPath});
// checkCollectionBrainz(BAE::loadSettings("BRAINZ", "BABE", false).toBool());
this->populateDB({BAE::MusicPath, BAE::YoutubeCachePath});
// checkCollectionBrainz(BAE::loadSettings("BRAINZ", "BABE", false).toBool());
connect(this->ytFetch, &YouTube::done, [this]()
{
this->populateDB({BAE::YoutubeCachePath});
});
connect(this->babeSocket, &Socket::message, this->ytFetch, &YouTube::fetch);
connect(this->babeSocket, &Socket::connected, [this](const int &index)
{
auto playlists = this->connection->getPlaylists();
qDebug()<<"Sending playlists to socket"<<playlists;
this->babeSocket->sendMessageTo(index, playlists.join(","));
});
connect(this->brainDeamon, &Brain::finished, [this]()
{
......@@ -97,16 +109,16 @@ BabeSettings::BabeSettings(QObject *parent) : QObject(parent)
{BAE::TABLEMAP[TABLE::PLAYLISTS], true}});
// this->startBrainz(true, 1500);
// this->startBrainz(true, 1500);
qDebug()<<"Finished inserting into DB";
}else
}/*else
{
this->dirs.clear();
this->collectionWatcher();
this->watcher->removePaths(watcher->directories());
this->startBrainz(BAE::loadSettings("BRAINZ", "BABE", false).toBool(), 3000);
}
}*/
});
......@@ -222,9 +234,7 @@ void BabeSettings::startBrainz(const bool &on, const uint &speed)
}
void BabeSettings::populateDB(const QStringList &paths)
{
qDebug() << "Function Name: " << Q_FUNC_INFO
<< "new path for database action: " << paths;
{
auto newPaths = paths;
for(auto path : newPaths)
......
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