mirror of
https://github.com/jellyfin/jellyfin.git
synced 2026-04-20 17:14:42 +01:00
allow request header overrides
This commit is contained in:
@@ -3,7 +3,6 @@ using System.Drawing;
|
||||
using System.Drawing.Drawing2D;
|
||||
using System.Drawing.Imaging;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
|
||||
namespace MediaBrowser.Controller.Drawing
|
||||
{
|
||||
@@ -61,7 +60,15 @@ namespace MediaBrowser.Controller.Drawing
|
||||
/// <returns>ImageCodecInfo.</returns>
|
||||
private static ImageCodecInfo GetImageCodecInfo(string mimeType)
|
||||
{
|
||||
return Encoders.FirstOrDefault(i => i.MimeType.Equals(mimeType, StringComparison.OrdinalIgnoreCase)) ?? Encoders.FirstOrDefault();
|
||||
foreach (var encoder in Encoders)
|
||||
{
|
||||
if (string.Equals(encoder.MimeType, mimeType, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return encoder;
|
||||
}
|
||||
}
|
||||
|
||||
return Encoders.Length == 0 ? null : Encoders[0];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -18,19 +18,22 @@ namespace MediaBrowser.Controller.Drawing
|
||||
/// <summary>
|
||||
/// The error message
|
||||
/// </summary>
|
||||
const string errorMessage = "Could not recognize image format.";
|
||||
const string ErrorMessage = "Could not recognize image format.";
|
||||
|
||||
/// <summary>
|
||||
/// The image format decoders
|
||||
/// </summary>
|
||||
private static readonly Dictionary<byte[], Func<BinaryReader, Size>> imageFormatDecoders = new Dictionary<byte[], Func<BinaryReader, Size>>
|
||||
private static readonly KeyValuePair<byte[], Func<BinaryReader, Size>>[] ImageFormatDecoders = new Dictionary<byte[], Func<BinaryReader, Size>>
|
||||
{
|
||||
{ new byte[] { 0x42, 0x4D }, DecodeBitmap },
|
||||
{ new byte[] { 0x47, 0x49, 0x46, 0x38, 0x37, 0x61 }, DecodeGif },
|
||||
{ new byte[] { 0x47, 0x49, 0x46, 0x38, 0x39, 0x61 }, DecodeGif },
|
||||
{ new byte[] { 0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A }, DecodePng },
|
||||
{ new byte[] { 0xff, 0xd8 }, DecodeJfif },
|
||||
};
|
||||
{ new byte[] { 0xff, 0xd8 }, DecodeJfif }
|
||||
|
||||
}.ToArray();
|
||||
|
||||
private static readonly int MaxMagicBytesLength = ImageFormatDecoders.Select(i => i.Key.Length).OrderByDescending(i => i).First();
|
||||
|
||||
/// <summary>
|
||||
/// Gets the dimensions of an image.
|
||||
@@ -81,12 +84,13 @@ namespace MediaBrowser.Controller.Drawing
|
||||
/// <exception cref="ArgumentException">The image was of an unrecognized format.</exception>
|
||||
private static Size GetDimensions(BinaryReader binaryReader)
|
||||
{
|
||||
int maxMagicBytesLength = imageFormatDecoders.Keys.OrderByDescending(x => x.Length).First().Length;
|
||||
var magicBytes = new byte[maxMagicBytesLength];
|
||||
for (int i = 0; i < maxMagicBytesLength; i += 1)
|
||||
var magicBytes = new byte[MaxMagicBytesLength];
|
||||
|
||||
for (var i = 0; i < MaxMagicBytesLength; i += 1)
|
||||
{
|
||||
magicBytes[i] = binaryReader.ReadByte();
|
||||
foreach (var kvPair in imageFormatDecoders)
|
||||
|
||||
foreach (var kvPair in ImageFormatDecoders)
|
||||
{
|
||||
if (StartsWith(magicBytes, kvPair.Key))
|
||||
{
|
||||
@@ -95,7 +99,7 @@ namespace MediaBrowser.Controller.Drawing
|
||||
}
|
||||
}
|
||||
|
||||
throw new ArgumentException(errorMessage, "binaryReader");
|
||||
throw new ArgumentException(ErrorMessage, "binaryReader");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -217,7 +221,7 @@ namespace MediaBrowser.Controller.Drawing
|
||||
}
|
||||
}
|
||||
|
||||
throw new ArgumentException(errorMessage);
|
||||
throw new ArgumentException(ErrorMessage);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,8 +3,6 @@ using MediaBrowser.Model.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using MoreLinq;
|
||||
|
||||
namespace MediaBrowser.Controller.IO
|
||||
{
|
||||
@@ -40,9 +38,14 @@ namespace MediaBrowser.Controller.IO
|
||||
if (!resolveShortcuts && flattenFolderDepth == 0)
|
||||
{
|
||||
// Seeing dupes on some users file system for some reason
|
||||
return entries
|
||||
.DistinctBy(i => i.FullName, StringComparer.OrdinalIgnoreCase)
|
||||
.ToDictionary(i => i.FullName, StringComparer.OrdinalIgnoreCase);
|
||||
var dictionary = new Dictionary<string, FileSystemInfo>(StringComparer.OrdinalIgnoreCase);
|
||||
|
||||
foreach (var info in entries)
|
||||
{
|
||||
dictionary[info.FullName] = info;
|
||||
}
|
||||
|
||||
return dictionary;
|
||||
}
|
||||
|
||||
var dict = new Dictionary<string, FileSystemInfo>(StringComparer.OrdinalIgnoreCase);
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using MediaBrowser.Common.Extensions;
|
||||
using MediaBrowser.Common.Extensions;
|
||||
using MediaBrowser.Controller.Configuration;
|
||||
using MediaBrowser.Controller.Entities;
|
||||
using MediaBrowser.Controller.Library;
|
||||
using MediaBrowser.Model.Entities;
|
||||
using MediaBrowser.Model.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
@@ -330,6 +330,16 @@ namespace MediaBrowser.Controller.Providers
|
||||
return GetFileSystemStamp(item);
|
||||
}
|
||||
|
||||
private Dictionary<string, string> _fileStampExtensionsDictionary;
|
||||
private Dictionary<string, string> FileStampExtensionsDictionary
|
||||
{
|
||||
get
|
||||
{
|
||||
return _fileStampExtensionsDictionary ??
|
||||
(_fileStampExtensionsDictionary =
|
||||
FilestampExtensions.ToDictionary(i => i, StringComparer.OrdinalIgnoreCase));
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Gets the file system stamp.
|
||||
/// </summary>
|
||||
@@ -362,20 +372,20 @@ namespace MediaBrowser.Controller.Providers
|
||||
|
||||
var sb = new StringBuilder();
|
||||
|
||||
var extensionsList = FilestampExtensions;
|
||||
var extensions = extensionsList.ToDictionary(i => i, StringComparer.OrdinalIgnoreCase);
|
||||
var extensions = FileStampExtensionsDictionary;
|
||||
var numExtensions = extensions.Count;
|
||||
|
||||
// Record the name of each file
|
||||
// Need to sort these because accoring to msdn docs, our i/o methods are not guaranteed in any order
|
||||
foreach (var file in resolveArgs.FileSystemChildren
|
||||
.Where(i => IncludeInFileStamp(i, extensions, extensionsList.Length))
|
||||
.Where(i => IncludeInFileStamp(i, extensions, numExtensions))
|
||||
.OrderBy(f => f.Name))
|
||||
{
|
||||
sb.Append(file.Name);
|
||||
}
|
||||
|
||||
foreach (var file in resolveArgs.MetadataFiles
|
||||
.Where(i => IncludeInFileStamp(i, extensions, extensionsList.Length))
|
||||
.Where(i => IncludeInFileStamp(i, extensions, numExtensions))
|
||||
.OrderBy(f => f.Name))
|
||||
{
|
||||
sb.Append(file.Name);
|
||||
|
||||
Reference in New Issue
Block a user