2024-06-10 19:15:57 +01:00
|
|
|
from typing import Union
|
|
|
|
|
|
|
|
import requests
|
|
|
|
|
|
|
|
|
|
|
|
class Overseerr(object):
|
|
|
|
def __init__(self, host: str, port: int, api_key: str, ssl: bool = True):
|
|
|
|
self.host = host
|
|
|
|
self.port = port
|
|
|
|
self.api_key = api_key
|
|
|
|
self.ssl = ssl
|
|
|
|
|
|
|
|
@property
|
|
|
|
def protocol(self):
|
|
|
|
return "https://" if self.ssl else "http://"
|
|
|
|
|
|
|
|
def _get(self, endpoint: str, params: dict = None):
|
|
|
|
url = self.protocol + self.host + ":" + str(self.port) + "/api/v1" + endpoint
|
|
|
|
return requests.get(url, headers={"X-Api-Key": self.api_key}, params=params)
|
|
|
|
|
|
|
|
def _post(self, endpoint: str, params: dict = None):
|
|
|
|
url = self.protocol + self.host + ":" + str(self.port) + "/api/v1" + endpoint
|
|
|
|
return requests.post(url, headers={"X-Api-Key": self.api_key}, json=params)
|
|
|
|
|
|
|
|
def test_connection(self):
|
|
|
|
print("Testing connection to Overseerr @", self.host)
|
|
|
|
settings = self._get("/settings/main").json()
|
|
|
|
if settings['applicationUrl'] == "":
|
|
|
|
return self.host
|
|
|
|
return settings['applicationUrl']
|
|
|
|
|
|
|
|
def get_tv_show(self, id):
|
|
|
|
return self._get(f"/tv/{id}").json()
|
|
|
|
|
|
|
|
def get_movie(self, id):
|
|
|
|
return self._get(f"/movie/{id}").json()
|
|
|
|
|
|
|
|
def update_request_status(self, req_id: int, status: Union["approve", "decline"]):
|
2024-06-10 19:23:41 +01:00
|
|
|
return self._post(f"/request/{req_id}/{status}").json()
|
|
|
|
|
|
|
|
def create_issue(self, message, media_id):
|
2024-06-10 19:27:46 +01:00
|
|
|
return self._post(f"/issue", params={"issueType": 0, "message": message, "mediaId": media_id}).json()
|