Check for more image files...

This commit is contained in:
craig.p.drummond
2014-01-16 19:31:49 +00:00
parent 88e7a4f700
commit 6b0f990156
3 changed files with 91 additions and 31 deletions

62
README
View File

@@ -240,28 +240,36 @@ For artist images:
...if MPD folder exists, is not specified as a http URL, and is readable, then
cantata will look for the following within the folder containing the song:
2. ${albumArtist}.jpg
3. ${albumArtist}.png
2. ${basicArtist}.jpg
3. ${basicArtist}.png
4. artist.jpg
5. artist.png
...the above will be repeated for the parent folder
...if song is from a Various Artists album, or file is a non-MPD file, then
cantata will look for the following within the MPD root folder:
6. ${basicArtist}/${basicArtist}.jpg
7. ${basicArtist}/${basicArtist}.png
8. ${basicArtist}/artist.jpg
9. ${basicArtist}/artist.png
...then Cantata will check its cache folder (~/.cache/cantata/covers), for :
6. ${albumArtist}.jpg
7. ${albumArtist}.png
10. ${albumArtist}.jpg
11. ${albumArtist}.png
...if the MPD folder was specified as a http URL
8. ${url}/${dirFromFile}/artist.jpg
9. ${url}/${dirFromFile}/artist.png
12. ${url}/${dirFromFile}/artist.jpg
13. ${url}/${dirFromFile}/artist.png
...the above will be repeated for the parent folder
...lastly
10. Query last.fm using ${albumArtist}. Cantata will attempt to download the
14. Query last.fm using ${albumArtist}. Cantata will attempt to download the
image specified with the "extralarge" size.
Downloaded images will be saved as artist.jpg/png, within the artist folder
@@ -274,36 +282,44 @@ will be saved as a JPG within covers-scaled.
For context view backdrops:
...if MPD folder exists, is not specified as a http URL, and is readable, then
cantata will look for the following within the folder containing the song:
...if MPD folder exists, is not specified as a http URL, and is readable, OR
the song's filename starts with '/', then cantata will look for the
following within the folder containing the song:
1. ${currentArtist}-backdrop.jpg
2. ${currentArtist}-backdrop.png
3. backdrop.jpg
4. backdrop.png
1. ${currentArtist}-backdrop.jpg
2. ${currentArtist}-backdrop.png
3. backdrop.jpg
4. backdrop.png
...the above will be repeated for the parent folder
...if song is from a Various Artists album, or file is a non-MPD file, then
cantata will look for the following within the MPD root folder:
5. ${currentArtist}/${currentArtist}-backdrop.jpg
6. ${currentArtist}/${currentArtist}-backdrop.png
7. ${currentArtist}/backdrop.jpg
8. ${currentArtist}/backdrop.png
...then Cantata will check its cache folder (~/.cache/cantata/backdrops), for :
5. ${currentArtist}.jpg
6. ${currentArtist}.png
9. ${currentArtist}.jpg
...internet services:
7. MusizBrainz is queried for an artist ID. If returned, this artist ID is used
to locate a cover from fanart.tv
8. Download image from discogs
10. MusizBrainz is queried for an artist ID. If returned, this artist ID is used
to locate a cover from fanart.tv
11. Download image from discogs
...lastly:
9. If all the above fails, a backdrop is created from all the album covers
featuring the artist.
12. If all the above fails, a backdrop is created from all the album covers
featuring the artist.
Downloaded images will be saved as backdrop.jpg, within the artist folder
if the current song is not from a Various Artists album, the folder heirarchy is
2 levels (artist/album/) and the user has write permissions. If not, then they
will be saved in Cantata's cache folder.
if the current song is not from a Various Artists album, the file is from MPD,
the folder heirarchy is 2 levels (artist/album/), and the user has write
permissions. If not, then they will be saved in Cantata's cache folder.
6. Advanced Config Items

View File

