Merge pull request #5276 from Bond-009/minor12

This commit is contained in:
Joshua M. Boniface 2021-02-22 21:00:34 -05:00 committed by GitHub
commit c0c4aff8a6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 21 additions and 119 deletions

View File

@ -10,7 +10,6 @@ using System.Net.Http;
using System.Net.Mime; using System.Net.Mime;
using System.Text; using System.Text;
using System.Text.Json; using System.Text.Json;
using System.Text.Json.Serialization;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using MediaBrowser.Common; using MediaBrowser.Common;

View File

@ -335,11 +335,6 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts.HdHomerun
return new Uri(url).AbsoluteUri.TrimEnd('/'); return new Uri(url).AbsoluteUri.TrimEnd('/');
} }
protected EncodingOptions GetEncodingOptions()
{
return Config.GetConfiguration<EncodingOptions>("encoding");
}
private static string GetHdHrIdFromChannelId(string channelId) private static string GetHdHrIdFromChannelId(string channelId)
{ {
return channelId.Split('_')[1]; return channelId.Split('_')[1];

View File

@ -8,7 +8,6 @@ using System.Linq;
using System.Net.WebSockets; using System.Net.WebSockets;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using MediaBrowser.Common.Extensions;
using MediaBrowser.Controller.Net; using MediaBrowser.Controller.Net;
using MediaBrowser.Controller.Session; using MediaBrowser.Controller.Session;
using MediaBrowser.Model.Net; using MediaBrowser.Model.Net;

View File

@ -113,14 +113,5 @@ namespace Jellyfin.Api.Extensions
return dtoOptions; return dtoOptions;
} }
/// <summary>
/// Check if DtoOptions contains field.
/// </summary>
/// <param name="dtoOptions">DtoOptions object.</param>
/// <param name="field">Field to check.</param>
/// <returns>Field existence.</returns>
internal static bool ContainsField(this DtoOptions dtoOptions, ItemFields field)
=> dtoOptions.Fields != null && dtoOptions.Fields.Contains(field);
} }
} }

View File

@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Globalization; using System.Globalization;
using System.Linq; using System.Linq;
using System.Net; using System.Net;
using System.Net.Mime;
using System.Security.Claims; using System.Security.Claims;
using System.Text; using System.Text;
using System.Threading; using System.Threading;
@ -171,13 +172,15 @@ namespace Jellyfin.Api.Helpers
var queryString = _httpContextAccessor.HttpContext.Request.QueryString.ToString(); var queryString = _httpContextAccessor.HttpContext.Request.QueryString.ToString();
// from universal audio service // from universal audio service
if (queryString.IndexOf("SegmentContainer", StringComparison.OrdinalIgnoreCase) == -1 && !string.IsNullOrWhiteSpace(state.Request.SegmentContainer)) if (!string.IsNullOrWhiteSpace(state.Request.SegmentContainer)
&& !queryString.Contains("SegmentContainer", StringComparison.OrdinalIgnoreCase))
{ {
queryString += "&SegmentContainer=" + state.Request.SegmentContainer; queryString += "&SegmentContainer=" + state.Request.SegmentContainer;
} }
// from universal audio service // from universal audio service
if (!string.IsNullOrWhiteSpace(state.Request.TranscodeReasons) && queryString.IndexOf("TranscodeReasons=", StringComparison.OrdinalIgnoreCase) == -1) if (!string.IsNullOrWhiteSpace(state.Request.TranscodeReasons)
&& !queryString.Contains("TranscodeReasons=", StringComparison.OrdinalIgnoreCase))
{ {
queryString += "&TranscodeReasons=" + state.Request.TranscodeReasons; queryString += "&TranscodeReasons=" + state.Request.TranscodeReasons;
} }
@ -560,13 +563,13 @@ namespace Jellyfin.Api.Helpers
profileString = state.GetRequestedProfiles(codec).FirstOrDefault() ?? string.Empty; profileString = state.GetRequestedProfiles(codec).FirstOrDefault() ?? string.Empty;
if (string.Equals(state.ActualOutputVideoCodec, "h264", StringComparison.OrdinalIgnoreCase)) if (string.Equals(state.ActualOutputVideoCodec, "h264", StringComparison.OrdinalIgnoreCase))
{ {
profileString = profileString ?? "high"; profileString ??= "high";
} }
if (string.Equals(state.ActualOutputVideoCodec, "h265", StringComparison.OrdinalIgnoreCase) if (string.Equals(state.ActualOutputVideoCodec, "h265", StringComparison.OrdinalIgnoreCase)
|| string.Equals(state.ActualOutputVideoCodec, "hevc", StringComparison.OrdinalIgnoreCase)) || string.Equals(state.ActualOutputVideoCodec, "hevc", StringComparison.OrdinalIgnoreCase))
{ {
profileString = profileString ?? "main"; profileString ??= "main";
} }
} }

View File

@ -245,7 +245,7 @@ namespace Jellyfin.Api.Helpers
var ext = string.IsNullOrWhiteSpace(state.OutputContainer) var ext = string.IsNullOrWhiteSpace(state.OutputContainer)
? GetOutputFileExtension(state) ? GetOutputFileExtension(state)
: ('.' + state.OutputContainer); : ("." + state.OutputContainer);
state.OutputFilePath = GetOutputFilePath(state, ext!, serverConfigurationManager, streamingRequest.DeviceId, streamingRequest.PlaySessionId); state.OutputFilePath = GetOutputFilePath(state, ext!, serverConfigurationManager, streamingRequest.DeviceId, streamingRequest.PlaySessionId);

View File

@ -98,7 +98,7 @@ namespace Jellyfin.Api.Models.PlaybackDtos
private EncodingOptions GetOptions() private EncodingOptions GetOptions()
{ {
return _config.GetConfiguration<EncodingOptions>("encoding"); return _config.GetEncodingOptions();
} }
private async void TimerCallback(object? state) private async void TimerCallback(object? state)

View File

@ -32,7 +32,7 @@ namespace Jellyfin.Server.Migrations.Routines
public void Perform() public void Perform()
{ {
// Set EnableThrottling to false since it wasn't used before and may introduce issues // Set EnableThrottling to false since it wasn't used before and may introduce issues
var encoding = _configManager.GetConfiguration<EncodingOptions>("encoding"); var encoding = _configManager.GetEncodingOptions();
if (encoding.EnableThrottling) if (encoding.EnableThrottling)
{ {
_logger.LogInformation("Disabling transcoding throttling during migration"); _logger.LogInformation("Disabling transcoding throttling during migration");

View File

@ -1,37 +0,0 @@
#nullable enable
using System;
namespace MediaBrowser.Common.Extensions
{
/// <summary>
/// Extensions methods to simplify string operations.
/// </summary>
public static class StringExtensions
{
/// <summary>
/// Returns the part on the left of the <c>needle</c>.
/// </summary>
/// <param name="haystack">The string to seek.</param>
/// <param name="needle">The needle to find.</param>
/// <returns>The part left of the <paramref name="needle" />.</returns>
public static ReadOnlySpan<char> LeftPart(this ReadOnlySpan<char> haystack, char needle)
{
var pos = haystack.IndexOf(needle);
return pos == -1 ? haystack : haystack[..pos];
}
/// <summary>
/// Returns the part on the left of the <c>needle</c>.
/// </summary>
/// <param name="haystack">The string to seek.</param>
/// <param name="needle">The needle to find.</param>
/// <param name="stringComparison">One of the enumeration values that specifies the rules for the search.</param>
/// <returns>The part left of the <c>needle</c>.</returns>
public static ReadOnlySpan<char> LeftPart(this ReadOnlySpan<char> haystack, ReadOnlySpan<char> needle, StringComparison stringComparison = default)
{
var pos = haystack.IndexOf(needle, stringComparison);
return pos == -1 ? haystack : haystack[..pos];
}
}
}

View File

@ -1,11 +1,6 @@
#pragma warning disable CA1062 // Validate arguments of public methods
using System; using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.Net; using System.Net;
using System.Runtime.CompilerServices;
using System.Text;
namespace MediaBrowser.Common.Net namespace MediaBrowser.Common.Net
{ {

View File

@ -103,7 +103,7 @@ namespace MediaBrowser.MediaEncoding.Encoder
public void SetFFmpegPath() public void SetFFmpegPath()
{ {
// 1) Custom path stored in config/encoding xml file under tag <EncoderAppPath> takes precedence // 1) Custom path stored in config/encoding xml file under tag <EncoderAppPath> takes precedence
if (!ValidatePath(_configurationManager.GetConfiguration<EncodingOptions>("encoding").EncoderAppPath, FFmpegLocation.Custom)) if (!ValidatePath(_configurationManager.GetEncodingOptions().EncoderAppPath, FFmpegLocation.Custom))
{ {
// 2) Check if the --ffmpeg CLI switch has been given // 2) Check if the --ffmpeg CLI switch has been given
if (!ValidatePath(_startupOptionFFmpegPath, FFmpegLocation.SetByArgument)) if (!ValidatePath(_startupOptionFFmpegPath, FFmpegLocation.SetByArgument))
@ -118,7 +118,7 @@ namespace MediaBrowser.MediaEncoding.Encoder
} }
// Write the FFmpeg path to the config/encoding.xml file as <EncoderAppPathDisplay> so it appears in UI // Write the FFmpeg path to the config/encoding.xml file as <EncoderAppPathDisplay> so it appears in UI
var config = _configurationManager.GetConfiguration<EncodingOptions>("encoding"); var config = _configurationManager.GetEncodingOptions();
config.EncoderAppPathDisplay = _ffmpegPath ?? string.Empty; config.EncoderAppPathDisplay = _ffmpegPath ?? string.Empty;
_configurationManager.SaveConfiguration("encoding", config); _configurationManager.SaveConfiguration("encoding", config);
@ -177,7 +177,7 @@ namespace MediaBrowser.MediaEncoding.Encoder
// Write the new ffmpeg path to the xml as <EncoderAppPath> // Write the new ffmpeg path to the xml as <EncoderAppPath>
// This ensures its not lost on next startup // This ensures its not lost on next startup
var config = _configurationManager.GetConfiguration<EncodingOptions>("encoding"); var config = _configurationManager.GetEncodingOptions();
config.EncoderAppPath = newPath; config.EncoderAppPath = newPath;
_configurationManager.SaveConfiguration("encoding", config); _configurationManager.SaveConfiguration("encoding", config);

View File

@ -37,28 +37,28 @@ namespace Jellyfin.Api.Tests
EnableIPV6 = ip6 EnableIPV6 = ip6
}; };
var result = match + ','; var result = match + ",";
ForwardedHeadersOptions options = new ForwardedHeadersOptions(); ForwardedHeadersOptions options = new ForwardedHeadersOptions();
// Need this here as ::1 and 127.0.0.1 are in them by default. // Need this here as ::1 and 127.0.0.1 are in them by default.
options.KnownProxies.Clear(); options.KnownProxies.Clear();
options.KnownNetworks.Clear(); options.KnownNetworks.Clear();
ApiServiceCollectionExtensions.AddProxyAddresses(settings, hostList.Split(","), options); ApiServiceCollectionExtensions.AddProxyAddresses(settings, hostList.Split(','), options);
var sb = new StringBuilder(); var sb = new StringBuilder();
foreach (var item in options.KnownProxies) foreach (var item in options.KnownProxies)
{ {
sb.Append(item); sb.Append(item)
sb.Append(','); .Append(',');
} }
foreach (var item in options.KnownNetworks) foreach (var item in options.KnownNetworks)
{ {
sb.Append(item.Prefix); sb.Append(item.Prefix)
sb.Append('/'); .Append('/')
sb.Append(item.PrefixLength.ToString(CultureInfo.InvariantCulture)); .Append(item.PrefixLength.ToString(CultureInfo.InvariantCulture))
sb.Append(','); .Append(',');
} }
Assert.Equal(sb.ToString(), result); Assert.Equal(sb.ToString(), result);

View File

@ -1,43 +0,0 @@
using System;
using MediaBrowser.Common.Extensions;
using Xunit;
namespace Jellyfin.Common.Tests.Extensions
{
public class StringExtensionsTests
{
[Theory]
[InlineData("", 'q', "")]
[InlineData("Banana split", ' ', "Banana")]
[InlineData("Banana split", 'q', "Banana split")]
public void LeftPart_ValidArgsCharNeedle_Correct(string str, char needle, string expectedResult)
{
var result = str.AsSpan().LeftPart(needle).ToString();
Assert.Equal(expectedResult, result);
}
[Theory]
[InlineData("", "", "")]
[InlineData("", "q", "")]
[InlineData("Banana split", "", "")]
[InlineData("Banana split", " ", "Banana")]
[InlineData("Banana split test", " split", "Banana")]
public void LeftPart_ValidArgsWithoutStringComparison_Correct(string str, string needle, string expectedResult)
{
var result = str.AsSpan().LeftPart(needle).ToString();
Assert.Equal(expectedResult, result);
}
[Theory]
[InlineData("", "", StringComparison.Ordinal, "")]
[InlineData("Banana split", " ", StringComparison.Ordinal, "Banana")]
[InlineData("Banana split test", " split", StringComparison.Ordinal, "Banana")]
[InlineData("Banana split test", " Split", StringComparison.Ordinal, "Banana split test")]
[InlineData("Banana split test", " Splït", StringComparison.InvariantCultureIgnoreCase, "Banana split test")]
public void LeftPart_ValidArgs_Correct(string str, string needle, StringComparison stringComparison, string expectedResult)
{
var result = str.AsSpan().LeftPart(needle, stringComparison).ToString();
Assert.Equal(expectedResult, result);
}
}
}