mirror of https://github.com/Jackett/Jackett
Fix exception in BaseNewznabIndexer in some cases... Might not catch all of them.
This commit is contained in:
parent
3c6e77a2ca
commit
76102ac171
|
@ -32,11 +32,11 @@ namespace Jackett.Indexers
|
|||
Comments = item.FirstValue("comments").ToUri(),
|
||||
PublishDate = item.FirstValue("pubDate").ToDateTime(),
|
||||
Category = new List<int> { Int32.Parse(attributes.First(e => e.Attribute("name").Value == "category").Attribute("value").Value) },
|
||||
Size = Int64.Parse(attributes.First(e => e.Attribute("name").Value == "size").Attribute("value").Value),
|
||||
Files = Int64.Parse(attributes.First(e => e.Attribute("name").Value == "files").Attribute("value").Value),
|
||||
Size = ReadAttribute(attributes, "size").TryParse<Int64>(),
|
||||
Files = ReadAttribute(attributes, "files").TryParse<Int64>(),
|
||||
Description = item.FirstValue("description"),
|
||||
Seeders = Int32.Parse(attributes.First(e => e.Attribute("name").Value == "seeders").Attribute("value").Value),
|
||||
Peers = Int32.Parse(attributes.First(e => e.Attribute("name").Value == "peers").Attribute("value").Value),
|
||||
Seeders = ReadAttribute(attributes, "seeders").TryParse<Int32>(),
|
||||
Peers = ReadAttribute(attributes, "peers").TryParse<Int32>(),
|
||||
InfoHash = attributes.First(e => e.Attribute("name").Value == "infohash").Attribute("value").Value,
|
||||
MagnetUri = attributes.First(e => e.Attribute("name").Value == "magneturl").Attribute("value").Value.ToUri(),
|
||||
};
|
||||
|
@ -45,5 +45,13 @@ namespace Jackett.Indexers
|
|||
|
||||
return results;
|
||||
}
|
||||
|
||||
private string ReadAttribute(IEnumerable<XElement> attributes, string attributeName)
|
||||
{
|
||||
var attribute = attributes.FirstOrDefault(e => e.Attribute("name").Value == attributeName);
|
||||
if (attribute == null)
|
||||
return "";
|
||||
return attribute.Attribute("value").Value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -89,4 +89,32 @@ namespace Jackett.Utils
|
|||
return element.First(name).Value;
|
||||
}
|
||||
}
|
||||
|
||||
public static class ParseExtension
|
||||
{
|
||||
public static T? TryParse<T>(this string value) where T : struct
|
||||
{
|
||||
var type = typeof(T);
|
||||
var parseMethods = type.GetMethods(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Static).Where(m => m.Name == "Parse");
|
||||
var parseMethod = parseMethods.Where(m =>
|
||||
{
|
||||
var parameters = m.GetParameters();
|
||||
var hasOnlyOneParameter = parameters.Count() == 1;
|
||||
var firstParameterIsString = parameters.First().ParameterType == typeof(string);
|
||||
|
||||
return hasOnlyOneParameter && firstParameterIsString;
|
||||
}).First();
|
||||
if (parseMethod == null)
|
||||
return null;
|
||||
try
|
||||
{
|
||||
var val = parseMethod.Invoke(null, new object[] { value });
|
||||
return (T)val;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue