コード例 #1
0
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();
}
コード例 #2
0
bool CMusicInfoScanner::DownloadArtistInfo(const CStdString& strPath, const CStdString& strArtist, CGUIDialogProgress* pDialog)
{
  DIRECTORY::MUSICDATABASEDIRECTORY::CQueryParams params;
  DIRECTORY::MUSICDATABASEDIRECTORY::CDirectoryNode::GetDatabaseInfo(strPath, params);
  CArtist artist;
  m_musicDatabase.Open();
  if (m_musicDatabase.GetArtistInfo(params.GetArtistId(),artist)) // already got the info
    return true;

  // find artist info
  SScraperInfo info;
  if (!m_musicDatabase.GetScraperForPath(strPath,info))
  {
    m_musicDatabase.Close();
    return false;
  }

  if (m_pObserver)
  {
    m_pObserver->OnStateChanged(DOWNLOADING_ARTIST_INFO);
    m_pObserver->OnDirectoryChanged(strArtist);  
  }

  CMusicInfoScraper scraper(info);
  // handle nfo files
  CStdString strArtistPath, strNfo;
  m_musicDatabase.GetArtistPath(params.GetArtistId(),strArtistPath);
  CUtil::AddFileToFolder(strArtistPath,"artist.nfo",strNfo);
  if (XFILE::CFile::Exists(strNfo))
  {
    CLog::Log(LOGDEBUG,"Found matching nfo file: %s", strNfo.c_str());
    CNfoFile nfoReader("albums");
    if (nfoReader.Create(strNfo) == S_OK)
    {
      if (nfoReader.m_strScraper == "NFO")
      {
        CLog::Log(LOGDEBUG, "%s Got details from nfo", __FUNCTION__);
        CArtist artist;
        nfoReader.GetDetails(artist);
        m_musicDatabase.SetArtistInfo(params.GetArtistId(), artist);
        m_musicDatabase.Close();
        return true;
      }
      else
      {
        CScraperUrl scrUrl(nfoReader.m_strImDbUrl); 
        CMusicArtistInfo artist("nfo",scrUrl);
        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();
      break;
    }
    Sleep(1);
  }

  if (scraper.Successfull() && scraper.GetArtistCount() >= 1)
  {
    int iSelectedArtist = 0;
    // now load the first match
    if (pDialog && scraper.GetArtistCount() > 1)
    {
      // if we found more then 1 album, let user choose one
      CGUIDialogSelect *pDlg = (CGUIDialogSelect*)m_gWindowManager.GetWindow(WINDOW_DIALOG_SELECT);
      if (pDlg)
      {
        pDlg->SetHeading(g_localizeStrings.Get(21890));
        pDlg->Reset();
        pDlg->EnableButton(true);
        pDlg->SetButtonLabel(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().strGenre.IsEmpty())
            strTemp.Format("[%s] %s",scraper.GetArtist(i).GetArtist().strGenre.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()) return false;
          // manual button pressed
          CStdString strNewArtist = strArtist;
          if (!CGUIDialogKeyboard::ShowAndGetInput(strNewArtist, g_localizeStrings.Get(16025), false)) return false;

          if (pDialog)
          {
            pDialog->SetLine(0, strNewArtist);
            pDialog->Progress();
          }
          m_musicDatabase.Close();
          return DownloadArtistInfo(strPath,strArtist,pDialog);
        }
        iSelectedArtist = pDlg->GetSelectedItem().m_idepth;
      }
    }
    
    scraper.LoadArtistinfo(iSelectedArtist);

    while (!scraper.Completed())
    {
      if (m_bStop)
      {
        scraper.Cancel();
        break;
      }
      Sleep(1);
    }

    if (scraper.Successfull())
    {
      artist = scraper.GetArtist(iSelectedArtist).GetArtist();
      m_musicDatabase.SetArtistInfo(params.GetArtistId(), artist);
    }
  }
  else
  {
    m_musicDatabase.Close();
    return false;
  }

  // check thumb stuff
  if (artist.thumbURL.m_url.size())
  {
    CFileItem item(strArtist);
    CStdString thumb = item.GetCachedArtistThumb();
    if (!XFILE::CFile::Exists(thumb))
      CScraperUrl::DownloadThumbnail(thumb,artist.thumbURL.m_url[0]);
  }
   
  m_musicDatabase.Close();
  return true;
}
コード例 #3
0
bool CMusicInfoScanner::DownloadAlbumInfo(const CStdString& strPath, const CStdString& strArtist, const CStdString& strAlbum, bool& bCanceled, CMusicAlbumInfo& albumInfo, CGUIDialogProgress* pDialog)
{
  CAlbum album;
  VECSONGS songs;
  DIRECTORY::MUSICDATABASEDIRECTORY::CQueryParams params;
  DIRECTORY::MUSICDATABASEDIRECTORY::CDirectoryNode::GetDatabaseInfo(strPath, params);
  bCanceled = false;
  m_musicDatabase.Open();
  if (m_musicDatabase.HasAlbumInfo(params.GetAlbumId()) && m_musicDatabase.GetAlbumInfo(params.GetAlbumId(),album,&songs))
    return true;

  // find album info
  SScraperInfo info;
  if (!m_musicDatabase.GetScraperForPath(strPath,info))
  {
    m_musicDatabase.Close();
    return false;
  }

  if (m_pObserver)
  {
    m_pObserver->OnStateChanged(DOWNLOADING_ALBUM_INFO);
    m_pObserver->OnDirectoryChanged(strAlbum);
  }

  CMusicInfoScraper scraper(info);

  // handle nfo files
  CStdString strAlbumPath, strNfo;
  m_musicDatabase.GetAlbumPath(params.GetAlbumId(),strAlbumPath);
  CUtil::AddFileToFolder(strAlbumPath,"album.nfo",strNfo);
  if (XFILE::CFile::Exists(strNfo))
  {
    CLog::Log(LOGDEBUG,"Found matching nfo file: %s", strNfo.c_str());
    CNfoFile nfoReader("albums");
    if (nfoReader.Create(strNfo) == S_OK)
    {
      if (nfoReader.m_strScraper == "NFO")
      {
        CLog::Log(LOGDEBUG, "%s Got details from nfo", __FUNCTION__);
        CAlbum album;
        VECSONGS songs;
        nfoReader.GetDetails(album);
        m_musicDatabase.SetAlbumInfo(params.GetAlbumId(), album, songs);
        m_musicDatabase.Close();
        return true;
      }
      else
      {
        CScraperUrl scrUrl(nfoReader.m_strImDbUrl); 
        CMusicAlbumInfo album("nfo",scrUrl);
        scraper.GetAlbums().push_back(album);
      }
    }
    else
      CLog::Log(LOGERROR,"Unable to find an url in nfo file: %s", strNfo.c_str());
  }

  if (!scraper.GetAlbumCount())
    scraper.FindAlbuminfo(strAlbum, strArtist);

  while (!scraper.Completed())
  {
    if (m_bStop)
    {
      scraper.Cancel();
      break;
    }
    Sleep(1);
  }

  CGUIDialogSelect *pDlg=NULL;
  int iSelectedAlbum=0;
  if (scraper.Successfull() && scraper.GetAlbumCount() >= 1)
  {
    int bestMatch = 0;
    double bestRelevance = 0;
    double minRelevance = THRESHOLD;
    if (scraper.GetAlbumCount() > 1) // score the matches
    {
      //show dialog with all albums found
      if (pDialog)
      {
        pDlg = (CGUIDialogSelect*)m_gWindowManager.GetWindow(WINDOW_DIALOG_SELECT);
        pDlg->SetHeading(g_localizeStrings.Get(181).c_str());
        pDlg->Reset();
        pDlg->EnableButton(true);
        pDlg->SetButtonLabel(413); // manual
      }

      double secondBestRelevance = 0;
      for (int i = 0; i < scraper.GetAlbumCount(); ++i)
      {
        CMusicAlbumInfo& info = scraper.GetAlbum(i);
        double relevance = CUtil::AlbumRelevance(info.GetAlbum().strAlbum, strAlbum, info.GetAlbum().strArtist, strArtist);

        // if we're doing auto-selection (ie querying all albums at once, then allow 95->100% for perfect matches)
        // otherwise, perfect matches only
        if (relevance >= max(minRelevance, bestRelevance))
        { // we auto-select the best of these
          secondBestRelevance = bestRelevance;
          bestRelevance = relevance;
          bestMatch = i;
        }
        if (pDialog)
        {
          // set the label to [relevance]  album - artist
          CStdString strTemp;
          strTemp.Format("[%0.2f]  %s", relevance, info.GetTitle2());
          CFileItem item(strTemp);
          item.m_idepth = i; // use this to hold the index of the album in the scraper
          pDlg->Add(&item);
        }
      }
    }
    else
    {
      CMusicAlbumInfo& info = scraper.GetAlbum(0);
      double relevance = CUtil::AlbumRelevance(info.GetAlbum().strAlbum, strAlbum, info.GetAlbum().strArtist, strArtist);
      if (relevance < THRESHOLD)
      {
        m_musicDatabase.Close();
        return false; 
      }
   }

    iSelectedAlbum = bestMatch;
    if (pDialog && bestRelevance < THRESHOLD)
    {
      pDlg->Sort(false);
      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 strNewAlbum = strAlbum;
        if (!CGUIDialogKeyboard::ShowAndGetInput(strNewAlbum, g_localizeStrings.Get(16011), false)) return false;
        if (strNewAlbum == "") return false;

        CStdString strNewArtist = strArtist;
        if (!CGUIDialogKeyboard::ShowAndGetInput(strNewArtist, g_localizeStrings.Get(16025), false)) return false;

        pDialog->SetLine(0, strNewAlbum);
        pDialog->SetLine(1, strNewArtist);
        pDialog->Progress();

        m_musicDatabase.Close();
        return DownloadAlbumInfo(strPath,strArtist,strAlbum,bCanceled,albumInfo,pDialog);
      }
      iSelectedAlbum = pDlg->GetSelectedItem().m_idepth;
    }
  }
  else
  {
    m_musicDatabase.Close();
    return false;
  }

  scraper.LoadAlbuminfo(iSelectedAlbum);
  while (!scraper.Completed())
  {
    if (m_bStop)
    {
      scraper.Cancel();
      break;
    }
    Sleep(1);
  }

  if (scraper.Successfull())
  {
    albumInfo = scraper.GetAlbum(iSelectedAlbum);
    album = scraper.GetAlbum(iSelectedAlbum).GetAlbum();
    m_musicDatabase.SetAlbumInfo(params.GetAlbumId(), album, scraper.GetAlbum(iSelectedAlbum).GetSongs(),false);
  }
  else
  {
    m_musicDatabase.Close();
    return false;
  }

  // check thumb stuff
  if (album.thumbURL.m_url.size())
  {
    CStdString thumb;
    if (!m_musicDatabase.GetAlbumThumb(params.GetAlbumId(),thumb) || thumb.IsEmpty() || !XFILE::CFile::Exists(thumb))
    {
      thumb = CUtil::GetCachedAlbumThumb(album.strAlbum,album.strArtist);
      CScraperUrl::DownloadThumbnail(thumb,album.thumbURL.m_url[0]);
      m_musicDatabase.SaveAlbumThumb(params.GetAlbumId(), thumb);
    }
  }

  m_musicDatabase.Close();
  return true;
}
コード例 #4
0
ファイル: MusicInfoLoader.cpp プロジェクト: Castlecard/plex
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;
}