Optimize tryparse

* Don't check for null before
* Don't try different formats when not needed (NumberFormat.Integer is the fast path)
This commit is contained in:
Bond_009 2023-02-19 16:52:29 +01:00
parent 1deb9f36ba
commit 24a7e210c3
23 changed files with 83 additions and 144 deletions

View File

@ -3,6 +3,7 @@ using System.Globalization;
using System.IO; using System.IO;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using Emby.Naming.Common; using Emby.Naming.Common;
using Jellyfin.Extensions;
namespace Emby.Naming.Audio namespace Emby.Naming.Audio
{ {
@ -58,13 +59,7 @@ namespace Emby.Naming.Audio
var tmp = trimmedFilename.Slice(prefix.Length).Trim(); var tmp = trimmedFilename.Slice(prefix.Length).Trim();
int index = tmp.IndexOf(' '); if (int.TryParse(tmp.LeftPart(' '), CultureInfo.InvariantCulture, out _))
if (index != -1)
{
tmp = tmp.Slice(0, index);
}
if (int.TryParse(tmp, NumberStyles.Integer, CultureInfo.InvariantCulture, out _))
{ {
return true; return true;
} }

View File

@ -1195,7 +1195,7 @@ namespace Emby.Server.Implementations.Data
Path = RestorePath(path.ToString()) Path = RestorePath(path.ToString())
}; };
if (long.TryParse(dateModified, NumberStyles.Any, CultureInfo.InvariantCulture, out var ticks) if (long.TryParse(dateModified, CultureInfo.InvariantCulture, out var ticks)
&& ticks >= DateTime.MinValue.Ticks && ticks >= DateTime.MinValue.Ticks
&& ticks <= DateTime.MaxValue.Ticks) && ticks <= DateTime.MaxValue.Ticks)
{ {

View File

@ -570,15 +570,13 @@ namespace Emby.Server.Implementations.LiveTv.Listings
_tokens.TryAdd(username, savedToken); _tokens.TryAdd(username, savedToken);
} }
if (!string.IsNullOrEmpty(savedToken.Name) && !string.IsNullOrEmpty(savedToken.Value)) if (!string.IsNullOrEmpty(savedToken.Name)
&& long.TryParse(savedToken.Value, CultureInfo.InvariantCulture, out long ticks))
{ {
if (long.TryParse(savedToken.Value, NumberStyles.Any, CultureInfo.InvariantCulture, out long ticks)) // If it's under 24 hours old we can still use it
if (DateTime.UtcNow.Ticks - ticks < TimeSpan.FromHours(20).Ticks)
{ {
// If it's under 24 hours old we can still use it return savedToken.Name;
if (DateTime.UtcNow.Ticks - ticks < TimeSpan.FromHours(20).Ticks)
{
return savedToken.Name;
}
} }
} }

View File

