Skip to content

Commit

Permalink
[Feature] add initial addition for cover art if a jpg is found in the…
Browse files Browse the repository at this point in the history
… directory as tracks are added to the db. also, correct old Generic paths, and test with sailjail.
  • Loading branch information
poetaster committed Mar 6, 2024
1 parent e88ff1e commit 68dc7f1
Show file tree
Hide file tree
Showing 18 changed files with 519 additions and 358 deletions.
6 changes: 5 additions & 1 deletion flowplayer.desktop
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,8 @@ Exec=flowplayer
Name=FlowPlayer

[X-Sailjail]
Sandboxing=Disabled
OrganizationName=sailfishos-applications
# ApplicationName does not have to be identical to Name
ApplicationName=flowplayer
# Add the required permissions here
Permissions=UserDirs;Audio;MediaIndexing;Bluetooth;Internet;RemovableMedia
5 changes: 5 additions & 0 deletions src/FlowPlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ static void migrateCache()
}
QDir(QStandardPaths::writableLocation(QStandardPaths::GenericCacheLocation)).rmdir("flowplayer");
}
// if the media-art directory does not exist, make it.
if (!QFileInfo(newCache).isDir()) {
QDir().mkpath( newCache );
QDir().mkpath( newCache + "/media-art" );
}
}

int main(int argc, char *argv[])
Expand Down
2 changes: 1 addition & 1 deletion src/coversearch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ void CoverSearch::paintImg(QString image, int index)

