bool CRecentlyAddedJob::UpdateMusic() { CGUIWindow* home = g_windowManager.GetWindow(WINDOW_HOME); if ( home == NULL ) return false; CLog::Log(LOGDEBUG, "CRecentlyAddedJob::UpdateMusic() - Running RecentlyAdded home screen update"); int i = 0; CFileItemList musicItems; CMusicDatabase musicdatabase; CMusicThumbLoader loader; loader.OnLoaderStart(); musicdatabase.Open(); if (musicdatabase.GetRecentlyAddedAlbumSongs("musicdb://songs/", musicItems, NUM_ITEMS)) { long idAlbum = -1; CStdString strAlbumThumb; CStdString strAlbumFanart; for (; i < musicItems.Size(); ++i) { CFileItemPtr item = musicItems.Get(i); CStdString value = StringUtils::Format("%i", i + 1); CStdString strRating; CStdString strAlbum = item->GetMusicInfoTag()->GetAlbum(); CStdString strArtist = StringUtils::Join(item->GetMusicInfoTag()->GetArtist(), g_advancedSettings.m_musicItemSeparator); if (idAlbum != item->GetMusicInfoTag()->GetAlbumId()) { strAlbumThumb.clear(); strAlbumFanart.clear(); idAlbum = item->GetMusicInfoTag()->GetAlbumId(); if (loader.LoadItem(item.get())) { strAlbumThumb = item->GetArt("thumb"); strAlbumFanart = item->GetArt("fanart"); } } strRating = StringUtils::Format("%c", item->GetMusicInfoTag()->GetRating()); home->SetProperty("LatestSong." + value + ".Title" , item->GetMusicInfoTag()->GetTitle()); home->SetProperty("LatestSong." + value + ".Year" , item->GetMusicInfoTag()->GetYear()); home->SetProperty("LatestSong." + value + ".Artist" , strArtist); home->SetProperty("LatestSong." + value + ".Album" , strAlbum); home->SetProperty("LatestSong." + value + ".Rating" , strRating); home->SetProperty("LatestSong." + value + ".Path" , item->GetMusicInfoTag()->GetURL()); home->SetProperty("LatestSong." + value + ".Thumb" , strAlbumThumb); home->SetProperty("LatestSong." + value + ".Fanart" , strAlbumFanart); } } for (; i < NUM_ITEMS; ++i) { CStdString value = StringUtils::Format("%i", i + 1); home->SetProperty("LatestSong." + value + ".Title" , ""); home->SetProperty("LatestSong." + value + ".Year" , ""); home->SetProperty("LatestSong." + value + ".Artist" , ""); home->SetProperty("LatestSong." + value + ".Album" , ""); home->SetProperty("LatestSong." + value + ".Rating" , ""); home->SetProperty("LatestSong." + value + ".Path" , ""); home->SetProperty("LatestSong." + value + ".Thumb" , ""); home->SetProperty("LatestSong." + value + ".Fanart" , ""); } i = 0; VECALBUMS albums; if (musicdatabase.GetRecentlyAddedAlbums(albums, NUM_ITEMS)) { for (; i < (int)albums.size(); ++i) { CAlbum& album=albums[i]; CStdString value = StringUtils::Format("%i", i + 1); CStdString strThumb = musicdatabase.GetArtForItem(album.idAlbum, MediaTypeAlbum, "thumb"); CStdString strFanart = musicdatabase.GetArtistArtForItem(album.idAlbum, MediaTypeAlbum, "fanart"); CStdString strDBpath = StringUtils::Format("musicdb://albums/%i/", album.idAlbum); CStdString strSQLAlbum = StringUtils::Format("idAlbum=%i", album.idAlbum); CStdString strArtist = musicdatabase.GetSingleValue("albumview", "strArtists", strSQLAlbum); home->SetProperty("LatestAlbum." + value + ".Title" , album.strAlbum); home->SetProperty("LatestAlbum." + value + ".Year" , album.iYear); home->SetProperty("LatestAlbum." + value + ".Artist" , strArtist); home->SetProperty("LatestAlbum." + value + ".Rating" , album.iRating); home->SetProperty("LatestAlbum." + value + ".Path" , strDBpath); home->SetProperty("LatestAlbum." + value + ".Thumb" , strThumb); home->SetProperty("LatestAlbum." + value + ".Fanart" , strFanart); } } for (; i < NUM_ITEMS; ++i) { CStdString value = StringUtils::Format("%i", i + 1); home->SetProperty("LatestAlbum." + value + ".Title" , ""); home->SetProperty("LatestAlbum." + value + ".Year" , ""); home->SetProperty("LatestAlbum." + value + ".Artist" , ""); home->SetProperty("LatestAlbum." + value + ".Rating" , ""); home->SetProperty("LatestAlbum." + value + ".Path" , ""); home->SetProperty("LatestAlbum." + value + ".Thumb" , ""); home->SetProperty("LatestAlbum." + value + ".Fanart" , ""); } musicdatabase.Close(); return true; }
bool CGUIDialogSongInfo::OnMessage(CGUIMessage& message) { switch (message.GetMessage()) { case GUI_MSG_WINDOW_DEINIT: { if (!m_cancelled && m_startRating != m_song->GetMusicInfoTag()->GetRating()) { CMusicDatabase db; if (db.Open()) // OpenForWrite() ? { db.SetSongRating(m_song->GetPath(), m_song->GetMusicInfoTag()->GetRating()); db.Close(); } m_needsUpdate = true; } else { // cancelled - reset the song rating SetRating(m_startRating); m_needsUpdate = false; } break; } case GUI_MSG_WINDOW_INIT: m_cancelled = false; break; case GUI_MSG_CLICKED: { int iControl = message.GetSenderId(); if (iControl == CONTROL_CANCEL) { m_cancelled = true; Close(); return true; } else if (iControl == CONTROL_OK) { m_cancelled = false; Close(); return true; } else if (iControl == CONTROL_ALBUMINFO) { CGUIWindowMusicBase *window = (CGUIWindowMusicBase *)g_windowManager.GetWindow(WINDOW_MUSIC_NAV); if (window) { CFileItem item(*m_song); std::string path = StringUtils::Format("musicdb://albums/%li",m_albumId); item.SetPath(path); item.m_bIsFolder = true; window->OnInfo(&item, true); } return true; } else if (iControl == CONTROL_GETTHUMB) { OnGetThumb(); return true; } } break; } return CGUIDialog::OnMessage(message); }
// Fetch full album/artist information including art types list bool DoWork() override { CGUIDialogMusicInfo *dialog = CServiceBroker::GetGUI()->GetWindowManager(). GetWindow<CGUIDialogMusicInfo>(WINDOW_DIALOG_MUSIC_INFO); if (!dialog) return false; if (dialog->IsCancelled()) return false; CFileItemPtr m_item = dialog->GetCurrentListItem(); CMusicInfoTag& tag = *m_item->GetMusicInfoTag(); CMusicDatabase database; database.Open(); // May only have partially populated item, so fetch all artist or album data from db if (tag.GetType() == MediaTypeArtist) { int artistId = tag.GetDatabaseId(); CArtist artist; if (!database.GetArtist(artistId, artist)) return false; tag.SetArtist(artist); CMusicDatabase::SetPropertiesFromArtist(*m_item, artist); m_item->SetLabel(artist.strArtist); // Get artist folder where local art could be found // Get the *name* of the folder for this artist within the Artist Info folder (may not exist). // If there is no Artist Info folder specified in settings this will be blank database.GetArtistPath(artist, artist.strPath); // Get the old location for those album artists with a unique folder (local to music files) // If there is no folder for the artist and *only* the artist this will be blank std::string oldartistpath; bool oldpathfound = database.GetOldArtistPath(artist.idArtist, oldartistpath); // Set up path for *item folder when browsing for art, by default this is // in the Artist Info Folder (when it exists), but could end up blank std::string artistItemPath = artist.strPath; if (!CDirectory::Exists(artistItemPath)) { // Fall back local to music files (historic location for those album artists with a unique folder) // although there may not be such a unique folder for the arist if (oldpathfound) artistItemPath = oldartistpath; else // Fall back further to browse the Artist Info Folder itself artistItemPath = CServiceBroker::GetSettings().GetString(CSettings::SETTING_MUSICLIBRARY_ARTISTSFOLDER); } m_item->SetPath(artistItemPath); // Store info as CArtist as well as item properties dialog->SetArtist(artist, oldartistpath); // Fetch artist discography as scraped from online sources, but always // include all the albums in the music library dialog->SetDiscography(database); } else { // tag.GetType == MediaTypeAlbum int albumId = tag.GetDatabaseId(); CAlbum album; if (!database.GetAlbum(albumId, album)) return false; tag.SetAlbum(album); CMusicDatabase::SetPropertiesFromAlbum(*m_item, album); // Get album folder where local art could be found database.GetAlbumPath(albumId, album.strPath); // Set up path for *item folder when browsing for art m_item->SetPath(album.strPath); // Store info as CAlbum as well as item properties dialog->SetAlbum(album, album.strPath); // Set the list of songs and related art dialog->SetSongs(album.songs); } database.Close(); /* Load current art (to CGUIListItem.m_art) For albums this includes related artist(s) art and artist fanart set as fallback album fanart. Clear item art first to ensure fresh not cached/partial art */ m_item->ClearArt(); CMusicThumbLoader loader; loader.LoadItem(m_item.get()); // Fill vector of possible art types with current art, when it exists, // for display on the art type selection dialog CFileItemList artlist; MUSIC_UTILS::FillArtTypesList(*m_item, artlist); dialog->SetArtTypeList(artlist); if (dialog->IsCancelled()) return false; // Tell waiting MusicDialog that job is complete dialog->FetchComplete(); return true; }
// 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 /* std::string thumbFromWeb; thumbFromWeb = URIUtils::AddFileToFolder(g_advancedSettings.m_cachePath, "allmusicThumb.jpg"); 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 std::string cachedLocalThumb; std::string 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); } std::string 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 std::string newThumb; if (result == "thumb://None") newThumb = "-"; else if (result == "thumb://allmusic.com") newThumb.clear(); 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; }
// Refresh album/artist information including art types list bool DoWork() override { CGUIDialogMusicInfo *dialog = CServiceBroker::GetGUI()->GetWindowManager(). GetWindow<CGUIDialogMusicInfo>(WINDOW_DIALOG_MUSIC_INFO); if (!dialog) return false; if (dialog->IsCancelled()) return false; CFileItemPtr m_item = dialog->GetCurrentListItem(); CMusicInfoTag& tag = *m_item->GetMusicInfoTag(); CArtist& m_artist = dialog->GetArtist(); CAlbum& m_album = dialog->GetAlbum(); CGUIDialogProgress* dlgProgress = GetProgressDialog(); CMusicDatabase database; database.Open(); if (tag.GetType() == MediaTypeArtist) { ADDON::ScraperPtr scraper; if (!database.GetScraper(m_artist.idArtist, CONTENT_ARTISTS, scraper)) return false; if (dlgProgress->IsCanceled()) return false; database.ClearArtistLastScrapedTime(m_artist.idArtist); if (dlgProgress->IsCanceled()) return false; CMusicInfoScanner scanner; if (scanner.UpdateArtistInfo(m_artist, scraper, true, dlgProgress) != CInfoScanner::INFO_ADDED) return false; else // Tell info dialog, so can show message dialog->SetScrapedInfo(true); if (dlgProgress->IsCanceled()) return false; //That changed DB and m_artist, now update dialog item with new info and art tag.SetArtist(m_artist); CMusicDatabase::SetPropertiesFromArtist(*m_item, m_artist); // Fetch artist discography as scraped from online sources, but always // include all the albums in the music library dialog->SetDiscography(database); } else { // tag.GetType == MediaTypeAlbum ADDON::ScraperPtr scraper; if (!database.GetScraper(m_album.idAlbum, CONTENT_ALBUMS, scraper)) return false; if (dlgProgress->IsCanceled()) return false; database.ClearAlbumLastScrapedTime(m_album.idAlbum); if (dlgProgress->IsCanceled()) return false; CMusicInfoScanner scanner; if (scanner.UpdateAlbumInfo(m_album, scraper, true, GetProgressDialog()) != CInfoScanner::INFO_ADDED) return false; else // Tell info dialog, so can show message dialog->SetScrapedInfo(true); if (dlgProgress->IsCanceled()) return false; //That changed DB and m_album, now update dialog item with new info and art // Album songs are unchanged by refresh (even with Musicbrainz sync?) tag.SetAlbum(m_album); CMusicDatabase::SetPropertiesFromAlbum(*m_item, m_album); // Set the list of songs and related art dialog->SetSongs(m_album.songs); } database.Close(); if (dlgProgress->IsCanceled()) return false; /* Load current art (to CGUIListItem.m_art) For albums this includes related artist(s) art and artist fanart set as fallback album fanart. Clear item art first to ensure fresh not cached/partial art */ m_item->ClearArt(); CMusicThumbLoader loader; loader.LoadItem(m_item.get()); if (dlgProgress->IsCanceled()) return false; // Fill vector of possible art types with current art, when it exists, // for display on the art type selection dialog CFileItemList artlist; MUSIC_UTILS::FillArtTypesList(*m_item, artlist); dialog->SetArtTypeList(artlist); if (dialog->IsCancelled()) return false; // Tell waiting MusicDialog that job is complete MarkFinished(); return true; }