mirror of
https://github.com/jellyfin/jellyfin.git
synced 2026-03-20 17:16:42 +00:00
Cleanup/simplification
* Removed useless copies/allocations * Reduced unneeded complexity
This commit is contained in:
@@ -36,7 +36,7 @@ namespace Emby.Server.Implementations.Collections
|
||||
return base.Supports(item);
|
||||
}
|
||||
|
||||
protected override List<BaseItem> GetItemsWithImages(BaseItem item)
|
||||
protected override IReadOnlyList<BaseItem> GetItemsWithImages(BaseItem item)
|
||||
{
|
||||
var playlist = (BoxSet)item;
|
||||
|
||||
@@ -80,7 +80,7 @@ namespace Emby.Server.Implementations.Collections
|
||||
.ToList();
|
||||
}
|
||||
|
||||
protected override string CreateImage(BaseItem item, List<BaseItem> itemsWithImages, string outputPathWithoutExtension, ImageType imageType, int imageIndex)
|
||||
protected override string CreateImage(BaseItem item, IReadOnlyCollection<BaseItem> itemsWithImages, string outputPathWithoutExtension, ImageType imageType, int imageIndex)
|
||||
{
|
||||
return CreateSingleImage(itemsWithImages, outputPathWithoutExtension, ImageType.Primary);
|
||||
}
|
||||
|
||||
@@ -7,7 +7,6 @@ using System.Text;
|
||||
using MediaBrowser.Common.Configuration;
|
||||
using MediaBrowser.Model.IO;
|
||||
using MediaBrowser.Model.System;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace Emby.Server.Implementations.IO
|
||||
@@ -711,20 +710,20 @@ namespace Emby.Server.Implementations.IO
|
||||
return GetFiles(path, null, false, recursive);
|
||||
}
|
||||
|
||||
public virtual IEnumerable<FileSystemMetadata> GetFiles(string path, string[] extensions, bool enableCaseSensitiveExtensions, bool recursive = false)
|
||||
public virtual IEnumerable<FileSystemMetadata> GetFiles(string path, IReadOnlyList<string> extensions, bool enableCaseSensitiveExtensions, bool recursive = false)
|
||||
{
|
||||
var searchOption = recursive ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly;
|
||||
|
||||
// On linux and osx the search pattern is case sensitive
|
||||
// If we're OK with case-sensitivity, and we're only filtering for one extension, then use the native method
|
||||
if ((enableCaseSensitiveExtensions || _isEnvironmentCaseInsensitive) && extensions != null && extensions.Length == 1)
|
||||
if ((enableCaseSensitiveExtensions || _isEnvironmentCaseInsensitive) && extensions != null && extensions.Count == 1)
|
||||
{
|
||||
return ToMetadata(new DirectoryInfo(path).EnumerateFiles("*" + extensions[0], searchOption));
|
||||
}
|
||||
|
||||
var files = new DirectoryInfo(path).EnumerateFiles("*", searchOption);
|
||||
|
||||
if (extensions != null && extensions.Length > 0)
|
||||
if (extensions != null && extensions.Count > 0)
|
||||
{
|
||||
files = files.Where(i =>
|
||||
{
|
||||
|
||||
@@ -20,6 +20,9 @@ namespace Emby.Server.Implementations.Images
|
||||
public abstract class BaseDynamicImageProvider<T> : IHasItemChangeMonitor, IForcedProvider, ICustomMetadataProvider<T>, IHasOrder
|
||||
where T : BaseItem
|
||||
{
|
||||
protected virtual IReadOnlyCollection<ImageType> SupportedImages { get; }
|
||||
= new ImageType[] { ImageType.Primary };
|
||||
|
||||
protected IFileSystem FileSystem { get; private set; }
|
||||
protected IProviderManager ProviderManager { get; private set; }
|
||||
protected IApplicationPaths ApplicationPaths { get; private set; }
|
||||
@@ -33,18 +36,7 @@ namespace Emby.Server.Implementations.Images
|
||||
ImageProcessor = imageProcessor;
|
||||
}
|
||||
|
||||
protected virtual bool Supports(BaseItem item)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public virtual ImageType[] GetSupportedImages(BaseItem item)
|
||||
{
|
||||
return new ImageType[]
|
||||
{
|
||||
ImageType.Primary
|
||||
};
|
||||
}
|
||||
protected virtual bool Supports(BaseItem _) => true;
|
||||
|
||||
public async Task<ItemUpdateType> FetchAsync(T item, MetadataRefreshOptions options, CancellationToken cancellationToken)
|
||||
{
|
||||
@@ -54,15 +46,14 @@ namespace Emby.Server.Implementations.Images
|
||||
}
|
||||
|
||||
var updateType = ItemUpdateType.None;
|
||||
var supportedImages = GetSupportedImages(item);
|
||||
|
||||
if (supportedImages.Contains(ImageType.Primary))
|
||||
if (SupportedImages.Contains(ImageType.Primary))
|
||||
{
|
||||
var primaryResult = await FetchAsync(item, ImageType.Primary, options, cancellationToken).ConfigureAwait(false);
|
||||
updateType = updateType | primaryResult;
|
||||
}
|
||||
|
||||
if (supportedImages.Contains(ImageType.Thumb))
|
||||
if (SupportedImages.Contains(ImageType.Thumb))
|
||||
{
|
||||
var thumbResult = await FetchAsync(item, ImageType.Thumb, options, cancellationToken).ConfigureAwait(false);
|
||||
updateType = updateType | thumbResult;
|
||||
@@ -94,7 +85,7 @@ namespace Emby.Server.Implementations.Images
|
||||
}
|
||||
|
||||
protected async Task<ItemUpdateType> FetchToFileInternal(BaseItem item,
|
||||
List<BaseItem> itemsWithImages,
|
||||
IReadOnlyList<BaseItem> itemsWithImages,
|
||||
ImageType imageType,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
@@ -119,9 +110,9 @@ namespace Emby.Server.Implementations.Images
|
||||
return ItemUpdateType.ImageUpdate;
|
||||
}
|
||||
|
||||
protected abstract List<BaseItem> GetItemsWithImages(BaseItem item);
|
||||
protected abstract IReadOnlyList<BaseItem> GetItemsWithImages(BaseItem item);
|
||||
|
||||
protected string CreateThumbCollage(BaseItem primaryItem, List<BaseItem> items, string outputPath)
|
||||
protected string CreateThumbCollage(BaseItem primaryItem, IEnumerable<BaseItem> items, string outputPath)
|
||||
{
|
||||
return CreateCollage(primaryItem, items, outputPath, 640, 360);
|
||||
}
|
||||
@@ -132,38 +123,38 @@ namespace Emby.Server.Implementations.Images
|
||||
.Select(i =>
|
||||
{
|
||||
var image = i.GetImageInfo(ImageType.Primary, 0);
|
||||
|
||||
if (image != null && image.IsLocalFile)
|
||||
{
|
||||
return image.Path;
|
||||
}
|
||||
|
||||
image = i.GetImageInfo(ImageType.Thumb, 0);
|
||||
|
||||
if (image != null && image.IsLocalFile)
|
||||
{
|
||||
return image.Path;
|
||||
}
|
||||
|
||||
return null;
|
||||
})
|
||||
.Where(i => !string.IsNullOrEmpty(i));
|
||||
}
|
||||
|
||||
protected string CreatePosterCollage(BaseItem primaryItem, List<BaseItem> items, string outputPath)
|
||||
protected string CreatePosterCollage(BaseItem primaryItem, IEnumerable<BaseItem> items, string outputPath)
|
||||
{
|
||||
return CreateCollage(primaryItem, items, outputPath, 400, 600);
|
||||
}
|
||||
|
||||
protected string CreateSquareCollage(BaseItem primaryItem, List<BaseItem> items, string outputPath)
|
||||
protected string CreateSquareCollage(BaseItem primaryItem, IEnumerable<BaseItem> items, string outputPath)
|
||||
{
|
||||
return CreateCollage(primaryItem, items, outputPath, 600, 600);
|
||||
}
|
||||
|
||||
protected string CreateThumbCollage(BaseItem primaryItem, List<BaseItem> items, string outputPath, int width, int height)
|
||||
protected string CreateThumbCollage(BaseItem primaryItem, IEnumerable<BaseItem> items, string outputPath, int width, int height)
|
||||
{
|
||||
return CreateCollage(primaryItem, items, outputPath, width, height);
|
||||
}
|
||||
|
||||
private string CreateCollage(BaseItem primaryItem, List<BaseItem> items, string outputPath, int width, int height)
|
||||
private string CreateCollage(BaseItem primaryItem, IEnumerable<BaseItem> items, string outputPath, int width, int height)
|
||||
{
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(outputPath));
|
||||
|
||||
@@ -192,7 +183,7 @@ namespace Emby.Server.Implementations.Images
|
||||
public string Name => "Dynamic Image Provider";
|
||||
|
||||
protected virtual string CreateImage(BaseItem item,
|
||||
List<BaseItem> itemsWithImages,
|
||||
IReadOnlyCollection<BaseItem> itemsWithImages,
|
||||
string outputPathWithoutExtension,
|
||||
ImageType imageType,
|
||||
int imageIndex)
|
||||
@@ -211,18 +202,15 @@ namespace Emby.Server.Implementations.Images
|
||||
|
||||
if (imageType == ImageType.Primary)
|
||||
{
|
||||
if (item is UserView)
|
||||
{
|
||||
return CreateSquareCollage(item, itemsWithImages, outputPath);
|
||||
}
|
||||
if (item is Playlist || item is MusicGenre || item is Genre || item is PhotoAlbum)
|
||||
if (item is UserView || item is Playlist || item is MusicGenre || item is Genre || item is PhotoAlbum)
|
||||
{
|
||||
return CreateSquareCollage(item, itemsWithImages, outputPath);
|
||||
}
|
||||
|
||||
return CreatePosterCollage(item, itemsWithImages, outputPath);
|
||||
}
|
||||
|
||||
throw new ArgumentException("Unexpected image type");
|
||||
throw new ArgumentException("Unexpected image type", nameof(imageType));
|
||||
}
|
||||
|
||||
protected virtual int MaxImageAgeDays => 7;
|
||||
@@ -234,13 +222,11 @@ namespace Emby.Server.Implementations.Images
|
||||
return false;
|
||||
}
|
||||
|
||||
var supportedImages = GetSupportedImages(item);
|
||||
|
||||
if (supportedImages.Contains(ImageType.Primary) && HasChanged(item, ImageType.Primary))
|
||||
if (SupportedImages.Contains(ImageType.Primary) && HasChanged(item, ImageType.Primary))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if (supportedImages.Contains(ImageType.Thumb) && HasChanged(item, ImageType.Thumb))
|
||||
if (SupportedImages.Contains(ImageType.Thumb) && HasChanged(item, ImageType.Thumb))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@@ -285,7 +271,7 @@ namespace Emby.Server.Implementations.Images
|
||||
|
||||
public int Order => 0;
|
||||
|
||||
protected string CreateSingleImage(List<BaseItem> itemsWithImages, string outputPathWithoutExtension, ImageType imageType)
|
||||
protected string CreateSingleImage(IEnumerable<BaseItem> itemsWithImages, string outputPathWithoutExtension, ImageType imageType)
|
||||
{
|
||||
var image = itemsWithImages
|
||||
.Where(i => i.HasImage(imageType) && i.GetImageInfo(imageType, 0).IsLocalFile && Path.HasExtension(i.GetImagePath(imageType)))
|
||||
|
||||
@@ -24,7 +24,7 @@ namespace Emby.Server.Implementations.Playlists
|
||||
{
|
||||
}
|
||||
|
||||
protected override List<BaseItem> GetItemsWithImages(BaseItem item)
|
||||
protected override IReadOnlyList<BaseItem> GetItemsWithImages(BaseItem item)
|
||||
{
|
||||
var playlist = (Playlist)item;
|
||||
|
||||
@@ -78,7 +78,7 @@ namespace Emby.Server.Implementations.Playlists
|
||||
_libraryManager = libraryManager;
|
||||
}
|
||||
|
||||
protected override List<BaseItem> GetItemsWithImages(BaseItem item)
|
||||
protected override IReadOnlyList<BaseItem> GetItemsWithImages(BaseItem item)
|
||||
{
|
||||
return _libraryManager.GetItemList(new InternalItemsQuery
|
||||
{
|
||||
@@ -89,7 +89,6 @@ namespace Emby.Server.Implementations.Playlists
|
||||
Recursive = true,
|
||||
ImageTypes = new[] { ImageType.Primary },
|
||||
DtoOptions = new DtoOptions(false)
|
||||
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -103,7 +102,7 @@ namespace Emby.Server.Implementations.Playlists
|
||||
_libraryManager = libraryManager;
|
||||
}
|
||||
|
||||
protected override List<BaseItem> GetItemsWithImages(BaseItem item)
|
||||
protected override IReadOnlyList<BaseItem> GetItemsWithImages(BaseItem item)
|
||||
{
|
||||
return _libraryManager.GetItemList(new InternalItemsQuery
|
||||
{
|
||||
@@ -116,11 +115,5 @@ namespace Emby.Server.Implementations.Playlists
|
||||
DtoOptions = new DtoOptions(false)
|
||||
});
|
||||
}
|
||||
|
||||
//protected override Task<string> CreateImage(IHasMetadata item, List<BaseItem> itemsWithImages, string outputPathWithoutExtension, ImageType imageType, int imageIndex)
|
||||
//{
|
||||
// return CreateSingleImage(itemsWithImages, outputPathWithoutExtension, ImageType.Primary);
|
||||
//}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -79,7 +79,7 @@ namespace Emby.Server.Implementations.SocketSharp
|
||||
byte[] copy = new byte[e.Length];
|
||||
|
||||
input.Position = e.Start;
|
||||
input.Read(copy, 0, (int)e.Length);
|
||||
await input.ReadAsync(copy, 0, (int)e.Length).ConfigureAwait(false);
|
||||
|
||||
form.Add(e.Name, (e.Encoding ?? ContentEncoding).GetString(copy, 0, copy.Length));
|
||||
}
|
||||
@@ -98,11 +98,11 @@ namespace Emby.Server.Implementations.SocketSharp
|
||||
var form = new WebROCollection();
|
||||
files = new Dictionary<string, HttpPostedFile>();
|
||||
|
||||
if (IsContentType("multipart/form-data", true))
|
||||
if (IsContentType("multipart/form-data"))
|
||||
{
|
||||
await LoadMultiPart(form).ConfigureAwait(false);
|
||||
}
|
||||
else if (IsContentType("application/x-www-form-urlencoded", true))
|
||||
else if (IsContentType("application/x-www-form-urlencoded"))
|
||||
{
|
||||
await LoadWwwForm(form).ConfigureAwait(false);
|
||||
}
|
||||
@@ -200,19 +200,14 @@ namespace Emby.Server.Implementations.SocketSharp
|
||||
return false;
|
||||
}
|
||||
|
||||
private bool IsContentType(string ct, bool starts_with)
|
||||
private bool IsContentType(string ct)
|
||||
{
|
||||
if (ct == null || ContentType == null)
|
||||
if (ContentType == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (starts_with)
|
||||
{
|
||||
return ContentType.StartsWith(ct, StringComparison.OrdinalIgnoreCase);
|
||||
}
|
||||
|
||||
return string.Equals(ContentType, ct, StringComparison.OrdinalIgnoreCase);
|
||||
return ContentType.StartsWith(ct, StringComparison.OrdinalIgnoreCase);
|
||||
}
|
||||
|
||||
private async Task LoadWwwForm(WebROCollection form)
|
||||
|
||||
@@ -4,7 +4,6 @@ using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
using Emby.Server.Implementations.HttpServer;
|
||||
using MediaBrowser.Model.Services;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Http.Extensions;
|
||||
@@ -405,8 +404,7 @@ namespace Emby.Server.Implementations.SocketSharp
|
||||
return null;
|
||||
}
|
||||
|
||||
var path = sbPathInfo.ToString();
|
||||
return path.Length > 1 ? path.TrimEnd('/') : "/";
|
||||
return sbPathInfo.Length > 1 ? sbPathInfo.ToString().TrimEnd('/') : "/";
|
||||
}
|
||||
|
||||
public string UserAgent => request.Headers[HeaderNames.UserAgent];
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using Emby.Server.Implementations.Images;
|
||||
using MediaBrowser.Common.Configuration;
|
||||
using MediaBrowser.Controller.Drawing;
|
||||
@@ -20,7 +19,7 @@ namespace Emby.Server.Implementations.UserViews
|
||||
{
|
||||
}
|
||||
|
||||
protected override List<BaseItem> GetItemsWithImages(BaseItem item)
|
||||
protected override IReadOnlyList<BaseItem> GetItemsWithImages(BaseItem item)
|
||||
{
|
||||
var view = (CollectionFolder)item;
|
||||
var viewType = view.CollectionType;
|
||||
@@ -56,7 +55,7 @@ namespace Emby.Server.Implementations.UserViews
|
||||
includeItemTypes = new string[] { "Video", "Audio", "Photo", "Movie", "Series" };
|
||||
}
|
||||
|
||||
var recursive = !new[] { CollectionType.Playlists }.Contains(view.CollectionType ?? string.Empty, StringComparer.OrdinalIgnoreCase);
|
||||
var recursive = !string.Equals(CollectionType.Playlists, viewType, StringComparison.OrdinalIgnoreCase);
|
||||
|
||||
return view.GetItemList(new InternalItemsQuery
|
||||
{
|
||||
@@ -71,7 +70,7 @@ namespace Emby.Server.Implementations.UserViews
|
||||
},
|
||||
IncludeItemTypes = includeItemTypes
|
||||
|
||||
}).ToList();
|
||||
});
|
||||
}
|
||||
|
||||
protected override bool Supports(BaseItem item)
|
||||
@@ -79,7 +78,7 @@ namespace Emby.Server.Implementations.UserViews
|
||||
return item is CollectionFolder;
|
||||
}
|
||||
|
||||
protected override string CreateImage(BaseItem item, List<BaseItem> itemsWithImages, string outputPathWithoutExtension, ImageType imageType, int imageIndex)
|
||||
protected override string CreateImage(BaseItem item, IReadOnlyCollection<BaseItem> itemsWithImages, string outputPathWithoutExtension, ImageType imageType, int imageIndex)
|
||||
{
|
||||
var outputPath = Path.ChangeExtension(outputPathWithoutExtension, ".png");
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ namespace Emby.Server.Implementations.UserViews
|
||||
_libraryManager = libraryManager;
|
||||
}
|
||||
|
||||
protected override List<BaseItem> GetItemsWithImages(BaseItem item)
|
||||
protected override IReadOnlyList<BaseItem> GetItemsWithImages(BaseItem item)
|
||||
{
|
||||
var view = (UserView)item;
|
||||
|
||||
@@ -46,8 +46,7 @@ namespace Emby.Server.Implementations.UserViews
|
||||
|
||||
var items = result.Select(i =>
|
||||
{
|
||||
var episode = i as Episode;
|
||||
if (episode != null)
|
||||
if (i is Episode episode)
|
||||
{
|
||||
var series = episode.Series;
|
||||
if (series != null)
|
||||
@@ -58,8 +57,7 @@ namespace Emby.Server.Implementations.UserViews
|
||||
return episode;
|
||||
}
|
||||
|
||||
var season = i as Season;
|
||||
if (season != null)
|
||||
if (i is Season season)
|
||||
{
|
||||
var series = season.Series;
|
||||
if (series != null)
|
||||
@@ -70,8 +68,7 @@ namespace Emby.Server.Implementations.UserViews
|
||||
return season;
|
||||
}
|
||||
|
||||
var audio = i as Audio;
|
||||
if (audio != null)
|
||||
if (i is Audio audio)
|
||||
{
|
||||
var album = audio.AlbumEntity;
|
||||
if (album != null && album.HasImage(ImageType.Primary))
|
||||
@@ -122,7 +119,7 @@ namespace Emby.Server.Implementations.UserViews
|
||||
return collectionStripViewTypes.Contains(view.ViewType ?? string.Empty);
|
||||
}
|
||||
|
||||
protected override string CreateImage(BaseItem item, List<BaseItem> itemsWithImages, string outputPathWithoutExtension, ImageType imageType, int imageIndex)
|
||||
protected override string CreateImage(BaseItem item, IReadOnlyCollection<BaseItem> itemsWithImages, string outputPathWithoutExtension, ImageType imageType, int imageIndex)
|
||||
{
|
||||
if (itemsWithImages.Count == 0)
|
||||
{
|
||||
|
||||
@@ -24,7 +24,7 @@ namespace Emby.Server.Implementations.UserViews
|
||||
_libraryManager = libraryManager;
|
||||
}
|
||||
|
||||
protected override List<BaseItem> GetItemsWithImages(BaseItem item)
|
||||
protected override IReadOnlyList<BaseItem> GetItemsWithImages(BaseItem item)
|
||||
{
|
||||
return _libraryManager.GetItemList(new InternalItemsQuery
|
||||
{
|
||||
@@ -40,7 +40,7 @@ namespace Emby.Server.Implementations.UserViews
|
||||
});
|
||||
}
|
||||
|
||||
protected override string CreateImage(BaseItem item, List<BaseItem> itemsWithImages, string outputPathWithoutExtension, ImageType imageType, int imageIndex)
|
||||
protected override string CreateImage(BaseItem item, IReadOnlyCollection<BaseItem> itemsWithImages, string outputPathWithoutExtension, ImageType imageType, int imageIndex)
|
||||
{
|
||||
return CreateSingleImage(itemsWithImages, outputPathWithoutExtension, ImageType.Primary);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user