fix add issue
This commit is contained in:
parent
5c88572ac7
commit
5c4bd3d7e8
67
data/download_queue.json
Normal file
67
data/download_queue.json
Normal file
@ -0,0 +1,67 @@
|
||||
{
|
||||
"pending": [
|
||||
{
|
||||
"id": "b8b02c5c-257c-400a-a8b1-2d2559acdaad",
|
||||
"serie_id": "beheneko-the-elf-girls-cat-is-secretly-an-s-ranked-monster",
|
||||
"serie_folder": "beheneko the elf girls cat is secretly an s ranked monster (2025) (2025)",
|
||||
"serie_name": "beheneko the elf girls cat is secretly an s ranked monster (2025) (2025)",
|
||||
"episode": {
|
||||
"season": 1,
|
||||
"episode": 2,
|
||||
"title": null
|
||||
},
|
||||
"status": "pending",
|
||||
"priority": "NORMAL",
|
||||
"added_at": "2025-11-02T14:41:55.086784Z",
|
||||
"started_at": null,
|
||||
"completed_at": null,
|
||||
"progress": null,
|
||||
"error": null,
|
||||
"retry_count": 0,
|
||||
"source_url": null
|
||||
},
|
||||
{
|
||||
"id": "e2dfbb04-b538-4635-92c3-1a967f7eef34",
|
||||
"serie_id": "beheneko-the-elf-girls-cat-is-secretly-an-s-ranked-monster",
|
||||
"serie_folder": "beheneko the elf girls cat is secretly an s ranked monster (2025) (2025)",
|
||||
"serie_name": "beheneko the elf girls cat is secretly an s ranked monster (2025) (2025)",
|
||||
"episode": {
|
||||
"season": 1,
|
||||
"episode": 3,
|
||||
"title": null
|
||||
},
|
||||
"status": "pending",
|
||||
"priority": "NORMAL",
|
||||
"added_at": "2025-11-02T14:41:55.086820Z",
|
||||
"started_at": null,
|
||||
"completed_at": null,
|
||||
"progress": null,
|
||||
"error": null,
|
||||
"retry_count": 0,
|
||||
"source_url": null
|
||||
},
|
||||
{
|
||||
"id": "8740a24e-7d49-4512-9e5f-328f5f4f61b1",
|
||||
"serie_id": "beheneko-the-elf-girls-cat-is-secretly-an-s-ranked-monster",
|
||||
"serie_folder": "beheneko the elf girls cat is secretly an s ranked monster (2025) (2025)",
|
||||
"serie_name": "beheneko the elf girls cat is secretly an s ranked monster (2025) (2025)",
|
||||
"episode": {
|
||||
"season": 1,
|
||||
"episode": 4,
|
||||
"title": null
|
||||
},
|
||||
"status": "pending",
|
||||
"priority": "NORMAL",
|
||||
"added_at": "2025-11-02T14:41:55.086860Z",
|
||||
"started_at": null,
|
||||
"completed_at": null,
|
||||
"progress": null,
|
||||
"error": null,
|
||||
"retry_count": 0,
|
||||
"source_url": null
|
||||
}
|
||||
],
|
||||
"active": [],
|
||||
"failed": [],
|
||||
"timestamp": "2025-11-02T14:42:15.345939+00:00"
|
||||
}
|
||||
@ -5,14 +5,13 @@ from functools import lru_cache
|
||||
from typing import List, Optional
|
||||
|
||||
import structlog
|
||||
from fastapi import Depends
|
||||
|
||||
from src.core.SeriesApp import SeriesApp
|
||||
from src.server.services.progress_service import (
|
||||
ProgressService,
|
||||
ProgressType,
|
||||
get_progress_service,
|
||||
)
|
||||
from src.server.utils.dependencies import get_series_app
|
||||
|
||||
logger = structlog.get_logger(__name__)
|
||||
|
||||
@ -32,19 +31,20 @@ class AnimeService:
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
directory: str,
|
||||
series_app: SeriesApp,
|
||||
progress_service: Optional[ProgressService] = None,
|
||||
):
|
||||
self._directory = directory
|
||||
self._app = series_app
|
||||
self._directory = series_app.directory_to_search
|
||||
self._progress_service = progress_service or get_progress_service()
|
||||
# Initialize SeriesApp with async methods
|
||||
try:
|
||||
self._app = Depends(get_series_app)
|
||||
# Subscribe to SeriesApp events
|
||||
self._app.download_status += self._on_download_status
|
||||
self._app.scan_status += self._on_scan_status
|
||||
# Note: Events library uses assignment (=), not += operator
|
||||
try:
|
||||
self._app.download_status = self._on_download_status
|
||||
self._app.scan_status = self._on_scan_status
|
||||
logger.debug("Successfully subscribed to SeriesApp events")
|
||||
except Exception as e:
|
||||
logger.exception("Failed to initialize SeriesApp")
|
||||
logger.exception("Failed to subscribe to SeriesApp events")
|
||||
raise AnimeServiceError("Initialization failed") from e
|
||||
|
||||
def _on_download_status(self, args) -> None:
|
||||
@ -237,6 +237,6 @@ class AnimeService:
|
||||
raise AnimeServiceError("Download failed") from exc
|
||||
|
||||
|
||||
def get_anime_service(directory: str = "./") -> AnimeService:
|
||||
"""Factory used by FastAPI dependency injection."""
|
||||
return AnimeService(directory)
|
||||
def get_anime_service(series_app: SeriesApp) -> AnimeService:
|
||||
"""Factory used for creating AnimeService with a SeriesApp instance."""
|
||||
return AnimeService(series_app)
|
||||
|
||||
@ -90,10 +90,19 @@ class DownloadService:
|
||||
self._download_speeds: deque[float] = deque(maxlen=10)
|
||||
|
||||
# Subscribe to SeriesApp download events for progress tracking
|
||||
# Note: Events library uses assignment (=), not += operator
|
||||
if hasattr(anime_service, '_app') and hasattr(
|
||||
anime_service._app, 'download_status'
|
||||
):
|
||||
anime_service._app.download_status += (
|
||||
# Save existing handler if any, and chain them
|
||||
existing_handler = anime_service._app.download_status
|
||||
if existing_handler:
|
||||
def chained_handler(args):
|
||||
existing_handler(args)
|
||||
self._on_seriesapp_download_status(args)
|
||||
anime_service._app.download_status = chained_handler
|
||||
else:
|
||||
anime_service._app.download_status = (
|
||||
self._on_seriesapp_download_status
|
||||
)
|
||||
|
||||
|
||||
@ -355,7 +355,9 @@ def get_anime_service() -> "AnimeService":
|
||||
try:
|
||||
from src.server.services.anime_service import AnimeService
|
||||
|
||||
_anime_service = AnimeService(settings.anime_directory)
|
||||
# Get the singleton SeriesApp instance
|
||||
series_app = get_series_app()
|
||||
_anime_service = AnimeService(series_app)
|
||||
except Exception as e:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user