Пример #1
0
        protected bool HasChanged(IHasImages item, ImageType type)
        {
            var image = item.GetImageInfo(type, 0);

            if (image != null)
            {
                if (!image.IsLocalFile)
                {
                    return(false);
                }

                if (!FileSystem.ContainsSubPath(item.GetInternalMetadataPath(), image.Path))
                {
                    return(false);
                }

                var age = DateTime.UtcNow - image.DateModified;
                if (age.TotalDays <= MaxImageAgeDays)
                {
                    return(false);
                }
            }

            return(true);
        }
        public List <LocalImageInfo> GetImages(IHasImages item, IDirectoryService directoryService)
        {
            var path = item.GetInternalMetadataPath();

            try
            {
                return(new LocalImageProvider(_fileSystem).GetImages(item, path, true, directoryService));
            }
            catch (DirectoryNotFoundException)
            {
                return(new List <LocalImageInfo>());
            }
        }
        public List<LocalImageInfo> GetImages(IHasImages item, IDirectoryService directoryService)
        {
            var path = item.GetInternalMetadataPath();

            try
            {
                return new LocalImageProvider(_fileSystem).GetImages(item, path, true, directoryService);
            }
            catch (DirectoryNotFoundException)
            {
                return new List<LocalImageInfo>();
            }
        }
        protected bool HasChanged(IHasImages item, ImageType type, string cacheKey)
        {
            var image = item.GetImageInfo(type, 0);

            if (image != null)
            {
                if (!FileSystem.ContainsSubPath(item.GetInternalMetadataPath(), image.Path))
                {
                    return(false);
                }

                var currentPathCacheKey = (Path.GetFileNameWithoutExtension(image.Path) ?? string.Empty).Split('_').LastOrDefault();
                if (string.Equals(cacheKey, currentPathCacheKey, StringComparison.OrdinalIgnoreCase))
                {
                    return(false);
                }
            }

            return(true);
        }
Пример #5
0
        protected async Task <ItemUpdateType> FetchAsync(IHasImages item, ImageType imageType, MetadataRefreshOptions options, CancellationToken cancellationToken)
        {
            var image = item.GetImageInfo(imageType, 0);

            if (image != null)
            {
                if (!image.IsLocalFile)
                {
                    return(ItemUpdateType.None);
                }

                if (!FileSystem.ContainsSubPath(item.GetInternalMetadataPath(), image.Path))
                {
                    return(ItemUpdateType.None);
                }
            }

            var items = await GetItemsWithImages(item).ConfigureAwait(false);

            return(await FetchToFileInternal(item, items, imageType, cancellationToken).ConfigureAwait(false));
        }
Пример #6
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 (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.IsInMixedFolder)
                {
                    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 ? "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 (item is Episode)
                {
                    path = Path.Combine(Path.GetDirectoryName(item.Path), "metadata", filename + extension);
                }

                else if (item.IsInMixedFolder)
                {
                    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;
        }
Пример #7
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)
        {
            string filename;

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

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

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

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

                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;
            }

            var extension = mimeType.Split('/').Last();

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

            extension = "." + extension.ToLower();

            string path = null;

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

                else if (item.IsInMixedFolder)
                {
                    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 = "folder";
                }
                path = Path.Combine(item.GetInternalMetadataPath(), filename + extension);
            }

            return(path);
        }
Пример #8
0
        private string GetCacheKeyPath(IHasImages item, ImageType type, string mimeType, string key)
        {
            var extension = MimeTypes.ToExtension(mimeType);

            return(Path.Combine(item.GetInternalMetadataPath(), type.ToString().ToLower() + "_key_" + key + extension));
        }
Пример #9
0
 /// <summary>
 /// Gets the chapter images data path.
 /// </summary>
 /// <value>The chapter images data path.</value>
 private string GetChapterImagesPath(IHasImages item)
 {
     return Path.Combine(item.GetInternalMetadataPath(), "chapters");
 }
Пример #10
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)
        {
            string filename;

            switch (type)
            {
                case ImageType.Art:
                    filename = "clearart";
                    break;
                case ImageType.BoxRear:
                    filename = "back";
                    break;
                case ImageType.Disc:
                    filename = item is MusicAlbum ? "cdart" : "disc";
                    break;
                case ImageType.Primary:
                    filename = item is Episode ? _fileSystem.GetFileNameWithoutExtension(item.Path) : "folder";
                    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;
            }

            var extension = mimeType.Split('/').Last();

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

            extension = "." + extension.ToLower();

            string path = null;

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

                else if (item.IsInMixedFolder)
                {
                    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 = "folder";
                }
                path = Path.Combine(item.GetInternalMetadataPath(), filename + extension);
            }

            return path;
        }
Пример #11
0
 /// <summary>
 /// Gets the chapter images data path.
 /// </summary>
 /// <value>The chapter images data path.</value>
 private string GetChapterImagesPath(IHasImages item)
 {
     return(Path.Combine(item.GetInternalMetadataPath(), "chapters"));
 }
Пример #12
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);
        }
Пример #13
0
 private string GetCacheKeyPath(IHasImages item, ImageType type, string mimeType, string key)
 {
     var extension = MimeTypes.ToExtension(mimeType);
     return Path.Combine(item.GetInternalMetadataPath(), type.ToString().ToLower() + "_key_" + key + extension);
 }