diff --git a/scanner/matcher/matcher.py b/scanner/matcher/matcher.py index 6d4db3f0..d45c8381 100644 --- a/scanner/matcher/matcher.py +++ b/scanner/matcher/matcher.py @@ -198,7 +198,7 @@ class Matcher: "episode": id_episode, } - current = await self._client.get(kind, kyoo_id) + current = await self._client.get(f"{kind}/{kyoo_id}") if self._provider.name not in current["externalId"]: logger.error( f"Could not refresh metadata of {kind}/{kyoo_id}. Missing provider id." diff --git a/scanner/providers/kyoo_client.py b/scanner/providers/kyoo_client.py index 5c305ad6..d759d90e 100644 --- a/scanner/providers/kyoo_client.py +++ b/scanner/providers/kyoo_client.py @@ -128,11 +128,9 @@ class KyooClient: await self.delete_issue(path) - async def get( - self, kind: Literal["movie", "show", "season", "episode", "collection"], id: str - ): + async def get(self, path: str): async with self.client.get( - f"{self._url}/{kind}/{id}", + f"{self._url}/{path}", headers={"X-API-Key": self._api_key}, ) as r: if not r.ok: diff --git a/scanner/scanner/__init__.py b/scanner/scanner/__init__.py index 76951d53..e034b653 100644 --- a/scanner/scanner/__init__.py +++ b/scanner/scanner/__init__.py @@ -4,6 +4,7 @@ async def main(): import logging from .monitor import monitor from .scanner import scan + from .refresher import refresh from .publisher import Publisher from providers.kyoo_client import KyooClient @@ -15,4 +16,5 @@ async def main(): await asyncio.gather( monitor(path, publisher), scan(path, publisher, client), + refresh(publisher, client), ) diff --git a/scanner/scanner/publisher.py b/scanner/scanner/publisher.py index 2c4e1838..315855e1 100644 --- a/scanner/scanner/publisher.py +++ b/scanner/scanner/publisher.py @@ -1,6 +1,7 @@ import os from guessit.jsonutils import json from aio_pika import Message, connect_robust +from typing import Literal class Publisher: @@ -31,3 +32,11 @@ class Publisher: async def delete(self, path: str): await self._publish({"action": "delete", "path": path}) + + async def refresh( + self, + kind: Literal["collection", "show", "movie", "season", "episode"], + id: str, + **_kwargs, + ): + await self._publish({"action": "refresh", "kind": kind, "id": id}) diff --git a/scanner/scanner/refresher.py b/scanner/scanner/refresher.py new file mode 100644 index 00000000..44c086ae --- /dev/null +++ b/scanner/scanner/refresher.py @@ -0,0 +1,16 @@ +import asyncio +from logging import getLogger + +from providers.kyoo_client import KyooClient +from scanner.publisher import Publisher + + +logger = getLogger(__name__) + + +async def refresh(publisher: Publisher, client: KyooClient): + while True: + # Check for updates every 4 hours + await asyncio.sleep(60 * 60 * 4) + todo = await client.get("refreshables") + await asyncio.gather(*(publisher.refresh(**x) for x in todo))