@@ -585,17 +585,19 @@ void ContextWidget::updateBackdrop()
return;
}
if (!currentSong.isStream() && MPDConnection::self()->getDetails().dirReadable) {
QString encoded=Covers::encodeName(currentArtist);
QStringList names=QStringList() << encoded+"-"+constBackdropName+".jpg" << encoded+"-"+constBackdropName+".png"
<< constBackdropName+".jpg" << constBackdropName+".png";
if (!currentSong.isStream()) {
bool localNonMpd=currentSong.file.startsWith(Utils::constDirSep);
QString dirName=localNonMpd ? QString() : MPDConnection::self()->getDetails().dir;
if (localNonMpd || (!dirName.isEmpty() && !dirName.startsWith(QLatin1String("http:/")))) {
if (localNonMpd || (!dirName.isEmpty() && !dirName.startsWith(QLatin1String("http:/")) && MPDConnection::self()->getDetails().dirReadable)) {
dirName+=Utils::getDir(currentSong.file);
QString encoded=Covers::encodeName(currentArtist);
QStringList names=QStringList() << encoded+"-"+constBackdropName+".jpg" << encoded+"-"+constBackdropName+".png"
<< constBackdropName+".jpg" << constBackdropName+".png";
for (int level=0; level<2; ++level) {
foreach (const QString &fileName, names) {
DBUG << "Checking file" << QString(dirName+fileName);
DBUG << "Checking file(1)" << QString(dirName+fileName);
if (QFile::exists(dirName+fileName)) {
QImage img(dirName+fileName);
@@ -614,6 +616,28 @@ void ContextWidget::updateBackdrop()
}
}
// For various artists tracks, or for non-MPD files, see if we have a matching backdrop in MPD.
// e.g. artist=Wibble, look for $mpdDir/Wibble/backdrop.png
if (currentSong.isVariousArtists() || currentSong.isNonMPD()) {
QString dirName=MPDConnection::self()->getDetails().dirReadable ? MPDConnection::self()->getDetails().dir : QString();
if (!dirName.isEmpty() && !dirName.startsWith(QLatin1String("http:/"))) {
dirName+=currentArtist+Utils::constDirSep;
foreach (const QString &fileName, names) {
DBUG << "Checking file(2)" << QString(dirName+fileName);
if (QFile::exists(dirName+fileName)) {
QImage img(dirName+fileName);
if (!img.isNull()) {
DBUG << "Got backdrop from" << QString(dirName+fileName);
updateImage(img);
QWidget::update();
return;
}
}
}
}
}
QString cacheName=cacheFileName(currentArtist, false);
QImage img(cacheName);
if (img.isNull()) {

View File

@@ -747,7 +747,7 @@ QString CoverDownloader::saveImg(const Job &job, const QImage &img, const QByteA
QString dir = Utils::cacheDir(Covers::constCoverDir);
if (!dir.isEmpty()) {
savedName=save(mimeType, extension, dir+Covers::encodeName(job.song.albumartist), img, raw);
savedName=save(mimeType, extension, dir+Covers::encodeName(job.song.basicArtist()), img, raw);
if (!savedName.isEmpty()) {
DBUG << job.song.file << savedName;
return savedName;
@@ -1047,7 +1047,8 @@ Covers::Image Covers::locateImage(const Song &song)
if (isArtistImage) {
QString artistFile=artistFileName(song);
QStringList names=QStringList() << song.albumartist+".jpg" << song.albumartist+".png" << artistFile+".jpg" << artistFile+".png";
QString basicArtist=song.basicArtist();
QStringList names=QStringList() << basicArtist+".jpg" << basicArtist+".png" << artistFile+".jpg" << artistFile+".png";
for (int level=0; level<2; ++level) {
foreach (const QString &fileName, names) {
if (QFile::exists(dirName+fileName)) {
@@ -1063,6 +1064,25 @@ Covers::Image Covers::locateImage(const Song &song)
d.cdUp();
dirName=Utils::fixPath(d.absolutePath());
}
// For various artists tracks, or for non-MPD files, see if we have a matching backdrop in MPD.
// e.g. artist=Wibble, look for $mpdDir/Wibble/backdrop.png
if (song.isVariousArtists() || song.isNonMPD()) {
dirName=MPDConnection::self()->getDetails().dirReadable ? MPDConnection::self()->getDetails().dir : QString();
if (!dirName.isEmpty() && !dirName.startsWith(QLatin1String("http:/"))) {
dirName+=basicArtist+Utils::constDirSep;
foreach (const QString &fileName, names) {
if (QFile::exists(dirName+fileName)) {
QImage img(dirName+fileName);
if (!img.isNull()) {
DBUG_CLASS("Covers") << "Got artist image" << QString(dirName+fileName);
return Image(img, dirName+fileName);
}
}
}
}
}
} else {
QStringList names;
QString mpdCover=albumFileName(song);