repo creation with initial code after cloning public repo
This commit is contained in:
@@ -0,0 +1,150 @@
|
||||
using System;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
|
||||
namespace MediaBrowser.Controller.Extensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Configuration extensions for <c>MediaBrowser.Controller</c>.
|
||||
/// </summary>
|
||||
public static class ConfigurationExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// The key for a setting that specifies the default redirect path
|
||||
/// to use for requests where the URL base prefix is invalid or missing..
|
||||
/// </summary>
|
||||
public const string DefaultRedirectKey = "DefaultRedirectPath";
|
||||
|
||||
/// <summary>
|
||||
/// The key for the address override option.
|
||||
/// </summary>
|
||||
public const string AddressOverrideKey = "PublishedServerUrl";
|
||||
|
||||
/// <summary>
|
||||
/// The key for a setting that indicates whether the application should host web client content.
|
||||
/// </summary>
|
||||
public const string HostWebClientKey = "hostwebclient";
|
||||
|
||||
/// <summary>
|
||||
/// The key for the FFmpeg probe size option.
|
||||
/// </summary>
|
||||
public const string FfmpegProbeSizeKey = "FFmpeg:probesize";
|
||||
|
||||
/// <summary>
|
||||
/// The key for the skipping FFmpeg validation.
|
||||
/// </summary>
|
||||
public const string FfmpegSkipValidationKey = "FFmpeg:novalidation";
|
||||
|
||||
/// <summary>
|
||||
/// The key for the FFmpeg analyze duration option.
|
||||
/// </summary>
|
||||
public const string FfmpegAnalyzeDurationKey = "FFmpeg:analyzeduration";
|
||||
|
||||
/// <summary>
|
||||
/// The key for the FFmpeg image extraction performance tradeoff option.
|
||||
/// </summary>
|
||||
public const string FfmpegImgExtractPerfTradeoffKey = "FFmpeg:imgExtractPerfTradeoff";
|
||||
|
||||
/// <summary>
|
||||
/// The key for the FFmpeg path option.
|
||||
/// </summary>
|
||||
public const string FfmpegPathKey = "ffmpeg";
|
||||
|
||||
/// <summary>
|
||||
/// The key for a setting that indicates whether kestrel should bind to a unix socket.
|
||||
/// </summary>
|
||||
public const string BindToUnixSocketKey = "kestrel:socket";
|
||||
|
||||
/// <summary>
|
||||
/// The key for the unix socket path.
|
||||
/// </summary>
|
||||
public const string UnixSocketPathKey = "kestrel:socketPath";
|
||||
|
||||
/// <summary>
|
||||
/// The permissions for the unix socket.
|
||||
/// </summary>
|
||||
public const string UnixSocketPermissionsKey = "kestrel:socketPermissions";
|
||||
|
||||
/// <summary>
|
||||
/// The cache size of the SQL database, see cache_size.
|
||||
/// </summary>
|
||||
public const string SqliteCacheSizeKey = "sqlite:cacheSize";
|
||||
|
||||
/// <summary>
|
||||
/// The key for a setting that indicates whether the application should detect network status change.
|
||||
/// </summary>
|
||||
public const string DetectNetworkChangeKey = "DetectNetworkChange";
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the application should host static web content from the <see cref="IConfiguration"/>.
|
||||
/// </summary>
|
||||
/// <param name="configuration">The configuration to retrieve the value from.</param>
|
||||
/// <returns>The parsed config value.</returns>
|
||||
/// <exception cref="FormatException">The config value is not a valid bool string. See <see cref="bool.Parse(string)"/>.</exception>
|
||||
public static bool HostWebClient(this IConfiguration configuration)
|
||||
=> configuration.GetValue<bool>(HostWebClientKey);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the FFmpeg probe size from the <see cref="IConfiguration" />.
|
||||
/// </summary>
|
||||
/// <param name="configuration">The configuration to read the setting from.</param>
|
||||
/// <returns>The FFmpeg probe size option.</returns>
|
||||
public static string? GetFFmpegProbeSize(this IConfiguration configuration)
|
||||
=> configuration[FfmpegProbeSizeKey];
|
||||
|
||||
/// <summary>
|
||||
/// Gets the FFmpeg analyze duration from the <see cref="IConfiguration" />.
|
||||
/// </summary>
|
||||
/// <param name="configuration">The configuration to read the setting from.</param>
|
||||
/// <returns>The FFmpeg analyze duration option.</returns>
|
||||
public static string? GetFFmpegAnalyzeDuration(this IConfiguration configuration)
|
||||
=> configuration[FfmpegAnalyzeDurationKey];
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the server should validate FFmpeg during startup.
|
||||
/// </summary>
|
||||
/// <param name="configuration">The configuration to read the setting from.</param>
|
||||
/// <returns><c>true</c> if the server should validate FFmpeg during startup, otherwise <c>false</c>.</returns>
|
||||
public static bool GetFFmpegSkipValidation(this IConfiguration configuration)
|
||||
=> configuration.GetValue<bool>(FfmpegSkipValidationKey);
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the server should trade off for performance during FFmpeg image extraction.
|
||||
/// </summary>
|
||||
/// <param name="configuration">The configuration to read the setting from.</param>
|
||||
/// <returns><c>true</c> if the server should trade off for performance during FFmpeg image extraction, otherwise <c>false</c>.</returns>
|
||||
public static bool GetFFmpegImgExtractPerfTradeoff(this IConfiguration configuration)
|
||||
=> configuration.GetValue<bool>(FfmpegImgExtractPerfTradeoffKey);
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether kestrel should bind to a unix socket from the <see cref="IConfiguration" />.
|
||||
/// </summary>
|
||||
/// <param name="configuration">The configuration to read the setting from.</param>
|
||||
/// <returns><c>true</c> if kestrel should bind to a unix socket, otherwise <c>false</c>.</returns>
|
||||
public static bool UseUnixSocket(this IConfiguration configuration)
|
||||
=> configuration.GetValue<bool>(BindToUnixSocketKey);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the path for the unix socket from the <see cref="IConfiguration" />.
|
||||
/// </summary>
|
||||
/// <param name="configuration">The configuration to read the setting from.</param>
|
||||
/// <returns>The unix socket path.</returns>
|
||||
public static string? GetUnixSocketPath(this IConfiguration configuration)
|
||||
=> configuration[UnixSocketPathKey];
|
||||
|
||||
/// <summary>
|
||||
/// Gets the permissions for the unix socket from the <see cref="IConfiguration" />.
|
||||
/// </summary>
|
||||
/// <param name="configuration">The configuration to read the setting from.</param>
|
||||
/// <returns>The unix socket permissions.</returns>
|
||||
public static string? GetUnixSocketPermissions(this IConfiguration configuration)
|
||||
=> configuration[UnixSocketPermissionsKey];
|
||||
|
||||
/// <summary>
|
||||
/// Gets the cache_size from the <see cref="IConfiguration" />.
|
||||
/// </summary>
|
||||
/// <param name="configuration">The configuration to read the setting from.</param>
|
||||
/// <returns>The sqlite cache size.</returns>
|
||||
public static int? GetSqliteCacheSize(this IConfiguration configuration)
|
||||
=> configuration.GetValue<int?>(SqliteCacheSizeKey);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,193 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Xml;
|
||||
using Jellyfin.Data.Enums;
|
||||
using MediaBrowser.Controller.Entities;
|
||||
|
||||
namespace MediaBrowser.Controller.Extensions;
|
||||
|
||||
/// <summary>
|
||||
/// Provides extension methods for <see cref="XmlReader"/> to parse <see cref="BaseItem"/>'s.
|
||||
/// </summary>
|
||||
public static class XmlReaderExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Reads a trimmed string from the current node.
|
||||
/// </summary>
|
||||
/// <param name="reader">The <see cref="XmlReader"/>.</param>
|
||||
/// <returns>The trimmed content.</returns>
|
||||
public static string ReadNormalizedString(this XmlReader reader)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(reader);
|
||||
|
||||
return reader.ReadElementContentAsString().Trim();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads an int from the current node.
|
||||
/// </summary>
|
||||
/// <param name="reader">The <see cref="XmlReader"/>.</param>
|
||||
/// <param name="value">The parsed <c>int</c>.</param>
|
||||
/// <returns>A value indicating whether the parsing succeeded.</returns>
|
||||
public static bool TryReadInt(this XmlReader reader, out int value)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(reader);
|
||||
|
||||
return int.TryParse(reader.ReadElementContentAsString(), CultureInfo.InvariantCulture, out value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parses a <see cref="DateTime"/> from the current node.
|
||||
/// </summary>
|
||||
/// <param name="reader">The <see cref="XmlReader"/>.</param>
|
||||
/// <param name="value">The parsed <see cref="DateTime"/>.</param>
|
||||
/// <returns>A value indicating whether the parsing succeeded.</returns>
|
||||
public static bool TryReadDateTime(this XmlReader reader, out DateTime value)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(reader);
|
||||
|
||||
return DateTime.TryParse(
|
||||
reader.ReadElementContentAsString(),
|
||||
CultureInfo.InvariantCulture,
|
||||
DateTimeStyles.AssumeUniversal | DateTimeStyles.AdjustToUniversal,
|
||||
out value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parses a <see cref="DateTime"/> from the current node.
|
||||
/// </summary>
|
||||
/// <param name="reader">The <see cref="XmlReader"/>.</param>
|
||||
/// <param name="formatString">The date format string.</param>
|
||||
/// <param name="value">The parsed <see cref="DateTime"/>.</param>
|
||||
/// <returns>A value indicating whether the parsing succeeded.</returns>
|
||||
public static bool TryReadDateTimeExact(this XmlReader reader, string formatString, out DateTime value)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(reader);
|
||||
ArgumentNullException.ThrowIfNull(formatString);
|
||||
|
||||
return DateTime.TryParseExact(
|
||||
reader.ReadElementContentAsString(),
|
||||
formatString,
|
||||
CultureInfo.InvariantCulture,
|
||||
DateTimeStyles.AssumeUniversal | DateTimeStyles.AdjustToUniversal,
|
||||
out value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parses a <see cref="PersonInfo"/> from the xml node.
|
||||
/// </summary>
|
||||
/// <param name="reader">The <see cref="XmlReader"/>.</param>
|
||||
/// <returns>A <see cref="PersonInfo"/>, or <c>null</c> if none is found.</returns>
|
||||
public static PersonInfo? GetPersonFromXmlNode(this XmlReader reader)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(reader);
|
||||
|
||||
if (reader.IsEmptyElement)
|
||||
{
|
||||
reader.Read();
|
||||
return null;
|
||||
}
|
||||
|
||||
var name = string.Empty;
|
||||
var type = PersonKind.Actor; // If type is not specified assume actor
|
||||
var role = string.Empty;
|
||||
int? sortOrder = null;
|
||||
string? imageUrl = null;
|
||||
|
||||
using var subtree = reader.ReadSubtree();
|
||||
subtree.MoveToContent();
|
||||
subtree.Read();
|
||||
|
||||
while (subtree is { EOF: false, ReadState: ReadState.Interactive })
|
||||
{
|
||||
if (subtree.NodeType != XmlNodeType.Element)
|
||||
{
|
||||
subtree.Read();
|
||||
continue;
|
||||
}
|
||||
|
||||
switch (subtree.Name)
|
||||
{
|
||||
case "name":
|
||||
case "Name":
|
||||
name = subtree.ReadNormalizedString();
|
||||
break;
|
||||
case "role":
|
||||
case "Role":
|
||||
role = subtree.ReadNormalizedString();
|
||||
break;
|
||||
case "type":
|
||||
case "Type":
|
||||
Enum.TryParse(subtree.ReadElementContentAsString(), true, out type);
|
||||
break;
|
||||
case "order":
|
||||
case "sortorder":
|
||||
case "SortOrder":
|
||||
if (subtree.TryReadInt(out var sortOrderVal))
|
||||
{
|
||||
sortOrder = sortOrderVal;
|
||||
}
|
||||
|
||||
break;
|
||||
case "thumb":
|
||||
imageUrl = subtree.ReadNormalizedString();
|
||||
break;
|
||||
default:
|
||||
subtree.Skip();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (string.IsNullOrWhiteSpace(name))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return new PersonInfo
|
||||
{
|
||||
Name = name,
|
||||
Role = role,
|
||||
Type = type,
|
||||
SortOrder = sortOrder,
|
||||
ImageUrl = imageUrl
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Used to split names of comma or pipe delimited genres and people.
|
||||
/// </summary>
|
||||
/// <param name="reader">The <see cref="XmlReader"/>.</param>
|
||||
/// <returns>IEnumerable{System.String}.</returns>
|
||||
public static IEnumerable<string> GetStringArray(this XmlReader reader)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(reader);
|
||||
var value = reader.ReadElementContentAsString();
|
||||
|
||||
// Only split by comma if there is no pipe in the string
|
||||
// We have to be careful to not split names like Matthew, Jr.
|
||||
ReadOnlySpan<char> separator = !value.Contains('|', StringComparison.Ordinal)
|
||||
&& !value.Contains(';', StringComparison.Ordinal)
|
||||
? stackalloc[] { ',' }
|
||||
: stackalloc[] { '|', ';' };
|
||||
|
||||
foreach (var part in value.AsSpan().Trim().Trim(separator).ToString().Split(separator))
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(part))
|
||||
{
|
||||
yield return part.Trim();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parses a <see cref="PersonInfo"/> array from the xml node.
|
||||
/// </summary>
|
||||
/// <param name="reader">The <see cref="XmlReader"/>.</param>
|
||||
/// <param name="personKind">The <see cref="PersonKind"/>.</param>
|
||||
/// <returns>The <see cref="IEnumerable{PersonInfo}"/>.</returns>
|
||||
public static IEnumerable<PersonInfo> GetPersonArray(this XmlReader reader, PersonKind personKind)
|
||||
=> reader.GetStringArray()
|
||||
.Select(part => new PersonInfo { Name = part, Type = personKind });
|
||||
}
|
||||
Reference in New Issue
Block a user