Commit b39f5c15 authored by Camilo higuita's avatar Camilo higuita

when adding sources check for cache artwork

parent 1e69f07e
......@@ -184,7 +184,8 @@ QString Babe::albumArt(const QString &album, const QString &artist)
TABLEMAP[TABLE::ALBUMS],
KEYMAP[KEY::ALBUM],album,
KEYMAP[KEY::ARTIST],artist);
auto albumCover = getDBData(queryStr);
auto albumCover = this->getDBData(queryStr);
if(!albumCover.isEmpty())
if(!albumCover.first()[KEY::ARTWORK].isEmpty() && albumCover.first()[KEY::ARTWORK] != SLANG[W::NONE])
......@@ -471,7 +472,7 @@ QStringList Babe::defaultSources()
QString Babe::loadCover(const QString &url)
{
auto map = getDBData(QStringList() << url);
auto map = this->getDBData(QStringList() << url);
if(map.isEmpty()) return "";
......
This diff is collapsed.
......@@ -44,7 +44,7 @@ class CollectionDB : public QObject
void insertArtwork(const BAE::DB &track);
void addTrack(const BAE::DB &track);
bool addTrack(const BAE::DB &track);
bool updateTrack(const BAE::DB &track);
Q_INVOKABLE bool rateTrack(const QString &path, const int &value);
Q_INVOKABLE bool colorTagTrack(const QString &path, const QString &value);
......
......@@ -82,12 +82,11 @@ BabeSettings::BabeSettings(QObject *parent) : QObject(parent)
connect(&this->fileLoader, &FileLoader::finished,[this](int size)
{
bDebug::Instance()->msg("Finished inserting into DB "+QString::number(size)+" tracks");
if(size > 0)
{
bDebug::Instance()->msg("Finished inserting into DB "+QString::number(size)+" tracks");
this->startBrainz(true, BAE::SEG::HALF);
}else
else
this->startBrainz(BAE::loadSettings("BRAINZ", "BABE", false).toBool(), BAE::SEG::TWO);
emit refreshTables(size);
......@@ -117,7 +116,7 @@ void BabeSettings::fetchYoutubeTrack(const QString &message)
void BabeSettings::checkCollectionBrainz(const bool &state)
{
bDebug::Instance()->msg("BRAINZ STATE<<"+state);
bDebug::Instance()->msg("BRAINZ STATE<<" + QString(state ? "true" : "false"));
this->startBrainz(state, BAE::SEG::THREE);
}
......@@ -141,5 +140,6 @@ void BabeSettings::populateDB(const QStringList &paths)
for(auto path : newPaths)
if(path.startsWith("file://"))
path.replace("file://", "");
fileLoader.requestPaths(newPaths);
}
#include "fileloader.h"
#include "../services/local/taginfo.h"
FileLoader::FileLoader() : CollectionDB(nullptr)
{
......@@ -20,8 +20,6 @@ FileLoader::~FileLoader()
void FileLoader::requestPaths(const QStringList& paths)
{
qDebug()<<"FROM file loader"<< paths;
this->go = true;
QMetaObject::invokeMethod(this, "getTracks", Q_ARG(QStringList, paths));
}
......@@ -33,8 +31,6 @@ void FileLoader::nextTrack()
void FileLoader::getTracks(const QStringList& paths)
{
qDebug()<<"GETTING TRACKS FROM SETTINGS";
QStringList urls;
for(auto path : paths)
......@@ -43,60 +39,63 @@ void FileLoader::getTracks(const QStringList& paths)
{
this->addFolder(path);
QDirIterator it(path, BAE::formats, QDir::Files, QDirIterator::Subdirectories);
while (it.hasNext()) urls<<it.next();
} else if (QFileInfo(path).isFile()) urls<<path;
}
while (it.hasNext())
urls << it.next();
qDebug()<<"URLS SIZEW FOR:"<<paths<< urls.size();
}else if (QFileInfo(path).isFile())
urls << path;
}
int newTracks = 0;
if(!urls.isEmpty())
if(urls.isEmpty()) return;
// this->execQuery("PRAGMA synchronous=OFF");
TagInfo info;
for(auto url : urls)
{
this->execQuery("PRAGMA synchronous=OFF");
if(!go)
break;
if(check_existance(BAE::TABLEMAP[BAE::TABLE::TRACKS],BAE::KEYMAP[BAE::KEY::URL], url))
continue;
if(!info.feed(url))
continue;
auto track= info.getTrack();
auto genre = info.getGenre();
auto album = BAE::fixString(info.getAlbum());
auto title = BAE::fixString(info.getTitle()); /* to fix*/
auto artist = BAE::fixString(info.getArtist());
auto sourceUrl = QFileInfo(url).dir().path();
auto duration = info.getDuration();
auto year = info.getYear();
for(auto url : urls)
BAE::DB trackMap =
{
if(go)
{
if(!check_existance(BAE::TABLEMAP[BAE::TABLE::TRACKS],BAE::KEYMAP[BAE::KEY::URL],url))
{
if(info.feed(url))
{
auto album = BAE::fixString(info.getAlbum());
auto track= info.getTrack();
auto title = BAE::fixString(info.getTitle()); /* to fix*/
auto artist = BAE::fixString(info.getArtist());
auto genre = info.getGenre();
auto sourceUrl = QFileInfo(url).dir().path();
auto duration = info.getDuration();
auto year = info.getYear();
BAE::DB trackMap =
{
{BAE::KEY::URL, url},
{BAE::KEY::TRACK, QString::number(track)},
{BAE::KEY::TITLE, title},
{BAE::KEY::ARTIST, artist},
{BAE::KEY::ALBUM, album},
{BAE::KEY::DURATION,QString::number(duration)},
{BAE::KEY::GENRE, genre},
{BAE::KEY::SOURCES_URL, sourceUrl},
{BAE::KEY::BABE, url.startsWith(BAE::YoutubeCachePath) ? "1": "0"},
{BAE::KEY::RELEASE_DATE, QString::number(year)}
};
qDebug()<<url;
this->addTrack(trackMap);
newTracks++;
}
}
}else break;
}
{BAE::KEY::URL, url},
{BAE::KEY::TRACK, QString::number(track)},
{BAE::KEY::TITLE, title},
{BAE::KEY::ARTIST, artist},
{BAE::KEY::ALBUM, album},
{BAE::KEY::DURATION,QString::number(duration)},
{BAE::KEY::GENRE, genre},
{BAE::KEY::SOURCES_URL, sourceUrl},
{BAE::KEY::BABE, url.startsWith(BAE::YoutubeCachePath) ? "1": "0"},
{BAE::KEY::RELEASE_DATE, QString::number(year)}
};
qDebug() << url;
BAE::artworkCache(trackMap, BAE::KEY::ALBUM);
if(this->addTrack(trackMap))
newTracks++;
}
this->t.msleep(100);
// this->t.msleep(100);
emit this->finished(newTracks);
this->go = false;
}
......@@ -5,7 +5,6 @@
#include <QObject>
#include <QDirIterator>
#include "../services/local/taginfo.h"
#include "../db/collectionDB.h"
class FileLoader : public CollectionDB
......@@ -35,7 +34,6 @@ private:
bool go = false;
bool wait = true;
QStringList queue;
TagInfo info;
};
......
......@@ -330,8 +330,10 @@ inline QString removeSubstring(const QString &newTitle, const QString &subString
{
const int indexFt = newTitle.indexOf(subString, 0, Qt::CaseInsensitive);
if (indexFt != -1) return newTitle.left(indexFt).simplified();
else return newTitle;
if (indexFt != -1)
return newTitle.left(indexFt).simplified();
else
return newTitle;
}
inline QString ucfirst(const QString &str)/*uppercase first letter*/
......@@ -368,12 +370,12 @@ inline QString fixString (const QString &str)
title = title.contains("(") && title.contains(")") ? fixTitle(title, "(",")") : title;
title = title.contains("[") && title.contains("]") ? fixTitle(title, "[","]") : title;
title = title.contains("{") && title.contains("}") ? fixTitle(title, "{","}") : title;
title = title.contains("ft") ? removeSubstring(title, "ft") : title;
title = title.contains("ft.") ? removeSubstring(title, "ft.") : title;
title = title.contains("featuring") ? removeSubstring(title, "featuring"):title;
title = title.contains("feat") ? removeSubstring(title, "feat") : title;
title = title.contains("official video")?removeSubstring(title, "official video"):title;
title = title.contains("live") ? removeSubstring(title, "live") : title;
title = title.contains("ft", Qt::CaseInsensitive) ? removeSubstring(title, "ft") : title;
title = title.contains("ft.", Qt::CaseInsensitive) ? removeSubstring(title, "ft.") : title;
title = title.contains("featuring", Qt::CaseInsensitive) ? removeSubstring(title, "featuring"):title;
title = title.contains("feat", Qt::CaseInsensitive) ? removeSubstring(title, "feat") : title;
title = title.contains("official video", Qt::CaseInsensitive) ? removeSubstring(title, "official video"):title;
title = title.contains("live", Qt::CaseInsensitive) ? removeSubstring(title, "live") : title;
title = title.contains("...") ? title.replace("..." ,"") : title;
title = title.contains("|") ? title.replace("|", "") : title;
title = title.contains("|") ? removeSubstring(title, "|") : title;
......@@ -387,9 +389,7 @@ inline QString fixString (const QString &str)
inline bool fileExists(const QString &url)
{
QFileInfo path(url);
if (path.exists()) return true;
else return false;
return FMH::fileExists(url);
}
inline BAE::TABLE albumType(const BAE::DB &albumMap)
......
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