예제 #1
0
        private void PopulateImages(IHasImages item, List <LocalImageInfo> images, List <FileSystemMetadata> files, bool supportParentSeriesFiles, IDirectoryService directoryService)
        {
            if (supportParentSeriesFiles)
            {
                var season = item as Season;

                if (season != null)
                {
                    PopulateSeasonImagesFromSeriesFolder(season, images, directoryService);
                }
            }

            var imagePrefix     = item.FileNameWithoutExtension + "-";
            var isInMixedFolder = item.DetectIsInMixedFolder();

            PopulatePrimaryImages(item, images, files, imagePrefix, isInMixedFolder);

            AddImage(files, images, "logo", imagePrefix, isInMixedFolder, ImageType.Logo);
            AddImage(files, images, "clearart", imagePrefix, isInMixedFolder, ImageType.Art);

            // For music albums, prefer cdart before disc
            if (item is MusicAlbum)
            {
                AddImage(files, images, "cdart", imagePrefix, isInMixedFolder, ImageType.Disc);
                AddImage(files, images, "disc", imagePrefix, isInMixedFolder, ImageType.Disc);
            }
            else
            {
                AddImage(files, images, "disc", imagePrefix, isInMixedFolder, ImageType.Disc);
                AddImage(files, images, "cdart", imagePrefix, isInMixedFolder, ImageType.Disc);
            }

            AddImage(files, images, "box", imagePrefix, isInMixedFolder, ImageType.Box);
            AddImage(files, images, "back", imagePrefix, isInMixedFolder, ImageType.BoxRear);
            AddImage(files, images, "boxrear", imagePrefix, isInMixedFolder, ImageType.BoxRear);
            AddImage(files, images, "menu", imagePrefix, isInMixedFolder, ImageType.Menu);

            // Banner
            AddImage(files, images, "banner", imagePrefix, isInMixedFolder, ImageType.Banner);

            // Thumb
            AddImage(files, images, "landscape", imagePrefix, isInMixedFolder, ImageType.Thumb);
            AddImage(files, images, "thumb", imagePrefix, isInMixedFolder, ImageType.Thumb);

            PopulateBackdrops(item, images, files, imagePrefix, isInMixedFolder, directoryService);
            PopulateScreenshots(images, files, imagePrefix, isInMixedFolder);
        }
