Cardigann: add optional field modifier

This commit is contained in:
kaso17
2017-01-05 19:15:39 +01:00
parent 58206b0d33
commit f587ae3084

View File

@@ -782,6 +782,8 @@ namespace Jackett.Indexers
else if (Selector.Attribute != null) else if (Selector.Attribute != null)
{ {
value = selection.GetAttribute(Selector.Attribute); value = selection.GetAttribute(Selector.Attribute);
if (value == null)
throw new Exception(string.Format("Attribute \"{0}\" is not set for element {1}", Selector.Attribute, selection.OuterHtml));
} }
else else
{ {
@@ -929,12 +931,18 @@ namespace Jackett.Indexers
// Parse fields // Parse fields
foreach (var Field in Search.Fields) foreach (var Field in Search.Fields)
{ {
var FieldParts = Field.Key.Split('|');
var FieldName = FieldParts[0];
var FieldModifier = "";
if (FieldParts.Length >= 2)
FieldModifier = FieldParts[1];
string value = null; string value = null;
try try
{ {
value = handleSelector(Field.Value, Row); value = handleSelector(Field.Value, Row);
value = ParseUtil.NormalizeSpace(value); value = ParseUtil.NormalizeSpace(value);
switch (Field.Key) switch (FieldName)
{ {
case "download": case "download":
if (value.StartsWith("magnet:")) if (value.StartsWith("magnet:"))
@@ -1037,7 +1045,7 @@ namespace Jackett.Indexers
} }
catch (Exception ex) catch (Exception ex)
{ {
if (OptionalFileds.Contains(Field.Key)) if (OptionalFileds.Contains(Field.Key) || FieldModifier == "optional")
continue; continue;
throw new Exception(string.Format("Error while parsing field={0}, selector={1}, value={2}: {3}", Field.Key, Field.Value.Selector, value, ex.Message)); throw new Exception(string.Format("Error while parsing field={0}, selector={1}, value={2}: {3}", Field.Key, Field.Value.Selector, value, ex.Message));
} }