@ -168,28 +168,24 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts
string numberString = null; string numberString = null;
string attributeValue; string attributeValue;
if (attributes.TryGetValue("tvg-chno", out attributeValue)) if (attributes.TryGetValue("tvg-chno", out attributeValue)
&& double.TryParse(attributeValue, CultureInfo.InvariantCulture, out _))
{ {
if (double.TryParse(attributeValue, NumberStyles.Any, CultureInfo.InvariantCulture, out _)) numberString = attributeValue;
{
numberString = attributeValue;
}
} }
if (!IsValidChannelNumber(numberString)) if (!IsValidChannelNumber(numberString))
{ {
if (attributes.TryGetValue("tvg-id", out attributeValue)) if (attributes.TryGetValue("tvg-id", out attributeValue))
{ {
if (double.TryParse(attributeValue, NumberStyles.Any, CultureInfo.InvariantCulture, out _)) if (double.TryParse(attributeValue, CultureInfo.InvariantCulture, out _))
{ {
numberString = attributeValue; numberString = attributeValue;
} }
else if (attributes.TryGetValue("channel-id", out attributeValue)) else if (attributes.TryGetValue("channel-id", out attributeValue)
&& double.TryParse(attributeValue, CultureInfo.InvariantCulture, out _))
{ {
if (double.TryParse(attributeValue, NumberStyles.Any, CultureInfo.InvariantCulture, out _)) numberString = attributeValue;
{
numberString = attributeValue;
}
} }
} }
@ -207,7 +203,7 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts
{ {
var numberPart = nameInExtInf.Slice(0, numberIndex).Trim(new[] { ' ', '.' }); var numberPart = nameInExtInf.Slice(0, numberIndex).Trim(new[] { ' ', '.' });
if (double.TryParse(numberPart, NumberStyles.Any, CultureInfo.InvariantCulture, out _)) if (double.TryParse(numberPart, CultureInfo.InvariantCulture, out _))
{ {
numberString = numberPart.ToString(); numberString = numberPart.ToString();
} }
@ -255,19 +251,14 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts
private static bool IsValidChannelNumber(string numberString) private static bool IsValidChannelNumber(string numberString)
{ {
if (string.IsNullOrWhiteSpace(numberString) || if (string.IsNullOrWhiteSpace(numberString)
string.Equals(numberString, "-1", StringComparison.OrdinalIgnoreCase) || || string.Equals(numberString, "-1", StringComparison.OrdinalIgnoreCase)
string.Equals(numberString, "0", StringComparison.OrdinalIgnoreCase)) || string.Equals(numberString, "0", StringComparison.OrdinalIgnoreCase))
{ {
return false; return false;
} }
if (!double.TryParse(numberString, NumberStyles.Any, CultureInfo.InvariantCulture, out _)) return double.TryParse(numberString, CultureInfo.InvariantCulture, out _);
{
return false;
}
return true;
} }
private static string GetChannelName(string extInf, Dictionary<string, string> attributes) private static string GetChannelName(string extInf, Dictionary<string, string> attributes)
@ -285,7 +276,7 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts
{ {
var numberPart = nameInExtInf.Substring(0, numberIndex).Trim(new[] { ' ', '.' }); var numberPart = nameInExtInf.Substring(0, numberIndex).Trim(new[] { ' ', '.' });
if (double.TryParse(numberPart, NumberStyles.Any, CultureInfo.InvariantCulture, out _)) if (double.TryParse(numberPart, CultureInfo.InvariantCulture, out _))
{ {
// channel.Number = number.ToString(); // channel.Number = number.ToString();
nameInExtInf = nameInExtInf.Substring(numberIndex + 1).Trim(new[] { ' ', '-' }); nameInExtInf = nameInExtInf.Substring(numberIndex + 1).Trim(new[] { ' ', '-' });

View File

@ -71,8 +71,7 @@ public static class ClaimsPrincipalExtensions
public static bool GetIsApiKey(this ClaimsPrincipal user) public static bool GetIsApiKey(this ClaimsPrincipal user)
{ {
var claimValue = GetClaimValue(user, InternalClaimTypes.IsApiKey); var claimValue = GetClaimValue(user, InternalClaimTypes.IsApiKey);
return !string.IsNullOrEmpty(claimValue) return bool.TryParse(claimValue, out var parsedClaimValue)
&& bool.TryParse(claimValue, out var parsedClaimValue)
&& parsedClaimValue; && parsedClaimValue;
} }

View File

@ -337,10 +337,10 @@ public static class StreamingHelpers
value = index == -1 value = index == -1
? value.Slice(npt.Length) ? value.Slice(npt.Length)
: value.Slice(npt.Length, index - npt.Length); : value.Slice(npt.Length, index - npt.Length);
if (value.IndexOf(':') == -1) if (!value.Contains(':'))
{ {
// Parses npt times in the format of '417.33' // Parses npt times in the format of '417.33'
if (double.TryParse(value, NumberStyles.Any, CultureInfo.InvariantCulture, out var seconds)) if (double.TryParse(value, CultureInfo.InvariantCulture, out var seconds))
{ {
return TimeSpan.FromSeconds(seconds).Ticks; return TimeSpan.FromSeconds(seconds).Ticks;
} }

View File

@ -457,8 +457,7 @@ public class TranscodingJobHelper : IDisposable
var videoCodec = state.ActualOutputVideoCodec; var videoCodec = state.ActualOutputVideoCodec;
var hardwareAccelerationTypeString = _serverConfigurationManager.GetEncodingOptions().HardwareAccelerationType; var hardwareAccelerationTypeString = _serverConfigurationManager.GetEncodingOptions().HardwareAccelerationType;
HardwareEncodingType? hardwareAccelerationType = null; HardwareEncodingType? hardwareAccelerationType = null;
if (!string.IsNullOrEmpty(hardwareAccelerationTypeString) if (Enum.TryParse<HardwareEncodingType>(hardwareAccelerationTypeString, out var parsedHardwareAccelerationType))
&& Enum.TryParse<HardwareEncodingType>(hardwareAccelerationTypeString, out var parsedHardwareAccelerationType))
{ {
hardwareAccelerationType = parsedHardwareAccelerationType; hardwareAccelerationType = parsedHardwareAccelerationType;
} }

View File

@ -316,7 +316,7 @@ namespace Jellyfin.Networking.Manager
/// <inheritdoc/> /// <inheritdoc/>
public string GetBindInterface(string source, out int? port) public string GetBindInterface(string source, out int? port)
{ {
if (!string.IsNullOrEmpty(source) && IPHost.TryParse(source, out IPHost host)) if (IPHost.TryParse(source, out IPHost host))
{ {
return GetBindInterface(host, out port); return GetBindInterface(host, out port);
} }

View File

@ -130,7 +130,7 @@ namespace Jellyfin.Server.Migrations.Routines
SkipForwardLength = dto.CustomPrefs.TryGetValue("skipForwardLength", out var length) && int.TryParse(length, out var skipForwardLength) SkipForwardLength = dto.CustomPrefs.TryGetValue("skipForwardLength", out var length) && int.TryParse(length, out var skipForwardLength)
? skipForwardLength ? skipForwardLength
: 30000, : 30000,
SkipBackwardLength = dto.CustomPrefs.TryGetValue("skipBackLength", out length) && !string.IsNullOrEmpty(length) && int.TryParse(length, out var skipBackwardLength) SkipBackwardLength = dto.CustomPrefs.TryGetValue("skipBackLength", out length) && int.TryParse(length, out var skipBackwardLength)
? skipBackwardLength ? skipBackwardLength
: 10000, : 10000,
EnableNextVideoInfoOverlay = dto.CustomPrefs.TryGetValue("enableNextVideoInfoOverlay", out var enabled) && !string.IsNullOrEmpty(enabled) EnableNextVideoInfoOverlay = dto.CustomPrefs.TryGetValue("enableNextVideoInfoOverlay", out var enabled) && !string.IsNullOrEmpty(enabled)

View File

@ -190,7 +190,7 @@ namespace MediaBrowser.Common.Net
/// <returns>Object representing the string, if it has successfully been parsed.</returns> /// <returns>Object representing the string, if it has successfully been parsed.</returns>
public static IPHost Parse(string host) public static IPHost Parse(string host)
{ {
if (!string.IsNullOrEmpty(host) && IPHost.TryParse(host, out IPHost res)) if (IPHost.TryParse(host, out IPHost res))
{ {
return res; return res;
} }
@ -206,7 +206,7 @@ namespace MediaBrowser.Common.Net
/// <returns>Object representing the string, if it has successfully been parsed.</returns> /// <returns>Object representing the string, if it has successfully been parsed.</returns>
public static IPHost Parse(string host, AddressFamily family) public static IPHost Parse(string host, AddressFamily family)
{ {
if (!string.IsNullOrEmpty(host) && IPHost.TryParse(host, out IPHost res)) if (IPHost.TryParse(host, out IPHost res))
{ {
if (family == AddressFamily.InterNetwork) if (family == AddressFamily.InterNetwork)
{ {

View File

@ -5,6 +5,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Globalization; using System.Globalization;
using System.Linq;
using System.Text.Json.Serialization; using System.Text.Json.Serialization;
using Jellyfin.Data.Enums; using Jellyfin.Data.Enums;
using Jellyfin.Extensions; using Jellyfin.Extensions;
@ -105,12 +106,9 @@ namespace MediaBrowser.Controller.LiveTv
protected override string CreateSortName() protected override string CreateSortName()
{ {
if (!string.IsNullOrEmpty(Number)) if (double.TryParse(Number, CultureInfo.InvariantCulture, out double number))
{ {
if (double.TryParse(Number, NumberStyles.Any, CultureInfo.InvariantCulture, out double number)) return string.Format(CultureInfo.InvariantCulture, "{0:00000.0}", number) + "-" + (Name ?? string.Empty);
{
return string.Format(CultureInfo.InvariantCulture, "{0:00000.0}", number) + "-" + (Name ?? string.Empty);
}
} }
return (Number ?? string.Empty) + "-" + (Name ?? string.Empty); return (Number ?? string.Empty) + "-" + (Name ?? string.Empty);
@ -122,9 +120,7 @@ namespace MediaBrowser.Controller.LiveTv
} }
public IEnumerable<BaseItem> GetTaggedItems() public IEnumerable<BaseItem> GetTaggedItems()
{ => Enumerable.Empty<BaseItem>();
return new List<BaseItem>();
}
public override List<MediaSourceInfo> GetMediaSources(bool enablePathSubstitution) public override List<MediaSourceInfo> GetMediaSources(bool enablePathSubstitution)
{ {

View File

@ -1143,7 +1143,7 @@ namespace MediaBrowser.Controller.MediaEncoding
public static string NormalizeTranscodingLevel(EncodingJobInfo state, string level) public static string NormalizeTranscodingLevel(EncodingJobInfo state, string level)
{ {
if (double.TryParse(level, NumberStyles.Any, CultureInfo.InvariantCulture, out double requestLevel)) if (double.TryParse(level, CultureInfo.InvariantCulture, out double requestLevel))
{ {
if (string.Equals(state.ActualOutputVideoCodec, "hevc", StringComparison.OrdinalIgnoreCase) if (string.Equals(state.ActualOutputVideoCodec, "hevc", StringComparison.OrdinalIgnoreCase)
|| string.Equals(state.ActualOutputVideoCodec, "h265", StringComparison.OrdinalIgnoreCase)) || string.Equals(state.ActualOutputVideoCodec, "h265", StringComparison.OrdinalIgnoreCase))
@ -1737,7 +1737,7 @@ namespace MediaBrowser.Controller.MediaEncoding
else if (string.Equals(videoEncoder, "hevc_qsv", StringComparison.OrdinalIgnoreCase)) else if (string.Equals(videoEncoder, "hevc_qsv", StringComparison.OrdinalIgnoreCase))
{ {
// hevc_qsv use -level 51 instead of -level 153. // hevc_qsv use -level 51 instead of -level 153.
if (double.TryParse(level, NumberStyles.Any, CultureInfo.InvariantCulture, out double hevcLevel)) if (double.TryParse(level, CultureInfo.InvariantCulture, out double hevcLevel))
{ {
param += " -level " + (hevcLevel / 3); param += " -level " + (hevcLevel / 3);
} }
@ -1916,8 +1916,7 @@ namespace MediaBrowser.Controller.MediaEncoding
// If a specific level was requested, the source must match or be less than // If a specific level was requested, the source must match or be less than
var level = state.GetRequestedLevel(videoStream.Codec); var level = state.GetRequestedLevel(videoStream.Codec);
if (!string.IsNullOrEmpty(level) if (double.TryParse(level, CultureInfo.InvariantCulture, out var requestLevel))
&& double.TryParse(level, NumberStyles.Any, CultureInfo.InvariantCulture, out var requestLevel))
{ {
if (!videoStream.Level.HasValue) if (!videoStream.Level.HasValue)
{ {

View File

@ -250,8 +250,7 @@ namespace MediaBrowser.Controller.MediaEncoding
} }
var level = GetRequestedLevel(ActualOutputVideoCodec); var level = GetRequestedLevel(ActualOutputVideoCodec);
if (!string.IsNullOrEmpty(level) if (double.TryParse(level, CultureInfo.InvariantCulture, out var result))
&& double.TryParse(level, NumberStyles.Any, CultureInfo.InvariantCulture, out var result))
{ {
return result; return result;
} }
@ -645,8 +644,7 @@ namespace MediaBrowser.Controller.MediaEncoding
if (!string.IsNullOrEmpty(codec)) if (!string.IsNullOrEmpty(codec))
{ {
var value = BaseRequest.GetOption(codec, "maxrefframes"); var value = BaseRequest.GetOption(codec, "maxrefframes");
if (!string.IsNullOrEmpty(value) if (int.TryParse(value, CultureInfo.InvariantCulture, out var result))
&& int.TryParse(value, NumberStyles.Any, CultureInfo.InvariantCulture, out var result))
{ {
return result; return result;
} }
@ -665,8 +663,7 @@ namespace MediaBrowser.Controller.MediaEncoding
if (!string.IsNullOrEmpty(codec)) if (!string.IsNullOrEmpty(codec))
{ {
var value = BaseRequest.GetOption(codec, "videobitdepth"); var value = BaseRequest.GetOption(codec, "videobitdepth");
if (!string.IsNullOrEmpty(value) if (int.TryParse(value, CultureInfo.InvariantCulture, out var result))
&& int.TryParse(value, NumberStyles.Any, CultureInfo.InvariantCulture, out var result))
{ {
return result; return result;
} }
@ -685,8 +682,7 @@ namespace MediaBrowser.Controller.MediaEncoding
if (!string.IsNullOrEmpty(codec)) if (!string.IsNullOrEmpty(codec))
{ {
var value = BaseRequest.GetOption(codec, "audiobitdepth"); var value = BaseRequest.GetOption(codec, "audiobitdepth");
if (!string.IsNullOrEmpty(value) if (int.TryParse(value, CultureInfo.InvariantCulture, out var result))
&& int.TryParse(value, NumberStyles.Any, CultureInfo.InvariantCulture, out var result))
{ {
return result; return result;
} }
@ -700,8 +696,7 @@ namespace MediaBrowser.Controller.MediaEncoding
if (!string.IsNullOrEmpty(codec)) if (!string.IsNullOrEmpty(codec))
{ {
var value = BaseRequest.GetOption(codec, "audiochannels"); var value = BaseRequest.GetOption(codec, "audiochannels");
if (!string.IsNullOrEmpty(value) if (int.TryParse(value, CultureInfo.InvariantCulture, out var result))
&& int.TryParse(value, NumberStyles.Any, CultureInfo.InvariantCulture, out var result))
{ {
return result; return result;
} }

View File

@ -86,7 +86,7 @@ namespace MediaBrowser.Controller.MediaEncoding
{ {
var rate = parts[i + 1]; var rate = parts[i + 1];
if (float.TryParse(rate, NumberStyles.Any, CultureInfo.InvariantCulture, out var val)) if (float.TryParse(rate, CultureInfo.InvariantCulture, out var val))
{ {
framerate = val; framerate = val;
} }
@ -95,7 +95,7 @@ namespace MediaBrowser.Controller.MediaEncoding
{ {
var rate = part.Split('=', 2)[^1]; var rate = part.Split('=', 2)[^1];
if (float.TryParse(rate, NumberStyles.Any, CultureInfo.InvariantCulture, out var val)) if (float.TryParse(rate, CultureInfo.InvariantCulture, out var val))
{ {
framerate = val; framerate = val;
} }
@ -127,7 +127,7 @@ namespace MediaBrowser.Controller.MediaEncoding
if (scale.HasValue) if (scale.HasValue)
{ {
if (long.TryParse(size, NumberStyles.Any, CultureInfo.InvariantCulture, out var val)) if (long.TryParse(size, CultureInfo.InvariantCulture, out var val))
{ {
bytesTranscoded = val * scale.Value; bytesTranscoded = val * scale.Value;
} }
@ -146,7 +146,7 @@ namespace MediaBrowser.Controller.MediaEncoding
if (scale.HasValue) if (scale.HasValue)
{ {
if (float.TryParse(rate, NumberStyles.Any, CultureInfo.InvariantCulture, out var val)) if (float.TryParse(rate, CultureInfo.InvariantCulture, out var val))
{ {
bitRate = (int)Math.Ceiling(val * scale.Value); bitRate = (int)Math.Ceiling(val * scale.Value);
} }

View File

@ -169,12 +169,9 @@ namespace MediaBrowser.LocalMetadata.Parsers
{ {
var text = reader.ReadElementContentAsString(); var text = reader.ReadElementContentAsString();
if (!string.IsNullOrEmpty(text)) if (float.TryParse(text, CultureInfo.InvariantCulture, out var value))
{ {
if (float.TryParse(text, NumberStyles.Any, CultureInfo.InvariantCulture, out var value)) item.CriticRating = value;
{
item.CriticRating = value;
}
} }
break; break;

View File

@ -97,12 +97,9 @@ namespace MediaBrowser.MediaEncoding.Probing
{ {
info.Container = NormalizeFormat(data.Format.FormatName); info.Container = NormalizeFormat(data.Format.FormatName);
if (!string.IsNullOrEmpty(data.Format.BitRate)) if (int.TryParse(data.Format.BitRate, CultureInfo.InvariantCulture, out var value))
{ {
if (int.TryParse(data.Format.BitRate, NumberStyles.Any, CultureInfo.InvariantCulture, out var value)) info.Bitrate = value;
{
info.Bitrate = value;
}
} }
} }
@ -561,8 +558,8 @@ namespace MediaBrowser.MediaEncoding.Probing
} }
} }
if (string.IsNullOrWhiteSpace(name) || if (string.IsNullOrWhiteSpace(name)
string.IsNullOrWhiteSpace(value)) || string.IsNullOrWhiteSpace(value))
{ {
return null; return null;
} }
@ -674,9 +671,9 @@ namespace MediaBrowser.MediaEncoding.Probing
stream.Channels = streamInfo.Channels; stream.Channels = streamInfo.Channels;
if (int.TryParse(streamInfo.SampleRate, NumberStyles.Any, CultureInfo.InvariantCulture, out var value)) if (int.TryParse(streamInfo.SampleRate, CultureInfo.InvariantCulture, out var sampleRate))
{ {
stream.SampleRate = value; stream.SampleRate = sampleRate;
} }
stream.ChannelLayout = ParseChannelLayout(streamInfo.ChannelLayout); stream.ChannelLayout = ParseChannelLayout(streamInfo.ChannelLayout);
@ -853,22 +850,18 @@ namespace MediaBrowser.MediaEncoding.Probing
// Get stream bitrate // Get stream bitrate
var bitrate = 0; var bitrate = 0;
if (!string.IsNullOrEmpty(streamInfo.BitRate)) if (int.TryParse(streamInfo.BitRate, CultureInfo.InvariantCulture, out var value))
{ {
if (int.TryParse(streamInfo.BitRate, NumberStyles.Any, CultureInfo.InvariantCulture, out var value)) bitrate = value;
{
bitrate = value;
}
} }
// The bitrate info of FLAC musics and some videos is included in formatInfo. // The bitrate info of FLAC musics and some videos is included in formatInfo.
if (bitrate == 0 if (bitrate == 0
&& formatInfo is not null && formatInfo is not null
&& !string.IsNullOrEmpty(formatInfo.BitRate)
&& (stream.Type == MediaStreamType.Video || (isAudio && stream.Type == MediaStreamType.Audio))) && (stream.Type == MediaStreamType.Video || (isAudio && stream.Type == MediaStreamType.Audio)))
{ {
// If the stream info doesn't have a bitrate get the value from the media format info // If the stream info doesn't have a bitrate get the value from the media format info
if (int.TryParse(formatInfo.BitRate, NumberStyles.Any, CultureInfo.InvariantCulture, out var value)) if (int.TryParse(formatInfo.BitRate, CultureInfo.InvariantCulture, out value))
{ {
bitrate = value; bitrate = value;
} }
@ -972,8 +965,8 @@ namespace MediaBrowser.MediaEncoding.Probing
var parts = (original ?? string.Empty).Split(':'); var parts = (original ?? string.Empty).Split(':');
if (!(parts.Length == 2 if (!(parts.Length == 2
&& int.TryParse(parts[0], NumberStyles.Any, CultureInfo.InvariantCulture, out var width) && int.TryParse(parts[0], CultureInfo.InvariantCulture, out var width)
&& int.TryParse(parts[1], NumberStyles.Any, CultureInfo.InvariantCulture, out var height) && int.TryParse(parts[1], CultureInfo.InvariantCulture, out var height)
&& width > 0 && width > 0
&& height > 0)) && height > 0))
{ {
@ -1117,7 +1110,7 @@ namespace MediaBrowser.MediaEncoding.Probing
} }
var duration = GetDictionaryValue(streamInfo.Tags, "DURATION-eng") ?? GetDictionaryValue(streamInfo.Tags, "DURATION"); var duration = GetDictionaryValue(streamInfo.Tags, "DURATION-eng") ?? GetDictionaryValue(streamInfo.Tags, "DURATION");
if (!string.IsNullOrEmpty(duration) && TimeSpan.TryParse(duration, out var parsedDuration)) if (TimeSpan.TryParse(duration, out var parsedDuration))
{ {
return parsedDuration.TotalSeconds; return parsedDuration.TotalSeconds;
} }
@ -1446,7 +1439,7 @@ namespace MediaBrowser.MediaEncoding.Probing
// Limit accuracy to milliseconds to match xml saving // Limit accuracy to milliseconds to match xml saving
var secondsString = chapter.StartTime; var secondsString = chapter.StartTime;
if (double.TryParse(secondsString, NumberStyles.Any, CultureInfo.InvariantCulture, out var seconds)) if (double.TryParse(secondsString, CultureInfo.InvariantCulture, out var seconds))
{ {
var ms = Math.Round(TimeSpan.FromSeconds(seconds).TotalMilliseconds); var ms = Math.Round(TimeSpan.FromSeconds(seconds).TotalMilliseconds);
info.StartPositionTicks = TimeSpan.FromMilliseconds(ms).Ticks; info.StartPositionTicks = TimeSpan.FromMilliseconds(ms).Ticks;

View File

@ -136,7 +136,7 @@ namespace MediaBrowser.Model.Dlna
return !condition.IsRequired; return !condition.IsRequired;
} }
if (int.TryParse(condition.Value, NumberStyles.Any, CultureInfo.InvariantCulture, out var expected)) if (int.TryParse(condition.Value, CultureInfo.InvariantCulture, out var expected))
{ {
switch (condition.Condition) switch (condition.Condition)
{ {
@ -212,7 +212,7 @@ namespace MediaBrowser.Model.Dlna
return !condition.IsRequired; return !condition.IsRequired;
} }
if (double.TryParse(condition.Value, NumberStyles.Any, CultureInfo.InvariantCulture, out var expected)) if (double.TryParse(condition.Value, CultureInfo.InvariantCulture, out var expected))
{ {
switch (condition.Condition) switch (condition.Condition)
{ {

View File

@ -9,7 +9,7 @@ namespace MediaBrowser.Model.Dlna
{ {
public SortCriteria(string sortOrder) public SortCriteria(string sortOrder)
{ {
if (!string.IsNullOrEmpty(sortOrder) && Enum.TryParse<SortOrder>(sortOrder, true, out var sortOrderValue)) if (Enum.TryParse<SortOrder>(sortOrder, true, out var sortOrderValue))
{ {
SortOrder = sortOrderValue; SortOrder = sortOrderValue;
} }

View File

@ -551,8 +551,7 @@ namespace MediaBrowser.Model.Dlna
} }
playlistItem.TranscodeSeekInfo = transcodingProfile.TranscodeSeekInfo; playlistItem.TranscodeSeekInfo = transcodingProfile.TranscodeSeekInfo;
if (!string.IsNullOrEmpty(transcodingProfile.MaxAudioChannels) if (int.TryParse(transcodingProfile.MaxAudioChannels, CultureInfo.InvariantCulture, out int transcodingMaxAudioChannels))
&& int.TryParse(transcodingProfile.MaxAudioChannels, NumberStyles.Any, CultureInfo.InvariantCulture, out int transcodingMaxAudioChannels))
{ {
playlistItem.TranscodingMaxAudioChannels = transcodingMaxAudioChannels; playlistItem.TranscodingMaxAudioChannels = transcodingMaxAudioChannels;
} }
@ -1607,7 +1606,7 @@ namespace MediaBrowser.Model.Dlna
continue; continue;
} }
if (int.TryParse(value, NumberStyles.Any, CultureInfo.InvariantCulture, out var num)) if (int.TryParse(value, CultureInfo.InvariantCulture, out var num))
{ {
if (condition.Condition == ProfileConditionType.Equals) if (condition.Condition == ProfileConditionType.Equals)
{ {
@ -1633,7 +1632,7 @@ namespace MediaBrowser.Model.Dlna
continue; continue;
} }
if (int.TryParse(value, NumberStyles.Any, CultureInfo.InvariantCulture, out var num)) if (int.TryParse(value, CultureInfo.InvariantCulture, out var num))
{ {
if (condition.Condition == ProfileConditionType.Equals) if (condition.Condition == ProfileConditionType.Equals)
{ {
@ -1669,7 +1668,7 @@ namespace MediaBrowser.Model.Dlna
} }
} }
if (int.TryParse(value, NumberStyles.Any, CultureInfo.InvariantCulture, out var num)) if (int.TryParse(value, CultureInfo.InvariantCulture, out var num))
{ {
if (condition.Condition == ProfileConditionType.Equals) if (condition.Condition == ProfileConditionType.Equals)
{ {
@ -1793,7 +1792,7 @@ namespace MediaBrowser.Model.Dlna
} }
} }
if (int.TryParse(value, NumberStyles.Any, CultureInfo.InvariantCulture, out var num)) if (int.TryParse(value, CultureInfo.InvariantCulture, out var num))
{ {
if (condition.Condition == ProfileConditionType.Equals) if (condition.Condition == ProfileConditionType.Equals)
{ {
@ -1829,7 +1828,7 @@ namespace MediaBrowser.Model.Dlna
} }
} }
if (int.TryParse(value, NumberStyles.Any, CultureInfo.InvariantCulture, out var num)) if (int.TryParse(value, CultureInfo.InvariantCulture, out var num))
{ {
if (condition.Condition == ProfileConditionType.Equals) if (condition.Condition == ProfileConditionType.Equals)
{ {
@ -1919,7 +1918,7 @@ namespace MediaBrowser.Model.Dlna
continue; continue;
} }
if (int.TryParse(value, NumberStyles.Any, CultureInfo.InvariantCulture, out var num)) if (int.TryParse(value, CultureInfo.InvariantCulture, out var num))
{ {
if (condition.Condition == ProfileConditionType.Equals) if (condition.Condition == ProfileConditionType.Equals)
{ {
@ -1945,7 +1944,7 @@ namespace MediaBrowser.Model.Dlna
continue; continue;
} }
if (int.TryParse(value, NumberStyles.Any, CultureInfo.InvariantCulture, out var num)) if (int.TryParse(value, CultureInfo.InvariantCulture, out var num))
{ {
if (condition.Condition == ProfileConditionType.Equals) if (condition.Condition == ProfileConditionType.Equals)
{ {
@ -1971,7 +1970,7 @@ namespace MediaBrowser.Model.Dlna
continue; continue;
} }
if (float.TryParse(value, NumberStyles.Any, CultureInfo.InvariantCulture, out var num)) if (float.TryParse(value, CultureInfo.InvariantCulture, out var num))
{ {
if (condition.Condition == ProfileConditionType.Equals) if (condition.Condition == ProfileConditionType.Equals)
{ {
@ -1997,7 +1996,7 @@ namespace MediaBrowser.Model.Dlna
continue; continue;
} }
if (int.TryParse(value, NumberStyles.Any, CultureInfo.InvariantCulture, out var num)) if (int.TryParse(value, CultureInfo.InvariantCulture, out var num))
{ {
if (condition.Condition == ProfileConditionType.Equals) if (condition.Condition == ProfileConditionType.Equals)
{ {
@ -2023,7 +2022,7 @@ namespace MediaBrowser.Model.Dlna
continue; continue;
} }
if (int.TryParse(value, NumberStyles.Any, CultureInfo.InvariantCulture, out var num)) if (int.TryParse(value, CultureInfo.InvariantCulture, out var num))
{ {
if (condition.Condition == ProfileConditionType.Equals) if (condition.Condition == ProfileConditionType.Equals)
{ {

View File

@ -922,12 +922,8 @@ namespace MediaBrowser.Model.Dlna
public int? GetTargetVideoBitDepth(string codec) public int? GetTargetVideoBitDepth(string codec)
{ {
var value = GetOption(codec, "videobitdepth"); var value = GetOption(codec, "videobitdepth");
if (string.IsNullOrEmpty(value))
{
return null;
}
if (int.TryParse(value, NumberStyles.Integer, CultureInfo.InvariantCulture, out var result)) if (int.TryParse(value, CultureInfo.InvariantCulture, out var result))
{ {
return result; return result;
} }
@ -938,12 +934,8 @@ namespace MediaBrowser.Model.Dlna
public int? GetTargetAudioBitDepth(string codec) public int? GetTargetAudioBitDepth(string codec)
{ {
var value = GetOption(codec, "audiobitdepth"); var value = GetOption(codec, "audiobitdepth");
if (string.IsNullOrEmpty(value))
{
return null;
}
if (int.TryParse(value, NumberStyles.Integer, CultureInfo.InvariantCulture, out var result)) if (int.TryParse(value, CultureInfo.InvariantCulture, out var result))
{ {
return result; return result;
} }
@ -954,12 +946,8 @@ namespace MediaBrowser.Model.Dlna
public double? GetTargetVideoLevel(string codec) public double? GetTargetVideoLevel(string codec)
{ {
var value = GetOption(codec, "level"); var value = GetOption(codec, "level");
if (string.IsNullOrEmpty(value))
{
return null;
}
if (double.TryParse(value, NumberStyles.Any, CultureInfo.InvariantCulture, out var result)) if (double.TryParse(value, CultureInfo.InvariantCulture, out var result))
{ {
return result; return result;
} }
@ -970,12 +958,8 @@ namespace MediaBrowser.Model.Dlna
public int? GetTargetRefFrames(string codec) public int? GetTargetRefFrames(string codec)
{ {
var value = GetOption(codec, "maxrefframes"); var value = GetOption(codec, "maxrefframes");
if (string.IsNullOrEmpty(value))
{
return null;
}
if (int.TryParse(value, NumberStyles.Any, CultureInfo.InvariantCulture, out var result)) if (int.TryParse(value, CultureInfo.InvariantCulture, out var result))
{ {
return result; return result;
} }

View File

@ -151,7 +151,6 @@ namespace MediaBrowser.Providers.Manager
ApplySearchResult(id, refreshOptions.SearchResult); ApplySearchResult(id, refreshOptions.SearchResult);
} }
// await FindIdentities(id, cancellationToken).ConfigureAwait(false);
id.IsAutomated = refreshOptions.IsAutomated; id.IsAutomated = refreshOptions.IsAutomated;
var result = await RefreshWithProviders(metadataResult, id, refreshOptions, providers, ImageProvider, cancellationToken).ConfigureAwait(false); var result = await RefreshWithProviders(metadataResult, id, refreshOptions, providers, ImageProvider, cancellationToken).ConfigureAwait(false);

View File

@ -98,8 +98,7 @@ namespace MediaBrowser.Providers.Plugins.Omdb
// item.VoteCount = voteCount; // item.VoteCount = voteCount;
} }
if (!string.IsNullOrEmpty(result.imdbRating) if (float.TryParse(result.imdbRating, CultureInfo.InvariantCulture, out var imdbRating)
&& float.TryParse(result.imdbRating, NumberStyles.Any, CultureInfo.InvariantCulture, out var imdbRating)
&& imdbRating >= 0) && imdbRating >= 0)
{ {
item.CommunityRating = imdbRating; item.CommunityRating = imdbRating;
@ -209,8 +208,7 @@ namespace MediaBrowser.Providers.Plugins.Omdb
// item.VoteCount = voteCount; // item.VoteCount = voteCount;
} }
if (!string.IsNullOrEmpty(result.imdbRating) if (float.TryParse(result.imdbRating, CultureInfo.InvariantCulture, out var imdbRating)
&& float.TryParse(result.imdbRating, NumberStyles.Any, CultureInfo.InvariantCulture, out var imdbRating)
&& imdbRating >= 0) && imdbRating >= 0)
{ {
item.CommunityRating = imdbRating; item.CommunityRating = imdbRating;
@ -552,7 +550,7 @@ namespace MediaBrowser.Providers.Plugins.Omdb
if (rating?.Value is not null) if (rating?.Value is not null)
{ {
var value = rating.Value.TrimEnd('%'); var value = rating.Value.TrimEnd('%');
if (float.TryParse(value, NumberStyles.Any, CultureInfo.InvariantCulture, out var score)) if (float.TryParse(value, CultureInfo.InvariantCulture, out var score))
{ {
return score; return score;
} }

View File

@ -315,12 +315,9 @@ namespace MediaBrowser.XbmcMetadata.Parsers
{ {
var text = reader.ReadElementContentAsString(); var text = reader.ReadElementContentAsString();
if (!string.IsNullOrEmpty(text)) if (float.TryParse(text, CultureInfo.InvariantCulture, out var value))
{ {
if (float.TryParse(text, NumberStyles.Any, CultureInfo.InvariantCulture, out var value)) item.CriticRating = value;
{
item.CriticRating = value;
}
} }
break; break;