示例#1
0
bool CGUIDialogSongInfo::DownloadThumbnail(const CStdString &thumbFile)
{
  // TODO: Obtain the source...
  CStdString source;
  CHTTP http;
  http.Download(source, thumbFile);
  return true;
}
示例#2
0
bool CFanart::DownloadImage(const CStdString &url, const CStdString &destination) const
{
  // Ideally we'd just call CPicture::CacheImage() directly, but for some
  // reason curl doesn't seem to like downloading these for us
  CHTTP http;
#ifdef RESAMPLE_CACHED_IMAGES
  CStdString tempFile = _P("Z:\\fanart_download.jpg");
  if (http.Download(url, tempFile))
  { 
    CPicture pic;
    pic.CacheImage(tempFile, destination);
    XFILE::CFile::Delete(tempFile);
    return true;
  }
  return false;
#else
  return http.Download(url, destination);
#endif
}
示例#3
0
void CLastFmManager::CacheTrackThumb(const int nrInitialTracksToAdd)
{
  DWORD start = timeGetTime();
  CSingleLock lock(m_lockCache);
  int iNrCachedTracks = m_RadioTrackQueue->size();
  CPicture pic;
  CHTTP http;
  for (int i = 0; i < nrInitialTracksToAdd && i < iNrCachedTracks; i++)
  {
    CFileItemPtr item = (*m_RadioTrackQueue)[i];
    if (!item->GetMusicInfoTag()->Loaded())
    {
      //cache albumthumb, GetThumbnailImage contains the url to cache
      if (item->HasThumbnail())
      {
        CStdString coverUrl = item->GetThumbnailImage();
        CStdString crcFile;
        CStdString cachedFile;
        CStdString thumbFile;

        Crc32 crc;
        crc.ComputeFromLowerCase(coverUrl);
        crcFile.Format("%08x.tbn", (__int32)crc);
        CUtil::AddFileToFolder(_P(g_advancedSettings.m_cachePath), crcFile, cachedFile);
        CUtil::AddFileToFolder(g_settings.GetLastFMThumbFolder(), crcFile, thumbFile);
        item->SetThumbnailImage("");
        try
        {
          //download to temp, then make a thumb
          if (CFile::Exists(thumbFile) || (http.Download(coverUrl, cachedFile) && pic.DoCreateThumbnail(cachedFile, thumbFile)))
          {
            if (CFile::Exists(cachedFile)) CFile::Delete(cachedFile);
            item->SetThumbnailImage(thumbFile);
          }
        }
        catch(...)
        {
          CLog::Log(LOGERROR, "LastFmManager: exception while caching %s to %s.", coverUrl.c_str(), thumbFile.c_str());
        }
      }
      if (!item->HasThumbnail())
      {
        item->SetThumbnailImage("defaultAlbumCover.png");
      }
      item->GetMusicInfoTag()->SetLoaded();
    }
  }
  CLog::Log(LOGDEBUG, "%s: Done (time: %i ms)", __FUNCTION__, (int)(timeGetTime() - start));
}
示例#4
0
/// This method queries imdb for movie poster art associated with an imdb number
bool CMediaMonitor::imdb_GetMovieArt(CStdString& strPath, CStdString& strPictureUrl, CStdString& strImagePath)
{
  CFileItem item(strPath, false);
  item.SetVideoThumb();

  if (item.HasThumbnail())
  {
    strImagePath = item.GetThumbnailImage();
    return true;
  }

  CStdString strThum(item.GetCachedVideoThumb());

  CStdString strExtension;
  CUtil::GetExtension(strPictureUrl, strExtension);

  if (strExtension.IsEmpty())
  {
    return false;
  }

  CStdString strTemp;
  strTemp.Format("Z:\\ram_temp%s", strExtension.c_str());
  ::DeleteFile(strTemp.c_str());

  CHTTP http;
  http.Download(strPictureUrl, strTemp);

  try
  {
    CPicture picture;
    picture.DoCreateThumbnail(strTemp, strThum);
  }
  catch (...)
  {
    ::DeleteFile(strThum.c_str());
  }

  ::DeleteFile(strTemp.c_str());

  if (CFile::Exists(strThum.c_str()))
  {
    strImagePath = strThum;
    return true;
  }

  return false;
}
示例#5
0
bool CFanart::DownloadThumb(unsigned int index, const CStdString &strDestination) const
{
  if (index >= m_fanart.size())
    return false;

  CStdString thumbURL;
  if (!m_fanart[index].strPreview.IsEmpty())
  {
    thumbURL = CUtil::AddFileToFolder(m_url, m_fanart[index].strPreview);

    CHTTP http;
    if (http.Download(thumbURL, strDestination))
      return true;
  }

  // try downloading the image instead
  thumbURL = CUtil::AddFileToFolder(m_url, m_fanart[index].strImage);
  return DownloadImage(thumbURL, strDestination);
}
示例#6
0
void CDownloadQueue::Process()
{
  CLog::Log(LOGNOTICE, "DownloadQueue ready.");

  CHTTP http;
  bool bSuccess;

  while ( !m_bStop )
  {
    while ( CDownloadQueue::Size() > 0 )
    {
      EnterCriticalSection(&m_critical);

      // get the first item, but don't pop it from our queue
      // so that the download can be interrupted
      Command request = m_queue.front();

      LeaveCriticalSection(&m_critical);

      bool bFileRequest = request.content.length() > 0;
      DWORD dwSize = 0;

      if (bFileRequest)
      {
        ::DeleteFile(request.content.c_str());
        bSuccess = http.Download(request.location, request.content, &dwSize);
      }
      else
      {
        bSuccess = http.Get(request.location, request.content);
      }

      // now re-grab the item as we may have cancelled our download
      // while we were working
      EnterCriticalSection(&m_critical);

      request = m_queue.front();
      m_queue.pop();

      // if the request has been cancelled our observer will be NULL
      if (NULL != request.observer)
      {
        try
        {
          if (bFileRequest)
          {
            request.observer->OnFileComplete(request.ticket, request.content, dwSize,
                                            bSuccess ? IDownloadQueueObserver::Succeeded : IDownloadQueueObserver::Failed );
          }
          else
          {
            request.observer->OnContentComplete(request.ticket, request.content,
                                                bSuccess ? IDownloadQueueObserver::Succeeded : IDownloadQueueObserver::Failed );
          }
        }
        catch (...)
        {
          CLog::Log(LOGERROR, "exception while updating download observer.");

          if (bFileRequest)
          {
            ::DeleteFile(request.content.c_str());
          }
        }
      }
      LeaveCriticalSection(&m_critical);
    }

    Sleep(500);
  }

  CLog::Log(LOGNOTICE, "DownloadQueue terminated.");
}