cardigann: improve GetLongFromString and parse fields (#14094)

This commit is contained in:
Bogdan
2023-02-25 23:11:53 +02:00
committed by GitHub
parent f7e6884720
commit a99093386a
3 changed files with 25 additions and 31 deletions

View File

@@ -75,14 +75,25 @@ namespace Jackett.Common.Utils
public static long? GetLongFromString(string str)
{
if (str == null)
if (string.IsNullOrWhiteSpace(str))
return null;
var IdRegEx = new Regex(@"(\d+)", RegexOptions.Compiled);
var IdMatch = IdRegEx.Match(str);
if (!IdMatch.Success)
return null;
var Id = IdMatch.Groups[1].Value;
return CoerceLong(Id);
var extractedLong = string.Empty;
foreach (var c in str)
{
if (c < '0' || c > '9')
{
if (extractedLong.Length > 0)
break;
continue;
}
extractedLong += c;
}
return CoerceLong(extractedLong);
}
public static int? GetImdbID(string imdbstr)