void CGUIWindowMusicBase::UpdateThumb(const CAlbum &album, const std::string &path) { // check user permissions bool saveDb = album.idAlbum != -1; bool saveDirThumb = true; if (!CProfilesManager::GetInstance().GetCurrentProfile().canWriteDatabases() && !g_passwordManager.bMasterUser) { saveDb = false; saveDirThumb = false; } std::string albumThumb = m_musicdatabase.GetArtForItem(album.idAlbum, MediaTypeAlbum, "thumb"); // Update the thumb in the music database (songs + albums) std::string albumPath(path); if (saveDb && CFile::Exists(albumThumb)) m_musicdatabase.SaveAlbumThumb(album.idAlbum, albumThumb); // Update currently playing song if it's from the same album. This is necessary as when the album // first gets it's cover, the info manager's item doesn't have the updated information (so will be // sending a blank thumb to the skin.) if (g_application.m_pPlayer->IsPlayingAudio()) { const CMusicInfoTag* tag=g_infoManager.GetCurrentSongTag(); if (tag) { // really, this may not be enough as it is to reliably update this item. eg think of various artists albums // that aren't tagged as such (and aren't yet scanned). But we probably can't do anything better than this // in that case if (album.strAlbum == tag->GetAlbum() && (album.artist == tag->GetAlbumArtist() || album.artist == tag->GetArtist())) { g_infoManager.SetCurrentAlbumThumb(albumThumb); } } } // Save this thumb as the directory thumb if it's the only album in the folder (files view nicety) // We do this by grabbing all the songs in the folder, and checking to see whether they come // from the same album. if (saveDirThumb && CFile::Exists(albumThumb) && !albumPath.empty() && !URIUtils::IsCDDA(albumPath)) { CFileItemList items; GetDirectory(albumPath, items); OnRetrieveMusicInfo(items); VECALBUMS albums; CMusicInfoScanner::FileItemsToAlbums(items, albums); if (albums.size() == 1) { // set as folder thumb as well CMusicThumbLoader loader; loader.SetCachedImage(items, "thumb", albumPath); } } // update the file listing - we have to update the whole lot, as it's likely that // more than just our thumbnaias changed // TODO: Ideally this would only be done when needed - at the moment we appear to be // doing this for every lookup, possibly twice (see ShowAlbumInfo) Refresh(true); // Do we have to autoswitch to the thumb control? m_guiState.reset(CGUIViewState::GetViewState(GetID(), *m_vecItems)); UpdateButtons(); }
void CMusicInfoScanner::FindArtForAlbums(VECALBUMS &albums, const std::string &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 = CTextureUtils::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 = CTextureUtils::GetWrappedImageURL(k->strFileName, "music"); } } } if (albums.size() == 1 && !albumArt.empty()) { // assign to folder thumb as well CFileItem albumItem(path, true); CMusicThumbLoader loader; loader.SetCachedImage(albumItem, "thumb", albumArt); } }