Example #1
0
        public static BasicArt FromUrl(DBBasicInfo mv, string url, bool ignoreRestrictions, out ImageLoadResults status)
        {
            ImageSize minSize = null;
            ImageSize maxSize = new ImageSize();

            if (mvs == null)
            {
                mvs = mv;
            }
            if (!ignoreRestrictions)
            {
                minSize = new ImageSize();
                if (mvs.GetType() == typeof(DBTrackInfo))
                {
                    minSize.Width  = mvCentralCore.Settings.MinimumTrackWidth;
                    minSize.Height = mvCentralCore.Settings.MinimumTrackHeight;
                }
                if (mvs.GetType() == typeof(DBAlbumInfo))
                {
                    minSize.Width  = mvCentralCore.Settings.MinimumAlbumWidth;
                    minSize.Height = mvCentralCore.Settings.MinimumAlbumHeight;
                }
                if (mvs.GetType() == typeof(DBArtistInfo))
                {
                    minSize.Width  = mvCentralCore.Settings.MinimumArtistWidth;
                    minSize.Height = mvCentralCore.Settings.MinimumArtistHeight;
                }
            }

            bool redownload = false;

            if (mvs.GetType() == typeof(DBTrackInfo))
            {
                maxSize.Width  = mvCentralCore.Settings.MaximumTrackWidth;
                maxSize.Height = mvCentralCore.Settings.MaximumTrackHeight;
                redownload     = mvCentralCore.Settings.RedownloadTrackArtwork;
            }
            if (mvs.GetType() == typeof(DBAlbumInfo))
            {
                maxSize.Width  = mvCentralCore.Settings.MaximumAlbumWidth;
                maxSize.Height = mvCentralCore.Settings.MaximumAlbumHeight;
                redownload     = mvCentralCore.Settings.RedownloadAlbumArtwork;
            }
            if (mvs.GetType() == typeof(DBArtistInfo))
            {
                maxSize.Width  = mvCentralCore.Settings.MaximumArtistWidth;
                maxSize.Height = mvCentralCore.Settings.MaximumArtistHeight;
                redownload     = mvCentralCore.Settings.RedownloadArtistArtwork;
            }

            BasicArt newTrack = new BasicArt(mv);

            newTrack.Filename = GenerateFilename(url);
            status            = newTrack.FromUrl(url, ignoreRestrictions, minSize, maxSize, redownload);

            switch (status)
            {
            case ImageLoadResults.SUCCESS:
                logger.Info("Added art for \"{0}\" from: {1}", mv.Basic, url);
                break;

            case ImageLoadResults.SUCCESS_REDUCED_SIZE:
                logger.Info("Added resized art for \"{0}\" from: {1}", mv.Basic, url);
                break;

            case ImageLoadResults.FAILED_ALREADY_LOADED:
                logger.Debug("Art for \"{0}\" from the following URL is already loaded: {1}", mv.Basic, url);
                return(null);

            case ImageLoadResults.FAILED_TOO_SMALL:
                logger.Debug("Downloaded art for \"{0}\" failed minimum resolution requirements: {1}", mv.Basic, url);
                return(null);

            case ImageLoadResults.FAILED:
                logger.Error("Failed downloading art for \"{0}\": {1}", mv.Basic, url);
                return(null);
            }

            return(newTrack);
        }
Example #2
0
        public static BasicArt FromFile(DBBasicInfo mv, string path, bool ignoreRestrictions, out ImageLoadResults status)
        {
            ImageSize minSize = null;
            ImageSize maxSize = new ImageSize();
            if (mvs == null) mvs = mv;
            if (!ignoreRestrictions)
            {
                minSize = new ImageSize();
                if (mvs.GetType() == typeof(DBTrackInfo))
                {
                    minSize.Width = mvCentralCore.Settings.MinimumTrackWidth;
                    minSize.Height = mvCentralCore.Settings.MinimumTrackHeight;
                }
                if (mvs.GetType() == typeof(DBAlbumInfo))
                {
                    minSize.Width = mvCentralCore.Settings.MinimumAlbumWidth;
                    minSize.Height = mvCentralCore.Settings.MinimumAlbumHeight;
                }
                if (mvs.GetType() == typeof(DBArtistInfo))
                {
                    minSize.Width = mvCentralCore.Settings.MinimumArtistWidth;
                    minSize.Height = mvCentralCore.Settings.MinimumArtistHeight;
                }
            }

            bool redownload = false;
            if (mvs.GetType() == typeof(DBTrackInfo))
            {
                maxSize.Width = mvCentralCore.Settings.MaximumTrackWidth;
                maxSize.Height = mvCentralCore.Settings.MaximumTrackHeight;
                redownload = mvCentralCore.Settings.RedownloadTrackArtwork;
            }
            if (mvs.GetType() == typeof(DBAlbumInfo))
            {
                maxSize.Width = mvCentralCore.Settings.MaximumAlbumWidth;
                maxSize.Height = mvCentralCore.Settings.MaximumAlbumHeight;
                redownload = mvCentralCore.Settings.RedownloadAlbumArtwork;
            }
            if (mvs.GetType() == typeof(DBArtistInfo))
            {
                maxSize.Width = mvCentralCore.Settings.MaximumArtistWidth;
                maxSize.Height = mvCentralCore.Settings.MaximumArtistHeight;
                redownload = mvCentralCore.Settings.RedownloadArtistArtwork;
            }

            BasicArt newTrack = new BasicArt(mv);
            newTrack.Filename = GenerateFilename(path);
            status = newTrack.FromFile(path, ignoreRestrictions, minSize, maxSize, redownload);

            string threadID = Thread.CurrentThread.ManagedThreadId.ToString();

            switch (status)
            {
                case ImageLoadResults.SUCCESS:
                    logger.Info("Added art for \"{0}\" from: {1}", mv.Basic, path);
                    break;
                case ImageLoadResults.SUCCESS_REDUCED_SIZE:
                    logger.Info("Added resized art for \"{1}\" from: {2}", mv.Basic, path);
                    break;
                case ImageLoadResults.FAILED_ALREADY_LOADED:
                    logger.Debug("art for \"{0}\" from the following path is already loaded: {1}", mv.Basic, path);
                    return null;
                case ImageLoadResults.FAILED_TOO_SMALL:
                    logger.Debug("Downloaded art for \"{0}\" failed minimum resolution requirements: {1}", mv.Basic, path);
                    return null;
                case ImageLoadResults.FAILED:
                    logger.Error("(Failed art for \"{0}\": {1}", mv.Basic, path);
                    return null;
            }

            return newTrack;
        }