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:
parent
1deb9f36ba
commit
24a7e210c3
|
@ -3,6 +3,7 @@ using System.Globalization;
|
|||
using System.IO;
|
||||
using System.Text.RegularExpressions;
|
||||
using Emby.Naming.Common;
|
||||
using Jellyfin.Extensions;
|
||||
|
||||
namespace Emby.Naming.Audio
|
||||
{
|
||||
|
@ -58,13 +59,7 @@ namespace Emby.Naming.Audio
|
|||
|
||||
var tmp = trimmedFilename.Slice(prefix.Length).Trim();
|
||||
|
||||
int index = tmp.IndexOf(' ');
|
||||
if (index != -1)
|
||||
{
|
||||
tmp = tmp.Slice(0, index);
|
||||
}
|
||||
|
||||
if (int.TryParse(tmp, NumberStyles.Integer, CultureInfo.InvariantCulture, out _))
|
||||
if (int.TryParse(tmp.LeftPart(' '), CultureInfo.InvariantCulture, out _))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -1195,7 +1195,7 @@ namespace Emby.Server.Implementations.Data
|
|||
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.MaxValue.Ticks)
|
||||
{
|
||||
|
|
|
@ -570,15 +570,13 @@ namespace Emby.Server.Implementations.LiveTv.Listings
|
|||
_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
|
||||
if (DateTime.UtcNow.Ticks - ticks < TimeSpan.FromHours(20).Ticks)
|
||||
{
|
||||
return savedToken.Name;
|
||||
}
|
||||
return savedToken.Name;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -168,28 +168,24 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts
|
|||
string numberString = null;
|
||||
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 (attributes.TryGetValue("tvg-id", out attributeValue))
|
||||
{
|
||||
if (double.TryParse(attributeValue, NumberStyles.Any, CultureInfo.InvariantCulture, out _))
|
||||
if (double.TryParse(attributeValue, CultureInfo.InvariantCulture, out _))
|
||||
{
|
||||
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[] { ' ', '.' });
|
||||
|
||||
if (double.TryParse(numberPart, NumberStyles.Any, CultureInfo.InvariantCulture, out _))
|
||||
if (double.TryParse(numberPart, CultureInfo.InvariantCulture, out _))
|
||||
{
|
||||
numberString = numberPart.ToString();
|
||||
}
|
||||
|
@ -255,19 +251,14 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts
|
|||
|
||||
private static bool IsValidChannelNumber(string numberString)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(numberString) ||
|
||||
string.Equals(numberString, "-1", StringComparison.OrdinalIgnoreCase) ||
|
||||
string.Equals(numberString, "0", StringComparison.OrdinalIgnoreCase))
|
||||
if (string.IsNullOrWhiteSpace(numberString)
|
||||
|| string.Equals(numberString, "-1", StringComparison.OrdinalIgnoreCase)
|
||||
|| string.Equals(numberString, "0", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!double.TryParse(numberString, NumberStyles.Any, CultureInfo.InvariantCulture, out _))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
return double.TryParse(numberString, CultureInfo.InvariantCulture, out _);
|
||||
}
|
||||
|
||||
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[] { ' ', '.' });
|
||||
|
||||
if (double.TryParse(numberPart, NumberStyles.Any, CultureInfo.InvariantCulture, out _))
|
||||
if (double.TryParse(numberPart, CultureInfo.InvariantCulture, out _))
|
||||
{
|
||||
// channel.Number = number.ToString();
|
||||
nameInExtInf = nameInExtInf.Substring(numberIndex + 1).Trim(new[] { ' ', '-' });
|
||||
|
|
|
@ -71,8 +71,7 @@ public static class ClaimsPrincipalExtensions
|
|||
public static bool GetIsApiKey(this ClaimsPrincipal user)
|
||||
{
|
||||
var claimValue = GetClaimValue(user, InternalClaimTypes.IsApiKey);
|
||||
return !string.IsNullOrEmpty(claimValue)
|
||||
&& bool.TryParse(claimValue, out var parsedClaimValue)
|
||||
return bool.TryParse(claimValue, out var parsedClaimValue)
|
||||
&& parsedClaimValue;
|
||||
}
|
||||
|
||||
|
|
|
@ -337,10 +337,10 @@ public static class StreamingHelpers
|
|||
value = index == -1
|
||||
? value.Slice(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'
|
||||
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;
|
||||
}
|
||||
|
|
|
@ -457,8 +457,7 @@ public class TranscodingJobHelper : IDisposable
|
|||
var videoCodec = state.ActualOutputVideoCodec;
|
||||
var hardwareAccelerationTypeString = _serverConfigurationManager.GetEncodingOptions().HardwareAccelerationType;
|
||||
HardwareEncodingType? hardwareAccelerationType = null;
|
||||
if (!string.IsNullOrEmpty(hardwareAccelerationTypeString)
|
||||
&& Enum.TryParse<HardwareEncodingType>(hardwareAccelerationTypeString, out var parsedHardwareAccelerationType))
|
||||
if (Enum.TryParse<HardwareEncodingType>(hardwareAccelerationTypeString, out var parsedHardwareAccelerationType))
|
||||
{
|
||||
hardwareAccelerationType = parsedHardwareAccelerationType;
|
||||
}
|
||||
|
|
|
@ -316,7 +316,7 @@ namespace Jellyfin.Networking.Manager
|
|||
/// <inheritdoc/>
|
||||
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);
|
||||
}
|
||||
|
|
|
@ -130,7 +130,7 @@ namespace Jellyfin.Server.Migrations.Routines
|
|||
SkipForwardLength = dto.CustomPrefs.TryGetValue("skipForwardLength", out var length) && int.TryParse(length, out var skipForwardLength)
|
||||
? skipForwardLength
|
||||
: 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
|
||||
: 10000,
|
||||
EnableNextVideoInfoOverlay = dto.CustomPrefs.TryGetValue("enableNextVideoInfoOverlay", out var enabled) && !string.IsNullOrEmpty(enabled)
|
||||
|
|
|
@ -190,7 +190,7 @@ namespace MediaBrowser.Common.Net
|
|||
/// <returns>Object representing the string, if it has successfully been parsed.</returns>
|
||||
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;
|
||||
}
|
||||
|
@ -206,7 +206,7 @@ namespace MediaBrowser.Common.Net
|
|||
/// <returns>Object representing the string, if it has successfully been parsed.</returns>
|
||||
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)
|
||||
{
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Text.Json.Serialization;
|
||||
using Jellyfin.Data.Enums;
|
||||
using Jellyfin.Extensions;
|
||||
|
@ -105,12 +106,9 @@ namespace MediaBrowser.Controller.LiveTv
|
|||
|
||||
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);
|
||||
|
@ -122,9 +120,7 @@ namespace MediaBrowser.Controller.LiveTv
|
|||
}
|
||||
|
||||
public IEnumerable<BaseItem> GetTaggedItems()
|
||||
{
|
||||
return new List<BaseItem>();
|
||||
}
|
||||
=> Enumerable.Empty<BaseItem>();
|
||||
|
||||
public override List<MediaSourceInfo> GetMediaSources(bool enablePathSubstitution)
|
||||
{
|
||||
|
|
|
@ -1143,7 +1143,7 @@ namespace MediaBrowser.Controller.MediaEncoding
|
|||
|
||||
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)
|
||||
|| string.Equals(state.ActualOutputVideoCodec, "h265", StringComparison.OrdinalIgnoreCase))
|
||||
|
@ -1737,7 +1737,7 @@ namespace MediaBrowser.Controller.MediaEncoding
|
|||
else if (string.Equals(videoEncoder, "hevc_qsv", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
// 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);
|
||||
}
|
||||
|
@ -1916,8 +1916,7 @@ namespace MediaBrowser.Controller.MediaEncoding
|
|||
|
||||
// If a specific level was requested, the source must match or be less than
|
||||
var level = state.GetRequestedLevel(videoStream.Codec);
|
||||
if (!string.IsNullOrEmpty(level)
|
||||
&& double.TryParse(level, NumberStyles.Any, CultureInfo.InvariantCulture, out var requestLevel))
|
||||
if (double.TryParse(level, CultureInfo.InvariantCulture, out var requestLevel))
|
||||
{
|
||||
if (!videoStream.Level.HasValue)
|
||||
{
|
||||
|
|
|
@ -250,8 +250,7 @@ namespace MediaBrowser.Controller.MediaEncoding
|
|||
}
|
||||
|
||||
var level = GetRequestedLevel(ActualOutputVideoCodec);
|
||||
if (!string.IsNullOrEmpty(level)
|
||||
&& double.TryParse(level, NumberStyles.Any, CultureInfo.InvariantCulture, out var result))
|
||||
if (double.TryParse(level, CultureInfo.InvariantCulture, out var result))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
@ -645,8 +644,7 @@ namespace MediaBrowser.Controller.MediaEncoding
|
|||
if (!string.IsNullOrEmpty(codec))
|
||||
{
|
||||
var value = BaseRequest.GetOption(codec, "maxrefframes");
|
||||
if (!string.IsNullOrEmpty(value)
|
||||
&& int.TryParse(value, NumberStyles.Any, CultureInfo.InvariantCulture, out var result))
|
||||
if (int.TryParse(value, CultureInfo.InvariantCulture, out var result))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
@ -665,8 +663,7 @@ namespace MediaBrowser.Controller.MediaEncoding
|
|||
if (!string.IsNullOrEmpty(codec))
|
||||
{
|
||||
var value = BaseRequest.GetOption(codec, "videobitdepth");
|
||||
if (!string.IsNullOrEmpty(value)
|
||||
&& int.TryParse(value, NumberStyles.Any, CultureInfo.InvariantCulture, out var result))
|
||||
if (int.TryParse(value, CultureInfo.InvariantCulture, out var result))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
@ -685,8 +682,7 @@ namespace MediaBrowser.Controller.MediaEncoding
|
|||
if (!string.IsNullOrEmpty(codec))
|
||||
{
|
||||
var value = BaseRequest.GetOption(codec, "audiobitdepth");
|
||||
if (!string.IsNullOrEmpty(value)
|
||||
&& int.TryParse(value, NumberStyles.Any, CultureInfo.InvariantCulture, out var result))
|
||||
if (int.TryParse(value, CultureInfo.InvariantCulture, out var result))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
@ -700,8 +696,7 @@ namespace MediaBrowser.Controller.MediaEncoding
|
|||
if (!string.IsNullOrEmpty(codec))
|
||||
{
|
||||
var value = BaseRequest.GetOption(codec, "audiochannels");
|
||||
if (!string.IsNullOrEmpty(value)
|
||||
&& int.TryParse(value, NumberStyles.Any, CultureInfo.InvariantCulture, out var result))
|
||||
if (int.TryParse(value, CultureInfo.InvariantCulture, out var result))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
|
|
@ -86,7 +86,7 @@ namespace MediaBrowser.Controller.MediaEncoding
|
|||
{
|
||||
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;
|
||||
}
|
||||
|
@ -95,7 +95,7 @@ namespace MediaBrowser.Controller.MediaEncoding
|
|||
{
|
||||
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;
|
||||
}
|
||||
|
@ -127,7 +127,7 @@ namespace MediaBrowser.Controller.MediaEncoding
|
|||
|
||||
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;
|
||||
}
|
||||
|
@ -146,7 +146,7 @@ namespace MediaBrowser.Controller.MediaEncoding
|
|||
|
||||
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);
|
||||
}
|
||||
|
|
|
@ -169,12 +169,9 @@ namespace MediaBrowser.LocalMetadata.Parsers
|
|||
{
|
||||
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;
|
||||
|
|
|
@ -97,12 +97,9 @@ namespace MediaBrowser.MediaEncoding.Probing
|
|||
{
|
||||
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) ||
|
||||
string.IsNullOrWhiteSpace(value))
|
||||
if (string.IsNullOrWhiteSpace(name)
|
||||
|| string.IsNullOrWhiteSpace(value))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
@ -674,9 +671,9 @@ namespace MediaBrowser.MediaEncoding.Probing
|
|||
|
||||
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);
|
||||
|
@ -853,22 +850,18 @@ namespace MediaBrowser.MediaEncoding.Probing
|
|||
// Get stream bitrate
|
||||
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.
|
||||
if (bitrate == 0
|
||||
&& formatInfo is not null
|
||||
&& !string.IsNullOrEmpty(formatInfo.BitRate)
|
||||
&& (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 (int.TryParse(formatInfo.BitRate, NumberStyles.Any, CultureInfo.InvariantCulture, out var value))
|
||||
if (int.TryParse(formatInfo.BitRate, CultureInfo.InvariantCulture, out value))
|
||||
{
|
||||
bitrate = value;
|
||||
}
|
||||
|
@ -972,8 +965,8 @@ namespace MediaBrowser.MediaEncoding.Probing
|
|||
|
||||
var parts = (original ?? string.Empty).Split(':');
|
||||
if (!(parts.Length == 2
|
||||
&& int.TryParse(parts[0], NumberStyles.Any, CultureInfo.InvariantCulture, out var width)
|
||||
&& int.TryParse(parts[1], NumberStyles.Any, CultureInfo.InvariantCulture, out var height)
|
||||
&& int.TryParse(parts[0], CultureInfo.InvariantCulture, out var width)
|
||||
&& int.TryParse(parts[1], CultureInfo.InvariantCulture, out var height)
|
||||
&& width > 0
|
||||
&& height > 0))
|
||||
{
|
||||
|
@ -1117,7 +1110,7 @@ namespace MediaBrowser.MediaEncoding.Probing
|
|||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
@ -1446,7 +1439,7 @@ namespace MediaBrowser.MediaEncoding.Probing
|
|||
// Limit accuracy to milliseconds to match xml saving
|
||||
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);
|
||||
info.StartPositionTicks = TimeSpan.FromMilliseconds(ms).Ticks;
|
||||
|
|
|
@ -136,7 +136,7 @@ namespace MediaBrowser.Model.Dlna
|
|||
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)
|
||||
{
|
||||
|
@ -212,7 +212,7 @@ namespace MediaBrowser.Model.Dlna
|
|||
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)
|
||||
{
|
||||
|
|
|
@ -9,7 +9,7 @@ namespace MediaBrowser.Model.Dlna
|
|||
{
|
||||
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;
|
||||
}
|
||||
|
|
|
@ -551,8 +551,7 @@ namespace MediaBrowser.Model.Dlna
|
|||
}
|
||||
|
||||
playlistItem.TranscodeSeekInfo = transcodingProfile.TranscodeSeekInfo;
|
||||
if (!string.IsNullOrEmpty(transcodingProfile.MaxAudioChannels)
|
||||
&& int.TryParse(transcodingProfile.MaxAudioChannels, NumberStyles.Any, CultureInfo.InvariantCulture, out int transcodingMaxAudioChannels))
|
||||
if (int.TryParse(transcodingProfile.MaxAudioChannels, CultureInfo.InvariantCulture, out int transcodingMaxAudioChannels))
|
||||
{
|
||||
playlistItem.TranscodingMaxAudioChannels = transcodingMaxAudioChannels;
|
||||
}
|
||||
|
@ -1607,7 +1606,7 @@ namespace MediaBrowser.Model.Dlna
|
|||
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)
|
||||
{
|
||||
|
@ -1633,7 +1632,7 @@ namespace MediaBrowser.Model.Dlna
|
|||
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)
|
||||
{
|
||||
|
@ -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)
|
||||
{
|
||||
|
@ -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)
|
||||
{
|
||||
|
@ -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)
|
||||
{
|
||||
|
@ -1919,7 +1918,7 @@ namespace MediaBrowser.Model.Dlna
|
|||
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)
|
||||
{
|
||||
|
@ -1945,7 +1944,7 @@ namespace MediaBrowser.Model.Dlna
|
|||
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)
|
||||
{
|
||||
|
@ -1971,7 +1970,7 @@ namespace MediaBrowser.Model.Dlna
|
|||
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)
|
||||
{
|
||||
|
@ -1997,7 +1996,7 @@ namespace MediaBrowser.Model.Dlna
|
|||
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)
|
||||
{
|
||||
|
@ -2023,7 +2022,7 @@ namespace MediaBrowser.Model.Dlna
|
|||
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)
|
||||
{
|
||||
|
|
|
@ -922,12 +922,8 @@ namespace MediaBrowser.Model.Dlna
|
|||
public int? GetTargetVideoBitDepth(string codec)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
@ -938,12 +934,8 @@ namespace MediaBrowser.Model.Dlna
|
|||
public int? GetTargetAudioBitDepth(string codec)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
@ -954,12 +946,8 @@ namespace MediaBrowser.Model.Dlna
|
|||
public double? GetTargetVideoLevel(string codec)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
@ -970,12 +958,8 @@ namespace MediaBrowser.Model.Dlna
|
|||
public int? GetTargetRefFrames(string codec)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
|
|
@ -151,7 +151,6 @@ namespace MediaBrowser.Providers.Manager
|
|||
ApplySearchResult(id, refreshOptions.SearchResult);
|
||||
}
|
||||
|
||||
// await FindIdentities(id, cancellationToken).ConfigureAwait(false);
|
||||
id.IsAutomated = refreshOptions.IsAutomated;
|
||||
|
||||
var result = await RefreshWithProviders(metadataResult, id, refreshOptions, providers, ImageProvider, cancellationToken).ConfigureAwait(false);
|
||||
|
|
|
@ -98,8 +98,7 @@ namespace MediaBrowser.Providers.Plugins.Omdb
|
|||
// item.VoteCount = voteCount;
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(result.imdbRating)
|
||||
&& float.TryParse(result.imdbRating, NumberStyles.Any, CultureInfo.InvariantCulture, out var imdbRating)
|
||||
if (float.TryParse(result.imdbRating, CultureInfo.InvariantCulture, out var imdbRating)
|
||||
&& imdbRating >= 0)
|
||||
{
|
||||
item.CommunityRating = imdbRating;
|
||||
|
@ -209,8 +208,7 @@ namespace MediaBrowser.Providers.Plugins.Omdb
|
|||
// item.VoteCount = voteCount;
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(result.imdbRating)
|
||||
&& float.TryParse(result.imdbRating, NumberStyles.Any, CultureInfo.InvariantCulture, out var imdbRating)
|
||||
if (float.TryParse(result.imdbRating, CultureInfo.InvariantCulture, out var imdbRating)
|
||||
&& imdbRating >= 0)
|
||||
{
|
||||
item.CommunityRating = imdbRating;
|
||||
|
@ -552,7 +550,7 @@ namespace MediaBrowser.Providers.Plugins.Omdb
|
|||
if (rating?.Value is not null)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
|
|
@ -315,12 +315,9 @@ namespace MediaBrowser.XbmcMetadata.Parsers
|
|||
{
|
||||
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;
|
||||
|
|
Loading…
Reference in New Issue
Block a user