예제 #2
0
        /// <summary>
        /// Gets the compatible save paths.
        /// </summary>
        /// <param name="item">The item.</param>
        /// <param name="type">The type.</param>
        /// <param name="imageIndex">Index of the image.</param>
        /// <param name="mimeType">Type of the MIME.</param>
        /// <returns>IEnumerable{System.String}.</returns>
        /// <exception cref="System.ArgumentNullException">imageIndex</exception>
        private string[] GetCompatibleSavePaths(IHasImages item, ImageType type, int?imageIndex, string mimeType)
        {
            var season = item as Season;

            var extension = MimeTypes.ToExtension(mimeType);

            // Backdrop paths
            if (type == ImageType.Backdrop)
            {
                if (!imageIndex.HasValue)
                {
                    throw new ArgumentNullException("imageIndex");
                }

                if (imageIndex.Value == 0)
                {
                    if (item.DetectIsInMixedFolder())
                    {
                        return(new[] { GetSavePathForItemInMixedFolder(item, type, "fanart", extension) });
                    }

                    if (season != null && season.IndexNumber.HasValue)
                    {
                        var seriesFolder = season.SeriesPath;

                        var seasonMarker = season.IndexNumber.Value == 0
                                               ? "-specials"
                                               : season.IndexNumber.Value.ToString("00", UsCulture);

                        var imageFilename = "season" + seasonMarker + "-fanart" + extension;

                        return(new[] { Path.Combine(seriesFolder, imageFilename) });
                    }

                    return(new[]
                    {
                        Path.Combine(item.ContainingFolderPath, "fanart" + extension)
                    });
                }

                var outputIndex = imageIndex.Value;

                if (item.DetectIsInMixedFolder())
                {
                    return(new[] { GetSavePathForItemInMixedFolder(item, type, "fanart" + outputIndex.ToString(UsCulture), extension) });
                }

                var extraFanartFilename = GetBackdropSaveFilename(item.GetImages(ImageType.Backdrop), "fanart", "fanart", outputIndex);

                var list = new List <string>
                {
                    Path.Combine(item.ContainingFolderPath, "extrafanart", extraFanartFilename + extension)
                };

                if (EnableExtraThumbsDuplication)
                {
                    list.Add(Path.Combine(item.ContainingFolderPath, "extrathumbs", "thumb" + outputIndex.ToString(UsCulture) + extension));
                }
                return(list.ToArray());
            }

            if (type == ImageType.Primary)
            {
                if (season != null && season.IndexNumber.HasValue)
                {
                    var seriesFolder = season.SeriesPath;

                    var seasonMarker = season.IndexNumber.Value == 0
                                           ? "-specials"
                                           : season.IndexNumber.Value.ToString("00", UsCulture);

                    var imageFilename = "season" + seasonMarker + "-poster" + extension;

                    return(new[] { Path.Combine(seriesFolder, imageFilename) });
                }

                if (item is Episode)
                {
                    var seasonFolder = Path.GetDirectoryName(item.Path);

                    var imageFilename = _fileSystem.GetFileNameWithoutExtension(item.Path) + "-thumb" + extension;

                    return(new[] { Path.Combine(seasonFolder, imageFilename) });
                }

                if (item.DetectIsInMixedFolder() || item is MusicVideo)
                {
                    return(new[] { GetSavePathForItemInMixedFolder(item, type, string.Empty, extension) });
                }

                if (item is MusicAlbum || item is MusicArtist)
                {
                    return(new[] { Path.Combine(item.ContainingFolderPath, "folder" + extension) });
                }

                return(new[] { Path.Combine(item.ContainingFolderPath, "poster" + extension) });
            }

            // All other paths are the same
            return(new[] { GetStandardSavePath(item, type, imageIndex, mimeType, true) });
        }
예제 #3
0
        /// <summary>
        /// Gets the save path.
        /// </summary>
        /// <param name="item">The item.</param>
        /// <param name="type">The type.</param>
        /// <param name="imageIndex">Index of the image.</param>
        /// <param name="mimeType">Type of the MIME.</param>
        /// <param name="saveLocally">if set to <c>true</c> [save locally].</param>
        /// <returns>System.String.</returns>
        /// <exception cref="System.ArgumentNullException">
        /// imageIndex
        /// or
        /// imageIndex
        /// </exception>
        private string GetStandardSavePath(IHasImages item, ImageType type, int?imageIndex, string mimeType, bool saveLocally)
        {
            var season    = item as Season;
            var extension = MimeTypes.ToExtension(mimeType);

            if (string.IsNullOrWhiteSpace(extension))
            {
                throw new ArgumentException(string.Format("Unable to determine image file extension from mime type {0}", mimeType));
            }

            if (type == ImageType.Thumb && saveLocally)
            {
                if (season != null && season.IndexNumber.HasValue)
                {
                    var seriesFolder = season.SeriesPath;

                    var seasonMarker = season.IndexNumber.Value == 0
                                           ? "-specials"
                                           : season.IndexNumber.Value.ToString("00", UsCulture);

                    var imageFilename = "season" + seasonMarker + "-landscape" + extension;

                    return(Path.Combine(seriesFolder, imageFilename));
                }

                if (item.DetectIsInMixedFolder())
                {
                    return(GetSavePathForItemInMixedFolder(item, type, "landscape", extension));
                }

                return(Path.Combine(item.ContainingFolderPath, "landscape" + extension));
            }

            if (type == ImageType.Banner && saveLocally)
            {
                if (season != null && season.IndexNumber.HasValue)
                {
                    var seriesFolder = season.SeriesPath;

                    var seasonMarker = season.IndexNumber.Value == 0
                                           ? "-specials"
                                           : season.IndexNumber.Value.ToString("00", UsCulture);

                    var imageFilename = "season" + seasonMarker + "-banner" + extension;

                    return(Path.Combine(seriesFolder, imageFilename));
                }
            }

            string filename;
            var    folderName = item is MusicAlbum ||
                                item is MusicArtist ||
                                item is PhotoAlbum ||
                                (saveLocally && _config.Configuration.ImageSavingConvention == ImageSavingConvention.Legacy) ?
                                "folder" :
                                "poster";

            switch (type)
            {
            case ImageType.Art:
                filename = "clearart";
                break;

            case ImageType.BoxRear:
                filename = "back";
                break;

            case ImageType.Thumb:
                filename = "landscape";
                break;

            case ImageType.Disc:
                filename = item is MusicAlbum ? "cdart" : "disc";
                break;

            case ImageType.Primary:
                filename = item is Episode?_fileSystem.GetFileNameWithoutExtension(item.Path) : folderName;

                break;

            case ImageType.Backdrop:
                filename = GetBackdropSaveFilename(item.GetImages(type), "backdrop", "backdrop", imageIndex);
                break;

            case ImageType.Screenshot:
                filename = GetBackdropSaveFilename(item.GetImages(type), "screenshot", "screenshot", imageIndex);
                break;

            default:
                filename = type.ToString().ToLower();
                break;
            }

            if (string.Equals(extension, ".jpeg", StringComparison.OrdinalIgnoreCase))
            {
                extension = ".jpg";
            }

            extension = extension.ToLower();

            string path = null;

            if (saveLocally)
            {
                if (type == ImageType.Primary && item is Episode)
                {
                    path = Path.Combine(Path.GetDirectoryName(item.Path), "metadata", filename + extension);
                }

                else if (item.DetectIsInMixedFolder())
                {
                    path = GetSavePathForItemInMixedFolder(item, type, filename, extension);
                }

                if (string.IsNullOrEmpty(path))
                {
                    path = Path.Combine(item.ContainingFolderPath, filename + extension);
                }
            }

            // None of the save local conditions passed, so store it in our internal folders
            if (string.IsNullOrEmpty(path))
            {
                if (string.IsNullOrEmpty(filename))
                {
                    filename = folderName;
                }
                path = Path.Combine(item.GetInternalMetadataPath(), filename + extension);
            }

            return(path);
        }
