Skip to content

Commit

Permalink
CoverArtCache - checking if the cover found is different from the cov…
Browse files Browse the repository at this point in the history
…er that is already stored in db

- it avoids calling 'updates' when there is nothing to update...
  • Loading branch information
cardinot committed Jul 29, 2014
1 parent 67300c3 commit 2b579de
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 16 deletions.
43 changes: 27 additions & 16 deletions src/library/coverartcache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ CoverArtCache::FutureResult CoverArtCache::searchImage(
res.trackId = coverInfo.trackId;
res.croppedImg = croppedPixmap;
res.emitSignals = emitSignals;
res.newImgFound = false;

// Looking for embedded cover art.
//
Expand All @@ -175,28 +176,34 @@ CoverArtCache::FutureResult CoverArtCache::searchImage(
if (res.md5Hash.isEmpty()) {
res.md5Hash = calculateMD5(res.img);
}
res.newImgFound = true;
}

// Looking for cover stored in track diretory.
//
if (!res.newImgFound) {
res.coverLocation = searchInTrackDirectory(coverInfo.trackDirectory,
coverInfo.trackBaseName,
coverInfo.album);
res.img = QImage(res.coverLocation);
res.md5Hash = calculateMD5(res.img);
res.newImgFound = true;
}

// adjusting the cover size according to the final purpose
if (res.newImgFound) {
if (res.croppedImg) {
res.img = cropImage(res.img);
} else {
res.img = rescaleBigImage(res.img);
}

return res;
}

// Looking for cover stored in track diretory.
//
res.coverLocation = searchInTrackDirectory(coverInfo.trackDirectory,
coverInfo.trackBaseName,
coverInfo.album);

res.img = QImage(res.coverLocation);
res.md5Hash = calculateMD5(res.img);
if (res.croppedImg) {
res.img = cropImage(res.img);
} else {
res.img = rescaleBigImage(res.img);
// check if this image is really new
// (different from the one that we have in db)
if (coverInfo.md5Hash == res.md5Hash)
{
res.newImgFound = false;
}

return res;
Expand Down Expand Up @@ -293,9 +300,13 @@ void CoverArtCache::imageFound() {
}
}
}

// update DB
int coverId = m_pCoverArtDAO->saveCoverArt(res.coverLocation, res.md5Hash);
m_pTrackDAO->updateCoverArt(res.trackId, coverId);
if (res.newImgFound) {
int coverId = m_pCoverArtDAO->saveCoverArt(res.coverLocation,
res.md5Hash);
m_pTrackDAO->updateCoverArt(res.trackId, coverId);
}

m_runningIds.remove(res.trackId);
}
Expand Down
1 change: 1 addition & 0 deletions src/library/coverartcache.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class CoverArtCache : public QObject, public Singleton<CoverArtCache>
QImage img;
bool croppedImg;
bool emitSignals;
bool newImgFound;
};

FutureResult searchImage(CoverArtDAO::CoverArtInfo coverInfo,
Expand Down

0 comments on commit 2b579de

Please sign in to comment.