Add custom sources - ZayrexDev/ACGPicDownload GitHub Wiki
There are already some sources in the default sources.json. You can see them to add your own source.
An available source should contain the following values in sources.json:
| Key | Type | Description | Detail |
|---|---|---|---|
| name | String | Name of the source | Required. Please make sure that each source has different names |
| description | String | Description of the source | Optional |
| returnType | String | The return type of the url | json or redirect, if it's empty, then the program will choose it automatically |
| url | String | The url used to fetch | Required |
| defaultArgs | JSON | The default values of the variables in the url | Required When using arguments in ## url |
| sourceKey | String | The path to image data(s) in the JSON | Optional, if it's empty, the program will try to parse the json directly |
| picUrl | String | The path to image url in each image data | Required |
| nameRule | String | The naming rules | It tells the program how to name the downloaded images |
url
You can add custom vars in the url with {sometext $varname}, and they are called variable block. And you need to define them in defaultArgs.
If the program can't find the the value of the variable, it will delete the whole variable block in the url.
For example, if the url is https://someurl/pic?{mode=$mode}{&num=$num}{&abc=$arg} , then with the --arg num=1 argument and the default value a for mode, the actual url will be https://someurl/pic?num=1
defaultArgs
Required to define arguments in url.
Every arg has the values below:
| Name | Type | Description |
|---|---|---|
| type | String | Required,define the type of the argument. string or int. |
| value | String | Optional, gives the argument a default value. |
For string arguments, there're these values:
| Name | Type | Description |
|---|---|---|
| from | Array | Optional, defines what can be the argument's value |
For int arguments, there're these values:
| Name | Type | Description |
|---|---|---|
| max | int | Optional, defines the max value |
| min | int | Optional, defines the min value |
| step | int | Optional, defines the step |
In the example of url , the defaultArgs can be like:
{
"defaultArgs": {
"num": {
"type": "int",
"min": 1,
"max": 100,
"value": 1
},
"mode": {
"type": "string",
"from": ["a","b","c"],
"value": "a"
},
"tag": {
"type": "string"
}
}
}
nameRule
You can use {sometext$varname} to use values from the return JSON as a part of the file name.
For example, if a JSON return result is :
{
"ext": "png",
"urls": {
"original": "....."
},
"author": "some_author",
"id": 6969,
"title": "some_title"
}
Then if the nameRule is {ID:$id }{$title}{ by $author}{.$ext}, the name of this result will
be ID:6969 some_title by some_author.png
If the nameRule is empty, the program will try to get the file name from the download link.
sourceKey
Because of some source does not return the JSON directly of the image data, for example:
{
"images": {
"data": [
{
"ext": "png",
"urls": {
"original": "....."
},
"author": "some_author",
"id": 6969,
"title": "some_title"
},
{
"ext": "png",
"urls": {
"original": "....."
},
"author": "more_author",
"id": 1145,
"title": "more_title"
}
]
}
}
The sourceKey of the JSON above should be images/data
picUrl
Just like the sourceKey, the url of each return value should be told.
For example, the picUrl of the following json should be urls/original
{
"urls": {
"original": "....."
},
"id": 6969,
"title": "some_title"
}
returnType
Different sources may have different return type, we only supports json and redirect for now.
If you open the
urlin your source directly and gets some texts, then thereturnTypeshould bejsonIf you get the image directly, then it should be
redirect