예제 #4
0
파일: ImageSaver.cs 프로젝트: t-andre/Emby
        /// <summary>
        /// Gets the compatible save paths.
        /// </summary>
        /// <param name="item">The item.</param>
        /// <param name="type">The type.</param>
        /// <param name="imageIndex">Index of the image.</param>
        /// <param name="mimeType">Type of the MIME.</param>
        /// <returns>IEnumerable{System.String}.</returns>
        /// <exception cref="System.ArgumentNullException">imageIndex</exception>
        private string[] GetCompatibleSavePaths(IHasImages item, ImageType type, int? imageIndex, string mimeType)
        {
            var season = item as Season;

            var extension = MimeTypes.ToExtension(mimeType);

            // Backdrop paths
            if (type == ImageType.Backdrop)
            {
                if (!imageIndex.HasValue)
                {
                    throw new ArgumentNullException("imageIndex");
                }

                if (imageIndex.Value == 0)
                {
                    if (item.DetectIsInMixedFolder())
                    {
                        return new[] { GetSavePathForItemInMixedFolder(item, type, "fanart", extension) };
                    }

                    if (season != null && season.IndexNumber.HasValue)
                    {
                        var seriesFolder = season.SeriesPath;

                        var seasonMarker = season.IndexNumber.Value == 0
                                               ? "-specials"
                                               : season.IndexNumber.Value.ToString("00", UsCulture);

                        var imageFilename = "season" + seasonMarker + "-fanart" + extension;

                        return new[] { Path.Combine(seriesFolder, imageFilename) };
                    }

                    return new[]
                        {
                            Path.Combine(item.ContainingFolderPath, "fanart" + extension)
                        };
                }

                var outputIndex = imageIndex.Value;

                if (item.DetectIsInMixedFolder())
                {
                    return new[] { GetSavePathForItemInMixedFolder(item, type, "fanart" + outputIndex.ToString(UsCulture), extension) };
                }

                var extraFanartFilename = GetBackdropSaveFilename(item.GetImages(ImageType.Backdrop), "fanart", "fanart", outputIndex);

                var list = new List<string>
                {
                    Path.Combine(item.ContainingFolderPath, "extrafanart", extraFanartFilename + extension)
                };

                if (EnableExtraThumbsDuplication)
                {
                    list.Add(Path.Combine(item.ContainingFolderPath, "extrathumbs", "thumb" + outputIndex.ToString(UsCulture) + extension));
                }
                return list.ToArray();
            }

            if (type == ImageType.Primary)
            {
                if (season != null && season.IndexNumber.HasValue)
                {
                    var seriesFolder = season.SeriesPath;

                    var seasonMarker = season.IndexNumber.Value == 0
                                           ? "-specials"
                                           : season.IndexNumber.Value.ToString("00", UsCulture);

                    var imageFilename = "season" + seasonMarker + "-poster" + extension;

                    return new[] { Path.Combine(seriesFolder, imageFilename) };
                }

                if (item is Episode)
                {
                    var seasonFolder = Path.GetDirectoryName(item.Path);

                    var imageFilename = _fileSystem.GetFileNameWithoutExtension(item.Path) + "-thumb" + extension;

                    return new[] { Path.Combine(seasonFolder, imageFilename) };
                }

                if (item.DetectIsInMixedFolder() || item is MusicVideo)
                {
                    return new[] { GetSavePathForItemInMixedFolder(item, type, string.Empty, extension) };
                }

                if (item is MusicAlbum || item is MusicArtist)
                {
                    return new[] { Path.Combine(item.ContainingFolderPath, "folder" + extension) };
                }

                return new[] { Path.Combine(item.ContainingFolderPath, "poster" + extension) };
            }

            // All other paths are the same
            return new[] { GetStandardSavePath(item, type, imageIndex, mimeType, true) };
        }
