Merge pull request #1058 from Bond-009/clean

Cleanup/simplification
This commit is contained in:
Vasily 2019-03-08 00:23:00 +03:00 committed by GitHub
commit 028a98d2c1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
19 changed files with 127 additions and 157 deletions

View File

@ -36,7 +36,7 @@ namespace Emby.Server.Implementations.Collections
return base.Supports(item); return base.Supports(item);
} }
protected override List<BaseItem> GetItemsWithImages(BaseItem item) protected override IReadOnlyList<BaseItem> GetItemsWithImages(BaseItem item)
{ {
var playlist = (BoxSet)item; var playlist = (BoxSet)item;
@ -80,7 +80,7 @@ namespace Emby.Server.Implementations.Collections
.ToList(); .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); return CreateSingleImage(itemsWithImages, outputPathWithoutExtension, ImageType.Primary);
} }

View File

@ -7,7 +7,6 @@ using System.Text;
using MediaBrowser.Common.Configuration; using MediaBrowser.Common.Configuration;
using MediaBrowser.Model.IO; using MediaBrowser.Model.IO;
using MediaBrowser.Model.System; using MediaBrowser.Model.System;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
namespace Emby.Server.Implementations.IO namespace Emby.Server.Implementations.IO
@ -711,20 +710,20 @@ namespace Emby.Server.Implementations.IO
return GetFiles(path, null, false, recursive); 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; var searchOption = recursive ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly;
// On linux and osx the search pattern is case sensitive // 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 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)); return ToMetadata(new DirectoryInfo(path).EnumerateFiles("*" + extensions[0], searchOption));
} }
var files = new DirectoryInfo(path).EnumerateFiles("*", searchOption); var files = new DirectoryInfo(path).EnumerateFiles("*", searchOption);
if (extensions != null && extensions.Length > 0) if (extensions != null && extensions.Count > 0)
{ {
files = files.Where(i => files = files.Where(i =>
{ {

View File

@ -20,6 +20,9 @@ namespace Emby.Server.Implementations.Images
public abstract class BaseDynamicImageProvider<T> : IHasItemChangeMonitor, IForcedProvider, ICustomMetadataProvider<T>, IHasOrder public abstract class BaseDynamicImageProvider<T> : IHasItemChangeMonitor, IForcedProvider, ICustomMetadataProvider<T>, IHasOrder
where T : BaseItem where T : BaseItem
{ {
protected virtual IReadOnlyCollection<ImageType> SupportedImages { get; }
= new ImageType[] { ImageType.Primary };
protected IFileSystem FileSystem { get; private set; } protected IFileSystem FileSystem { get; private set; }
protected IProviderManager ProviderManager { get; private set; } protected IProviderManager ProviderManager { get; private set; }
protected IApplicationPaths ApplicationPaths { get; private set; } protected IApplicationPaths ApplicationPaths { get; private set; }
@ -33,18 +36,7 @@ namespace Emby.Server.Implementations.Images
ImageProcessor = imageProcessor; ImageProcessor = imageProcessor;
} }
protected virtual bool Supports(BaseItem item) protected virtual bool Supports(BaseItem _) => true;
{
return true;
}
public virtual ImageType[] GetSupportedImages(BaseItem item)
{
return new ImageType[]
{
ImageType.Primary
};
}
public async Task<ItemUpdateType> FetchAsync(T item, MetadataRefreshOptions options, CancellationToken cancellationToken) 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 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); var primaryResult = await FetchAsync(item, ImageType.Primary, options, cancellationToken).ConfigureAwait(false);
updateType = updateType | primaryResult; updateType = updateType | primaryResult;
} }
if (supportedImages.Contains(ImageType.Thumb)) if (SupportedImages.Contains(ImageType.Thumb))
{ {
var thumbResult = await FetchAsync(item, ImageType.Thumb, options, cancellationToken).ConfigureAwait(false); var thumbResult = await FetchAsync(item, ImageType.Thumb, options, cancellationToken).ConfigureAwait(false);
updateType = updateType | thumbResult; updateType = updateType | thumbResult;
@ -94,7 +85,7 @@ namespace Emby.Server.Implementations.Images
} }
protected async Task<ItemUpdateType> FetchToFileInternal(BaseItem item, protected async Task<ItemUpdateType> FetchToFileInternal(BaseItem item,
List<BaseItem> itemsWithImages, IReadOnlyList<BaseItem> itemsWithImages,
ImageType imageType, ImageType imageType,
CancellationToken cancellationToken) CancellationToken cancellationToken)
{ {
@ -119,9 +110,9 @@ namespace Emby.Server.Implementations.Images
return ItemUpdateType.ImageUpdate; 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); return CreateCollage(primaryItem, items, outputPath, 640, 360);
} }
@ -132,38 +123,38 @@ namespace Emby.Server.Implementations.Images
.Select(i => .Select(i =>
{ {
var image = i.GetImageInfo(ImageType.Primary, 0); var image = i.GetImageInfo(ImageType.Primary, 0);
if (image != null && image.IsLocalFile) if (image != null && image.IsLocalFile)
{ {
return image.Path; return image.Path;
} }
image = i.GetImageInfo(ImageType.Thumb, 0); image = i.GetImageInfo(ImageType.Thumb, 0);
if (image != null && image.IsLocalFile) if (image != null && image.IsLocalFile)
{ {
return image.Path; return image.Path;
} }
return null; return null;
}) })
.Where(i => !string.IsNullOrEmpty(i)); .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); 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); 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); 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)); Directory.CreateDirectory(Path.GetDirectoryName(outputPath));
@ -192,7 +183,7 @@ namespace Emby.Server.Implementations.Images
public string Name => "Dynamic Image Provider"; public string Name => "Dynamic Image Provider";
protected virtual string CreateImage(BaseItem item, protected virtual string CreateImage(BaseItem item,
List<BaseItem> itemsWithImages, IReadOnlyCollection<BaseItem> itemsWithImages,
string outputPathWithoutExtension, string outputPathWithoutExtension,
ImageType imageType, ImageType imageType,
int imageIndex) int imageIndex)
@ -211,18 +202,15 @@ namespace Emby.Server.Implementations.Images
if (imageType == ImageType.Primary) if (imageType == ImageType.Primary)
{ {
if (item is UserView) if (item is UserView || item is Playlist || item is MusicGenre || item is Genre || item is PhotoAlbum)
{
return CreateSquareCollage(item, itemsWithImages, outputPath);
}
if (item is Playlist || item is MusicGenre || item is Genre || item is PhotoAlbum)
{ {
return CreateSquareCollage(item, itemsWithImages, outputPath); return CreateSquareCollage(item, itemsWithImages, outputPath);
} }
return CreatePosterCollage(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; protected virtual int MaxImageAgeDays => 7;
@ -234,13 +222,11 @@ namespace Emby.Server.Implementations.Images
return false; 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; return true;
} }
if (supportedImages.Contains(ImageType.Thumb) && HasChanged(item, ImageType.Thumb)) if (SupportedImages.Contains(ImageType.Thumb) && HasChanged(item, ImageType.Thumb))
{ {
return true; return true;
} }
@ -285,7 +271,7 @@ namespace Emby.Server.Implementations.Images
public int Order => 0; 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 var image = itemsWithImages
.Where(i => i.HasImage(imageType) && i.GetImageInfo(imageType, 0).IsLocalFile && Path.HasExtension(i.GetImagePath(imageType))) .Where(i => i.HasImage(imageType) && i.GetImageInfo(imageType, 0).IsLocalFile && Path.HasExtension(i.GetImagePath(imageType)))

View File

@ -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; var playlist = (Playlist)item;
@ -78,7 +78,7 @@ namespace Emby.Server.Implementations.Playlists
_libraryManager = libraryManager; _libraryManager = libraryManager;
} }
protected override List<BaseItem> GetItemsWithImages(BaseItem item) protected override IReadOnlyList<BaseItem> GetItemsWithImages(BaseItem item)
{ {
return _libraryManager.GetItemList(new InternalItemsQuery return _libraryManager.GetItemList(new InternalItemsQuery
{ {
@ -89,7 +89,6 @@ namespace Emby.Server.Implementations.Playlists
Recursive = true, Recursive = true,
ImageTypes = new[] { ImageType.Primary }, ImageTypes = new[] { ImageType.Primary },
DtoOptions = new DtoOptions(false) DtoOptions = new DtoOptions(false)
}); });
} }
} }
@ -103,7 +102,7 @@ namespace Emby.Server.Implementations.Playlists
_libraryManager = libraryManager; _libraryManager = libraryManager;
} }
protected override List<BaseItem> GetItemsWithImages(BaseItem item) protected override IReadOnlyList<BaseItem> GetItemsWithImages(BaseItem item)
{ {
return _libraryManager.GetItemList(new InternalItemsQuery return _libraryManager.GetItemList(new InternalItemsQuery
{ {
@ -116,11 +115,5 @@ namespace Emby.Server.Implementations.Playlists
DtoOptions = new DtoOptions(false) 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);
//}
} }
} }

View File

@ -79,7 +79,7 @@ namespace Emby.Server.Implementations.SocketSharp
byte[] copy = new byte[e.Length]; byte[] copy = new byte[e.Length];
input.Position = e.Start; 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)); 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(); var form = new WebROCollection();
files = new Dictionary<string, HttpPostedFile>(); files = new Dictionary<string, HttpPostedFile>();
if (IsContentType("multipart/form-data", true)) if (IsContentType("multipart/form-data"))
{ {
await LoadMultiPart(form).ConfigureAwait(false); 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); await LoadWwwForm(form).ConfigureAwait(false);
} }
@ -200,19 +200,14 @@ namespace Emby.Server.Implementations.SocketSharp
return false; 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; return false;
} }
if (starts_with) return ContentType.StartsWith(ct, StringComparison.OrdinalIgnoreCase);
{
return ContentType.StartsWith(ct, StringComparison.OrdinalIgnoreCase);
}
return string.Equals(ContentType, ct, StringComparison.OrdinalIgnoreCase);
} }
private async Task LoadWwwForm(WebROCollection form) private async Task LoadWwwForm(WebROCollection form)

