Warning, /multimedia/kdenlive/data/resourceproviders/README.md is written in an unsupported language. File is not indexed.

0001 # How To Write Provider Configurations
0002 Instruction written 2021 by Julius Künzel as part of Kdenlive (www.kdenlive.org)
0003 ## Overview
0004 Provider configuration files are json files.
0005 Here is an example for [freesound](https://freesound.org)
0006 ```json
0007 {
0008     "name": "Freesound",
0009     "homepage": "https://freesound.org",
0010     "type": "sound",
0011     "integration": "buildin",
0012     "downloadOAuth2": true,
0013     "clientkey": "1234",
0014     "api": {
0015         "root": "https://freesound.org/apiv2",
0016         "oauth2": {
0017             "authorizationUrl": "https://freesound.org/apiv2/oauth2/authorize/",
0018             "accessTokenUrl": "https://freesound.org/apiv2/oauth2/access_token/",
0019             "clientId": "9876"
0020         },
0021         "search": {
0022             "req": {
0023                 "path": "/search/text/",
0024                 "method": "GET",
0025                 "params": [
0026                     { "key": "format", "value": "json" },
0027                     { "key": "fields", "value": "id,url,name,description,license,filesize,duration,username,download,previews,images,type" },
0028                     { "key": "page_size", "value": "%perpage%" },
0029                     { "key": "page", "value": "%pagenum%" },
0030                     { "key": "query", "value": "%query%" },
0031                     { "key": "token", "value": "%clientkey%" }
0032                 ]
0033             },
0034             "res": {
0035                 "format": "json",
0036                 "resultCount":"count",
0037                 "list":"results",
0038                 "name":"name",
0039                 "filetype":"type",
0040                 "id":"id",
0041                 "url":"url",
0042                 "licenseUrl":"license",
0043                 "description": "description",
0044                 "author": "username",
0045                 "authorUrl": "$https://freesound.org/people/{username}",
0046                 "duration": "duration",
0047                 "filesize":"filesize",
0048                 "downloadUrl": "download",
0049                 "previewUrl": "previews.preview-hq-mp3",
0050                 "imageUrl": "images.waveform_m"
0051             }
0052         }
0053     }
0054 }
0055 ```
0056 
0057 ## Base Structure
0058 Each provider config files should only specify a certain media type such as `video`. If the provider provides multiple types, create one config file for each.
0059 
0060 | Key | Type | Required | Description |
0061 | :------------- | :------------- | :------------- | :------------- |
0062 | name | String | yes | Name of the provider (not translatable!!!) |
0063 | homepage | String | yes | Url pointing to the providers webpage |
0064 | type | String | yes | one of `video`, `image`, `music`, `sound` |
0065 | integration | String | yes | Must be `buildin` as this is the only supported value at the moment |
0066 | clientkey | String | If OAuth2 or `%clientkey%` is used | The client key to access the api. </br>_Kdenlive has some keys build in:  `%pixabay_apikey%`, `%freesound_apikey%` and `%pexels_apikey%` will be replaced by a key for the certain provider._ |
0067 | downloadOAuth2 | bool | no | Whether OAuth2 authentication is needed to download files
0068 | api | Object | yes | see  [Api](#api) |
0069 
0070 ## Api
0071 The `api` object describs the api endpoints
0072 
0073 | Key | Type | Required | Description |
0074 | :------------- | :------------- | :------------- | :------------- |
0075 | root | String | yes | The apis base url (should *not* end with `/`) |
0076 | oauth2 | Object | If [`downloadOAuth2`](#base-structure) is `true` | See [OAuth2](#oauth2) |
0077 | search | Object | yes | See [Search](#search) |
0078 | downloadUrls | Object | yes | See [Fetch Download Urls](#fetch-download-urls) |
0079 
0080 ### OAuth2
0081 
0082 | Key | Type | Required | Description |
0083 | :------------- | :------------- | :------------- | :------------- |
0084 | authorizationUrl | String | yes | The url to authorize |
0085 | accessTokenUrl | String | yes | The url to request an access token |
0086 | clientId | String | yes | The clients id |
0087 
0088 ### Search
0089 The `search` object should hold the two objects `req` and `res`.
0090 #### Request
0091 | Key | Type | Required | Description |
0092 | :------------- | :------------- | :------------- | :------------- |
0093 | path | String | yes | Path to the search endpoint (appended to [`root`](#api), should start with `/`) |
0094 | method | String | yes | HTTP method. Only `GET` is supported at the moment |
0095 | params | Array of Objects | no | List of HTTP params |
0096 | header | Array of Objects| no | List HTTP headers |
0097 
0098 The objects in the arrays in `params` and `header` should contain two fields: `key` and `value`
0099 
0100 #### Response
0101 | Key | Type | Required | Description |
0102 | :------------- | :------------- | :------------- | :------------- |
0103 | format | String | yes | Format of the response. Only `json` is supported at the moment |
0104 | resultCount | String | yes | Number of total result |
0105 | list | String | | Name of the key containing the list holding the search results. All of the following fields are relative to a item of this list |
0106 | name | String | no | The items name |
0107 | filetype | String | no | The items filetype |
0108 | id | String | yes | Name of the key in a list element holding the items id |
0109 | url | String | | Url to the item to be opened in a external browser |
0110 | licenseUrl | String | | Url to the license to be opened in a external browser. If you use a [template](#templates), always use link to the english license version. Kdenlive can generate License names out of links to Creative Commons, Pexels and Pixabay Licenses for all other links the License name is "Unknown License". |
0111 | description | String | no | Description of the item |
0112 | author | String | no | Name of the items author |
0113 | authorUrl | String | no | Link to the items authors page to be opened in a external browser |
0114 | duration | String | no | Duration of the item (for video and audio)|
0115 | width | String | no | Width of the item (for video and image) |
0116 | height | String | no | Height of the item (for video and image) |
0117 | downloadUrl | String | no, if `downloadUrls` or [Fetch Download Urls](#fetch-download-urls) | To be used when there is only one download url (i.e. one file version) for the item |
0118 | downloadUrls | Object | no, if `downloadUrl` or [Fetch Download Urls](#fetch-download-urls) | To be used when there are multiple download url (i.e. one file version) for the item. See description in [table](#mutliple-download-urls) below |
0119 | previewUrl | String | no | Url to preview file of the item |
0120 | imageUrl | String | no | Url to image thumb of the item (for audio e.g. album cover, for video a still)|
0121 
0122 ##### Multiple Download Urls
0123 
0124 | Key | Type | Required | Description |
0125 | :------------- | :------------- | :------------- | :------------- |
0126 | key | String | yes | Name of the key containing the list holding the files. The following fields are relative to a item of this list |
0127 | url | String | yes | Name of the key in a list element holding the download url |
0128 | name | String | yes | Label for the certain file version |
0129 
0130 ###### Example
0131 ```json
0132 "downloadUrls": {
0133     "key": "video_files",
0134     "url":"link",
0135     "name":"${quality} {width}x{height}"
0136 }
0137 ```
0138 
0139 ### Fetch Download Urls
0140 Only necessary in special cases (e.g. https://archive.org) when no download urls are provided with the search response i.e. neither `downloadUrl` nor `downloadUrls` can be set in [Search `res`](#response)
0141 
0142 For the `req` object see the description of the [`req` obeject for `search`](#request)
0143 
0144 The `res` object should hold two fields: `format` (same as in [search response](#response)) and `downloadUrl` (same as in [search response](#response)) or `downloadUrls`. The field `downloadUrls` is again similar to the one in [search response](#response), but has some additional fields:
0145 
0146 | Key | Type | Required | Description |
0147 | :------------- | :------------- | :------------- | :------------- |
0148 | isObject | Boolean | no | Whether the list not a normal array but a object and each subobject contains metadata about a file (e.g. `"files": { "file1": { "name": "&" }, "file2": { … }, …}`)|
0149 | format | String | no | Format of the file |
0150 
0151 If `isObject` is `true` there is a special case for `format`, `url` and `name`: if they have the value `&` (or `{&}` within a [template](#templates)) it is replace by the key of the parent object. In the example in the table above this means `name` will be `file1`
0152 
0153 #### Example
0154 ```json
0155 "downloadUrls": {
0156     "req": {
0157         "path": "/details/%id%",
0158         "method": "GET",
0159         "params": [
0160             { "key": "output", "value": "json"}
0161         ]
0162     },
0163     "res": {
0164         "format": "json",
0165         "downloadUrls": {"key":"files", "isObject":true, "url":"$http://archive.org/download/%id%{&}", "format": "format", "name":"${source} {format} {width}x{height}"}
0166     }
0167 }
0168 ```
0169 ### Special Keys
0170 Special keys are available for the following fields in [Search `res`](#response): `author`, `authorUrl`, `name`, `filetype`, `description`, `id`, `url`, `licenseUrl`, `imageUrl`, `previewUrl`, `downloadUrl`, `downloadUrls.url` and `downloadUrls.name`.
0171 
0172 In [`res` of Fetch Download Urls](#fetch-download-urls) they are available for these fields: `downloadUrl`, `downloadUrls.format`,`downloadUrls.url` and `downloadUrls.name`
0173 #### Placeholders
0174 Placeholders are expressions that will be replaced by something.
0175 
0176 For `params` and `header` these of placeholders are available.
0177 
0178 | Placeholder | Replaced By | Hint |
0179 | :------------- | :------------- | :------------- |
0180 | %query% | The search query the user entered | Only for search |
0181 | %pagenum% | Th number of the page to request results for | Only for search |
0182 | %perpage% | Number of results that should be shown per page | |
0183 | %shortlocale% | Short local like `en-US` (at the moment always `en-US`) | |
0184 | %clientkey% | The clients apikey defined in [`clientkey`](#base-structure) | |
0185 | %id% | Id of the item to fetch urls for | Only for Fetch Download Urls |
0186 
0187 #### Templates
0188 Templates must always start with `$`. Within a template string you can use keys like this `{username}`.
0189 
0190 *NOTE: You can not use the general key like `author`. You must use the key of the response like `username` in the [example for freesound](#Overview)!*
0191 
0192 ##### Example
0193 
0194 If your response looks like
0195 ```json
0196 {
0197   "results": [
0198     {
0199       "name": "example",
0200       "files": [
0201         {"picname": "nice-picture", "id": "1234"},
0202         ...
0203       ]
0204     }
0205   ]
0206 }
0207 
0208 ```
0209 and your config like this
0210 ```json
0211 {
0212   ...
0213   "api": {
0214     ...
0215     "search": {
0216       ...
0217       "res" {
0218         ...
0219         "downloadUrls": {
0220             "key": "files",
0221             "url":"$https://example.org/files/{picname}-{id}",
0222             "name":"picname"
0223         }
0224       }
0225     }
0226   }
0227 }
0228 ```
0229 you will finally get `https://example.org/files/nice-picture-1234` as url.