예제 #5
0
파일: ImageSaver.cs 프로젝트: t-andre/Emby
        /// <summary>
        /// Gets the save path.
        /// </summary>
        /// <param name="item">The item.</param>
        /// <param name="type">The type.</param>
        /// <param name="imageIndex">Index of the image.</param>
        /// <param name="mimeType">Type of the MIME.</param>
        /// <param name="saveLocally">if set to <c>true</c> [save locally].</param>
        /// <returns>System.String.</returns>
        /// <exception cref="System.ArgumentNullException">
        /// imageIndex
        /// or
        /// imageIndex
        /// </exception>
        private string GetStandardSavePath(IHasImages item, ImageType type, int? imageIndex, string mimeType, bool saveLocally)
        {
            var season = item as Season;
            var extension = MimeTypes.ToExtension(mimeType);

            if (string.IsNullOrWhiteSpace(extension))
            {
                throw new ArgumentException(string.Format("Unable to determine image file extension from mime type {0}", mimeType));
            }

            if (type == ImageType.Thumb && saveLocally)
            {
                if (season != null && season.IndexNumber.HasValue)
                {
                    var seriesFolder = season.SeriesPath;

                    var seasonMarker = season.IndexNumber.Value == 0
                                           ? "-specials"
                                           : season.IndexNumber.Value.ToString("00", UsCulture);

                    var imageFilename = "season" + seasonMarker + "-landscape" + extension;

                    return Path.Combine(seriesFolder, imageFilename);
                }

                if (item.DetectIsInMixedFolder())
                {
                    return GetSavePathForItemInMixedFolder(item, type, "landscape", extension);
                }

                return Path.Combine(item.ContainingFolderPath, "landscape" + extension);
            }

            if (type == ImageType.Banner && saveLocally)
            {
                if (season != null && season.IndexNumber.HasValue)
                {
                    var seriesFolder = season.SeriesPath;

                    var seasonMarker = season.IndexNumber.Value == 0
                                           ? "-specials"
                                           : season.IndexNumber.Value.ToString("00", UsCulture);

                    var imageFilename = "season" + seasonMarker + "-banner" + extension;

                    return Path.Combine(seriesFolder, imageFilename);
                }
            }

            string filename;
            var folderName = item is MusicAlbum ||
                item is MusicArtist ||
                item is PhotoAlbum ||
                (saveLocally && _config.Configuration.ImageSavingConvention == ImageSavingConvention.Legacy) ?
                "folder" :
                "poster";

            switch (type)
            {
                case ImageType.Art:
                    filename = "clearart";
                    break;
                case ImageType.BoxRear:
                    filename = "back";
                    break;
                case ImageType.Thumb:
                    filename = "landscape";
                    break;
                case ImageType.Disc:
                    filename = item is MusicAlbum ? "cdart" : "disc";
                    break;
                case ImageType.Primary:
                    filename = item is Episode ? _fileSystem.GetFileNameWithoutExtension(item.Path) : folderName;
                    break;
                case ImageType.Backdrop:
                    filename = GetBackdropSaveFilename(item.GetImages(type), "backdrop", "backdrop", imageIndex);
                    break;
                case ImageType.Screenshot:
                    filename = GetBackdropSaveFilename(item.GetImages(type), "screenshot", "screenshot", imageIndex);
                    break;
                default:
                    filename = type.ToString().ToLower();
                    break;
            }

            if (string.Equals(extension, ".jpeg", StringComparison.OrdinalIgnoreCase))
            {
                extension = ".jpg";
            }

            extension = extension.ToLower();

            string path = null;

            if (saveLocally)
            {
                if (type == ImageType.Primary && item is Episode)
                {
                    path = Path.Combine(Path.GetDirectoryName(item.Path), "metadata", filename + extension);
                }

                else if (item.DetectIsInMixedFolder())
                {
                    path = GetSavePathForItemInMixedFolder(item, type, filename, extension);
                }

                if (string.IsNullOrEmpty(path))
                {
                    path = Path.Combine(item.ContainingFolderPath, filename + extension);
                }
            }

            // None of the save local conditions passed, so store it in our internal folders
            if (string.IsNullOrEmpty(path))
            {
                if (string.IsNullOrEmpty(filename))
                {
                    filename = folderName;
                }
                path = Path.Combine(item.GetInternalMetadataPath(), filename + extension);
            }

            return path;
        }
