Add refresh listener on the scanner

This commit is contained in:
Zoe Roux 2024-04-23 22:20:31 +02:00
parent 9ee35534bd
commit 733817216f
No known key found for this signature in database
5 changed files with 30 additions and 5 deletions

View File

@ -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."

View File

@ -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:

View File

@ -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),
)

View File

@ -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})

View File

@ -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))