mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-05-24 02:02:36 -04:00
Add refresh listener on the scanner
This commit is contained in:
parent
9ee35534bd
commit
733817216f
@ -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."
|
||||
|
@ -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:
|
||||
|
@ -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),
|
||||
)
|
||||
|
@ -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})
|
||||
|
16
scanner/scanner/refresher.py
Normal file
16
scanner/scanner/refresher.py
Normal 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))
|
Loading…
x
Reference in New Issue
Block a user