コード例 #1
0
        // Attempts to load cover art for this movie from a given URL. Optionally
        // ignores minimum resolution restrictions
        public ImageLoadResults AddCoverFromURL(string url, bool ignoreRestrictions)
        {
            ImageLoadResults status;
            Cover            newCover = Cover.FromUrl(this, url, ignoreRestrictions, out status);

            if (status != ImageLoadResults.SUCCESS && status != ImageLoadResults.SUCCESS_REDUCED_SIZE)
            {
                return(status);
            }

            AlternateCovers.Add(newCover.Filename);
            GenerateThumbnail();
            commitNeeded = true;
            return(ImageLoadResults.SUCCESS);
        }
コード例 #2
0
        public bool AddCoverFromFile(string filename)
        {
            int    minWidth  = MovingPicturesCore.Settings.MinimumCoverWidth;
            int    minHeight = MovingPicturesCore.Settings.MinimumCoverHeight;
            string artFolder = MovingPicturesCore.Settings.CoverArtFolder;

            Image newCover = null;

            try {
                newCover = Image.FromFile(filename);
            }
            catch (OutOfMemoryException) {
                logger.Debug("Invalid image or image format not supported: " + filename);
            }
            catch (FileNotFoundException) {
                logger.Debug("File not found: " + filename);
            }

            if (newCover == null)
            {
                logger.Error("Failed loading cover artwork for '" + Title + "' [" + ID + "] from " + filename + ".");
                return(false);
            }

            // check if the image file is already in the cover folder
            FileInfo newFile         = new FileInfo(filename);
            bool     alreadyInFolder = newFile.Directory.FullName.Equals(new DirectoryInfo(artFolder).FullName);

            // if the file isnt in the cover folder, generate a name and save it there
            if (!alreadyInFolder)
            {
                string safeName    = Title.Replace(' ', '.').ToValidFilename() + "-" + Year;
                string newFileName = artFolder + "\\{" + safeName + "} [" + filename.GetHashCode() + "].jpg";

                if (!File.Exists(newFileName) && saveImage(newFileName, newCover))
                {
                    AlternateCovers.Add(newFileName);
                    commitNeeded = true;
                }
                else
                {
                    return(false);
                }
            }

            // if it's already in the folder, just store the filename in the db
            else
            {
                if (!AlternateCovers.Contains(filename))
                {
                    AlternateCovers.Add(filename);
                    commitNeeded = true;
                }
                else
                {
                    return(false);
                }
            }

            // create a thumbnail for the cover
            newCover.Dispose();
            commitNeeded = true;
            GenerateThumbnail();
            logger.Info("Added cover art for '" + Title + "' from: " + filename);

            return(true);
        }