From 3cf7483343caad6bd8134bcfd2601c919ec9ab03 Mon Sep 17 00:00:00 2001 From: Thomas Erlang Date: Thu, 23 May 2024 12:33:17 +0200 Subject: [PATCH] Fix broken episode parser --- seplis_play_server/main.py | 21 +++++++++++-------- seplis_play_server/scanners/episodes.py | 9 +++++--- .../scanners/test_episodes.py | 12 ++++++----- 3 files changed, 25 insertions(+), 17 deletions(-) diff --git a/seplis_play_server/main.py b/seplis_play_server/main.py index a9ad5e5..758effb 100644 --- a/seplis_play_server/main.py +++ b/seplis_play_server/main.py @@ -1,21 +1,23 @@ from fastapi import FastAPI -from fastapi.staticfiles import StaticFiles from fastapi.middleware.cors import CORSMiddleware -from seplis_play_server.logger import set_logger +from fastapi.staticfiles import StaticFiles + from seplis_play_server.config import config +from seplis_play_server.logger import set_logger + set_logger(f'play-server-{config.port}.log') from .database import database from .routes import ( - health, - sources, - thumbnails, - keep_alive, - subtitle_file, close_session, download_source, - request_media, + health, hls, + keep_alive, + request_media, + sources, + subtitle_file, + thumbnails, ) app = FastAPI( @@ -50,6 +52,7 @@ async def startup(): async def shutdown(): await database.engine.dispose() - from .transcoders.video import sessions, close_session as cs + from .transcoders.video import close_session as cs + from .transcoders.video import sessions for session in list(sessions): cs(session) \ No newline at end of file diff --git a/seplis_play_server/scanners/episodes.py b/seplis_play_server/scanners/episodes.py index 4eb7617..5de663a 100644 --- a/seplis_play_server/scanners/episodes.py +++ b/seplis_play_server/scanners/episodes.py @@ -295,13 +295,16 @@ def regex_parse_file_name(self, filename: str): int(match.group('month')), int(match.group('day')), ) + return result except re.error as error: logger.exception(f'episode parse re error: {error}') except Exception: logger.exception(f'episode parse pattern: {pattern}') - return result + + return result if result.title and (result.episode_number or (result.season and result.episode)) else None + - def guessit_parse_file_name(self, filename: str) -> schemas.Parsed_file_episode: + def guessit_parse_file_name(self, filename: str): d = guessit( filename, { @@ -324,9 +327,9 @@ def guessit_parse_file_name(self, filename: str) -> schemas.Parsed_file_episode: result.episode_number = d['episode'] if d.get('date'): result.date = d['date'] + return result else: logger.info(f"{filename} doesn't look like an episode") - return result async def get_paths_matching_base_path(self, base_path: str): async with database.session() as session: diff --git a/tests/seplis_play_server/scanners/test_episodes.py b/tests/seplis_play_server/scanners/test_episodes.py index 5e48f65..264811b 100644 --- a/tests/seplis_play_server/scanners/test_episodes.py +++ b/tests/seplis_play_server/scanners/test_episodes.py @@ -1,12 +1,14 @@ -import pytest +from datetime import date, datetime +from unittest import mock + import httpx +import pytest import respx import sqlalchemy as sa -from unittest import mock -from datetime import date, datetime -from seplis_play_server.testbase import run_file -from seplis_play_server.database import Database + from seplis_play_server import models, schemas +from seplis_play_server.database import Database +from seplis_play_server.testbase import run_file @pytest.mark.asyncio