Update overseerr.py

This commit is contained in:
pacnpal
2024-09-30 20:46:28 -04:00
parent 93c73404d0
commit db14c37b6b

View File

@@ -1,12 +1,13 @@
from redbot.core import commands, Config
from redbot.core.bot import Red
import aiohttp
import asyncio
import json
class Overseerr(commands.Cog):
def __init__(self, bot: Red):
self.bot = bot
self.config = Config.get_conf(self, identifier=336473788746)
self.config = Config.get_conf(self, identifier=1234567890)
default_global = {
"overseerr_url": None,
"overseerr_api_key": None,
@@ -43,9 +44,10 @@ class Overseerr(commands.Cog):
overseerr_url = await self.config.overseerr_url()
overseerr_api_key = await self.config.overseerr_api_key()
url = f"{overseerr_url}/api/v1/{'movie' if media_type == 'movie' else 'tv'}/{media_id}"
headers = {"X-Api-key": overseerr_api_key}
headers = {"X-Api-Key": overseerr_api_key}
async with self.bot.session.get(url, headers=headers) as resp:
async with aiohttp.ClientSession() as session:
async with session.get(url, headers=headers) as resp:
if resp.status == 200:
data = await resp.json()
status = "Available" if data.get('mediaInfo', {}).get('status') == 3 else "Not Available"
@@ -73,7 +75,8 @@ class Overseerr(commands.Cog):
}
# Search for the movie or TV show
async with self.bot.session.get(search_url, headers=headers, params={"query": query}) as resp:
async with aiohttp.ClientSession() as session:
async with session.get(search_url, headers=headers, params={"query": query}) as resp:
search_results = await resp.json()
if not search_results['results']:
@@ -122,7 +125,8 @@ class Overseerr(commands.Cog):
"mediaType": media_type
}
async with self.bot.session.post(request_url, headers=headers, json=request_data) as resp:
async with aiohttp.ClientSession() as session:
async with session.post(request_url, headers=headers, json=request_data) as resp:
if resp.status == 200:
response_data = await resp.json()
request_id = response_data.get('id')
@@ -152,7 +156,8 @@ class Overseerr(commands.Cog):
"Content-Type": "application/json"
}
async with self.bot.session.post(approve_url, headers=headers) as resp:
async with aiohttp.ClientSession() as session:
async with session.post(approve_url, headers=headers) as resp:
if resp.status == 200:
await ctx.send(f"Request {request_id} has been approved!")
else: