Small fixes & error handling

This commit is contained in:
Zoe Roux 2025-05-12 13:03:36 +02:00
parent f8331c083a
commit decb09ecca
No known key found for this signature in database
3 changed files with 50 additions and 43 deletions

View File

@ -18,7 +18,7 @@ class KyooClient:
print("Missing environment variable 'KYOO_APIKEY'.")
exit(2)
self._client = ClientSession(
base_url=os.environ.get("KYOO_URL", "http://api:3567/api"),
base_url=os.environ.get("KYOO_URL", "http://api:3567/api") + "/",
headers={
"User-Agent": "kyoo scanner v5",
"X-API-KEY": api_key,
@ -37,7 +37,7 @@ class KyooClient:
await self._client.close()
async def get_videos_info(self) -> VideoInfo:
async with self._client.get("/videos") as r:
async with self._client.get("videos") as r:
r.raise_for_status()
return VideoInfo(**await r.json())

View File

@ -39,6 +39,7 @@ class Scanner:
logger.info("Starting scan at %s. This may take some time...", path)
if self._ignore_pattern:
logger.info(f"Applying ignore pattern: {self._ignore_pattern}")
try:
videos = self.walk_fs(path)
self._info = await self._client.get_videos_info()
@ -65,9 +66,13 @@ class Scanner:
await self._register(to_register)
logger.info("Scan finished for %s.", path)
except Exception as e:
logger.error("Unexpected error while running scan.", exc_info=e)
async def monitor(self):
logger.info(f"Watching for new files in {self._root_path}")
async for changes in awatch(self._root_path, ignore_permission_denied=True):
try:
for event, file in changes:
if not isdir(file) and not is_video(file):
continue
@ -89,6 +94,8 @@ class Scanner:
await self._client.delete_videos([file])
case Change.modified:
pass
except Exception as e:
logger.error("Unexpected error while monitoring files.", exc_info=e)
async def _register(self, videos: list[str] | set[str]):
# TODO: we should probably chunk those

View File

@ -31,7 +31,7 @@ class TheMovieDatabase(Provider):
def __init__(self) -> None:
super().__init__()
self._client = ClientSession(
base_url="https://api.themoviedb.org/3",
base_url="https://api.themoviedb.org/3/",
headers={
"User-Agent": "kyoo scanner v5",
"X-API-KEY": (