File size: 2,094 Bytes
4b81310 73e339f 1fa8166 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
import requests
import logging
class InstancesAPI:
def __init__(self, instances):
self.instances = instances
def fetch_reports(self):
reports = {}
for instance_url in self.instances:
try:
response = requests.get(f"{instance_url}/api/get/report")
response.raise_for_status()
reports[instance_url] = response.json()
except requests.exceptions.RequestException as e:
logging.error(f"Error contacting instance {instance_url}: {e}")
return reports
def download_film(self, instance_url, title):
"""
Download a film to an instance.
If the download started, it returns a JSON like this:
example:
{"film_id": "my_spy_2020",
"status": "Download started"}
If the film has already been downloaded, it will return the video file.
"""
data = {}
try:
response = requests.get(f"{instance_url}/api/film/{title}")
response.raise_for_status()
data = response.json()
except requests.exceptions.RequestException as e:
logging.error(f"Error contacting instance {instance_url}: {e}")
data = {"error": str(e)}
return data
def download_episode(self, instance_url, title, season, episode):
"""
Download a film to an instance.
If the download started, it returns a JSON like this:
example:
{"film_id": "my_spy_2020",
"status": "Download started"}
If the film has already been downloaded, it will return the video file.
"""
data = {}
try:
response = requests.get(f"{instance_url}/api/tv/{title}/{season}/{episode}")
response.raise_for_status()
data = response.json()
except requests.exceptions.RequestException as e:
logging.error(f"Error contacting instance {instance_url}: {e}")
data = {"error": str(e)}
return data
|