bool CMusicInfoTagLoaderDatabase::Load(const CStdString& strFileName, CMusicInfoTag& tag) { tag.SetLoaded(false); CMusicDatabase database; database.Open(); DIRECTORY::MUSICDATABASEDIRECTORY::CQueryParams param; DIRECTORY::MUSICDATABASEDIRECTORY::CDirectoryNode::GetDatabaseInfo(strFileName,param); CSong song; if (database.GetSongById(param.GetSongId(),song)) tag.SetSong(song); database.Close(); return tag.Loaded(); }
bool CMusicInfoLoader::LoadItem(CFileItem* pItem) { if (m_pProgressCallback && !pItem->m_bIsFolder) m_pProgressCallback->SetProgressAdvance(); if (pItem->m_bIsFolder || pItem->IsPlayList() || pItem->IsNFO() || pItem->IsInternetStream()) return false; if (pItem->HasMusicInfoTag() && pItem->GetMusicInfoTag()->Loaded()) return true; // first check the cached item CFileItemPtr mapItem = (*m_mapFileItems)[pItem->m_strPath]; if (mapItem && mapItem->m_dateTime==pItem->m_dateTime && mapItem->HasMusicInfoTag() && mapItem->GetMusicInfoTag()->Loaded()) { // Query map if we previously cached the file on HD *pItem->GetMusicInfoTag() = *mapItem->GetMusicInfoTag(); pItem->SetThumbnailImage(mapItem->GetThumbnailImage()); return true; } CStdString strPath; CUtil::GetDirectory(pItem->m_strPath, strPath); CUtil::AddSlashAtEnd(strPath); if (strPath!=m_strPrevPath) { // The item is from another directory as the last one, // query the database for the new directory... m_musicDatabase.GetSongsByPath(strPath, m_songsMap); m_databaseHits++; } CSong *song=NULL; if ((song=m_songsMap.Find(pItem->m_strPath))!=NULL) { // Have we loaded this item from database before pItem->GetMusicInfoTag()->SetSong(*song); pItem->SetThumbnailImage(song->strThumb); } else if (pItem->IsMusicDb()) { // a music db item that doesn't have tag loaded - grab details from the database DIRECTORY::MUSICDATABASEDIRECTORY::CQueryParams param; DIRECTORY::MUSICDATABASEDIRECTORY::CDirectoryNode::GetDatabaseInfo(pItem->m_strPath,param); CSong song; if (m_musicDatabase.GetSongById(param.GetSongId(), song)) { pItem->GetMusicInfoTag()->SetSong(song); pItem->SetThumbnailImage(song.strThumb); } } else if (g_guiSettings.GetBool("musicfiles.usetags") || pItem->IsCDDA()) { // Nothing found, load tag from file, // always try to load cddb info // get correct tag parser auto_ptr<IMusicInfoTagLoader> pLoader (CMusicInfoTagLoaderFactory::CreateLoader(pItem->m_strPath)); if (NULL != pLoader.get()) // get tag pLoader->Load(pItem->m_strPath, *pItem->GetMusicInfoTag()); m_tagReads++; } m_strPrevPath = strPath; return true; }