bool CMusicInfoLoader::LoadAdditionalTagInfo(CFileItem* pItem) { if (!pItem || pItem->m_bIsFolder || pItem->IsPlayList() || pItem->IsNFO() || pItem->IsInternetStream()) return false; if (pItem->GetProperty("hasfullmusictag") == "true") return false; // already have the information std::string path(pItem->GetPath()); if (pItem->IsMusicDb()) { // set the artist / album properties XFILE::MUSICDATABASEDIRECTORY::CQueryParams param; XFILE::MUSICDATABASEDIRECTORY::CDirectoryNode::GetDatabaseInfo(pItem->GetPath(),param); CArtist artist; CMusicDatabase database; database.Open(); if (database.GetArtist(param.GetArtistId(), artist, false)) CMusicDatabase::SetPropertiesFromArtist(*pItem,artist); CAlbum album; if (database.GetAlbum(param.GetAlbumId(), album, false)) CMusicDatabase::SetPropertiesFromAlbum(*pItem,album); path = pItem->GetMusicInfoTag()->GetURL(); } CLog::Log(LOGDEBUG, "Loading additional tag info for file %s", path.c_str()); // we load up the actual tag for this file in order to // fetch the lyrics and add it to the current music info tag CFileItem tempItem(path, false); std::unique_ptr<IMusicInfoTagLoader> pLoader (CMusicInfoTagLoaderFactory::CreateLoader(tempItem)); if (NULL != pLoader.get()) { CMusicInfoTag tag; pLoader->Load(path, tag); pItem->GetMusicInfoTag()->SetLyrics(tag.GetLyrics()); pItem->SetProperty("hasfullmusictag", "true"); return true; } return false; }
bool CMusicInfoScanner::DownloadArtistInfo(const CStdString& strPath, const CStdString& strArtist, bool& bCanceled, CGUIDialogProgress* pDialog) { XFILE::MUSICDATABASEDIRECTORY::CQueryParams params; XFILE::MUSICDATABASEDIRECTORY::CDirectoryNode::GetDatabaseInfo(strPath, params); bCanceled = false; CArtist artist; m_musicDatabase.Open(); if (m_musicDatabase.GetArtistInfo(params.GetArtistId(),artist)) // already got the info return true; // find artist info ADDON::ScraperPtr info; if (!m_musicDatabase.GetScraperForPath(strPath, info, ADDON::ADDON_SCRAPER_ARTISTS) || !info) { m_musicDatabase.Close(); return false; } if (m_handle) { m_handle->SetTitle(StringUtils::Format(g_localizeStrings.Get(20320), info->Name().c_str())); m_handle->SetText(strArtist); } // clear our scraper cache info->ClearCache(); CMusicInfoScraper scraper(info); // handle nfo files CStdString strArtistPath, strNfo; m_musicDatabase.GetArtistPath(params.GetArtistId(),strArtistPath); URIUtils::AddFileToFolder(strArtistPath,"artist.nfo",strNfo); CNfoFile::NFOResult result=CNfoFile::NO_NFO; CNfoFile nfoReader; if (XFILE::CFile::Exists(strNfo)) { CLog::Log(LOGDEBUG,"Found matching nfo file: %s", strNfo.c_str()); result = nfoReader.Create(strNfo, info); if (result == CNfoFile::FULL_NFO) { CLog::Log(LOGDEBUG, "%s Got details from nfo", __FUNCTION__); CArtist artist; nfoReader.GetDetails(artist); m_musicDatabase.SetArtistInfo(params.GetArtistId(), artist); map<string, string> artwork = GetArtistArtwork(params.GetArtistId(), &artist); m_musicDatabase.SetArtForItem(params.GetArtistId(), "artist", artwork); m_musicDatabase.Close(); return true; } else if (result == CNfoFile::URL_NFO || result == CNfoFile::COMBINED_NFO) { CScraperUrl scrUrl(nfoReader.ScraperUrl()); CMusicArtistInfo artist("nfo",scrUrl); info = nfoReader.GetScraperInfo(); CLog::Log(LOGDEBUG,"-- nfo-scraper: %s",info->Name().c_str()); CLog::Log(LOGDEBUG,"-- nfo url: %s", scrUrl.m_url[0].m_url.c_str()); scraper.SetScraperInfo(info); scraper.GetArtists().push_back(artist); } else CLog::Log(LOGERROR,"Unable to find an url in nfo file: %s", strNfo.c_str()); } if (!scraper.GetArtistCount()) { scraper.FindArtistInfo(strArtist); while (!scraper.Completed()) { if (m_bStop) { scraper.Cancel(); bCanceled = true; } Sleep(1); } } int iSelectedArtist = 0; if (result == CNfoFile::NO_NFO) { if (scraper.Succeeded() && scraper.GetArtistCount() >= 1) { // now load the first match if (pDialog && scraper.GetArtistCount() > 1) { // if we found more then 1 album, let user choose one CGUIDialogSelect *pDlg = (CGUIDialogSelect*)g_windowManager.GetWindow(WINDOW_DIALOG_SELECT); if (pDlg) { pDlg->SetHeading(g_localizeStrings.Get(21890)); pDlg->Reset(); pDlg->EnableButton(true, 413); // manual for (int i = 0; i < scraper.GetArtistCount(); ++i) { // set the label to artist CFileItem item(scraper.GetArtist(i).GetArtist()); CStdString strTemp=scraper.GetArtist(i).GetArtist().strArtist; if (!scraper.GetArtist(i).GetArtist().strBorn.IsEmpty()) strTemp += " ("+scraper.GetArtist(i).GetArtist().strBorn+")"; if (!scraper.GetArtist(i).GetArtist().genre.empty()) { CStdString genres = StringUtils::Join(scraper.GetArtist(i).GetArtist().genre, g_advancedSettings.m_musicItemSeparator); if (!genres.empty()) strTemp.Format("[%s] %s", genres.c_str(), strTemp.c_str()); } item.SetLabel(strTemp); item.m_idepth = i; // use this to hold the index of the album in the scraper pDlg->Add(&item); } pDlg->DoModal(); // and wait till user selects one if (pDlg->GetSelectedLabel() < 0) { // none chosen if (!pDlg->IsButtonPressed()) { bCanceled = true; return false; } // manual button pressed CStdString strNewArtist = strArtist; if (!CGUIKeyboardFactory::ShowAndGetInput(strNewArtist, g_localizeStrings.Get(16025), false)) return false; if (pDialog) { pDialog->SetLine(0, strNewArtist); pDialog->Progress(); } m_musicDatabase.Close(); return DownloadArtistInfo(strPath,strNewArtist,bCanceled,pDialog); } iSelectedArtist = pDlg->GetSelectedItem()->m_idepth; } } } else { m_musicDatabase.Close(); return false; } } scraper.LoadArtistInfo(iSelectedArtist, strArtist); while (!scraper.Completed()) { if (m_bStop) { scraper.Cancel(); bCanceled = true; } Sleep(1); } if (scraper.Succeeded()) { artist = scraper.GetArtist(iSelectedArtist).GetArtist(); if (result == CNfoFile::COMBINED_NFO) nfoReader.GetDetails(artist,NULL,true); m_musicDatabase.SetArtistInfo(params.GetArtistId(), artist); } // check thumb stuff map<string, string> artwork = GetArtistArtwork(params.GetArtistId(), &artist); m_musicDatabase.SetArtForItem(params.GetArtistId(), "artist", artwork); m_musicDatabase.Close(); return true; }