diff --git a/scanner/providers/types/status.py b/scanner/providers/types/status.py index f065d3b3..4881db5d 100644 --- a/scanner/providers/types/status.py +++ b/scanner/providers/types/status.py @@ -1,7 +1,7 @@ from enum import Enum -class Status(Enum): +class Status(str, Enum): UNKNOWN = "unknown" FINISHED = "finished" AIRING = "airing" diff --git a/scanner/scanner/scanner.py b/scanner/scanner/scanner.py index d1294b26..23c7d70c 100644 --- a/scanner/scanner/scanner.py +++ b/scanner/scanner/scanner.py @@ -1,3 +1,4 @@ +from functools import wraps import os import asyncio import logging @@ -6,6 +7,15 @@ from pathlib import Path from guessit import guessit from providers.provider import Provider +def log_errors(f): + @wraps(f) + async def internal(*args, **kwargs): + try: + await f(*args, **kwargs) + except Exception as e: + logging.exception("Unhandled error", exc_info=e) + return internal + class Scanner: def __init__(self, client: ClientSession, languages: list[str]) -> None: @@ -15,8 +25,9 @@ class Scanner: async def scan(self, path: str): videos = filter(lambda p: p.is_file(), Path(path).rglob("*")) - await asyncio.gather(*map(self.identify, videos), return_exceptions=True) + await asyncio.gather(*map(self.identify, videos)) + @log_errors async def identify(self, path: Path): raw = guessit(path) logging.info("Identied %s: %s", path, raw) @@ -36,7 +47,8 @@ class Scanner: logging.warn("Unknown video file type: %s", raw["type"]) async def post(self, path: str, *, data: object): + url = os.environ.get('KYOO_URL', "http://back:5000") async with self._client.post( - f"{os.environ['KYOO_URL']}/{path}", json=data + f"{url}/{path}", json=data ) as r: r.raise_for_status() diff --git a/shell.nix b/shell.nix index 1530ea1b..777d543c 100644 --- a/shell.nix +++ b/shell.nix @@ -1,28 +1,27 @@ -{pkgs ? import {}}: -pkgs.mkShell { - packages = with pkgs; [ - nodejs-16_x - nodePackages.yarn - (with dotnetCorePackages; - combinePackages [ - sdk_6_0 - aspnetcore_6_0 - ]) - python3 - python3Packages.venvShellHook - ]; - - # Run this command, only after creating the virtual environment +{pkgs ? import {}}: let venvDir = "./.venv"; - postVenvCreation = '' - unset SOURCE_DATE_EPOCH - pip install -r ./scanner/requirements.txt - ''; + pythonPkgs = ./scanner/requirements.txt; +in + pkgs.mkShell { + packages = with pkgs; [ + nodejs-16_x + nodePackages.yarn + (with dotnetCorePackages; + combinePackages [ + sdk_6_0 + aspnetcore_6_0 + ]) + python3 + ]; - # Now we can execute any commands within the virtual environment. - # This is optional and can be left out to run pip manually. - postShellHook = '' - # allow pip to install wheels - unset SOURCE_DATE_EPOCH - ''; -} + shellHook = '' + # Install python modules + SOURCE_DATE_EPOCH=$(date +%s) + if [ ! -d "${venvDir}" ]; then + ${pkgs.python3} -m venv "${venvDir}" + fi + source "${venvDir}/bin/activate" + export PIP_DISABLE_PIP_VERSION_CHECK=1 + pip install -r ${pythonPkgs} + ''; + }