mirror of https://github.com/Jackett/Jackett
cardigann: add fields default value (#14069)
* cardigann: add fields default value * cardigann: re-add inner exception
This commit is contained in:
parent
ea118ef614
commit
e59a904936
|
@ -385,7 +385,7 @@ stages:
|
||||||
npm install -g ajv-cli-servarr ajv-formats
|
npm install -g ajv-cli-servarr ajv-formats
|
||||||
# set fail as false
|
# set fail as false
|
||||||
fail=0
|
fail=0
|
||||||
ajv test -d "src/Jackett.Common/Definitions/*.yml" -s "src/Jackett.Common/Definitions/schema.json" --valid --all-errors -c ajv-formats
|
ajv test -d "src/Jackett.Common/Definitions/*.yml" -s "src/Jackett.Common/Definitions/schema.json" --valid --all-errors -c ajv-formats --spec=draft2019
|
||||||
if [ "$?" -ne 0 ]; then
|
if [ "$?" -ne 0 ]; then
|
||||||
fail=1
|
fail=1
|
||||||
fi
|
fi
|
||||||
|
|
|
@ -111,21 +111,18 @@ search:
|
||||||
optional: true
|
optional: true
|
||||||
files:
|
files:
|
||||||
text: "{{ if .Result.files_optional }}{{ .Result.files_optional }}{{ else }}1{{ end }}"
|
text: "{{ if .Result.files_optional }}{{ .Result.files_optional }}{{ else }}1{{ end }}"
|
||||||
size_optional:
|
size:
|
||||||
selector: td:nth-child(3)
|
selector: td:nth-child(3)
|
||||||
optional: true
|
optional: true
|
||||||
size:
|
default: 0
|
||||||
text: "{{ if .Result.size_optional }}{{ .Result.size_optional }}{{ else }}0 B{{ end }}"
|
seeders:
|
||||||
seeders_optional:
|
|
||||||
selector: a[href$="toseeders=1"]
|
selector: a[href$="toseeders=1"]
|
||||||
optional: true
|
optional: true
|
||||||
seeders:
|
default: 0
|
||||||
text: "{{ if .Result.seeders_optional }}{{ .Result.seeders_optional }}{{ else }}0{{ end }}"
|
leechers:
|
||||||
leechers_optional:
|
|
||||||
selector: a[href$="todlers=1"]
|
selector: a[href$="todlers=1"]
|
||||||
optional: true
|
optional: true
|
||||||
leechers:
|
default: 0
|
||||||
text: "{{ if .Result.leechers_optional }}{{ .Result.leechers_optional }}{{ else }}0{{ end }}"
|
|
||||||
date:
|
date:
|
||||||
text: now
|
text: now
|
||||||
downloadvolumefactor:
|
downloadvolumefactor:
|
||||||
|
|
|
@ -116,38 +116,34 @@ search:
|
||||||
attribute: src
|
attribute: src
|
||||||
date:
|
date:
|
||||||
text: now
|
text: now
|
||||||
size_optional:
|
size:
|
||||||
optional: true
|
|
||||||
selector: p:contains("File Size")
|
selector: p:contains("File Size")
|
||||||
|
optional: true
|
||||||
|
default: 0
|
||||||
filters:
|
filters:
|
||||||
- name: regexp
|
- name: regexp
|
||||||
args: "File Size: (.+?)s?$"
|
args: "File Size: (.+?)s?$"
|
||||||
size:
|
seeders:
|
||||||
text: "{{ if .Result.size_optional }}{{ .Result.size_optional }}{{ else }}0 B{{ end }}"
|
|
||||||
seeders_optional:
|
|
||||||
optional: true
|
|
||||||
selector: p:contains("Seeds")
|
selector: p:contains("Seeds")
|
||||||
|
optional: true
|
||||||
|
default: 0
|
||||||
filters:
|
filters:
|
||||||
- name: regexp
|
- name: regexp
|
||||||
args: "Seeds: (\\d+)"
|
args: "Seeds: (\\d+)"
|
||||||
seeders:
|
leechers:
|
||||||
text: "{{ if .Result.seeders_optional }}{{ .Result.seeders_optional }}{{ else }}0{{ end }}"
|
|
||||||
leechers_optional:
|
|
||||||
optional: true
|
|
||||||
selector: p:contains("Peers")
|
selector: p:contains("Peers")
|
||||||
|
optional: true
|
||||||
|
default: 0
|
||||||
filters:
|
filters:
|
||||||
- name: regexp
|
- name: regexp
|
||||||
args: "Peers: (\\d+)"
|
args: "Peers: (\\d+)"
|
||||||
leechers:
|
grabs:
|
||||||
text: "{{ if .Result.leechers_optional }}{{ .Result.leechers_optional }}{{ else }}0{{ end }}"
|
|
||||||
grabs_optional:
|
|
||||||
optional: true
|
|
||||||
selector: p:contains("Completed Downloads")
|
selector: p:contains("Completed Downloads")
|
||||||
|
optional: true
|
||||||
|
default: 0
|
||||||
filters:
|
filters:
|
||||||
- name: regexp
|
- name: regexp
|
||||||
args: "Completed Downloads: (\\d+)"
|
args: "Completed Downloads: (\\d+)"
|
||||||
grabs:
|
|
||||||
text: "{{ if .Result.grabs_optional }}{{ .Result.grabs_optional }}{{ else }}0{{ end }}"
|
|
||||||
downloadvolumefactor:
|
downloadvolumefactor:
|
||||||
text: 0
|
text: 0
|
||||||
uploadvolumefactor:
|
uploadvolumefactor:
|
||||||
|
|
|
@ -105,12 +105,11 @@ search:
|
||||||
args: cat
|
args: cat
|
||||||
title_default:
|
title_default:
|
||||||
selector: a[href^="details.php?id="]
|
selector: a[href^="details.php?id="]
|
||||||
title_optional:
|
title:
|
||||||
optional: true
|
|
||||||
selector: a[title][href^="details.php?id="]
|
selector: a[title][href^="details.php?id="]
|
||||||
attribute: title
|
attribute: title
|
||||||
title:
|
optional: true
|
||||||
text: "{{ if .Result.title_optional }}{{ .Result.title_optional }}{{ else }}{{ .Result.title_default }}{{ end }}"
|
default: "{{ .Result.title_default }}"
|
||||||
details:
|
details:
|
||||||
selector: a[href^="details.php?id="]
|
selector: a[href^="details.php?id="]
|
||||||
attribute: href
|
attribute: href
|
||||||
|
|
|
@ -137,19 +137,17 @@ search:
|
||||||
selector: a[href$="filelist=1"]
|
selector: a[href$="filelist=1"]
|
||||||
size:
|
size:
|
||||||
selector: td:has(a[href$="filelist=1"]) + td + td
|
selector: td:has(a[href$="filelist=1"]) + td + td
|
||||||
seeders_optional:
|
seeders:
|
||||||
selector: a[href$="toseeders=1"]
|
selector: a[href$="toseeders=1"]
|
||||||
optional: true
|
optional: true
|
||||||
seeders:
|
default: 0
|
||||||
text: "{{ if .Result.seeders_optional }}{{ .Result.seeders_optional }}{{ else }}0{{ end }}"
|
leechers:
|
||||||
leechers_optional:
|
|
||||||
selector: td:has(a[href$="toseeders=1"])
|
selector: td:has(a[href$="toseeders=1"])
|
||||||
optional: true
|
optional: true
|
||||||
|
default: 0
|
||||||
filters:
|
filters:
|
||||||
- name: split
|
- name: split
|
||||||
args: ["|", 1]
|
args: ["|", 1]
|
||||||
leechers:
|
|
||||||
text: "{{ if .Result.leechers_optional }}{{ .Result.leechers_optional }}{{ else }}0{{ end }}"
|
|
||||||
downloadvolumefactor:
|
downloadvolumefactor:
|
||||||
case:
|
case:
|
||||||
img[src$="pic/free_icon.gif"]: 0
|
img[src$="pic/free_icon.gif"]: 0
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
{
|
{
|
||||||
"$schema": "http://json-schema.org/draft-07/schema#",
|
"$schema": "https://json-schema.org/draft/2019-09/schema",
|
||||||
"$ref": "#/definitions/SchemaRoot",
|
"$ref": "#/definitions/SchemaRoot",
|
||||||
"definitions": {
|
"definitions": {
|
||||||
"SchemaRoot": {
|
"SchemaRoot": {
|
||||||
|
@ -413,6 +413,16 @@
|
||||||
"optional": {
|
"optional": {
|
||||||
"type": "boolean"
|
"type": "boolean"
|
||||||
},
|
},
|
||||||
|
"default": {
|
||||||
|
"oneOf": [
|
||||||
|
{
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "number"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
"case": {
|
"case": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"additionalProperties": false,
|
"additionalProperties": false,
|
||||||
|
@ -441,6 +451,31 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"dependentRequired": {
|
||||||
|
"default": [
|
||||||
|
"optional"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"allOf": [
|
||||||
|
{
|
||||||
|
"if": {
|
||||||
|
"properties": {
|
||||||
|
"default": {
|
||||||
|
"not": {
|
||||||
|
"const": null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"then": {
|
||||||
|
"properties": {
|
||||||
|
"optional": {
|
||||||
|
"const": true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
"title": "SelectorBlock"
|
"title": "SelectorBlock"
|
||||||
},
|
},
|
||||||
"Search": {
|
"Search": {
|
||||||
|
|
|
@ -1482,6 +1482,7 @@ namespace Jackett.Common.Indexers
|
||||||
string value = null;
|
string value = null;
|
||||||
var variablesKey = ".Result." + FieldName;
|
var variablesKey = ".Result." + FieldName;
|
||||||
var isOptional = OptionalFields.Contains(Field.Key) || FieldModifiers.Contains("optional") || Field.Value.Optional;
|
var isOptional = OptionalFields.Contains(Field.Key) || FieldModifiers.Contains("optional") || Field.Value.Optional;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var parentObj = mulRow;
|
var parentObj = mulRow;
|
||||||
|
@ -1489,27 +1490,34 @@ namespace Jackett.Common.Indexers
|
||||||
parentObj = Row.Value<JObject>();
|
parentObj = Row.Value<JObject>();
|
||||||
|
|
||||||
value = handleJsonSelector(Field.Value, parentObj, variables, !isOptional);
|
value = handleJsonSelector(Field.Value, parentObj, variables, !isOptional);
|
||||||
|
|
||||||
if (isOptional && string.IsNullOrWhiteSpace(value))
|
if (isOptional && string.IsNullOrWhiteSpace(value))
|
||||||
{
|
{
|
||||||
variables[variablesKey] = null;
|
var defaultValue = applyGoTemplateText(Field.Value.Default, variables);
|
||||||
continue;
|
|
||||||
|
if (string.IsNullOrWhiteSpace(defaultValue))
|
||||||
|
{
|
||||||
|
variables[variablesKey] = null;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
value = defaultValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
variables[variablesKey] = ParseFields(value, FieldName, release, FieldModifiers, searchUrlUri);
|
variables[variablesKey] = ParseFields(value, FieldName, release, FieldModifiers, searchUrlUri);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
if (!variables.ContainsKey(variablesKey))
|
if (!variables.ContainsKey(variablesKey) || isOptional)
|
||||||
variables[variablesKey] = null;
|
variables[variablesKey] = null;
|
||||||
|
|
||||||
if (isOptional)
|
if (isOptional)
|
||||||
{
|
|
||||||
variables[variablesKey] = null;
|
|
||||||
continue;
|
continue;
|
||||||
}
|
|
||||||
throw new Exception($"Error while parsing field={Field.Key}, selector={Field.Value.Selector}, value={value ?? "<null>"}: {ex.Message}", ex);
|
throw new Exception($"Error while parsing field={Field.Key}, selector={Field.Value.Selector}, value={value ?? "<null>"}: {ex.Message}", ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var Filters = Definition.Search.Rows.Filters;
|
var Filters = Definition.Search.Rows.Filters;
|
||||||
var SkipRelease = ParseRowFilters(Filters, release, query, variables, Row);
|
var SkipRelease = ParseRowFilters(Filters, release, query, variables, Row);
|
||||||
|
|
||||||
|
@ -1574,7 +1582,6 @@ namespace Jackett.Common.Indexers
|
||||||
|
|
||||||
var rowsSelector = applyGoTemplateText(Search.Rows.Selector, variables);
|
var rowsSelector = applyGoTemplateText(Search.Rows.Selector, variables);
|
||||||
rowsDom = SearchResultDocument.QuerySelectorAll(rowsSelector);
|
rowsDom = SearchResultDocument.QuerySelectorAll(rowsSelector);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var Rows = new List<IElement>();
|
var Rows = new List<IElement>();
|
||||||
|
@ -1623,26 +1630,34 @@ namespace Jackett.Common.Indexers
|
||||||
string value = null;
|
string value = null;
|
||||||
var variablesKey = ".Result." + FieldName;
|
var variablesKey = ".Result." + FieldName;
|
||||||
var isOptional = OptionalFields.Contains(Field.Key) || FieldModifiers.Contains("optional") || Field.Value.Optional;
|
var isOptional = OptionalFields.Contains(Field.Key) || FieldModifiers.Contains("optional") || Field.Value.Optional;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
value = handleSelector(Field.Value, Row, variables, !isOptional);
|
value = handleSelector(Field.Value, Row, variables, !isOptional);
|
||||||
|
|
||||||
if (isOptional && string.IsNullOrWhiteSpace(value))
|
if (isOptional && string.IsNullOrWhiteSpace(value))
|
||||||
{
|
{
|
||||||
variables[variablesKey] = null;
|
var defaultValue = applyGoTemplateText(Field.Value.Default, variables);
|
||||||
continue;
|
|
||||||
|
if (string.IsNullOrWhiteSpace(defaultValue))
|
||||||
|
{
|
||||||
|
variables[variablesKey] = null;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
value = defaultValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
variables[variablesKey] = ParseFields(value, FieldName, release, FieldModifiers, searchUrlUri);
|
variables[variablesKey] = ParseFields(value, FieldName, release, FieldModifiers, searchUrlUri);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
if (!variables.ContainsKey(variablesKey))
|
if (!variables.ContainsKey(variablesKey) || isOptional)
|
||||||
variables[variablesKey] = null;
|
variables[variablesKey] = null;
|
||||||
|
|
||||||
if (isOptional)
|
if (isOptional)
|
||||||
{
|
|
||||||
variables[variablesKey] = null;
|
|
||||||
continue;
|
continue;
|
||||||
}
|
|
||||||
throw new Exception($"Error while parsing field={Field.Key}, selector={Field.Value.Selector}, value={value ?? "<null>"}: {ex.Message}", ex);
|
throw new Exception($"Error while parsing field={Field.Key}, selector={Field.Value.Selector}, value={value ?? "<null>"}: {ex.Message}", ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1707,8 +1722,10 @@ namespace Jackett.Common.Indexers
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (query.Limit > 0)
|
if (query.Limit > 0)
|
||||||
releases = releases.Take(query.Limit).ToList();
|
releases = releases.Take(query.Limit).ToList();
|
||||||
|
|
||||||
return releases;
|
return releases;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -110,6 +110,7 @@ namespace Jackett.Common.Models
|
||||||
{
|
{
|
||||||
public string Selector { get; set; }
|
public string Selector { get; set; }
|
||||||
public bool Optional { get; set; } = false;
|
public bool Optional { get; set; } = false;
|
||||||
|
public string Default { get; set; }
|
||||||
public string Text { get; set; }
|
public string Text { get; set; }
|
||||||
public string Attribute { get; set; }
|
public string Attribute { get; set; }
|
||||||
public string Remove { get; set; }
|
public string Remove { get; set; }
|
||||||
|
|
Loading…
Reference in New Issue