bool CVideoThumbLoader::FillLibraryArt(CFileItem &item) { CVideoInfoTag &tag = *item.GetVideoInfoTag(); if (tag.m_iDbId > -1 && !tag.m_type.empty()) { std::map<std::string, std::string> artwork; m_videoDatabase->Open(); if (m_videoDatabase->GetArtForItem(tag.m_iDbId, tag.m_type, artwork)) SetArt(item, artwork); else if (tag.m_type == "actor" && !tag.m_artist.empty()) { // we retrieve music video art from the music database (no backward compat) CMusicDatabase database; database.Open(); int idArtist = database.GetArtistByName(item.GetLabel()); if (database.GetArtForItem(idArtist, MediaTypeArtist, artwork)) item.SetArt(artwork); } else if (tag.m_type == MediaTypeAlbum) { // we retrieve music video art from the music database (no backward compat) CMusicDatabase database; database.Open(); int idAlbum = database.GetAlbumByName(item.GetLabel(), tag.m_artist); if (database.GetArtForItem(idAlbum, MediaTypeAlbum, artwork)) item.SetArt(artwork); } if (tag.m_type == MediaTypeEpisode || tag.m_type == MediaTypeSeason) { // For episodes and seasons, we want to set fanart for that of the show if (!item.HasArt("tvshow.fanart") && tag.m_iIdShow >= 0) { const ArtMap& artmap = GetArtFromCache(MediaTypeTvShow, tag.m_iIdShow); if (!artmap.empty()) { item.AppendArt(artmap, MediaTypeTvShow); item.SetArtFallback("fanart", "tvshow.fanart"); item.SetArtFallback("tvshow.thumb", "tvshow.poster"); } } if (tag.m_type == MediaTypeEpisode && !item.HasArt("season.poster") && tag.m_iSeason > -1) { const ArtMap& artmap = GetArtFromCache(MediaTypeSeason, tag.m_iIdSeason); if (!artmap.empty()) item.AppendArt(artmap, MediaTypeSeason); } } else if (tag.m_type == MediaTypeMovie && tag.m_set.id >= 0 && !item.HasArt("set.fanart")) { const ArtMap& artmap = GetArtFromCache(MediaTypeVideoCollection, tag.m_set.id); if (!artmap.empty()) item.AppendArt(artmap, MediaTypeVideoCollection); } m_videoDatabase->Close(); } return !item.GetArt().empty(); }
bool CVideoThumbLoader::FillLibraryArt(CFileItem &item) { CVideoInfoTag &tag = *item.GetVideoInfoTag(); if (tag.m_iDbId > -1 && !tag.m_type.IsEmpty()) { map<string, string> artwork; m_database->Open(); if (m_database->GetArtForItem(tag.m_iDbId, tag.m_type, artwork)) item.SetArt(artwork); else if (tag.m_type == "artist") { // we retrieve music video art from the music database (no backward compat) CMusicDatabase database; database.Open(); int idArtist = database.GetArtistByName(item.GetLabel()); if (database.GetArtForItem(idArtist, "artist", artwork)) item.SetArt(artwork); } else if (tag.m_type == "album") { // we retrieve music video art from the music database (no backward compat) CMusicDatabase database; database.Open(); int idAlbum = database.GetAlbumByName(item.GetLabel(), tag.m_artist); if (database.GetArtForItem(idAlbum, "album", artwork)) item.SetArt(artwork); } // For episodes and seasons, we want to set fanart for that of the show if (!item.HasArt("fanart") && tag.m_iIdShow >= 0) { ArtCache::const_iterator i = m_showArt.find(tag.m_iIdShow); if (i != m_showArt.end()) item.AppendArt(i->second); else { map<string, string> showArt, cacheArt; if (m_database->GetArtForItem(tag.m_iIdShow, "tvshow", showArt)) { for (CGUIListItem::ArtMap::iterator i = showArt.begin(); i != showArt.end(); ++i) { if (i->first == "fanart") cacheArt.insert(*i); else cacheArt.insert(make_pair("tvshow." + i->first, i->second)); } item.AppendArt(cacheArt); } m_showArt.insert(make_pair(tag.m_iIdShow, cacheArt)); } } m_database->Close(); } return !item.GetArt().empty(); }
bool CMusicThumbLoader::FillLibraryArt(CFileItem &item) { CMusicInfoTag &tag = *item.GetMusicInfoTag(); if (tag.GetDatabaseId() > -1 && !tag.GetType().empty()) { m_musicDatabase->Open(); map<string, string> artwork; if (m_musicDatabase->GetArtForItem(tag.GetDatabaseId(), tag.GetType(), artwork)) item.SetArt(artwork); else if (tag.GetType() == "song") { // no art for the song, try the album ArtCache::const_iterator i = m_albumArt.find(tag.GetAlbumId()); if (i == m_albumArt.end()) { m_musicDatabase->GetArtForItem(tag.GetAlbumId(), "album", artwork); i = m_albumArt.insert(make_pair(tag.GetAlbumId(), artwork)).first; } if (i != m_albumArt.end()) { item.AppendArt(i->second, "album"); for (map<string, string>::const_iterator j = i->second.begin(); j != i->second.end(); ++j) item.SetArtFallback(j->first, "album." + j->first); } } if (tag.GetType() == "song" || tag.GetType() == "album") { // fanart from the artist string fanart = m_musicDatabase->GetArtistArtForItem(tag.GetDatabaseId(), tag.GetType(), "fanart"); if (!fanart.empty()) { item.SetArt("artist.fanart", fanart); item.SetArtFallback("fanart", "artist.fanart"); } else if (tag.GetType() == "song") { // If no artist fanart, try for album artist fanart fanart = m_musicDatabase->GetArtistArtForItem(tag.GetAlbumId(), "album", "fanart"); if (!fanart.empty()) { item.SetArt("albumartist.fanart", fanart); item.SetArtFallback("fanart", "albumartist.fanart"); } } } m_musicDatabase->Close(); } return !item.GetArt().empty(); }
bool CVideoThumbLoader::FillLibraryArt(CFileItem &item) { CVideoInfoTag &tag = *item.GetVideoInfoTag(); if (tag.m_iDbId > -1 && !tag.m_type.empty()) { map<string, string> artwork; m_videoDatabase->Open(); if (m_videoDatabase->GetArtForItem(tag.m_iDbId, tag.m_type, artwork)) SetArt(item, artwork); else if (tag.m_type == MediaTypeArtist) { // we retrieve music video art from the music database (no backward compat) CMusicDatabase database; database.Open(); int idArtist = database.GetArtistByName(item.GetLabel()); if (database.GetArtForItem(idArtist, MediaTypeArtist, artwork)) item.SetArt(artwork); } else if (tag.m_type == MediaTypeAlbum) { // we retrieve music video art from the music database (no backward compat) CMusicDatabase database; database.Open(); int idAlbum = database.GetAlbumByName(item.GetLabel(), tag.m_artist); if (database.GetArtForItem(idAlbum, MediaTypeAlbum, artwork)) item.SetArt(artwork); } // For episodes and seasons, we want to set fanart for that of the show if (!item.HasArt("fanart") && tag.m_iIdShow >= 0) { ArtCache::const_iterator i = m_showArt.find(tag.m_iIdShow); if (i == m_showArt.end()) { map<string, string> showArt; m_videoDatabase->GetArtForItem(tag.m_iIdShow, MediaTypeTvShow, showArt); i = m_showArt.insert(make_pair(tag.m_iIdShow, showArt)).first; } if (i != m_showArt.end()) { item.AppendArt(i->second, "tvshow"); item.SetArtFallback("fanart", "tvshow.fanart"); item.SetArtFallback("tvshow.thumb", "tvshow.poster"); } } m_videoDatabase->Close(); } return !item.GetArt().empty(); }
bool CMusicThumbLoader::FillLibraryArt(CFileItem &item) { /* Called for any item with MusicInfoTag and no art. Items on Genres, Sources and Roles nodes have ID (although items on Years node do not) so check for song/album/artist specifically. Non-library songs (file view) can also have MusicInfoTag but no ID or type */ bool artfound(false); std::vector<ArtForThumbLoader> art; CMusicInfoTag &tag = *item.GetMusicInfoTag(); if (tag.GetDatabaseId() > -1 && (tag.GetType() == MediaTypeSong || tag.GetType() == MediaTypeAlbum || tag.GetType() == MediaTypeArtist)) { // Item in music library, fetch the art m_musicDatabase->Open(); if (tag.GetType() == MediaTypeSong) artfound = m_musicDatabase->GetArtForItem(tag.GetDatabaseId(), tag.GetAlbumId(), -1, false, art); else if (tag.GetType() == MediaTypeAlbum) artfound = m_musicDatabase->GetArtForItem(-1, tag.GetDatabaseId(), -1, false, art); else //Artist artfound = m_musicDatabase->GetArtForItem(-1, -1, tag.GetDatabaseId(), true, art); m_musicDatabase->Close(); } else if (!tag.GetArtist().empty() && (tag.GetType() == MediaTypeNone || tag.GetType() == MediaTypeSong)) { /* Could be non-library song - has musictag but no ID or type (may have thumb already). Try to fetch both song artist(s) and album artist(s) art by artist name, e.g. "artist.thumb", "artist.fanart", "artist.clearlogo", "artist.banner", "artist1.thumb", "artist1.fanart", "artist1.clearlogo", "artist1.banner", "albumartist.thumb", "albumartist.fanart" etc. Set fanart as fallback. */ CSong song; // Try to split song artist names (various tags) into artist credits song.SetArtistCredits(tag.GetArtist(), tag.GetMusicBrainzArtistHints(), tag.GetMusicBrainzArtistID()); if (!song.artistCredits.empty()) { tag.SetType(MediaTypeSong); // Makes "Information" context menu visible m_musicDatabase->Open(); int iOrder = 0; // Song artist art for (const auto& artistCredit : song.artistCredits) { int idArtist = m_musicDatabase->GetArtistByName(artistCredit.GetArtist()); if (idArtist > 0) { std::vector<ArtForThumbLoader> artistart; if (m_musicDatabase->GetArtForItem(-1, -1, idArtist, true, artistart)) { for (auto& artitem : artistart) { if (iOrder > 0) artitem.prefix = StringUtils::Format("artist%i", iOrder); else artitem.prefix = "artist"; } art.insert(art.end(), artistart.begin(), artistart.end()); } } ++iOrder; } // Album artist art if (!tag.GetAlbumArtist().empty() && tag.GetArtistString().compare(tag.GetAlbumArtistString()) != 0) { // Split song artist names correctly into artist credits from various tag // arrays, inc. fallback to song artist names CAlbum album; album.SetArtistCredits(tag.GetAlbumArtist(), tag.GetMusicBrainzAlbumArtistHints(), tag.GetMusicBrainzAlbumArtistID(), tag.GetArtist(), tag.GetMusicBrainzArtistHints(), tag.GetMusicBrainzArtistID()); iOrder = 0; for (const auto& artistCredit : album.artistCredits) { int idArtist = m_musicDatabase->GetArtistByName(artistCredit.GetArtist()); if (idArtist > 0) { std::vector<ArtForThumbLoader> artistart; if (m_musicDatabase->GetArtForItem(-1, -1, idArtist, true, artistart)) { for (auto& artitem : artistart) { if (iOrder > 0) artitem.prefix = StringUtils::Format("albumartist%i", iOrder); else artitem.prefix = "albumartist"; } art.insert(art.end(), artistart.begin(), artistart.end()); } } ++iOrder; } } else { // Replicate the artist art as album artist art std::vector<ArtForThumbLoader> artistart; for (const auto& artitem : art) { ArtForThumbLoader newart; newart.artType = artitem.artType; newart.mediaType = artitem.mediaType; newart.prefix = "album" + artitem.prefix; newart.url = artitem.url; artistart.emplace_back(newart); } art.insert(art.end(), artistart.begin(), artistart.end()); } artfound = !art.empty(); m_musicDatabase->Close(); } } if (artfound) { std::string fanartfallback; bool bDiscSetThumbSet = false; std::map<std::string, std::string> artmap; for (auto artitem : art) { /* Add art to artmap, naming according to media type. For example: artists have "thumb", "fanart", "poster" etc., albums have "thumb", "artist.thumb", "artist.fanart",... "artist1.thumb", "artist1.fanart" etc., songs have "thumb", "album.thumb", "artist.thumb", "albumartist.thumb", "albumartist1.thumb" etc. */ std::string artname; if (tag.GetType() == artitem.mediaType) artname = artitem.artType; else if (artitem.prefix.empty()) artname = artitem.mediaType + "." + artitem.artType; else { if (tag.GetType() == MediaTypeAlbum) StringUtils::Replace(artitem.prefix, "albumartist", "artist"); artname = artitem.prefix + "." + artitem.artType; } artmap.insert(std::make_pair(artname, artitem.url)); // Add fallback art for "thumb" and "fanart" art types only // Set album thumb as the fallback used when song thumb is missing // or use extra album thumb when part of disc set if (tag.GetType() == MediaTypeSong && artitem.mediaType == MediaTypeAlbum) { if (artitem.artType == "thumb" && !bDiscSetThumbSet) item.SetArtFallback(artitem.artType, artname); else if (StringUtils::StartsWith(artitem.artType, "thumb")) { int number = atoi(artitem.artType.substr(5).c_str()); if (number > 0 && tag.GetDiscNumber() == number) { item.SetArtFallback("thumb", artname); bDiscSetThumbSet = true; } } } // For albums and songs set fallback fanart from the artist. // For songs prefer primary song artist over primary albumartist fanart as fallback fanart if (artitem.prefix == "artist" && artitem.artType == "fanart") fanartfallback = artname; if (artitem.prefix == "albumartist" && artitem.artType == "fanart" && fanartfallback.empty()) fanartfallback = artname; } if (!fanartfallback.empty()) item.SetArtFallback("fanart", fanartfallback); item.AppendArt(artmap); } return artfound; }