{
    "swagger": "2.0",
    "info": {
        "description": "Torrent streaming server.",
        "title": "Swagger Torrserver API",
        "contact": {},
        "license": {
            "name": "GPL 3.0"
        },
        "version": "{version.Version}"
    },
    "basePath": "/",
    "paths": {
        "/cache": {
            "post": {
                "description": "Return cache stats.",
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "API"
                ],
                "summary": "Return cache stats",
                "parameters": [
                    {
                        "description": "Cache stats request",
                        "name": "request",
                        "in": "body",
                        "required": true,
                        "schema": {
                            "$ref": "#/definitions/api.cacheReqJS"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Cache stats",
                        "schema": {
                            "$ref": "#/definitions/state.CacheState"
                        }
                    }
                }
            }
        },
        "/download/{size}": {
            "get": {
                "description": "Download the test file of given size (for speed testing purpose).",
                "produces": [
                    "application/octet-stream"
                ],
                "tags": [
                    "API"
                ],
                "summary": "Generates test file of given size",
                "parameters": [
                    {
                        "type": "string",
                        "description": "Test file size (in MB)",
                        "name": "size",
                        "in": "path",
                        "required": true
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "type": "file"
                        }
                    }
                }
            }
        },
        "/echo": {
            "get": {
                "description": "Tests whether server is alive or not",
                "produces": [
                    "text/plain"
                ],
                "tags": [
                    "API"
                ],
                "summary": "Tests server status",
                "responses": {
                    "200": {
                        "description": "Server version",
                        "schema": {
                            "type": "string"
                        }
                    }
                }
            }
        },
        "/ffp/{hash}/{id}": {
            "get": {
                "description": "Gather informations using ffprobe.",
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "API"
                ],
                "summary": "Gather informations using ffprobe",
                "parameters": [
                    {
                        "type": "string",
                        "description": "Torrent hash",
                        "name": "hash",
                        "in": "path",
                        "required": true
                    },
                    {
                        "type": "string",
                        "description": "File index in torrent",
                        "name": "id",
                        "in": "path",
                        "required": true
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Data returned from ffprobe"
                    }
                }
            }
        },
        "/magnets": {
            "get": {
                "description": "Get HTML of magnet links.",
                "produces": [
                    "text/html"
                ],
                "tags": [
                    "Pages"
                ],
                "summary": "Get HTML of magnet links",
                "responses": {
                    "200": {
                        "description": "Magnet links"
                    }
                }
            }
        },
        "/msx/imdb": {
            "get": {
                "description": "Get MSX IMDB informations.",
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "MSX"
                ],
                "summary": "Get MSX IMDB informations",
                "responses": {
                    "200": {
                        "description": "JSON MSX IMDB informations"
                    }
                }
            }
        },
        "/msx/imdb/{id}": {
            "get": {
                "description": "Get MSX IMDB informations.",
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "MSX"
                ],
                "summary": "Get MSX IMDB informations",
                "parameters": [
                    {
                        "type": "string",
                        "description": "IMDB ID",
                        "name": "id",
                        "in": "path",
                        "required": true
                    }
                ],
                "responses": {
                    "200": {
                        "description": "JSON MSX IMDB informations"
                    }
                }
            }
        },
        "/msx/{pth}": {
            "get": {
                "description": "Multi usage endpoint.",
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "MSX"
                ],
                "summary": "Multi usage endpoint",
                "parameters": [
                    {
                        "type": "string",
                        "description": "Route MSX pages",
                        "name": "link",
                        "in": "path",
                        "required": true
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Data returned according to path"
                    }
                }
            }
        },
        "/play/{hash}/{id}": {
            "get": {
                "description": "Play given torrent referenced by hash.",
                "produces": [
                    "application/octet-stream"
                ],
                "tags": [
                    "API"
                ],
                "summary": "Play given torrent referenced by hash",
                "parameters": [
                    {
                        "type": "string",
                        "description": "Torrent hash",
                        "name": "hash",
                        "in": "path",
                        "required": true
                    },
                    {
                        "type": "string",
                        "description": "File index in torrent",
                        "name": "id",
                        "in": "path",
                        "required": true
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Torrent data"
                    }
                }
            }
        },
        "/playlist": {
            "get": {
                "description": "Get HTTP link of torrent in M3U list.",
                "produces": [
                    "audio/x-mpegurl"
                ],
                "tags": [
                    "API"
                ],
                "summary": "Get HTTP link of torrent in M3U list",
                "parameters": [
                    {
                        "type": "string",
                        "description": "Torrent hash",
                        "name": "hash",
                        "in": "query",
                        "required": true
                    },
                    {
                        "type": "boolean",
                        "description": "From last play file",
                        "name": "fromlast",
                        "in": "query"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "type": "file"
                        }
                    }
                }
            }
        },
        "/playlistall/all.m3u": {
            "get": {
                "description": "Retrieve all torrents and generates a bundled M3U playlist.",
                "produces": [
                    "audio/x-mpegurl"
                ],
                "tags": [
                    "API"
                ],
                "summary": "Get a M3U playlist with all torrents",
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "type": "file"
                        }
                    }
                }
            }
        },
        "/search": {
            "get": {
                "description": "Makes a rutor search.",
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "API"
                ],
                "summary": "Makes a rutor search",
                "parameters": [
                    {
                        "type": "string",
                        "description": "Rutor query",
                        "name": "query",
                        "in": "query",
                        "required": true
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Rutor torrent search result(s)",
                        "schema": {
                            "type": "array",
                            "items": {
                                "$ref": "#/definitions/models.TorrentDetails"
                            }
                        }
                    }
                }
            }
        },
        "/settings": {
            "post": {
                "description": "Allow to get or set server settings.",
                "consumes": [
                    "application/json"
                ],
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "API"
                ],
                "summary": "Get / Set server settings",
                "parameters": [
                    {
                        "description": "Settings request",
                        "name": "request",
                        "in": "body",
                        "required": true,
                        "schema": {
                            "$ref": "#/definitions/api.setsReqJS"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Depends on what action has been asked",
                        "schema": {
                            "$ref": "#/definitions/settings.BTSets"
                        }
                    }
                }
            }
        },
        "/shutdown": {
            "get": {
                "description": "Gracefully shuts down server after 1 second.",
                "tags": [
                    "API"
                ],
                "summary": "Shuts down server",
                "responses": {
                    "200": {
                        "description": "OK"
                    }
                }
            }
        },
        "/stat": {
            "get": {
                "description": "Stat server.",
                "produces": [
                    "text/plain"
                ],
                "tags": [
                    "Pages"
                ],
                "summary": "Stat server",
                "responses": {
                    "200": {
                        "description": "Stats"
                    }
                }
            }
        },
        "/stream": {
            "get": {
                "description": "Multi usage endpoint.",
                "produces": [
                    "application/octet-stream"
                ],
                "tags": [
                    "API"
                ],
                "summary": "Multi usage endpoint",
                "parameters": [
                    {
                        "type": "string",
                        "description": "Magnet/hash/link to torrent",
                        "name": "link",
                        "in": "query",
                        "required": true
                    },
                    {
                        "type": "string",
                        "description": "File index in torrent",
                        "name": "index",
                        "in": "query"
                    },
                    {
                        "type": "string",
                        "description": "Should preload torrent",
                        "name": "preload",
                        "in": "query"
                    },
                    {
                        "type": "string",
                        "description": "Get statistics from torrent",
                        "name": "stat",
                        "in": "query"
                    },
                    {
                        "type": "string",
                        "description": "Should save torrent",
                        "name": "save",
                        "in": "query"
                    },
                    {
                        "type": "string",
                        "description": "Get torrent as M3U playlist",
                        "name": "m3u",
                        "in": "query"
                    },
                    {
                        "type": "string",
                        "description": "Get M3U from last played file",
                        "name": "fromlast",
                        "in": "query"
                    },
                    {
                        "type": "string",
                        "description": "Start stream torrent",
                        "name": "play",
                        "in": "query"
                    },
                    {
                        "type": "string",
                        "description": "Set title of torrent",
                        "name": "title",
                        "in": "query"
                    },
                    {
                        "type": "string",
                        "description": "Set poster link of torrent",
                        "name": "poster",
                        "in": "query"
                    },
                    {
                        "type": "string",
                        "description": "Set category of torrent, used in web: movie, tv, music, other",
                        "name": "category",
                        "in": "query"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Data returned according to query"
                    }
                }
            }
        },
        "/torrent/upload": {
            "post": {
                "description": "Only one file support.",
                "consumes": [
                    "multipart/form-data"
                ],
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "API"
                ],
                "summary": "Only one file support",
                "parameters": [
                    {
                        "type": "file",
                        "description": "Torrent file to insert",
                        "name": "file",
                        "in": "formData",
                        "required": true
                    },
                    {
                        "type": "string",
                        "description": "Save to DB",
                        "name": "save",
                        "in": "formData"
                    },
                    {
                        "type": "string",
                        "description": "Torrent title",
                        "name": "title",
                        "in": "formData"
                    },
                    {
                        "type": "string",
                        "description": "Torrent category",
                        "name": "category",
                        "in": "formData"
                    },
                    {
                        "type": "string",
                        "description": "Torrent poster",
                        "name": "poster",
                        "in": "formData"
                    },
                    {
                        "type": "string",
                        "description": "Torrent data",
                        "name": "data",
                        "in": "formData"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Torrent status",
                        "schema": {
                            "$ref": "#/definitions/state.TorrentStatus"
                        }
                    }
                }
            }
        },
        "/torrents": {
            "post": {
                "description": "Allow to add, get or set torrents to server. The action depends of what has been asked.",
                "consumes": [
                    "application/json"
                ],
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "API"
                ],
                "summary": "Handle torrents informations",
                "parameters": [
                    {
                        "description": "Torrent request",
                        "name": "request",
                        "in": "body",
                        "required": true,
                        "schema": {
                            "$ref": "#/definitions/api.torrReqJS"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK"
                    }
                }
            }
        },
        "/viewed": {
            "post": {
                "description": "Allow to set, list or remove viewed torrents from server.",
                "consumes": [
                    "application/json"
                ],
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "API"
                ],
                "summary": "Set / List / Remove viewed torrents",
                "parameters": [
                    {
                        "description": "Viewed torrent request",
                        "name": "request",
                        "in": "body",
                        "required": true,
                        "schema": {
                            "$ref": "#/definitions/api.viewedReqJS"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "type": "array",
                            "items": {
                                "$ref": "#/definitions/settings.Viewed"
                            }
                        }
                    }
                }
            }
        }
    },
    "definitions": {
        "api.cacheReqJS": {
            "type": "object",
            "properties": {
                "action": {
                    "type": "string"
                },
                "hash": {
                    "type": "string"
                }
            }
        },
        "api.setsReqJS": {
            "type": "object",
            "properties": {
                "action": {
                    "type": "string"
                },
                "sets": {
                    "$ref": "#/definitions/settings.BTSets"
                }
            }
        },
        "api.torrReqJS": {
            "type": "object",
            "properties": {
                "action": {
                    "type": "string"
                },
                "category": {
                    "type": "string"
                },
                "data": {
                    "type": "string"
                },
                "hash": {
                    "type": "string"
                },
                "link": {
                    "type": "string"
                },
                "poster": {
                    "type": "string"
                },
                "save_to_db": {
                    "type": "boolean"
                },
                "title": {
                    "type": "string"
                }
            }
        },
        "api.viewedReqJS": {
            "type": "object",
            "properties": {
                "action": {
                    "type": "string"
                },
                "file_index": {
                    "type": "integer"
                },
                "hash": {
                    "type": "string"
                }
            }
        },
        "models.TorrentDetails": {
            "type": "object",
            "properties": {
                "audioQuality": {
                    "type": "integer"
                },
                "categories": {
                    "type": "string"
                },
                "createDate": {
                    "type": "string"
                },
                "hash": {
                    "type": "string"
                },
                "imdbid": {
                    "type": "string"
                },
                "link": {
                    "type": "string"
                },
                "magnet": {
                    "type": "string"
                },
                "name": {
                    "type": "string"
                },
                "names": {
                    "type": "array",
                    "items": {
                        "type": "string"
                    }
                },
                "peer": {
                    "type": "integer"
                },
                "seed": {
                    "type": "integer"
                },
                "size": {
                    "type": "string"
                },
                "title": {
                    "type": "string"
                },
                "tracker": {
                    "type": "string"
                },
                "videoQuality": {
                    "type": "integer"
                },
                "year": {
                    "type": "integer"
                }
            }
        },
        "settings.BTSets": {
            "type": "object",
            "properties": {
                "cacheSize": {
                    "description": "Cache",
                    "type": "integer"
                },
                "connectionsLimit": {
                    "type": "integer"
                },
                "disableDHT": {
                    "type": "boolean"
                },
                "disablePEX": {
                    "type": "boolean"
                },
                "disableTCP": {
                    "type": "boolean"
                },
                "disableUPNP": {
                    "type": "boolean"
                },
                "disableUTP": {
                    "type": "boolean"
                },
                "disableUpload": {
                    "type": "boolean"
                },
                "downloadRateLimit": {
                    "description": "in kb, 0 - inf",
                    "type": "integer"
                },
                "enableDLNA": {
                    "description": "DLNA",
                    "type": "boolean"
                },
                "enableDebug": {
                    "description": "debug logs",
                    "type": "boolean"
                },
                "enableIPv6": {
                    "description": "BT Config",
                    "type": "boolean"
                },
                "enableRutorSearch": {
                    "description": "Rutor",
                    "type": "boolean"
                },
                "forceEncrypt": {
                    "description": "Torrent",
                    "type": "boolean"
                },
                "friendlyName": {
                    "type": "string"
                },
                "peersListenPort": {
                    "type": "integer"
                },
                "preloadCache": {
                    "description": "in percent",
                    "type": "integer"
                },
                "readerReadAHead": {
                    "description": "in percent, 5%-100%, [...S__X__E...] [S-E] not clean",
                    "type": "integer"
                },
                "removeCacheOnDrop": {
                    "type": "boolean"
                },
                "retrackersMode": {
                    "description": "0 - don`t add, 1 - add retrackers (def), 2 - remove retrackers 3 - replace retrackers",
                    "type": "integer"
                },
                "sslCert": {
                    "type": "string"
                },
                "sslKey": {
                    "type": "string"
                },
                "sslPort": {
                    "description": "HTTPS",
                    "type": "integer"
                },
                "torrentDisconnectTimeout": {
                    "description": "in seconds",
                    "type": "integer"
                },
                "torrentsSavePath": {
                    "type": "string"
                },
                "uploadRateLimit": {
                    "description": "in kb, 0 - inf",
                    "type": "integer"
                },
                "useDisk": {
                    "description": "Disk",
                    "type": "boolean"
                }
            }
        },
        "settings.Viewed": {
            "type": "object",
            "properties": {
                "file_index": {
                    "type": "integer"
                },
                "hash": {
                    "type": "string"
                }
            }
        },
        "state.CacheState": {
            "type": "object",
            "properties": {
                "capacity": {
                    "type": "integer"
                },
                "filled": {
                    "type": "integer"
                },
                "hash": {
                    "type": "string"
                },
                "pieces": {
                    "type": "object",
                    "additionalProperties": {
                        "$ref": "#/definitions/state.ItemState"
                    }
                },
                "piecesCount": {
                    "type": "integer"
                },
                "piecesLength": {
                    "type": "integer"
                },
                "readers": {
                    "type": "array",
                    "items": {
                        "$ref": "#/definitions/state.ReaderState"
                    }
                },
                "torrent": {
                    "$ref": "#/definitions/state.TorrentStatus"
                }
            }
        },
        "state.ItemState": {
            "type": "object",
            "properties": {
                "completed": {
                    "type": "boolean"
                },
                "id": {
                    "type": "integer"
                },
                "length": {
                    "type": "integer"
                },
                "priority": {
                    "type": "integer"
                },
                "size": {
                    "type": "integer"
                }
            }
        },
        "state.ReaderState": {
            "type": "object",
            "properties": {
                "end": {
                    "type": "integer"
                },
                "reader": {
                    "type": "integer"
                },
                "start": {
                    "type": "integer"
                }
            }
        },
        "state.TorrentFileStat": {
            "type": "object",
            "properties": {
                "id": {
                    "type": "integer"
                },
                "length": {
                    "type": "integer"
                },
                "path": {
                    "type": "string"
                }
            }
        },
        "state.TorrentStat": {
            "type": "integer",
            "enum": [
                0,
                1,
                2,
                3,
                4,
                5
            ],
            "x-enum-varnames": [
                "TorrentAdded",
                "TorrentGettingInfo",
                "TorrentPreload",
                "TorrentWorking",
                "TorrentClosed",
                "TorrentInDB"
            ]
        },
        "state.TorrentStatus": {
            "type": "object",
            "properties": {
                "active_peers": {
                    "type": "integer"
                },
                "bit_rate": {
                    "type": "string"
                },
                "bytes_read": {
                    "type": "integer"
                },
                "bytes_read_data": {
                    "type": "integer"
                },
                "bytes_read_useful_data": {
                    "type": "integer"
                },
                "bytes_written": {
                    "type": "integer"
                },
                "bytes_written_data": {
                    "type": "integer"
                },
                "category": {
                    "type": "string"
                },
                "chunks_read": {
                    "type": "integer"
                },
                "chunks_read_useful": {
                    "type": "integer"
                },
                "chunks_read_wasted": {
                    "type": "integer"
                },
                "chunks_written": {
                    "type": "integer"
                },
                "connected_seeders": {
                    "type": "integer"
                },
                "data": {
                    "type": "string"
                },
                "download_speed": {
                    "type": "number"
                },
                "duration_seconds": {
                    "type": "number"
                },
                "file_stats": {
                    "type": "array",
                    "items": {
                        "$ref": "#/definitions/state.TorrentFileStat"
                    }
                },
                "half_open_peers": {
                    "type": "integer"
                },
                "hash": {
                    "type": "string"
                },
                "loaded_size": {
                    "type": "integer"
                },
                "name": {
                    "type": "string"
                },
                "pending_peers": {
                    "type": "integer"
                },
                "pieces_dirtied_bad": {
                    "type": "integer"
                },
                "pieces_dirtied_good": {
                    "type": "integer"
                },
                "poster": {
                    "type": "string"
                },
                "preload_size": {
                    "type": "integer"
                },
                "preloaded_bytes": {
                    "type": "integer"
                },
                "stat": {
                    "$ref": "#/definitions/state.TorrentStat"
                },
                "stat_string": {
                    "type": "string"
                },
                "timestamp": {
                    "type": "integer"
                },
                "title": {
                    "type": "string"
                },
                "torrent_size": {
                    "type": "integer"
                },
                "total_peers": {
                    "type": "integer"
                },
                "upload_speed": {
                    "type": "number"
                }
            }
        }
    },
    "securityDefinitions": {
        "BasicAuth": {
            "type": "basic"
        }
    },
    "externalDocs": {
        "description": "OpenAPI",
        "url": "https://swagger.io/resources/open-api/"
    }
}