web: web debugs
Local Docker Build (Dev) / build-dev (push) Successful in 5s

This commit is contained in:
2025-10-26 12:37:49 -04:00
parent eba70ec045
commit 07cdbf1a29
+121 -118
View File
@@ -2278,71 +2278,63 @@ def register_routes(app, dependencies: dict):
# #
# Web interface available on separate container port 8081 # Web interface available on separate container port 8081
@app.get("/admin/nfo-repair-scan") @app.get("/admin/nfo-repair-scan")
async def nfo_repair_scan(dependencies: dict): async def _nfo_repair_scan():
"""Scan filesystem for episodes/movies missing dateadded elements in NFO files""" return await nfo_repair_scan(dependencies)
from nfoguard.utils.db_utils import get_db_connection
import os async def nfo_repair_scan(dependencies: dict):
import xml.etree.ElementTree as ET """Scan filesystem for episodes/movies missing dateadded elements in NFO files"""
from nfoguard.utils.db_utils import get_db_connection
import os
import xml.etree.ElementTree as ET
logger = dependencies.get("logger")
config = dependencies.get("config")
if not logger or not config:
raise HTTPException(status_code=500, detail="Dependencies not available")
logger.info("🔧 Starting NFO repair scan from core container")
missing_items = {
"episodes": [],
"movies": []
}
try:
# Get database connection
db_conn = get_db_connection(config)
if not db_conn:
raise HTTPException(status_code=500, detail="Database connection failed")
logger = dependencies.get("logger") # Scan episodes
config = dependencies.get("config") logger.info("📺 Scanning episodes for missing dateadded elements")
episode_query = """
SELECT DISTINCT imdb_id, season, episode, series_name, episode_name, dateadded
FROM episodes
WHERE dateadded IS NOT NULL
ORDER BY imdb_id, season, episode
"""
if not logger or not config: episodes = db_conn.fetch_all(episode_query)
raise HTTPException(status_code=500, detail="Dependencies not available") logger.info(f"📊 Found {len(episodes)} episodes in database")
logger.info("🔧 Starting NFO repair scan from core container") for episode in episodes:
# Build NFO path
missing_items = { nfo_path = os.path.join(
"episodes": [], config.tv_library_path,
"movies": [] episode["series_name"],
} f"Season {episode['season']:02d}",
f"S{episode['season']:02d}E{episode['episode']:02d}.nfo"
try: )
# Get database connection
db_conn = get_db_connection(config)
if not db_conn:
raise HTTPException(status_code=500, detail="Database connection failed")
# Scan episodes # Check if NFO file exists and has dateadded
logger.info("📺 Scanning episodes for missing dateadded elements") if os.path.exists(nfo_path):
episode_query = """ try:
SELECT DISTINCT imdb_id, season, episode, series_name, episode_name, dateadded tree = ET.parse(nfo_path)
FROM episodes root = tree.getroot()
WHERE dateadded IS NOT NULL dateadded_elem = root.find("dateadded")
ORDER BY imdb_id, season, episode
""" if dateadded_elem is None or not dateadded_elem.text:
episodes = db_conn.fetch_all(episode_query)
logger.info(f"📊 Found {len(episodes)} episodes in database")
for episode in episodes:
# Build NFO path
nfo_path = os.path.join(
config.tv_library_path,
episode["series_name"],
f"Season {episode['season']:02d}",
f"S{episode['season']:02d}E{episode['episode']:02d}.nfo"
)
# Check if NFO file exists and has dateadded
if os.path.exists(nfo_path):
try:
tree = ET.parse(nfo_path)
root = tree.getroot()
dateadded_elem = root.find("dateadded")
if dateadded_elem is None or not dateadded_elem.text:
missing_items["episodes"].append({
"imdb_id": episode["imdb_id"],
"season": episode["season"],
"episode": episode["episode"],
"series_name": episode["series_name"],
"episode_name": episode["episode_name"],
"dateadded": episode["dateadded"],
"nfo_path": nfo_path
})
except ET.ParseError as e:
logger.warning(f"⚠️ Could not parse NFO file {nfo_path}: {e}")
missing_items["episodes"].append({ missing_items["episodes"].append({
"imdb_id": episode["imdb_id"], "imdb_id": episode["imdb_id"],
"season": episode["season"], "season": episode["season"],
@@ -2350,70 +2342,81 @@ def register_routes(app, dependencies: dict):
"series_name": episode["series_name"], "series_name": episode["series_name"],
"episode_name": episode["episode_name"], "episode_name": episode["episode_name"],
"dateadded": episode["dateadded"], "dateadded": episode["dateadded"],
"nfo_path": nfo_path, "nfo_path": nfo_path
"error": f"Parse error: {str(e)}"
}) })
except ET.ParseError as e:
logger.warning(f"⚠️ Could not parse NFO file {nfo_path}: {e}")
missing_items["episodes"].append({
"imdb_id": episode["imdb_id"],
"season": episode["season"],
"episode": episode["episode"],
"series_name": episode["series_name"],
"episode_name": episode["episode_name"],
"dateadded": episode["dateadded"],
"nfo_path": nfo_path,
"error": f"Parse error: {str(e)}"
})
# Scan movies
logger.info("🎬 Scanning movies for missing dateadded elements")
movie_query = """
SELECT DISTINCT imdb_id, title, dateadded
FROM movies
WHERE dateadded IS NOT NULL
ORDER BY title
"""
movies = db_conn.fetch_all(movie_query)
logger.info(f"📊 Found {len(movies)} movies in database")
for movie in movies:
# Build NFO path
nfo_path = os.path.join(
config.movie_library_path,
movie["title"],
f"{movie['title']}.nfo"
)
# Scan movies # Check if NFO file exists and has dateadded
logger.info("🎬 Scanning movies for missing dateadded elements") if os.path.exists(nfo_path):
movie_query = """ try:
SELECT DISTINCT imdb_id, title, dateadded tree = ET.parse(nfo_path)
FROM movies root = tree.getroot()
WHERE dateadded IS NOT NULL dateadded_elem = root.find("dateadded")
ORDER BY title
""" if dateadded_elem is None or not dateadded_elem.text:
movies = db_conn.fetch_all(movie_query)
logger.info(f"📊 Found {len(movies)} movies in database")
for movie in movies:
# Build NFO path
nfo_path = os.path.join(
config.movie_library_path,
movie["title"],
f"{movie['title']}.nfo"
)
# Check if NFO file exists and has dateadded
if os.path.exists(nfo_path):
try:
tree = ET.parse(nfo_path)
root = tree.getroot()
dateadded_elem = root.find("dateadded")
if dateadded_elem is None or not dateadded_elem.text:
missing_items["movies"].append({
"imdb_id": movie["imdb_id"],
"title": movie["title"],
"dateadded": movie["dateadded"],
"nfo_path": nfo_path
})
except ET.ParseError as e:
logger.warning(f"⚠️ Could not parse NFO file {nfo_path}: {e}")
missing_items["movies"].append({ missing_items["movies"].append({
"imdb_id": movie["imdb_id"], "imdb_id": movie["imdb_id"],
"title": movie["title"], "title": movie["title"],
"dateadded": movie["dateadded"], "dateadded": movie["dateadded"],
"nfo_path": nfo_path, "nfo_path": nfo_path
"error": f"Parse error: {str(e)}"
}) })
except ET.ParseError as e:
db_conn.close() logger.warning(f"⚠️ Could not parse NFO file {nfo_path}: {e}")
missing_items["movies"].append({
total_missing = len(missing_items["episodes"]) + len(missing_items["movies"]) "imdb_id": movie["imdb_id"],
logger.info(f"✅ NFO repair scan complete: {total_missing} items missing dateadded elements") "title": movie["title"],
"dateadded": movie["dateadded"],
return { "nfo_path": nfo_path,
"status": "success", "error": f"Parse error: {str(e)}"
"total_missing": total_missing, })
"episodes_missing": len(missing_items["episodes"]),
"movies_missing": len(missing_items["movies"]), db_conn.close()
"missing_items": missing_items
} total_missing = len(missing_items["episodes"]) + len(missing_items["movies"])
logger.info(f"✅ NFO repair scan complete: {total_missing} items missing dateadded elements")
except Exception as e:
logger.error(f"❌ Error during NFO repair scan: {str(e)}") return {
raise HTTPException(status_code=500, detail=f"NFO repair scan failed: {str(e)}") "status": "success",
"total_missing": total_missing,
"episodes_missing": len(missing_items["episodes"]),
"movies_missing": len(missing_items["movies"]),
"missing_items": missing_items
}
except Exception as e:
logger.error(f"❌ Error during NFO repair scan: {str(e)}")
raise HTTPException(status_code=500, detail=f"NFO repair scan failed: {str(e)}")
# --------------------------- # ---------------------------
# Core API - No Web Interface # Core API - No Web Interface