From 2d397a0ce1e9898e9e2602866dd1b5c05f0ba693 Mon Sep 17 00:00:00 2001 From: Zoe Roux Date: Wed, 7 May 2025 22:47:32 +0200 Subject: [PATCH] wip: Start scan request processor --- api/src/controllers/seed/images.ts | 2 +- scanner/requirements.txt | 1 + scanner/scanner/fsscan.py | 2 +- scanner/scanner/identify.py | 2 +- scanner/scanner/queue.py | 25 +++++++++++++++++++++++++ 5 files changed, 29 insertions(+), 3 deletions(-) diff --git a/api/src/controllers/seed/images.ts b/api/src/controllers/seed/images.ts index d61ee9f1..106f9277 100644 --- a/api/src/controllers/seed/images.ts +++ b/api/src/controllers/seed/images.ts @@ -21,7 +21,7 @@ type ImageTask = { }; // this will only push a task to the image downloader service and not download it instantly. -// this is both done to prevent to many requests to be sent at once and to make sure POST +// this is both done to prevent too many requests to be sent at once and to make sure POST // requests are not blocked by image downloading or blurhash calculation export const enqueueOptImage = async ( tx: Transaction, diff --git a/scanner/requirements.txt b/scanner/requirements.txt index a957fb31..445fe7d4 100644 --- a/scanner/requirements.txt +++ b/scanner/requirements.txt @@ -4,3 +4,4 @@ guessit@git+https://github.com/zoriya/guessit aiohttp watchfiles langcodes +psycopg[binary] diff --git a/scanner/scanner/fsscan.py b/scanner/scanner/fsscan.py index eb486ff6..8e87f4c2 100644 --- a/scanner/scanner/fsscan.py +++ b/scanner/scanner/fsscan.py @@ -26,7 +26,7 @@ class Scanner: except re.error as e: logger.error(f"Invalid ignore pattern. Ignoring. Error: {e}") - async def scan(self, path: Optional[str], remove_deleted=False): + async def scan(self, path: Optional[str] = None, remove_deleted=False): if path is None: logger.info("Starting scan at %s. This may take some time...", path) if self._ignore_pattern: diff --git a/scanner/scanner/identify.py b/scanner/scanner/identify.py index 3e38f2c2..e8cbadfd 100644 --- a/scanner/scanner/identify.py +++ b/scanner/scanner/identify.py @@ -1,7 +1,7 @@ from hashlib import sha256 from itertools import zip_longest from logging import getLogger -from typing import Awaitable, Callable, Literal, Optional, cast +from typing import Awaitable, Callable, Literal, cast from .guess.guess import guessit from .models.videos import Guess, Video diff --git a/scanner/scanner/queue.py b/scanner/scanner/queue.py index 1ade3aba..ea7ea9c2 100644 --- a/scanner/scanner/queue.py +++ b/scanner/scanner/queue.py @@ -2,6 +2,7 @@ from __future__ import annotations from typing import Literal, Optional +from .client import KyooClient from .models.videos import Guess from .utils import Model @@ -20,4 +21,28 @@ class Request(Model): async def enqueue(requests: list[Request]): # insert all requests # on conflict(kind,title,year) add to the `videos` list + + # notify + + # TODO: how will this conflict be handled if the request is already locked for update (being processed) pass + +class RequestProcessor: + def __init__(self, client: KyooClient): + self._client = client + + async def process_scan_requests(self): + # select for update skip_locked limit 1 + request: Request = ... + + if request.kind == "movie": + movie = await providers.get_movie(request.title, request.year) + movie.videos = request.videos + await self._client.create_movie(movie) + else: + serie = await providers.get_serie(request.title, request.year) + # for vid in request.videos: + # for ep in vid.episodes: + # entry = next(x for x in series.entries if (ep.season is None or x.season == ep.season), None) + await self._client.create_serie(serie) + # delete request