Skip to content

Commit

Permalink
Fix broken episode parser
Browse files Browse the repository at this point in the history
  • Loading branch information
thomaserlang committed May 23, 2024
1 parent 25862ae commit 3cf7483
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 17 deletions.
21 changes: 12 additions & 9 deletions seplis_play_server/main.py
Original file line number Diff line number Diff line change
@@ -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(
Expand Down Expand Up @@ -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)
9 changes: 6 additions & 3 deletions seplis_play_server/scanners/episodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
{
Expand All @@ -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:
Expand Down
12 changes: 7 additions & 5 deletions tests/seplis_play_server/scanners/test_episodes.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 3cf7483

Please sign in to comment.