Пример #1
0
bool CScraperUrl::DownloadThumbnail(const CStdString &thumb, const CScraperUrl::SUrlEntry& entry)
{
    if (entry.m_url.IsEmpty())
        return false;

    CHTTP http;
    http.SetReferer(entry.m_spoof);
    string thumbData;
    if (http.Get(entry.m_url, thumbData))
    {
        try
        {
            CPicture picture;
            picture.CreateThumbnailFromMemory((const BYTE *)thumbData.c_str(), thumbData.size(), CUtil::GetExtension(entry.m_url), thumb);
            return true;
        }
        catch (...)
        {
            ::DeleteFile(thumb.c_str());
        }
    }
    return false;
}
Пример #2
0
bool CID3Tag::Parse()
{
  ParseReplayGainInfo();

  CMusicInfoTag& tag=m_musicInfoTag;

  tag.SetTrackNumber(GetTrack());

  tag.SetPartOfSet(GetPartOfSet());

  tag.SetGenre(GetGenre());

  tag.SetTitle(GetTitle());

  tag.SetArtist(GetArtist());

  tag.SetAlbum(GetAlbum());

  tag.SetAlbumArtist(GetAlbumArtist());

  tag.SetComment(GetComment());

  tag.SetLyrics(GetLyrics());

  tag.SetRating(GetRating());

  if (!tag.GetTitle().IsEmpty() || !tag.GetArtist().IsEmpty() || !tag.GetAlbum().IsEmpty())
    tag.SetLoaded();

  SYSTEMTIME dateTime;
  dateTime.wYear = atoi(GetYear());
  tag.SetReleaseDate(dateTime);

  id3_length_t lenght;
  const LPCSTR pb=(LPCSTR)GetUniqueFileIdentifier("http://musicbrainz.org", &lenght);
  if (pb)
  {
    CStdString strTrackId(pb, lenght);
    tag.SetMusicBrainzTrackID(strTrackId);
  }

  tag.SetMusicBrainzArtistID(GetUserText("MusicBrainz Artist Id"));
  tag.SetMusicBrainzAlbumID(GetUserText("MusicBrainz Album Id"));
  tag.SetMusicBrainzAlbumArtistID(GetUserText("MusicBrainz Album Artist Id"));
  tag.SetMusicBrainzTRMID(GetUserText("MusicBrainz TRM Id"));

  // extract Cover Art and save as album thumb
  bool bFound = false;
  id3_picture_type pictype = ID3_PICTURE_TYPE_COVERFRONT;
  if (HasPicture(pictype))
  {
    bFound = true;
  }
  else
  {
    pictype = ID3_PICTURE_TYPE_OTHER;
    if (HasPicture(pictype))
      bFound = true;
    else if (GetFirstNonStandardPictype(&pictype))
      bFound = true;
  }

  // if we don't have an album tag, cache with the full file path so that
  // other non-tagged files don't get this album image
  CStdString strCoverArt;
  if (!tag.GetAlbum().IsEmpty() && (!tag.GetAlbumArtist().IsEmpty() || !tag.GetArtist().IsEmpty()))
    strCoverArt = CUtil::GetCachedAlbumThumb(tag.GetAlbum(), tag.GetAlbumArtist().IsEmpty() ? tag.GetArtist() : tag.GetAlbumArtist());
  else
    strCoverArt = CUtil::GetCachedMusicThumb(tag.GetURL());
  if (bFound && !CUtil::ThumbExists(strCoverArt))
  {
    CStdString strExtension=GetPictureMimeType(pictype);

    int nPos = strExtension.Find('/');
    if (nPos > -1)
      strExtension.Delete(0, nPos + 1);

    id3_length_t nBufSize = 0;
    const BYTE* pPic = GetPictureData(pictype, &nBufSize );
    if (pPic != NULL && nBufSize > 0)
    {
      CPicture pic;
      if (pic.CreateThumbnailFromMemory(pPic, nBufSize, strExtension, strCoverArt))
      {
        CUtil::ThumbCacheAdd(strCoverArt, true);
      }
      else
      {
        CUtil::ThumbCacheAdd(strCoverArt, false);
        CLog::Log(LOGERROR, "Tag loader mp3: Unable to create album art for %s (extension=%s, size=%lu)", tag.GetURL().c_str(), strExtension.c_str(), nBufSize);
      }
    }
  }

  return tag.Loaded();
}