// Allow user to select a Fanart void CGUIDialogMusicInfo::OnGetFanart() { CFileItemList items; if (m_albumItem->HasArt("fanart")) { CFileItemPtr itemCurrent(new CFileItem("fanart://Current",false)); itemCurrent->SetArt("thumb", m_albumItem->GetArt("fanart")); itemCurrent->SetLabel(g_localizeStrings.Get(20440)); items.Add(itemCurrent); } // Grab the thumbnails from the web for (unsigned int i = 0; i < m_artist.fanart.GetNumFanarts(); i++) { std::string strItemPath = StringUtils::Format("fanart://Remote%i",i); CFileItemPtr item(new CFileItem(strItemPath, false)); std::string thumb = m_artist.fanart.GetPreviewURL(i); item->SetArt("thumb", CTextureUtils::GetWrappedThumbURL(thumb)); item->SetIconImage("DefaultPicture.png"); item->SetLabel(g_localizeStrings.Get(20441)); //! @todo Do we need to clear the cached image? // CTextureCache::GetInstance().ClearCachedImage(thumb); items.Add(item); } // Grab a local fanart std::string strLocal; CMusicDatabase database; database.Open(); // First look for fanart in the artists folder, the primary location std::string strArtistPath = m_artist.strPath; // Get path when don't already have it. bool artistpathfound = !strArtistPath.empty(); if (!artistpathfound) artistpathfound = database.GetArtistPath(m_artist, strArtistPath); if (artistpathfound) { CFileItem item(strArtistPath, true); strLocal = item.GetLocalFanart(); } // If not there fall back local to music files (historic location for those album artists with a unique folder) if (strLocal.empty()) { artistpathfound = database.GetOldArtistPath(m_artist.idArtist, strArtistPath); if (artistpathfound) { CFileItem item(strArtistPath, true); strLocal = item.GetLocalFanart(); } } if (!strLocal.empty()) { CFileItemPtr itemLocal(new CFileItem("fanart://Local",false)); itemLocal->SetArt("thumb", strLocal); itemLocal->SetLabel(g_localizeStrings.Get(20438)); //! @todo Do we need to clear the cached image? CTextureCache::GetInstance().ClearCachedImage(strLocal); items.Add(itemLocal); } else { CFileItemPtr itemNone(new CFileItem("fanart://None", false)); itemNone->SetIconImage("DefaultArtist.png"); itemNone->SetLabel(g_localizeStrings.Get(20439)); items.Add(itemNone); } std::string result; bool flip = false; VECSOURCES sources(*CMediaSourceSettings::GetInstance().GetSources("music")); AddItemPathToFileBrowserSources(sources, *m_albumItem); g_mediaManager.GetLocalDrives(sources); if (!CGUIDialogFileBrowser::ShowAndGetImage(items, sources, g_localizeStrings.Get(20437), result, &flip, 20445)) return; // user cancelled // delete the thumbnail if that's what the user wants, else overwrite with the // new thumbnail if (StringUtils::EqualsNoCase(result, "fanart://Current")) return; if (StringUtils::EqualsNoCase(result, "fanart://Local")) result = strLocal; if (StringUtils::StartsWith(result, "fanart://Remote")) { int iFanart = atoi(result.substr(15).c_str()); m_artist.fanart.SetPrimaryFanart(iFanart); result = m_artist.fanart.GetImageURL(); } else if (StringUtils::EqualsNoCase(result, "fanart://None") || !CFile::Exists(result)) result.clear(); if (flip && !result.empty()) result = CTextureUtils::GetWrappedImageURL(result, "", "flipped"); // update thumb in the database CMusicDatabase db; if (db.Open()) { db.SetArtForItem(m_albumItem->GetMusicInfoTag()->GetDatabaseId(), m_albumItem->GetMusicInfoTag()->GetType(), "fanart", result); db.Close(); } m_albumItem->SetArt("fanart", result); m_hasUpdatedThumb = true; // tell our GUI to completely reload all controls (as some of them // are likely to have had this image in use so will need refreshing) CGUIMessage msg(GUI_MSG_NOTIFY_ALL, 0, 0, GUI_MSG_REFRESH_THUMBS); g_windowManager.SendMessage(msg); // Update our screen Update(); }
//! @todo Currently no support for "embedded thumb" as there is no easy way to grab it //! without sending a file that has this as it's album to this class void CGUIDialogMusicInfo::OnGetThumb() { CFileItemList items; // Current thumb if (CFile::Exists(m_albumItem->GetArt("thumb"))) { CFileItemPtr item(new CFileItem("thumb://Current", false)); item->SetArt("thumb", m_albumItem->GetArt("thumb")); item->SetLabel(g_localizeStrings.Get(20016)); items.Add(item); } // Grab the thumbnail(s) from the web std::vector<std::string> thumbs; if (m_bArtistInfo) m_artist.thumbURL.GetThumbURLs(thumbs); else m_album.thumbURL.GetThumbURLs(thumbs); for (unsigned int i = 0; i < thumbs.size(); ++i) { std::string strItemPath; strItemPath = StringUtils::Format("thumb://Remote%i", i); CFileItemPtr item(new CFileItem(strItemPath, false)); item->SetArt("thumb", thumbs[i]); item->SetIconImage("DefaultPicture.png"); item->SetLabel(g_localizeStrings.Get(20015)); //! @todo Do we need to clear the cached image? // CTextureCache::GetInstance().ClearCachedImage(thumb); items.Add(item); } // local thumb std::string localThumb; bool existsThumb = false; if (m_bArtistInfo) { CMusicDatabase database; database.Open(); // First look for thumb in the artists folder, the primary location std::string strArtistPath = m_artist.strPath; // Get path when don't already have it. bool artistpathfound = !strArtistPath.empty(); if (!artistpathfound) artistpathfound = database.GetArtistPath(m_artist, strArtistPath); if (artistpathfound) { localThumb = URIUtils::AddFileToFolder(strArtistPath, "folder.jpg"); existsThumb = CFile::Exists(localThumb); } // If not there fall back local to music files (historic location for those album artists with a unique folder) if (!existsThumb) { artistpathfound = database.GetOldArtistPath(m_artist.idArtist, strArtistPath); if (artistpathfound) { localThumb = URIUtils::AddFileToFolder(strArtistPath, "folder.jpg"); existsThumb = CFile::Exists(localThumb); } } } else { localThumb = m_albumItem->GetUserMusicThumb(); existsThumb = CFile::Exists(localThumb); } if (existsThumb) { CFileItemPtr item(new CFileItem("thumb://Local", false)); item->SetArt("thumb", localThumb); item->SetLabel(g_localizeStrings.Get(20017)); items.Add(item); } else { CFileItemPtr item(new CFileItem("thumb://None", false)); if (m_bArtistInfo) item->SetIconImage("DefaultArtist.png"); else item->SetIconImage("DefaultAlbumCover.png"); item->SetLabel(g_localizeStrings.Get(20018)); items.Add(item); } std::string result; bool flip=false; VECSOURCES sources(*CMediaSourceSettings::GetInstance().GetSources("music")); AddItemPathToFileBrowserSources(sources, *m_albumItem); g_mediaManager.GetLocalDrives(sources); if (!CGUIDialogFileBrowser::ShowAndGetImage(items, sources, g_localizeStrings.Get(1030), result, &flip)) return; // user cancelled if (result == "thumb://Current") return; // user chose the one they have std::string newThumb; if (StringUtils::StartsWith(result, "thumb://Remote")) { int number = atoi(result.substr(14).c_str()); newThumb = thumbs[number]; } else if (result == "thumb://Local") newThumb = localThumb; else if (CFile::Exists(result)) newThumb = result; // update thumb in the database CMusicDatabase db; if (db.Open()) { db.SetArtForItem(m_albumItem->GetMusicInfoTag()->GetDatabaseId(), m_albumItem->GetMusicInfoTag()->GetType(), "thumb", newThumb); db.Close(); } m_albumItem->SetArt("thumb", newThumb); m_hasUpdatedThumb = true; // tell our GUI to completely reload all controls (as some of them // are likely to have had this image in use so will need refreshing) CGUIMessage msg(GUI_MSG_NOTIFY_ALL, 0, 0, GUI_MSG_REFRESH_THUMBS); g_windowManager.SendMessage(msg); // Update our screen Update(); }
// Allow user to select a Fanart void CGUIDialogMusicInfo::OnGetFanart() { CFileItemList items; if (m_albumItem->HasProperty("fanart_image")) { CFileItemPtr itemCurrent(new CFileItem("fanart://Current",false)); itemCurrent->SetThumbnailImage(m_albumItem->GetProperty("fanart_image").asString()); itemCurrent->SetLabel(g_localizeStrings.Get(20440)); items.Add(itemCurrent); } // Grab the thumbnails from the web for (unsigned int i = 0; i < m_artist.fanart.GetNumFanarts(); i++) { CStdString strItemPath; strItemPath.Format("fanart://Remote%i",i); CFileItemPtr item(new CFileItem(strItemPath, false)); CStdString thumb = m_artist.fanart.GetPreviewURL(i); item->SetThumbnailImage(CTextureCache::GetWrappedThumbURL(thumb)); item->SetIconImage("DefaultPicture.png"); item->SetLabel(g_localizeStrings.Get(20441)); // TODO: Do we need to clear the cached image? // CTextureCache::Get().ClearCachedImage(thumb); items.Add(item); } // Grab a local thumb CMusicDatabase database; database.Open(); CStdString strArtistPath; database.GetArtistPath(m_artist.idArtist,strArtistPath); CFileItem item(strArtistPath,true); CStdString strLocal = item.GetLocalFanart(); if (!strLocal.IsEmpty()) { CFileItemPtr itemLocal(new CFileItem("fanart://Local",false)); itemLocal->SetThumbnailImage(strLocal); itemLocal->SetLabel(g_localizeStrings.Get(20438)); // TODO: Do we need to clear the cached image? CTextureCache::Get().ClearCachedImage(strLocal); items.Add(itemLocal); } else { CFileItemPtr itemNone(new CFileItem("fanart://None", false)); itemNone->SetIconImage("DefaultArtist.png"); itemNone->SetLabel(g_localizeStrings.Get(20439)); items.Add(itemNone); } CStdString result; VECSOURCES sources(g_settings.m_musicSources); g_mediaManager.GetLocalDrives(sources); bool flip=false; if (!CGUIDialogFileBrowser::ShowAndGetImage(items, sources, g_localizeStrings.Get(20437), result, &flip, 20445)) return; // user cancelled // delete the thumbnail if that's what the user wants, else overwrite with the // new thumbnail if (result.Equals("fanart://Current")) return; if (result.Equals("fanart://Local")) result = strLocal; if (result.Left(15) == "fanart://Remote") { int iFanart = atoi(result.Mid(15).c_str()); m_artist.fanart.SetPrimaryFanart(iFanart); result = m_artist.fanart.GetImageURL(); } else if (result.Equals("fanart://None") || !CFile::Exists(result)) result.clear(); if (flip && !result.empty()) result = CTextureCache::GetWrappedImageURL(result, "", "flipped"); // update thumb in the database CMusicDatabase db; if (db.Open()) { db.SetArtForItem(m_albumItem->GetMusicInfoTag()->GetDatabaseId(), m_albumItem->GetMusicInfoTag()->GetType(), "fanart", result); db.Close(); } if (!result.empty()) m_albumItem->SetProperty("fanart_image",result); else m_albumItem->ClearProperty("fanart_image"); m_hasUpdatedThumb = true; // tell our GUI to completely reload all controls (as some of them // are likely to have had this image in use so will need refreshing) CGUIMessage msg(GUI_MSG_NOTIFY_ALL, 0, 0, GUI_MSG_REFRESH_THUMBS); g_windowManager.SendMessage(msg); // Update our screen Update(); }
// TODO: Currently no support for "embedded thumb" as there is no easy way to grab it // without sending a file that has this as it's album to this class void CGUIDialogMusicInfo::OnGetThumb() { CFileItemList items; // Current thumb if (CFile::Exists(m_albumItem->GetThumbnailImage())) { CFileItemPtr item(new CFileItem("thumb://Current", false)); item->SetThumbnailImage(m_albumItem->GetThumbnailImage()); item->SetLabel(g_localizeStrings.Get(20016)); items.Add(item); } // Grab the thumbnail(s) from the web vector<CStdString> thumbs; if (m_bArtistInfo) m_artist.thumbURL.GetThumbURLs(thumbs); else m_album.thumbURL.GetThumbURLs(thumbs); for (unsigned int i = 0; i < thumbs.size(); ++i) { CStdString strItemPath; strItemPath.Format("thumb://Remote%i", i); CFileItemPtr item(new CFileItem(strItemPath, false)); item->SetThumbnailImage(thumbs[i]); item->SetIconImage("DefaultPicture.png"); item->SetLabel(g_localizeStrings.Get(20015)); // TODO: Do we need to clear the cached image? // CTextureCache::Get().ClearCachedImage(thumb); items.Add(item); } // local thumb CStdString localThumb; if (m_bArtistInfo) { CMusicDatabase database; database.Open(); CStdString strArtistPath; if (database.GetArtistPath(m_artist.idArtist,strArtistPath)) URIUtils::AddFileToFolder(strArtistPath,"folder.jpg",localThumb); } else localThumb = m_albumItem->GetUserMusicThumb(); if (CFile::Exists(localThumb)) { CFileItemPtr item(new CFileItem("thumb://Local", false)); item->SetThumbnailImage(localThumb); item->SetLabel(g_localizeStrings.Get(20017)); items.Add(item); } else { CFileItemPtr item(new CFileItem("thumb://None", false)); if (m_bArtistInfo) item->SetIconImage("DefaultArtist.png"); else item->SetIconImage("DefaultAlbumCover.png"); item->SetLabel(g_localizeStrings.Get(20018)); items.Add(item); } CStdString result; bool flip=false; VECSOURCES sources(g_settings.m_musicSources); g_mediaManager.GetLocalDrives(sources); if (!CGUIDialogFileBrowser::ShowAndGetImage(items, sources, g_localizeStrings.Get(1030), result, &flip)) return; // user cancelled if (result == "thumb://Current") return; // user chose the one they have CStdString newThumb; if (result.Left(14) == "thumb://Remote") { int number = atoi(result.Mid(14)); newThumb = thumbs[number]; } else if (result == "thumb://Local") newThumb = localThumb; else if (CFile::Exists(result)) newThumb = result; else // none newThumb = "-"; // force local thumbs to be ignored // update thumb in the database CMusicDatabase db; if (db.Open()) { db.SetArtForItem(m_albumItem->GetMusicInfoTag()->GetDatabaseId(), m_albumItem->GetMusicInfoTag()->GetType(), "thumb", newThumb); db.Close(); } m_albumItem->SetThumbnailImage(newThumb); m_hasUpdatedThumb = true; // tell our GUI to completely reload all controls (as some of them // are likely to have had this image in use so will need refreshing) CGUIMessage msg(GUI_MSG_NOTIFY_ALL, 0, 0, GUI_MSG_REFRESH_THUMBS); g_windowManager.SendMessage(msg); // Update our screen Update(); }
// TODO: Currently no support for "embedded thumb" as there is no easy way to grab it // without sending a file that has this as it's album to this class void CGUIDialogSongInfo::OnGetThumb() { CFileItemList items; // Grab the thumbnail from the web CStdString thumbFromWeb; /* URIUtils::AddFileToFolder(g_advancedSettings.m_cachePath, "allmusicThumb.jpg", thumbFromWeb); if (DownloadThumbnail(thumbFromWeb)) { CFileItemPtr item(new CFileItem("thumb://allmusic.com", false)); item->SetArt("thumb", thumbFromWeb); item->SetLabel(g_localizeStrings.Get(20055)); items.Add(item); }*/ // Current thumb if (CFile::Exists(m_song->GetArt("thumb"))) { CFileItemPtr item(new CFileItem("thumb://Current", false)); item->SetArt("thumb", m_song->GetArt("thumb")); item->SetLabel(g_localizeStrings.Get(20016)); items.Add(item); } // local thumb CStdString cachedLocalThumb; CStdString localThumb(m_song->GetUserMusicThumb(true)); if (m_song->IsMusicDb()) { CFileItem item(m_song->GetMusicInfoTag()->GetURL(), false); localThumb = item.GetUserMusicThumb(true); } if (CFile::Exists(localThumb)) { CFileItemPtr item(new CFileItem("thumb://Local", false)); item->SetArt("thumb", localThumb); item->SetLabel(g_localizeStrings.Get(20017)); items.Add(item); } else { // no local thumb exists, so we are just using the allmusic.com thumb or cached thumb // which is probably the allmusic.com thumb. These could be wrong, so allow the user // to delete the incorrect thumb CFileItemPtr item(new CFileItem("thumb://None", false)); item->SetArt("thumb", "DefaultAlbumCover.png"); item->SetLabel(g_localizeStrings.Get(20018)); items.Add(item); } CStdString result; VECSOURCES sources(*CMediaSourceSettings::Get().GetSources("music")); CGUIDialogMusicInfo::AddItemPathToFileBrowserSources(sources, *m_song); g_mediaManager.GetLocalDrives(sources); if (!CGUIDialogFileBrowser::ShowAndGetImage(items, sources, g_localizeStrings.Get(1030), result)) return; // user cancelled if (result == "thumb://Current") return; // user chose the one they have // delete the thumbnail if that's what the user wants, else overwrite with the // new thumbnail CStdString newThumb; if (result == "thumb://None") newThumb = "-"; else if (result == "thumb://allmusic.com") newThumb = thumbFromWeb; else if (result == "thumb://Local") newThumb = localThumb; else newThumb = result; // update thumb in the database CMusicDatabase db; if (db.Open()) { db.SetArtForItem(m_song->GetMusicInfoTag()->GetDatabaseId(), m_song->GetMusicInfoTag()->GetType(), "thumb", newThumb); db.Close(); } m_song->SetArt("thumb", newThumb); // tell our GUI to completely reload all controls (as some of them // are likely to have had this image in use so will need refreshing) CGUIMessage msg(GUI_MSG_NOTIFY_ALL, 0, 0, GUI_MSG_REFRESH_THUMBS); g_windowManager.SendMessage(msg); // m_hasUpdatedThumb = true; }
JSONRPC_STATUS CAudioLibrary::SetSongDetails(const std::string &method, ITransportLayer *transport, IClient *client, const CVariant ¶meterObject, CVariant &result) { int id = (int)parameterObject["songid"].asInteger(); CMusicDatabase musicdatabase; if (!musicdatabase.Open()) return InternalError; CSong song; if (!musicdatabase.GetSong(id, song) || song.idSong != id) return InvalidParams; if (ParameterNotNull(parameterObject, "title")) song.strTitle = parameterObject["title"].asString(); if (ParameterNotNull(parameterObject, "displayartist")) song.strArtistDesc = parameterObject["displayartist"].asString(); // Set album sort string before processing artist credits if (ParameterNotNull(parameterObject, "sortartist")) song.strArtistSort = parameterObject["sortartist"].asString(); // Match up artist names and mbids to make new artist credits // Mbid values only apply if there are names bool updateartists = false; if (ParameterNotNull(parameterObject, "artist")) { std::vector<std::string> artists, mbids; updateartists = true; CopyStringArray(parameterObject["artist"], artists); // Check for Musicbrainz ids if (ParameterNotNull(parameterObject, "musicbrainzartistid")) CopyStringArray(parameterObject["musicbrainzartistid"], mbids); // When display artist is not provided and yet artists is changing make by concatenation if (!ParameterNotNull(parameterObject, "displayartist")) song.strArtistDesc = StringUtils::Join(artists, g_advancedSettings.m_musicItemSeparator); song.SetArtistCredits(artists, std::vector<std::string>(), mbids); } if (ParameterNotNull(parameterObject, "genre")) CopyStringArray(parameterObject["genre"], song.genre); if (ParameterNotNull(parameterObject, "year")) song.iYear = (int)parameterObject["year"].asInteger(); if (ParameterNotNull(parameterObject, "rating")) song.rating = parameterObject["rating"].asFloat(); if (ParameterNotNull(parameterObject, "userrating")) song.userrating = parameterObject["userrating"].asInteger(); if (ParameterNotNull(parameterObject, "track")) song.iTrack = (song.iTrack & 0xffff0000) | ((int)parameterObject["track"].asInteger() & 0xffff); if (ParameterNotNull(parameterObject, "disc")) song.iTrack = (song.iTrack & 0xffff) | ((int)parameterObject["disc"].asInteger() << 16); if (ParameterNotNull(parameterObject, "duration")) song.iDuration = (int)parameterObject["duration"].asInteger(); if (ParameterNotNull(parameterObject, "comment")) song.strComment = parameterObject["comment"].asString(); if (ParameterNotNull(parameterObject, "musicbrainztrackid")) song.strMusicBrainzTrackID = parameterObject["musicbrainztrackid"].asString(); if (ParameterNotNull(parameterObject, "playcount")) song.iTimesPlayed = static_cast<int>(parameterObject["playcount"].asInteger()); if (ParameterNotNull(parameterObject, "lastplayed")) song.lastPlayed.SetFromDBDateTime(parameterObject["lastplayed"].asString()); if (ParameterNotNull(parameterObject, "mood")) song.strAlbum = parameterObject["mood"].asString(); // Update existing art. Any existing artwork that isn't specified in this request stays as is. // If the value is null then the existing art with that type is removed. if (ParameterNotNull(parameterObject, "art")) { // Get current artwork std::map<std::string, std::string> artwork; musicdatabase.GetArtForItem(song.idSong, MediaTypeSong, artwork); std::set<std::string> removedArtwork; CVariant art = parameterObject["art"]; for (CVariant::const_iterator_map artIt = art.begin_map(); artIt != art.end_map(); artIt++) { if (artIt->second.isString() && !artIt->second.asString().empty()) artwork[artIt->first] = CTextureUtils::UnwrapImageURL(artIt->second.asString()); else if (artIt->second.isNull()) { artwork.erase(artIt->first); removedArtwork.insert(artIt->first); } } //Update artwork, not done in update song musicdatabase.SetArtForItem(song.idSong, MediaTypeSong, artwork); if (!musicdatabase.RemoveArtForItem(song.idSong, MediaTypeSong, removedArtwork)) return InternalError; } // Update song (not including artwork) if (!musicdatabase.UpdateSong(song, updateartists)) return InternalError; CJSONRPCUtils::NotifyItemUpdated(); return ACK; }