This commit is contained in:
@@ -2083,6 +2083,59 @@ def stop_scan_tracking():
|
||||
# Route Registration
|
||||
# ---------------------------
|
||||
|
||||
async def update_episode_nfo(imdb_id: str, season: int, episode: int, request: Request, dependencies: dict):
|
||||
"""Update NFO file for a specific episode with new dateadded"""
|
||||
try:
|
||||
# Get request data
|
||||
payload = await request.json()
|
||||
dateadded = payload.get('dateadded')
|
||||
source = payload.get('source', 'manual')
|
||||
aired = payload.get('aired')
|
||||
|
||||
# Get dependencies
|
||||
config = dependencies["config"]
|
||||
nfo_manager = dependencies["nfo_manager"]
|
||||
|
||||
if not config.manage_nfo:
|
||||
return {"success": False, "message": "NFO management is disabled"}
|
||||
|
||||
# Find the series directory based on IMDb ID
|
||||
series_path = None
|
||||
for tv_path in config.tv_paths:
|
||||
for series_dir in Path(tv_path).iterdir():
|
||||
if series_dir.is_dir() and imdb_id.lower() in series_dir.name.lower():
|
||||
series_path = series_dir
|
||||
break
|
||||
if series_path:
|
||||
break
|
||||
|
||||
if not series_path:
|
||||
return {"success": False, "message": f"Series directory not found for {imdb_id}"}
|
||||
|
||||
# Get season directory
|
||||
season_dir = series_path / config.tv_season_dir_format.format(season=season)
|
||||
if not season_dir.exists():
|
||||
return {"success": False, "message": f"Season directory not found: {season_dir}"}
|
||||
|
||||
# Update NFO file
|
||||
nfo_manager.create_episode_nfo(
|
||||
season_dir=season_dir,
|
||||
season_num=season,
|
||||
episode_num=episode,
|
||||
aired=aired,
|
||||
dateadded=dateadded,
|
||||
source=source,
|
||||
lock_metadata=config.lock_metadata
|
||||
)
|
||||
|
||||
print(f"✅ Updated NFO file for {imdb_id} S{season:02d}E{episode:02d}")
|
||||
return {"success": True, "message": f"NFO file updated for {imdb_id} S{season:02d}E{episode:02d}"}
|
||||
|
||||
except Exception as e:
|
||||
print(f"❌ Error updating NFO file for {imdb_id} S{season:02d}E{episode:02d}: {e}")
|
||||
return {"success": False, "message": f"Failed to update NFO file: {str(e)}"}
|
||||
|
||||
|
||||
def register_routes(app, dependencies: dict):
|
||||
"""
|
||||
Register all routes with the FastAPI app
|
||||
@@ -2137,6 +2190,10 @@ def register_routes(app, dependencies: dict):
|
||||
async def _delete_episode(imdb_id: str, season: int, episode: int):
|
||||
return await delete_episode(imdb_id, season, episode, dependencies)
|
||||
|
||||
@app.post("/api/episodes/{imdb_id}/{season}/{episode}/update-nfo")
|
||||
async def _update_episode_nfo(imdb_id: str, season: int, episode: int, request: Request):
|
||||
return await update_episode_nfo(imdb_id, season, episode, request, dependencies)
|
||||
|
||||
@app.delete("/database/series/{imdb_id}/episodes")
|
||||
async def _delete_series_episodes(imdb_id: str):
|
||||
return await delete_series_episodes(imdb_id, dependencies)
|
||||
|
||||
+39
-3
@@ -597,10 +597,46 @@ async def update_episode_date(dependencies: dict, imdb_id: str, season: int, epi
|
||||
has_video_file=episode_data.get('has_video_file', False)
|
||||
)
|
||||
|
||||
# Note: NFO file updates are handled by the core container
|
||||
# The web container only updates the database
|
||||
# Trigger NFO file update via core container
|
||||
try:
|
||||
import urllib.request
|
||||
import urllib.parse
|
||||
import json
|
||||
import os
|
||||
|
||||
# Get core container connection details
|
||||
core_host = os.environ.get("CORE_API_HOST", "nfoguard-core")
|
||||
core_port = os.environ.get("CORE_API_PORT", "8080")
|
||||
|
||||
# Call core container to update NFO file
|
||||
nfo_update_url = f"http://{core_host}:{core_port}/api/episodes/{imdb_id}/{season}/{episode}/update-nfo"
|
||||
|
||||
# Create request data
|
||||
request_data = {
|
||||
"dateadded": dateadded,
|
||||
"source": source,
|
||||
"aired": episode_data.get('aired').isoformat() if episode_data.get('aired') else None
|
||||
}
|
||||
|
||||
# Make POST request to core container
|
||||
req = urllib.request.Request(
|
||||
nfo_update_url,
|
||||
data=json.dumps(request_data).encode('utf-8'),
|
||||
headers={'Content-Type': 'application/json'},
|
||||
method='POST'
|
||||
)
|
||||
|
||||
with urllib.request.urlopen(req, timeout=10) as response:
|
||||
if response.status == 200:
|
||||
print(f"✅ Database and NFO file updated for {imdb_id} S{season:02d}E{episode:02d}")
|
||||
else:
|
||||
print(f"✅ Database updated for {imdb_id} S{season:02d}E{episode:02d}")
|
||||
print(f"ℹ️ NFO file updates will be handled by the core container on next scan")
|
||||
print(f"⚠️ NFO file update failed (HTTP {response.status})")
|
||||
|
||||
except Exception as e:
|
||||
print(f"✅ Database updated for {imdb_id} S{season:02d}E{episode:02d}")
|
||||
print(f"⚠️ NFO file update failed: {e}")
|
||||
print(f"ℹ️ NFO will be updated on next scan")
|
||||
|
||||
# Add to processing history
|
||||
db.add_processing_history(
|
||||
|
||||
Reference in New Issue
Block a user