View File

@ -4,7 +4,6 @@ using System.Globalization;
using System.IO; using System.IO;
using System.Net; using System.Net;
using System.Text; using System.Text;
using Emby.Server.Implementations.HttpServer;
using MediaBrowser.Model.Services; using MediaBrowser.Model.Services;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.Extensions; using Microsoft.AspNetCore.Http.Extensions;
@ -405,8 +404,7 @@ namespace Emby.Server.Implementations.SocketSharp
return null; return null;
} }
var path = sbPathInfo.ToString(); return sbPathInfo.Length > 1 ? sbPathInfo.ToString().TrimEnd('/') : "/";
return path.Length > 1 ? path.TrimEnd('/') : "/";
} }
public string UserAgent => request.Headers[HeaderNames.UserAgent]; public string UserAgent => request.Headers[HeaderNames.UserAgent];

View File

@ -1,7 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq;
using Emby.Server.Implementations.Images; using Emby.Server.Implementations.Images;
using MediaBrowser.Common.Configuration; using MediaBrowser.Common.Configuration;
using MediaBrowser.Controller.Drawing; 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 view = (CollectionFolder)item;
var viewType = view.CollectionType; var viewType = view.CollectionType;
@ -56,7 +55,7 @@ namespace Emby.Server.Implementations.UserViews
includeItemTypes = new string[] { "Video", "Audio", "Photo", "Movie", "Series" }; 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 return view.GetItemList(new InternalItemsQuery
{ {
@ -71,7 +70,7 @@ namespace Emby.Server.Implementations.UserViews
}, },
IncludeItemTypes = includeItemTypes IncludeItemTypes = includeItemTypes
}).ToList(); });
} }
protected override bool Supports(BaseItem item) protected override bool Supports(BaseItem item)
@ -79,7 +78,7 @@ namespace Emby.Server.Implementations.UserViews
return item is CollectionFolder; 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"); var outputPath = Path.ChangeExtension(outputPathWithoutExtension, ".png");

