Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Add local cover art when importing tracks #75

Merged
merged 19 commits into from
Mar 14, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Olf0 marked this conversation as resolved.
Show resolved Hide resolved
# ApplicationName does not have to be identical to Name
ApplicationName=flowplayer
# Add the required permissions here
Permissions=UserDirs;Audio;Bluetooth;Internet;RemovableMedia
3 changes: 3 additions & 0 deletions src/FlowPlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,9 @@ int main(int argc, char *argv[])

app->installTranslator(&translator);

// ensure the media cache dir is created
const QString mediaCacheDir = QStandardPaths::writableLocation(QStandardPaths::CacheLocation) + "/media-art";
QDir().mkpath( mediaCacheDir );
Olf0 marked this conversation as resolved.
Show resolved Hide resolved

QScopedPointer<QQuickView> window(SailfishApp::createView());
window->setTitle("FlowPlayer");
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
31 changes: 31 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>
poetaster marked this conversation as resolved.
Show resolved Hide resolved
#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;
Olf0 marked this conversation as resolved.
Show resolved Hide resolved

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

Expand All @@ -202,6 +208,31 @@ 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();
// we are explicit about two common factors,
// suffix jpg or png, basename cover or folder
if (iterator.fileInfo().isFile()) {
if ( ( iterator.fileInfo().suffix() == "jpg" ||
Olf0 marked this conversation as resolved.
Show resolved Hide resolved
iterator.fileInfo().suffix() == "jpeg" ||
iterator.fileInfo().suffix() == "png" ) &&
( iterator.fileInfo().baseName() == "cover" ||
iterator.fileInfo().baseName() == "folder" )
)
{
QString th2 = QStandardPaths::writableLocation(QStandardPaths::CacheLocation) + "/media-art/album-"+ doubleHash(m_artist, m_album) + ".jpeg";
Olf0 marked this conversation as resolved.
Show resolved Hide resolved
qDebug() << "PROCESSING FILE: " << iterator.filePath() ;
QFile::copy(iterator.filePath(), th2 );
Olf0 marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
}

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
Loading
Loading