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); if (!albumArt.empty()) albums[0].art["thumb"] = albumArt; } for (VECALBUMS::iterator i = albums.begin(); i != albums.end(); ++i) { CAlbum &album = *i; if (albums.size() != 1) albumArt = ""; /* Find art that is common across these items If we find a single art image we treat it as the album art and discard song art else we use first as album art and 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; } } /* assign the first art found to the album - better than no art at all */ if (art && albumArt.empty()) { if (!art->strThumb.empty()) albumArt = art->strThumb; else albumArt = CTextureCache::GetWrappedImageURL(art->strFileName, "music"); } if (!albumArt.empty()) album.art["thumb"] = albumArt; if (singleArt) { //if singleArt then we can clear the artwork for all songs for (VECSONGS::iterator k = album.songs.begin(); k != album.songs.end(); ++k) k->strThumb.clear(); } else { // more than one piece of art was found for these songs, so cache per song 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); } }