void CoverSearch::saveImage(QString artist, QString album, QString imagepath)
{
QString th2 = QStandardPaths::writableLocation(QStandardPaths::GenericCacheLocation) + "/media-art/album-"+ doubleHash(artist, album) + ".jpeg";
QString th2 = QStandardPaths::writableLocation(QStandardPaths::CacheLocation) + "/media-art/album-"+ doubleHash(artist, album) + ".jpeg";

QImage image(imagepath);
image.save(th2, "JPEG");
Expand Down
25 changes: 25 additions & 0 deletions src/datareader.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "datareader.h"
#include "globalutils.h"

#include <mpegfile.h>
#include <flacfile.h>
Expand All @@ -19,12 +20,15 @@
#include <xmfile.h>


#include <QCryptographicHash>
#include <QDir>
#include <QImage>
#include <QDirIterator>
#include <QString>
#include <QStringList>
#include <QSettings>
#include <QDebug>
#include <QStandardPaths>

extern bool databaseWorking;
extern bool isDBOpened;
Expand Down Expand Up @@ -185,6 +189,8 @@ TagLib::File* DataReader::getFileByMimeType(QString file)

void DataReader::readFile(QString file)
{
QString oFile = file;

file.remove("file://");
TagLib::File* tf = getFileByMimeType(file);

Expand All @@ -202,6 +208,25 @@ void DataReader::readFile(QString file)
m_tracknum = QString::number(tagFile->tag()->track());

if (m_title=="") m_title = QFileInfo(file).baseName();

// if we have artist and album, we check for a cover image.
if (m_artist != "" && m_album != "") {
QFileInfo info(file);
QDirIterator iterator(info.dir().path(), QDirIterator::Subdirectories);
while (iterator.hasNext()) {
iterator.next();
if (!iterator.fileInfo().isDir()) {
if ( iterator.filePath().toLower().endsWith(".jpg") ||
iterator.filePath().toLower().endsWith(".jpeg") )
{
QString th2 = QStandardPaths::writableLocation(QStandardPaths::CacheLocation) + "/media-art/album-"+ doubleHash(m_artist, m_album) + ".jpeg";
qDebug() << "PROCESSING FILE: " << iterator.filePath() ;
QFile::copy(iterator.filePath(), th2 );
}
}
}
}

if (m_artist=="") m_artist = tr("Unknown artist");
if (m_album=="") m_album = tr("Unknown album");

Expand Down
4 changes: 2 additions & 2 deletions src/datos.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ bool namefileLessThan(const QStringList &d1, const QStringList &d2)

QString Datos::getThumbnail(QString data, int index)
{
QString th1 = QStandardPaths::writableLocation(QStandardPaths::GenericCacheLocation) + "/media-art/album-"+ data + ".jpeg";
QString th1 = QStandardPaths::writableLocation(QStandardPaths::CacheLocation) + "/media-art/album-"+ data + ".jpeg";

/*QString th2 = QStandardPaths::writableLocation(QStandardPaths::CacheLocation) + "/flowplayer/62/album-"+ data + ".jpeg";
Expand Down Expand Up @@ -320,7 +320,7 @@ void Datos::DatosPrivate::populateItems()
item->band = q->listado[i][3];
item->songs = q->listado[i][4];
item->hash = doubleHash(item->acount=="1"? item->artist : item->title, item->title);
item->coverart = QStandardPaths::writableLocation(QStandardPaths::GenericCacheLocation) + "/media-art/album-"+ item->hash + ".jpeg";
item->coverart = QStandardPaths::writableLocation(QStandardPaths::CacheLocation) + "/media-art/album-"+ item->hash + ".jpeg";
item->isSelected = false;
} else if (groupFilter=="artist") {
item->artist = q->listado[i][1]=="1"? tr("1 album") : tr("%1 albums").arg( q->listado[i][1].toInt());
Expand Down
16 changes: 8 additions & 8 deletions src/loadwebimage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ bool WebThread::checkInternal()

if (QFileInfo(dir + "/folder.jpg").exists())
{
QString th2 = QStandardPaths::writableLocation(QStandardPaths::GenericCacheLocation) + "/media-art/album-"+ doubleHash(artist, album) + ".jpeg";
QString th2 = QStandardPaths::writableLocation(QStandardPaths::CacheLocation) + "/media-art/album-"+ doubleHash(artist, album) + ".jpeg";
QImage image(dir + "/folder.jpg");
image.save(th2, "JPEG");
emit imgLoaded(th2, files[0][2].toInt());
Expand All @@ -89,7 +89,7 @@ bool WebThread::checkInternal()

else if (QFileInfo(dir + "/folder.jpeg").exists())
{
QString th2 = QStandardPaths::writableLocation(QStandardPaths::GenericCacheLocation) + "/media-art/album-"+ doubleHash(artist, album) + ".jpeg";
QString th2 = QStandardPaths::writableLocation(QStandardPaths::CacheLocation) + "/media-art/album-"+ doubleHash(artist, album) + ".jpeg";
QImage image(dir + "/folder.jpeg");
image.save(th2, "JPEG");
emit imgLoaded(th2, files[0][2].toInt());
Expand All @@ -98,7 +98,7 @@ bool WebThread::checkInternal()

else if (QFileInfo(dir + "/cover.jpg").exists())
{
QString th2 = QStandardPaths::writableLocation(QStandardPaths::GenericCacheLocation) + "/media-art/album-"+ doubleHash(artist, album) + ".jpeg";
QString th2 = QStandardPaths::writableLocation(QStandardPaths::CacheLocation) + "/media-art/album-"+ doubleHash(artist, album) + ".jpeg";
QImage image(dir + "/cover.jpg");
image.save(th2, "JPEG");
emit imgLoaded(th2, files[0][2].toInt());
Expand All @@ -107,7 +107,7 @@ bool WebThread::checkInternal()

if (QFileInfo(dir + "/Folder.jpg").exists())
{
QString th2 = QStandardPaths::writableLocation(QStandardPaths::GenericCacheLocation) + "/media-art/album-"+ doubleHash(artist, album) + ".jpeg";
QString th2 = QStandardPaths::writableLocation(QStandardPaths::CacheLocation) + "/media-art/album-"+ doubleHash(artist, album) + ".jpeg";
QImage image(dir + "/Folder.jpg");
image.save(th2, "JPEG");
emit imgLoaded(th2, files[0][2].toInt());
Expand All @@ -116,7 +116,7 @@ bool WebThread::checkInternal()

else if (QFileInfo(dir + "/Folder.jpeg").exists())
{
QString th2 = QStandardPaths::writableLocation(QStandardPaths::GenericCacheLocation) + "/media-art/album-"+ doubleHash(artist, album) + ".jpeg";
QString th2 = QStandardPaths::writableLocation(QStandardPaths::CacheLocation) + "/media-art/album-"+ doubleHash(artist, album) + ".jpeg";
QImage image(dir + "/Folder.jpeg");
image.save(th2, "JPEG");
emit imgLoaded(th2, files[0][2].toInt());
Expand All @@ -125,7 +125,7 @@ bool WebThread::checkInternal()

else if (QFileInfo(dir + "/Cover.jpg").exists())
{
QString th2 = QStandardPaths::writableLocation(QStandardPaths::GenericCacheLocation) + "/media-art/album-"+ doubleHash(artist, album) + ".jpeg";
QString th2 = QStandardPaths::writableLocation(QStandardPaths::CacheLocation) + "/media-art/album-"+ doubleHash(artist, album) + ".jpeg";
QImage image(dir + "/Cover.jpg");
image.save(th2, "JPEG");
emit imgLoaded(th2, files[0][2].toInt());
Expand Down Expand Up @@ -292,7 +292,7 @@ QString WebThread::saveToDisk(QIODevice *reply)

QString art = files[0][0];
QString alb = files[0][1];
QString th2 = QStandardPaths::writableLocation(QStandardPaths::GenericCacheLocation) + "/media-art/album-"+ doubleHash(art, alb) + ".jpeg";
QString th2 = QStandardPaths::writableLocation(QStandardPaths::CacheLocation) + "/media-art/album-"+ doubleHash(art, alb) + ".jpeg";

QImage image = QImage::fromData(reply->readAll());
image.save(th2, "JPEG");
Expand All @@ -304,7 +304,7 @@ QString WebThread::saveToDiskExtern(QIODevice *reply)
{
QImage image = QImage::fromData(reply->readAll());

QString path = QStandardPaths::writableLocation(QStandardPaths::GenericCacheLocation) + "/flowplayer/" + hash(curImage) + ".jpeg";
QString path = QStandardPaths::writableLocation(QStandardPaths::CacheLocation) + "/flowplayer/" + hash(curImage) + ".jpeg";

image.save(path, "JPEG");

Expand Down
4 changes: 2 additions & 2 deletions src/missing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,10 @@ void Missing::loadData()

if (dato1!=tr("Unknown album") && dato2!=tr("Unknown artist"))
{
QString th2 = QStandardPaths::writableLocation(QStandardPaths::GenericCacheLocation) + "/media-art/album-"+ doubleHash(dato2, dato1) + ".jpeg";
QString th2 = QStandardPaths::writableLocation(QStandardPaths::CacheLocation) + "/media-art/album-"+ doubleHash(dato2, dato1) + ".jpeg";
if ( ! QFileInfo(th2).exists() )
{
QString th3 = QStandardPaths::writableLocation(QStandardPaths::GenericCacheLocation) + "/media-art/album-"+ doubleHash(dato1, dato1); + ".jpeg";
QString th3 = QStandardPaths::writableLocation(QStandardPaths::CacheLocation) + "/media-art/album-"+ doubleHash(dato1, dato1); + ".jpeg";
if ( ! QFileInfo(th3).exists() )
{
//qDebug() << dato1 << " doesn't exist. Adding to list";
Expand Down
22 changes: 11 additions & 11 deletions src/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ void Utils::readLyrics(QString artist, QString song)
QString sng = cleanItem(song);
if ( ( art!="" ) && ( sng!="" ) )
{
QString th1 = QStandardPaths::writableLocation(QStandardPaths::GenericCacheLocation) + "/lyrics/"+art+"-"+sng+".txt";
QString th1 = QStandardPaths::writableLocation(QStandardPaths::CacheLocation) + "/lyrics/"+art+"-"+sng+".txt";

if ( QFileInfo(th1).exists() )
{
Expand Down Expand Up @@ -116,10 +116,10 @@ QString Utils::thumbnail(QString artist, QString album, QString count)
QString art = count=="1"? artist : album;
QString alb = album;

QString th1 = QStandardPaths::writableLocation(QStandardPaths::GenericCacheLocation) + "/media-art/album-"+ doubleHash(art, alb) + ".jpeg";
QString th1 = QStandardPaths::writableLocation(QStandardPaths::CacheLocation) + "/media-art/album-"+ doubleHash(art, alb) + ".jpeg";

if (!QFileInfo(th1).exists()) {
QString th2 = QStandardPaths::writableLocation(QStandardPaths::GenericCacheLocation) + "/media-art/album-"+ doubleHash(alb, alb) + ".jpeg";
QString th2 = QStandardPaths::writableLocation(QStandardPaths::CacheLocation) + "/media-art/album-"+ doubleHash(alb, alb) + ".jpeg";
if (QFileInfo(th2).exists())
return th2;
}
Expand Down Expand Up @@ -355,11 +355,11 @@ void Utils::downloaded(QNetworkReply *respuesta)
void Utils::saveLyrics(QString artist, QString song, QString lyrics)
{
QDir d;
d.mkdir(QStandardPaths::writableLocation(QStandardPaths::GenericCacheLocation) + "/lyrics");
d.mkdir(QStandardPaths::writableLocation(QStandardPaths::CacheLocation) + "/lyrics");

QString art = cleanItem(artist);
QString sng = cleanItem(song);
QString f = QStandardPaths::writableLocation(QStandardPaths::GenericCacheLocation) + "/lyrics/"+art+"-"+sng+".txt";
QString f = QStandardPaths::writableLocation(QStandardPaths::CacheLocation) + "/lyrics/"+art+"-"+sng+".txt";

if ( QFileInfo(f).exists() )
QFile::remove(f);
Expand All @@ -377,11 +377,11 @@ void Utils::saveLyrics(QString artist, QString song, QString lyrics)
void Utils::saveLyrics2(QString artist, QString song, QString lyrics)
{
QDir d;
d.mkdir(QStandardPaths::writableLocation(QStandardPaths::GenericCacheLocation) + "/lyrics");
d.mkdir(QStandardPaths::writableLocation(QStandardPaths::CacheLocation) + "/lyrics");

QString art = cleanItem(artist);
QString sng = cleanItem(song);
QString f = QStandardPaths::writableLocation(QStandardPaths::GenericCacheLocation) + "/lyrics/"+art+"-"+sng+".txt";
QString f = QStandardPaths::writableLocation(QStandardPaths::CacheLocation) + "/lyrics/"+art+"-"+sng+".txt";

if ( QFileInfo(f).exists() )
QFile::remove(f);
Expand Down Expand Up @@ -421,10 +421,10 @@ void Utils::Finished(int requestId, bool)
QImage img;
img.loadFromData(bytes);

QString th1 = QStandardPaths::writableLocation(QStandardPaths::GenericCacheLocation) + "/media-art/album-" + doubleHash(albumArtArtist, albumArtAlbum) + ".jpeg";
if ( QFileInfo(QStandardPaths::writableLocation(QStandardPaths::GenericCacheLocation) + "/media-art/preview.jpeg").exists() )
QString th1 = QStandardPaths::writableLocation(QStandardPaths::CacheLocation) + "/media-art/album-" + doubleHash(albumArtArtist, albumArtAlbum) + ".jpeg";
if ( QFileInfo(QStandardPaths::writableLocation(QStandardPaths::CacheLocation) + "/media-art/preview.jpeg").exists() )
removePreview();
img.save(QStandardPaths::writableLocation(QStandardPaths::GenericCacheLocation) + "/media-art/preview.jpeg");
img.save(QStandardPaths::writableLocation(QStandardPaths::CacheLocation) + "/media-art/preview.jpeg");
downloadedAlbumArt = th1;
emit coverDownloaded();
}
Expand All @@ -434,7 +434,7 @@ void Utils::Finished(int requestId, bool)

void Utils::removePreview()
{
QFile f(QStandardPaths::writableLocation(QStandardPaths::GenericCacheLocation) + "/media-art/preview.jpeg");
QFile f(QStandardPaths::writableLocation(QStandardPaths::CacheLocation) + "/media-art/preview.jpeg");
f.remove();
}

Expand Down

0 comments on commit 68dc7f1

Please sign in to comment.