private void PerformRequest()
        {
            MusicTag musicTag       = _filetag;
            string   filename       = _filename;
            string   strFolderThumb = string.Empty;

            strFolderThumb = MediaPortal.Util.Utils.GetLocalFolderThumb(filename);

            string strRemoteFolderThumb = string.Empty;

            //strRemoteFolderThumb = String.Format(@"{0}\folder.jpg", MediaPortal.Util.Utils.RemoveTrailingSlash(filename));
            strRemoteFolderThumb = MediaPortal.Util.Utils.GetFolderThumb(filename);

            if (!File.Exists(strRemoteFolderThumb))
            {
                // no folder.jpg in this share but maybe there's downloaded album art we can save now.
                try
                {
                    if (musicTag != null && musicTag.Album != string.Empty && musicTag.Artist != string.Empty)
                    {
                        string formattedArtist = musicTag.Artist.Trim(trimChars);
                        string formattedAlbum  = musicTag.Album.Trim(trimChars);

                        string albumThumb = Util.Utils.GetAlbumThumbName(formattedArtist, formattedAlbum);

                        if (File.Exists(albumThumb))
                        {
                            string largeAlbumThumb = Util.Utils.ConvertToLargeCoverArt(albumThumb);
                            if (File.Exists(largeAlbumThumb))
                            {
                                File.Copy(largeAlbumThumb, strRemoteFolderThumb, false);
                                File.SetAttributes(strRemoteFolderThumb,
                                                   File.GetAttributes(strRemoteFolderThumb) | FileAttributes.Hidden);
                            }
                            else
                            {
                                File.Copy(albumThumb, strRemoteFolderThumb, false);
                                File.SetAttributes(strRemoteFolderThumb,
                                                   File.GetAttributes(strRemoteFolderThumb) | FileAttributes.Hidden);
                            }
                            Log.Info("GUIMusicFiles: Using album art for missing folder thumb {0}", strRemoteFolderThumb);

                            // now we need to cache that new thumb, too
                            if (File.Exists(strRemoteFolderThumb))
                            {
                                FolderThumbCacher cacheNow = new FolderThumbCacher(Path.GetDirectoryName(strRemoteFolderThumb), false);
                                File.SetAttributes(strRemoteFolderThumb,
                                                   File.GetAttributes(strRemoteFolderThumb) | FileAttributes.Hidden);
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    Log.Error("FolderThumbCreator:PerformRequest {0}", ex.Message);
                    return;
                }
            }
        }
Esempio n. 2
0
    public static string GetCoverArt(bool isfolder, string filename, MusicTag tag)
    {
      string strAlbumName = string.Empty;
      string strArtistName = string.Empty;
      if (tag != null)
      {
        if (!string.IsNullOrEmpty(tag.Album))
        {
          strAlbumName = tag.Album;
        }
        if (!string.IsNullOrEmpty(tag.Artist))
        {
          strArtistName = tag.Artist;
        }
      }

      // attempt to pick up album thumb if already scanned 
      string strThumb = Util.Utils.GetAlbumThumbName(strArtistName, strAlbumName);
      if (Util.Utils.FileExistsInCache(strThumb))
      {
        if (_createMissingFolderThumbs && _createMissingFolderThumbCache)
        {
          string folderThumb = Util.Utils.GetFolderThumb(filename);
          if (!Util.Utils.FileExistsInCache(folderThumb))
          {
            FolderThumbCreator thumbCreator = new FolderThumbCreator(filename, tag);
          }
        }
        return strThumb;
      }

      // attempt to load folder.jpg
      if (!Util.Utils.IsAVStream(filename))
      {
        string strFolderThumb = string.Empty;
        if (isfolder)
        {
          strFolderThumb = Util.Utils.GetLocalFolderThumbForDir(filename);
        }
        else
        {
          strFolderThumb = Util.Utils.GetLocalFolderThumb(filename);
        }

        if (Util.Utils.FileExistsInCache(strFolderThumb))
        {
          return strFolderThumb;
        }
        else
        {
          if (_createMissingFolderThumbCache)
          {
            FolderThumbCacher thumbworker = new FolderThumbCacher(filename, false);
          }
        }
      }

      //TODO: consider lookup of embedded artwork

      return string.Empty;
    }
Esempio n. 3
0
    protected bool SaveCoverArtImage(AlbumInfo albumInfo, string aAlbumSharePath, bool aSaveToAlbumShare,
                                     bool aSaveToAlbumThumbFolder)
    {
      bool result = false;
      bool isCdOrDVD = Util.Utils.IsDVD(aAlbumSharePath);
      string sharePath = Util.Utils.RemoveTrailingSlash(aAlbumSharePath);

      try
      {
        Image coverImg = AmazonWebservice.GetImageFromURL(albumInfo.Image);
        string thumbPath = Util.Utils.GetAlbumThumbName(albumInfo.Artist, albumInfo.Album);

        if (thumbPath.Length == 0 || coverImg == null)
        {
          return false;
        }

        //if (bSaveToThumbsFolder)
        if (aSaveToAlbumShare && !isCdOrDVD)
        {
          string folderjpg = String.Format(@"{0}\folder.jpg", sharePath);

          if (Util.Utils.FileExistsInCache(folderjpg))
          {
            File.Delete(folderjpg);
          }

          coverImg.Save(folderjpg);
          File.SetAttributes(folderjpg, File.GetAttributes(folderjpg) | FileAttributes.Hidden);
          // no need to check for that option as it is the user's decision.   if (_createMissingFolderThumbCache)
          FolderThumbCacher thumbworker = new FolderThumbCacher(sharePath, true);
          result = true;
        }

        if (aSaveToAlbumThumbFolder || isCdOrDVD)
        {
          if (Util.Utils.FileExistsInCache(thumbPath))
          {
            File.Delete(thumbPath);
          }

          if (Util.Picture.CreateThumbnail(coverImg, thumbPath, (int)Thumbs.ThumbResolution,
                                           (int)Thumbs.ThumbResolution, 0, Thumbs.SpeedThumbsSmall))
          {
            result = true;
            Util.Picture.CreateThumbnail(coverImg, thumbPath, (int)Thumbs.ThumbLargeResolution,
                                         (int)Thumbs.ThumbLargeResolution, 0, Thumbs.SpeedThumbsLarge);
          }
        }
      }

      catch
      {
        result = false;
      }

      return result;
    }
    /// <summary>
    /// Returns the Folder Thumb
    /// </summary>
    /// <param name="isfolder">Indicator, if we are on a folder</param>
    /// <param name="filename">The Song Filename</param>
    /// <returns>String with the name of the Cover Art file to be used</returns>
    private static string GetFolderCoverArt(bool isfolder, string filename)
    {
      // Attempt to load folder.jpg
      if (!Util.Utils.IsAVStream(filename))
      {
        string strFolderThumb;
        if (isfolder)
        {
          strFolderThumb = Util.Utils.GetLocalFolderThumbForDir(filename);
        }
        else
        {
          strFolderThumb = Util.Utils.GetLocalFolderThumb(filename);
        }

        if (Util.Utils.FileExistsInCache(strFolderThumb))
        {
          return strFolderThumb;
        }
        else
        {
          if (_createMissingFolderThumbCache)
          {
            var thumbworker = new FolderThumbCacher(filename, false);
          }
        }
      }
      return string.Empty;
    }
    private void PerformRequest()
    {
      MusicTag musicTag = _filetag;
      string filename = _filename;
      string strFolderThumb = string.Empty;
      strFolderThumb = MediaPortal.Util.Utils.GetLocalFolderThumb(filename);

      string strRemoteFolderThumb = string.Empty;
      //strRemoteFolderThumb = String.Format(@"{0}\folder.jpg", MediaPortal.Util.Utils.RemoveTrailingSlash(filename));
      strRemoteFolderThumb = MediaPortal.Util.Utils.GetFolderThumb(filename);

      if (!File.Exists(strRemoteFolderThumb))
      {
        // no folder.jpg in this share but maybe there's downloaded album art we can save now.
        try
        {
          if (musicTag != null && musicTag.Album != string.Empty && musicTag.Artist != string.Empty)
          {
            string formattedArtist = musicTag.Artist.Trim(trimChars);
            string formattedAlbum = musicTag.Album.Trim(trimChars);

            string albumThumb = Util.Utils.GetAlbumThumbName(formattedArtist, formattedAlbum);

            if (File.Exists(albumThumb))
            {
              string largeAlbumThumb = Util.Utils.ConvertToLargeCoverArt(albumThumb);
              if (File.Exists(largeAlbumThumb))
              {
                File.Copy(largeAlbumThumb, strRemoteFolderThumb, false);
                File.SetAttributes(strRemoteFolderThumb,
                                   File.GetAttributes(strRemoteFolderThumb) | FileAttributes.Hidden);
              }
              else
              {
                File.Copy(albumThumb, strRemoteFolderThumb, false);
                File.SetAttributes(strRemoteFolderThumb,
                                   File.GetAttributes(strRemoteFolderThumb) | FileAttributes.Hidden);
              }
              Log.Info("GUIMusicFiles: Using album art for missing folder thumb {0}", strRemoteFolderThumb);

              // now we need to cache that new thumb, too
              if (File.Exists(strRemoteFolderThumb))
              {
                FolderThumbCacher cacheNow = new FolderThumbCacher(Path.GetDirectoryName(strRemoteFolderThumb), false);
                File.SetAttributes(strRemoteFolderThumb,
                                   File.GetAttributes(strRemoteFolderThumb) | FileAttributes.Hidden);
              }
            }
          }
        }
        catch (Exception)
        {
          return;
        }
      }
    }