Permalink
Browse files

[infoscanner] assign embedded art to the album if a single album is i…

…n the folder
  • Loading branch information...
1 parent 9f08d93 commit 8c4d9fb1ac0e81adb3740c6c8434d5b4f3377d74 Jonathan Marshall committed Jul 2, 2012
@@ -4116,6 +4116,7 @@ bool CMusicDatabase::RemoveSongsFromPath(const CStdString &path1, CSongMap &song
while (!m_pDS->eof())
{
CSong song = GetSongFromDataset();
+ song.strThumb = GetArtForItem(song.idSong, "song", "thumb");
songs.Add(song.strFileName, song);
songIds += PrepareSQL("%i,", song.idSong);
ids.push_back(song.idSong);
@@ -50,6 +50,7 @@
#include "utils/URIUtils.h"
#include "ThumbnailCache.h"
#include "TextureCache.h"
+#include "ThumbLoader.h"
#include "interfaces/AnnouncementManager.h"
#include <algorithm>
@@ -383,9 +384,6 @@ bool CMusicInfoScanner::DoScan(const CStdString& strDirectory)
CStdString hash;
GetPathHash(items, hash);
- // get the folder's thumb (this will cache the album thumb).
- items.SetMusicThumb(true); // true forces it to get a remote thumb
-
// check whether we need to rescan or not
CStdString dbHash;
if (!m_musicDatabase.GetPathHash(strDirectory, dbHash) || dbHash != hash)
@@ -513,16 +511,17 @@ int CMusicInfoScanner::RetrieveMusicInfo(CFileItemList& items, const CStdString&
song.iStartOffset = pItem->m_lStartOffset;
song.iEndOffset = pItem->m_lEndOffset;
+ song.strThumb = pItem->GetUserMusicThumb(true);
if (dbSong)
{ // keep the db-only fields intact on rescan...
song.iTimesPlayed = dbSong->iTimesPlayed;
song.lastPlayed = dbSong->lastPlayed;
song.iKaraokeNumber = dbSong->iKaraokeNumber;
if (song.rating == '0') song.rating = dbSong->rating;
+ if (song.strThumb.empty())
+ song.strThumb = dbSong->strThumb;
}
- pItem->SetMusicThumb();
- song.strThumb = pItem->GetThumbnailImage();
songsToAdd.push_back(song);
// CLog::Log(LOGDEBUG, "%s - Tag loaded for: %s", __FUNCTION__, pItem->GetPath().c_str());
}
@@ -533,9 +532,7 @@ int CMusicInfoScanner::RetrieveMusicInfo(CFileItemList& items, const CStdString&
VECALBUMS albums;
CategoriseAlbums(songsToAdd, albums);
-
- if (!items.HasThumbnail())
- UpdateFolderThumb(songsToAdd, items.GetPath());
+ FindArtForAlbums(albums, items.GetPath());
// finally, add these to the database
m_musicDatabase.BeginTransaction();
@@ -731,6 +728,73 @@ void CMusicInfoScanner::CategoriseAlbums(VECSONGS &songsToCheck, VECALBUMS &albu
}
}
+void CMusicInfoScanner::FindArtForAlbums(VECALBUMS &albums, const CStdString &path)
+{
+ /*
+ If there's a single album in the folder, then art can be taken from
+ the folder art.
+ */
+ std::string albumArt;
+ if (albums.size() == 1)
+ {
+ CFileItem album(path, true);
+ albumArt = album.GetUserMusicThumb(true);
+ albums[0].art["thumb"] = albumArt;
+ }
+ for (VECALBUMS::iterator i = albums.begin(); i != albums.end(); ++i)
+ {
+ CAlbum &album = *i;
+ /*
+ Find art that is common across these items
+ If we find a single art image we treat it as the album art
+ else we keep everything as song art.
+ */
+ bool singleArt = true;
+ CSong *art = NULL;
+ for (VECSONGS::iterator k = album.songs.begin(); k != album.songs.end(); ++k)
+ {
+ CSong &song = *k;
+ if (song.HasArt())
+ {
+ if (art && !art->ArtMatches(song))
+ {
+ singleArt = false;
+ break;
+ }
+ if (!art)
+ art = &song;
+ }
+ }
+ if (singleArt)
+ { // a single piece of art was found for these songs so assign to the album
+ // and clear out of the songs
+ if (art && albumArt.empty())
+ {
+ if (!art->strThumb.empty())
+ albumArt = art->strThumb;
+ else
+ albumArt = CTextureCache::GetWrappedImageURL(art->strFileName, "music");
+ }
+ for (VECSONGS::iterator k = album.songs.begin(); k != album.songs.end(); ++k)
+ k->strThumb.clear();
+ albums[0].art["thumb"] = albumArt;
+ }
+ else
+ { // more than one piece of art was found for these songs, so cache per song
+ // and don't assign to the album
+ for (VECSONGS::iterator k = album.songs.begin(); k != album.songs.end(); ++k)
+ {
+ if (k->strThumb.empty() && !k->embeddedArt.empty())
+ k->strThumb = CTextureCache::GetWrappedImageURL(k->strFileName, "music");
+ }
+ }
+ }
+ if (albums.size() == 1 && !albumArt.empty())
+ { // assign to folder thumb as well
+ CMusicThumbLoader::SetCachedImage(path, "thumb", albumArt);
+ }
+}
+
void CMusicInfoScanner::CheckForVariousArtists(VECSONGS &songsToCheck)
{
// first, find all the album names for these songs
@@ -77,6 +77,22 @@ class CMusicInfoScanner : CThread, public IRunnable
*/
static void CategoriseAlbums(VECSONGS &songs, VECALBUMS &albums);
+ /*! \brief Find art for albums
+ Based on the albums in the folder, finds whether we have unique album art
+ and assigns to the album if we do.
+
+ In order of priority:
+ 1. If there is a single album in the folder, then the folder art is assigned to the album.
+ 2. We find the art for each song. A .tbn file takes priority over embedded art.
+ 3. If we have a unique piece of art for all songs in the album, we assign that to the album
+ and remove that art from each song so that they inherit from the album.
+ 4. If there is not a unique piece of art for each song, then no art is assigned
+ to the album.
+
+ \param albums [in/out] list of albums to categorise - art field may be altered.
+ \param path [in] path containing albums.
+ */
+ static void FindArtForAlbums(VECALBUMS &albums, const CStdString &path);
static void CheckForVariousArtists(VECSONGS &songs);
static bool HasSingleAlbum(const VECSONGS &songs, CStdString &album, CStdString &artist);

0 comments on commit 8c4d9fb

Please sign in to comment.