qbit_manage/modules/bhd.py

34 lines
1.1 KiB
Python
Raw Normal View History

import logging
from modules.util import Failed
from json import JSONDecodeError
logger = logging.getLogger("qBit Manage")
base_url = "https://beyond-hd.me/api/"
2021-12-29 01:19:58 +08:00
class BeyondHD:
def __init__(self, config, params):
self.config = config
self.apikey = params["apikey"]
2021-12-29 01:19:58 +08:00
json = {"search": "test"}
self.search(json)
def search(self, json, path="torrents/"):
url = f"{base_url}{path}{self.apikey}"
json["action"] = "search"
if self.config.trace_mode:
logger.debug(url.replace(self.apikey, "APIKEY"))
logger.debug(f"JSON: {json}")
try:
response = self.config.post(url, json=json)
response_json = response.json()
except JSONDecodeError as e:
if response.status_code >= 400:
raise Failed(e)
if response.status_code >= 400:
logger.debug(f"Response: {response_json}")
raise Failed(f"({response.status_code} [{response.reason}]) {response_json}")
if not response_json["success"]:
raise Failed(f"BHD Error: {response_json['status_message']}")
2021-12-29 01:19:58 +08:00
return response.json()