92 lines
3.4 KiB
Python
92 lines
3.4 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
TV Show processing logic for NFOGuard
|
|
"""
|
|
import os
|
|
import glob
|
|
from pathlib import Path
|
|
from typing import Optional, Dict, Any, List, Tuple
|
|
from datetime import datetime, timezone, timedelta
|
|
|
|
# Import core components
|
|
from core.database import NFOGuardDatabase
|
|
from core.nfo_manager import NFOManager
|
|
from core.path_mapper import PathMapper
|
|
from core.logging import _log
|
|
from clients.sonarr_client import SonarrClient
|
|
from clients.external_clients import ExternalClientManager
|
|
from config.settings import config
|
|
|
|
|
|
class TVProcessor:
|
|
"""Handles TV series processing"""
|
|
|
|
def __init__(self, db: NFOGuardDatabase, nfo_manager: NFOManager, path_mapper: PathMapper):
|
|
self.db = db
|
|
self.nfo_manager = nfo_manager
|
|
self.path_mapper = path_mapper
|
|
self.sonarr = SonarrClient(
|
|
os.environ.get("SONARR_URL", ""),
|
|
os.environ.get("SONARR_API_KEY", "")
|
|
)
|
|
self.external_clients = ExternalClientManager()
|
|
|
|
def find_series_path(self, series_title: str, imdb_id: str, sonarr_path: str = None) -> Optional[Path]:
|
|
"""Find series directory path"""
|
|
# Try webhook path first
|
|
if sonarr_path:
|
|
container_path = self.path_mapper.sonarr_path_to_container_path(sonarr_path)
|
|
path_obj = Path(container_path)
|
|
if path_obj.exists():
|
|
return path_obj
|
|
|
|
# Search by IMDb ID or title
|
|
for media_path in config.tv_paths:
|
|
if not media_path.exists():
|
|
continue
|
|
|
|
# Search by IMDb ID
|
|
if imdb_id:
|
|
pattern = str(media_path / f"*[imdb-{imdb_id}]*")
|
|
matches = glob.glob(pattern)
|
|
if matches:
|
|
return Path(matches[0])
|
|
|
|
# Search by title
|
|
if series_title:
|
|
title_clean = series_title.lower().replace(" ", "").replace("-", "")
|
|
for item in media_path.iterdir():
|
|
if item.is_dir() and "[imdb-" in item.name.lower():
|
|
item_clean = item.name.lower().replace(" ", "").replace("-", "")
|
|
if title_clean in item_clean:
|
|
return item
|
|
|
|
return None
|
|
|
|
# NOTE: This is a placeholder extraction - the full 763-line class implementation
|
|
# needs to be copied from the original nfoguard.py file (lines 299-1061)
|
|
#
|
|
# Key methods that need to be extracted include:
|
|
# - process_series()
|
|
# - process_webhook_episodes()
|
|
# - process_season()
|
|
# - _process_episode()
|
|
# - _gather_episode_dates()
|
|
# - _extract_title_from_filename()
|
|
# - _get_episode_metadata()
|
|
# - Various helper methods for date handling and processing
|
|
#
|
|
# This placeholder allows the import structure to work while we continue
|
|
# the refactoring process.
|
|
|
|
def process_series(self, series_path: Path) -> None:
|
|
"""Process a TV series directory - PLACEHOLDER"""
|
|
_log("INFO", f"Processing TV series: {series_path}")
|
|
# Full implementation needs to be copied from original file
|
|
pass
|
|
|
|
def process_webhook_episodes(self, series_path: Path, episodes_data: List[Dict]) -> None:
|
|
"""Process specific episodes from webhook data - PLACEHOLDER"""
|
|
_log("INFO", f"Processing {len(episodes_data)} episodes for series: {series_path}")
|
|
# Full implementation needs to be copied from original file
|
|
pass |