예제 #6
0
        private void PopulateImages(IHasImages item, List<LocalImageInfo> images, List<FileSystemMetadata> files, bool supportParentSeriesFiles, IDirectoryService directoryService)
        {
            if (supportParentSeriesFiles)
            {
                var season = item as Season;

                if (season != null)
                {
                    PopulateSeasonImagesFromSeriesFolder(season, images, directoryService);
                }
            }
            
            var imagePrefix = item.FileNameWithoutExtension + "-";
            var isInMixedFolder = item.DetectIsInMixedFolder();

            PopulatePrimaryImages(item, images, files, imagePrefix, isInMixedFolder);

            AddImage(files, images, "logo", imagePrefix, isInMixedFolder, ImageType.Logo);
            AddImage(files, images, "clearart", imagePrefix, isInMixedFolder, ImageType.Art);

            // For music albums, prefer cdart before disc
            if (item is MusicAlbum)
            {
                AddImage(files, images, "cdart", imagePrefix, isInMixedFolder, ImageType.Disc);
                AddImage(files, images, "disc", imagePrefix, isInMixedFolder, ImageType.Disc);
            }
            else
            {
                AddImage(files, images, "disc", imagePrefix, isInMixedFolder, ImageType.Disc);
                AddImage(files, images, "cdart", imagePrefix, isInMixedFolder, ImageType.Disc);
            }

            AddImage(files, images, "box", imagePrefix, isInMixedFolder, ImageType.Box);
            AddImage(files, images, "back", imagePrefix, isInMixedFolder, ImageType.BoxRear);
            AddImage(files, images, "boxrear", imagePrefix, isInMixedFolder, ImageType.BoxRear);
            AddImage(files, images, "menu", imagePrefix, isInMixedFolder, ImageType.Menu);

            // Banner
            AddImage(files, images, "banner", imagePrefix, isInMixedFolder, ImageType.Banner);

            // Thumb
            AddImage(files, images, "landscape", imagePrefix, isInMixedFolder, ImageType.Thumb);
            AddImage(files, images, "thumb", imagePrefix, isInMixedFolder, ImageType.Thumb);

            PopulateBackdrops(item, images, files, imagePrefix, isInMixedFolder, directoryService);
            PopulateScreenshots(images, files, imagePrefix, isInMixedFolder);
        }