View File

@ -28,7 +28,7 @@ namespace Emby.Server.Implementations.UserViews
_libraryManager = libraryManager; _libraryManager = libraryManager;
} }
protected override List<BaseItem> GetItemsWithImages(BaseItem item) protected override IReadOnlyList<BaseItem> GetItemsWithImages(BaseItem item)
{ {
var view = (UserView)item; var view = (UserView)item;
@ -46,8 +46,7 @@ namespace Emby.Server.Implementations.UserViews
var items = result.Select(i => var items = result.Select(i =>
{ {
var episode = i as Episode; if (i is Episode episode)
if (episode != null)
{ {
var series = episode.Series; var series = episode.Series;
if (series != null) if (series != null)
@ -58,8 +57,7 @@ namespace Emby.Server.Implementations.UserViews
return episode; return episode;
} }
var season = i as Season; if (i is Season season)
if (season != null)
{ {
var series = season.Series; var series = season.Series;
if (series != null) if (series != null)
@ -70,8 +68,7 @@ namespace Emby.Server.Implementations.UserViews
return season; return season;
} }
var audio = i as Audio; if (i is Audio audio)
if (audio != null)
{ {
var album = audio.AlbumEntity; var album = audio.AlbumEntity;
if (album != null && album.HasImage(ImageType.Primary)) if (album != null && album.HasImage(ImageType.Primary))
@ -122,7 +119,7 @@ namespace Emby.Server.Implementations.UserViews
return collectionStripViewTypes.Contains(view.ViewType ?? string.Empty); 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) if (itemsWithImages.Count == 0)
{ {

View File

@ -24,7 +24,7 @@ namespace Emby.Server.Implementations.UserViews
_libraryManager = libraryManager; _libraryManager = libraryManager;
} }
protected override List<BaseItem> GetItemsWithImages(BaseItem item) protected override IReadOnlyList<BaseItem> GetItemsWithImages(BaseItem item)
{ {
return _libraryManager.GetItemList(new InternalItemsQuery 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); return CreateSingleImage(itemsWithImages, outputPathWithoutExtension, ImageType.Primary);
} }

View File

@ -312,35 +312,35 @@ namespace MediaBrowser.Api.Images
private ImageInfo GetImageInfo(BaseItem item, ItemImageInfo info, int? imageIndex) private ImageInfo GetImageInfo(BaseItem item, ItemImageInfo info, int? imageIndex)
{ {
int? width = null;
int? height = null;
long length = 0;
try try
{ {
int? width = null; if (info.IsLocalFile)
int? height = null;
long length = 0;
try
{ {
if (info.IsLocalFile) var fileInfo = _fileSystem.GetFileInfo(info.Path);
length = fileInfo.Length;
ImageDimensions size = _imageProcessor.GetImageDimensions(item, info, true);
width = size.Width;
height = size.Height;
if (width <= 0 || height <= 0)
{ {
var fileInfo = _fileSystem.GetFileInfo(info.Path); width = null;
length = fileInfo.Length; height = null;
ImageDimensions size = _imageProcessor.GetImageDimensions(item, info, true);
width = size.Width;
height = size.Height;
if (width <= 0 || height <= 0)
{
width = null;
height = null;
}
} }
} }
catch }
{ catch (Exception ex)
{
Logger.LogError(ex, "Error getting image information for {Item}", item.Name);
}
} try
{
return new ImageInfo return new ImageInfo
{ {
Path = info.Path, Path = info.Path,
@ -354,7 +354,7 @@ namespace MediaBrowser.Api.Images
} }
catch (Exception ex) catch (Exception ex)
{ {
Logger.LogError(ex, "Error getting image information for {path}", info.Path); Logger.LogError(ex, "Error getting image information for {Path}", info.Path);
return null; return null;
} }
@ -519,16 +519,16 @@ namespace MediaBrowser.Api.Images
request.AddPlayedIndicator = true; request.AddPlayedIndicator = true;
} }
} }
if (request.PercentPlayed.HasValue) if (request.PercentPlayed.HasValue)
{ {
request.UnplayedCount = null; request.UnplayedCount = null;
} }
if (request.UnplayedCount.HasValue)
if (request.UnplayedCount.HasValue
&& request.UnplayedCount.Value <= 0)
{ {
if (request.UnplayedCount.Value <= 0) request.UnplayedCount = null;
{
request.UnplayedCount = null;
}
} }
if (item == null) if (item == null)
@ -542,7 +542,6 @@ namespace MediaBrowser.Api.Images
} }
var imageInfo = GetImageInfo(request, item); var imageInfo = GetImageInfo(request, item);
if (imageInfo == null) if (imageInfo == null)
{ {
var displayText = item == null ? itemId.ToString() : item.Name; var displayText = item == null ? itemId.ToString() : item.Name;
@ -550,7 +549,6 @@ namespace MediaBrowser.Api.Images
} }
IImageEnhancer[] supportedImageEnhancers; IImageEnhancer[] supportedImageEnhancers;
if (_imageProcessor.ImageEnhancers.Length > 0) if (_imageProcessor.ImageEnhancers.Length > 0)
{ {
if (item == null) if (item == null)
@ -565,13 +563,15 @@ namespace MediaBrowser.Api.Images
supportedImageEnhancers = Array.Empty<IImageEnhancer>(); supportedImageEnhancers = Array.Empty<IImageEnhancer>();
} }
var cropwhitespace = request.Type == ImageType.Logo || bool cropwhitespace;
request.Type == ImageType.Art;
if (request.CropWhitespace.HasValue) if (request.CropWhitespace.HasValue)
{ {
cropwhitespace = request.CropWhitespace.Value; cropwhitespace = request.CropWhitespace.Value;
} }
else
{
cropwhitespace = request.Type == ImageType.Logo || request.Type == ImageType.Art;
}
var outputFormats = GetOutputFormats(request); var outputFormats = GetOutputFormats(request);
@ -653,12 +653,10 @@ namespace MediaBrowser.Api.Images
private ImageFormat[] GetOutputFormats(ImageRequest request) private ImageFormat[] GetOutputFormats(ImageRequest request)
{ {
if (!string.IsNullOrWhiteSpace(request.Format)) if (!string.IsNullOrWhiteSpace(request.Format)
&& Enum.TryParse(request.Format, true, out ImageFormat format))
{ {
if (Enum.TryParse(request.Format, true, out ImageFormat format)) return new ImageFormat[] { format };
{
return new ImageFormat[] { format };
}
} }
return GetClientSupportedFormats(); return GetClientSupportedFormats();
@ -666,8 +664,19 @@ namespace MediaBrowser.Api.Images
private ImageFormat[] GetClientSupportedFormats() private ImageFormat[] GetClientSupportedFormats()
{ {
//logger.LogDebug("Request types: {0}", string.Join(",", Request.AcceptTypes ?? Array.Empty<string>())); var supportedFormats = Request.AcceptTypes ?? Array.Empty<string>();
var supportedFormats = (Request.AcceptTypes ?? Array.Empty<string>()).Select(i => i.Split(';')[0]).ToArray(); if (supportedFormats.Length > 0)
{
for (int i = 0; i < supportedFormats.Length; i++)
{
int index = supportedFormats[i].IndexOf(';');
if (index != -1)
{
supportedFormats[i] = supportedFormats[i].Substring(0, index);
}
}
}
var acceptParam = Request.QueryString["accept"]; var acceptParam = Request.QueryString["accept"];
var supportsWebP = SupportsFormat(supportedFormats, acceptParam, "webp", false); var supportsWebP = SupportsFormat(supportedFormats, acceptParam, "webp", false);
@ -700,7 +709,7 @@ namespace MediaBrowser.Api.Images
return formats.ToArray(); return formats.ToArray();
} }
private bool SupportsFormat(string[] requestAcceptTypes, string acceptParam, string format, bool acceptAll) private bool SupportsFormat(IEnumerable<string> requestAcceptTypes, string acceptParam, string format, bool acceptAll)
{ {
var mimeType = "image/" + format; var mimeType = "image/" + format;

View File

@ -36,10 +36,20 @@ namespace MediaBrowser.Controller.Entities
/// </summary> /// </summary>
public abstract class BaseItem : IHasProviderIds, IHasLookupInfo<ItemLookupInfo> public abstract class BaseItem : IHasProviderIds, IHasLookupInfo<ItemLookupInfo>
{ {
protected static MetadataFields[] EmptyMetadataFieldsArray = Array.Empty<MetadataFields>(); private static readonly List<string> _supportedExtensions = new List<string>(SupportedImageExtensions)
protected static MediaUrl[] EmptyMediaUrlArray = Array.Empty<MediaUrl>(); {
protected static ItemImageInfo[] EmptyItemImageInfoArray = Array.Empty<ItemImageInfo>(); ".nfo",
public static readonly LinkedChild[] EmptyLinkedChildArray = Array.Empty<LinkedChild>(); ".xml",
".srt",
".vtt",
".sub",
".idx",
".txt",
".edl",
".bif",
".smi",
".ttml"
};
protected BaseItem() protected BaseItem()
{ {
@ -49,8 +59,8 @@ namespace MediaBrowser.Controller.Entities
Genres = Array.Empty<string>(); Genres = Array.Empty<string>();
Studios = Array.Empty<string>(); Studios = Array.Empty<string>();
ProviderIds = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase); ProviderIds = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
LockedFields = EmptyMetadataFieldsArray; LockedFields = Array.Empty<MetadataFields>();
ImageInfos = EmptyItemImageInfoArray; ImageInfos = Array.Empty<ItemImageInfo>();
ProductionLocations = Array.Empty<string>(); ProductionLocations = Array.Empty<string>();
RemoteTrailers = Array.Empty<MediaUrl>(); RemoteTrailers = Array.Empty<MediaUrl>();
ExtraIds = Array.Empty<Guid>(); ExtraIds = Array.Empty<Guid>();
@ -2452,10 +2462,8 @@ namespace MediaBrowser.Controller.Entities
} }
var filename = System.IO.Path.GetFileNameWithoutExtension(Path); var filename = System.IO.Path.GetFileNameWithoutExtension(Path);
var extensions = new List<string> { ".nfo", ".xml", ".srt", ".vtt", ".sub", ".idx", ".txt", ".edl", ".bif", ".smi", ".ttml" };
extensions.AddRange(SupportedImageExtensions);
return FileSystem.GetFiles(System.IO.Path.GetDirectoryName(Path), extensions.ToArray(), false, false) return FileSystem.GetFiles(System.IO.Path.GetDirectoryName(Path), _supportedExtensions, false, false)
.Where(i => System.IO.Path.GetFileNameWithoutExtension(i.FullName).StartsWith(filename, StringComparison.OrdinalIgnoreCase)) .Where(i => System.IO.Path.GetFileNameWithoutExtension(i.FullName).StartsWith(filename, StringComparison.OrdinalIgnoreCase))
.ToList(); .ToList();
} }

View File

@ -43,7 +43,7 @@ namespace MediaBrowser.Controller.Entities
public Folder() public Folder()
{ {
LinkedChildren = EmptyLinkedChildArray; LinkedChildren = Array.Empty<LinkedChild>();
} }
[IgnoreDataMember] [IgnoreDataMember]

View File

@ -25,22 +25,10 @@ namespace MediaBrowser.Controller.Entities
public DateTime DateModified { get; set; } public DateTime DateModified { get; set; }
public int Width { get; set; } public int Width { get; set; }
public int Height { get; set; } public int Height { get; set; }
[IgnoreDataMember] [IgnoreDataMember]
public bool IsLocalFile public bool IsLocalFile => Path == null || !Path.StartsWith("http", StringComparison.OrdinalIgnoreCase);
{
get
{
if (Path != null)
{
if (Path.StartsWith("http", StringComparison.OrdinalIgnoreCase))
{
return false;
}
}
return true;
}
}
} }
} }

View File

@ -17,7 +17,7 @@ namespace MediaBrowser.Controller.Entities.Movies
{ {
public BoxSet() public BoxSet()
{ {
RemoteTrailers = EmptyMediaUrlArray; RemoteTrailers = Array.Empty<MediaUrl>();
LocalTrailerIds = Array.Empty<Guid>(); LocalTrailerIds = Array.Empty<Guid>();
RemoteTrailerIds = Array.Empty<Guid>(); RemoteTrailerIds = Array.Empty<Guid>();

View File

@ -21,10 +21,10 @@ namespace MediaBrowser.Controller.Entities.Movies
public Movie() public Movie()
{ {
SpecialFeatureIds = new Guid[] { }; SpecialFeatureIds = Array.Empty<Guid>();
RemoteTrailers = EmptyMediaUrlArray; RemoteTrailers = Array.Empty<MediaUrl>();
LocalTrailerIds = new Guid[] { }; LocalTrailerIds = Array.Empty<Guid>();
RemoteTrailerIds = new Guid[] { }; RemoteTrailerIds = Array.Empty<Guid>();
} }
public Guid[] LocalTrailerIds { get; set; } public Guid[] LocalTrailerIds { get; set; }

View File

@ -18,7 +18,7 @@ namespace MediaBrowser.Controller.Entities.TV
{ {
public Episode() public Episode()
{ {
RemoteTrailers = EmptyMediaUrlArray; RemoteTrailers = Array.Empty<MediaUrl>();
LocalTrailerIds = Array.Empty<Guid>(); LocalTrailerIds = Array.Empty<Guid>();
RemoteTrailerIds = Array.Empty<Guid>(); RemoteTrailerIds = Array.Empty<Guid>();
} }

View File

@ -7,7 +7,6 @@ using MediaBrowser.Controller.Dto;
using MediaBrowser.Controller.Providers; using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Configuration; using MediaBrowser.Model.Configuration;
using MediaBrowser.Model.Entities; using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Extensions;
using MediaBrowser.Model.Providers; using MediaBrowser.Model.Providers;
using MediaBrowser.Model.Querying; using MediaBrowser.Model.Querying;
using MediaBrowser.Model.Serialization; using MediaBrowser.Model.Serialization;
@ -22,7 +21,7 @@ namespace MediaBrowser.Controller.Entities.TV
{ {
public Series() public Series()
{ {
RemoteTrailers = EmptyMediaUrlArray; RemoteTrailers = Array.Empty<MediaUrl>();
LocalTrailerIds = Array.Empty<Guid>(); LocalTrailerIds = Array.Empty<Guid>();
RemoteTrailerIds = Array.Empty<Guid>(); RemoteTrailerIds = Array.Empty<Guid>();
AirDays = Array.Empty<DayOfWeek>(); AirDays = Array.Empty<DayOfWeek>();

View File

@ -167,7 +167,7 @@ namespace MediaBrowser.Controller.Entities
AdditionalParts = Array.Empty<string>(); AdditionalParts = Array.Empty<string>();
LocalAlternateVersions = Array.Empty<string>(); LocalAlternateVersions = Array.Empty<string>();
SubtitleFiles = Array.Empty<string>(); SubtitleFiles = Array.Empty<string>();
LinkedAlternateVersions = EmptyLinkedChildArray; LinkedAlternateVersions = Array.Empty<LinkedChild>();
} }
public override bool CanDownload() public override bool CanDownload()

View File

@ -1,7 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Text;
namespace MediaBrowser.Model.IO namespace MediaBrowser.Model.IO
{ {
@ -177,7 +176,7 @@ namespace MediaBrowser.Model.IO
/// </summary> /// </summary>
IEnumerable<FileSystemMetadata> GetFiles(string path, bool recursive = false); IEnumerable<FileSystemMetadata> GetFiles(string path, bool recursive = false);
IEnumerable<FileSystemMetadata> GetFiles(string path, string[] extensions, bool enableCaseSensitiveExtensions, bool recursive); IEnumerable<FileSystemMetadata> GetFiles(string path, IReadOnlyList<string> extensions, bool enableCaseSensitiveExtensions, bool recursive);
/// <summary> /// <summary>
/// Gets the file system entries. /// Gets the file system entries.