mirror of
				https://github.com/jellyfin/jellyfin.git
				synced 2025-11-03 19:17:24 -05:00 
			
		
		
		
	
		
			
				
	
	
		
			88 lines
		
	
	
		
			2.7 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
			
		
		
	
	
			88 lines
		
	
	
		
			2.7 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
using MediaBrowser.Controller.Entities;
 | 
						|
using MediaBrowser.Controller.Entities.TV;
 | 
						|
using MediaBrowser.Controller.Providers;
 | 
						|
using MediaBrowser.Model.Entities;
 | 
						|
using System;
 | 
						|
using System.Collections.Generic;
 | 
						|
using System.Linq;
 | 
						|
 | 
						|
using MediaBrowser.Model.IO;
 | 
						|
 | 
						|
namespace MediaBrowser.LocalMetadata.Images
 | 
						|
{
 | 
						|
    public class EpisodeLocalLocalImageProvider : ILocalImageFileProvider, IHasOrder
 | 
						|
    {
 | 
						|
        private readonly IFileSystem _fileSystem;
 | 
						|
 | 
						|
        public EpisodeLocalLocalImageProvider(IFileSystem fileSystem)
 | 
						|
        {
 | 
						|
            _fileSystem = fileSystem;
 | 
						|
        }
 | 
						|
 | 
						|
        public string Name
 | 
						|
        {
 | 
						|
            get { return "Local Images"; }
 | 
						|
        }
 | 
						|
 | 
						|
        public int Order
 | 
						|
        {
 | 
						|
            get { return 0; }
 | 
						|
        }
 | 
						|
 | 
						|
        public bool Supports(IHasMetadata item)
 | 
						|
        {
 | 
						|
            return item is Episode && item.SupportsLocalMetadata;
 | 
						|
        }
 | 
						|
 | 
						|
        public List<LocalImageInfo> GetImages(IHasMetadata item, IDirectoryService directoryService)
 | 
						|
        {
 | 
						|
            var parentPath = _fileSystem.GetDirectoryName(item.Path);
 | 
						|
 | 
						|
            var parentPathFiles = directoryService.GetFiles(parentPath);
 | 
						|
 | 
						|
            var nameWithoutExtension = _fileSystem.GetFileNameWithoutExtension(item.Path);
 | 
						|
 | 
						|
            return GetFilesFromParentFolder(nameWithoutExtension, parentPathFiles);
 | 
						|
        }
 | 
						|
 | 
						|
        private List<LocalImageInfo> GetFilesFromParentFolder(string filenameWithoutExtension, List<FileSystemMetadata> parentPathFiles)
 | 
						|
        {
 | 
						|
            var thumbName = filenameWithoutExtension + "-thumb";
 | 
						|
 | 
						|
            var list = new List<LocalImageInfo>(1);
 | 
						|
 | 
						|
            foreach (var i in parentPathFiles)
 | 
						|
            {
 | 
						|
                if (i.IsDirectory)
 | 
						|
                {
 | 
						|
                    continue;
 | 
						|
                }
 | 
						|
 | 
						|
                if (BaseItem.SupportedImageExtensions.Contains(i.Extension, StringComparer.OrdinalIgnoreCase))
 | 
						|
                {
 | 
						|
                    var currentNameWithoutExtension = _fileSystem.GetFileNameWithoutExtension(i);
 | 
						|
 | 
						|
                    if (string.Equals(filenameWithoutExtension, currentNameWithoutExtension, StringComparison.OrdinalIgnoreCase))
 | 
						|
                    {
 | 
						|
                        list.Add(new LocalImageInfo
 | 
						|
                        {
 | 
						|
                            FileInfo = i,
 | 
						|
                            Type = ImageType.Primary
 | 
						|
                        });
 | 
						|
                    }
 | 
						|
 | 
						|
                    else if (string.Equals(thumbName, currentNameWithoutExtension, StringComparison.OrdinalIgnoreCase))
 | 
						|
                    {
 | 
						|
                        list.Add(new LocalImageInfo
 | 
						|
                        {
 | 
						|
                            FileInfo = i,
 | 
						|
                            Type = ImageType.Primary
 | 
						|
                        });
 | 
						|
                    }
 | 
						|
                }
 | 
						|
            }
 | 
						|
            return list;
 | 
						|
        }
 | 
						|
    }
 | 
						|
}
 |