diff --git a/scanner/scanner/__init__.py b/scanner/scanner/__init__.py index afa6ab81..f2cd0c63 100644 --- a/scanner/scanner/__init__.py +++ b/scanner/scanner/__init__.py @@ -5,7 +5,7 @@ app = FastAPI( description="API to control the long running scanner or interacting with external databases (themoviedb, tvdb...)\n\n" + "Most of those APIs are for admins only.", openapi_prefix="/scanner", - #lifetime=smth + # lifetime=smth ) diff --git a/scanner/scanner/guess/guess.py b/scanner/scanner/guess/guess.py index b6ffcc43..0b483e1e 100644 --- a/scanner/scanner/guess/guess.py +++ b/scanner/scanner/guess/guess.py @@ -33,7 +33,7 @@ def guessit( "episode_prefer_number": True, "excludes": "language", "expected_title": expected_titles, - "enforce_list": True + "enforce_list": True, } | extra_flags, ) @@ -43,6 +43,7 @@ def guessit( if __name__ == "__main__": import sys import json + # from providers.implementations.thexem import TheXemClient from guessit.jsonutils import GuessitEncoder from aiohttp import ClientSession diff --git a/scanner/scanner/identify.py b/scanner/scanner/identify.py index 71a81d7f..8fe40047 100644 --- a/scanner/scanner/identify.py +++ b/scanner/scanner/identify.py @@ -1,7 +1,17 @@ -from .models.videos import Video, Guess -from .guess.guess import guessit -from typing import Literal from itertools import zip_longest +from logging import getLogger +from typing import Awaitable, Callable, Literal + +from .guess.guess import guessit +from .models.videos import Guess, Video + +logger = getLogger(__name__) + +pipeline: list[Callable[[str, Guess], Awaitable[Guess]]] = [ + # TODO: add nfo scanner + # TODO: add thexem + # TODO: add anilist +] async def identify(path: str) -> Video: @@ -38,6 +48,12 @@ async def identify(path: str) -> Video: raw=raw, ) + for step in pipeline: + try: + guess = await step(path, guess) + except Exception as e: + logger.error("Couldn't run %s.", step.__name__, exc_info=e) + return Video( path=path, rendering="", diff --git a/scanner/scanner/models/extra.py b/scanner/scanner/models/extra.py index 627241dc..f5ca9a41 100644 --- a/scanner/scanner/models/extra.py +++ b/scanner/scanner/models/extra.py @@ -1,11 +1,10 @@ from typing import Literal type ExtraKind = ( - Literal["other"] | - Literal["trailer"] | - Literal["interview"] | - Literal["behind-the-scene"] | - Literal["deleted-scene"] | - Literal["blooper"] + Literal["other"] + | Literal["trailer"] + | Literal["interview"] + | Literal["behind-the-scene"] + | Literal["deleted-scene"] + | Literal["blooper"] ) -