web: table update and nfo scan update
Local Docker Build (Dev) / build-dev (push) Successful in 5s

This commit is contained in:
2025-10-26 15:23:35 -04:00
parent 9fbb9e37ab
commit c6b6b0ef64
4 changed files with 168 additions and 42 deletions
+38 -23
View File
@@ -2391,7 +2391,7 @@ def register_routes(app, dependencies: dict):
imdb_id = "unknown"
try:
# Parse the NFO file we already know exists (since grep found it missing dateadded)
# Try to parse the NFO file we already know exists (since grep found it missing dateadded)
tree = ET.parse(nfo_file)
root = tree.getroot()
@@ -2418,26 +2418,43 @@ def register_routes(app, dependencies: dict):
imdb_text = content_match.group(1)
print(f"✅ Found IMDb {imdb_text} in NFO content: {os.path.basename(nfo_file)}")
return imdb_text
# Method 4: Fallback - check folder structure for episodes
if is_episode:
series_folder = os.path.dirname(os.path.dirname(nfo_file))
folder_name = os.path.basename(series_folder)
folder_match = re.search(r'\[imdb-(tt\d+)\]', folder_name, re.IGNORECASE)
if folder_match:
print(f"✅ Found IMDb {folder_match.group(1)} in folder: {folder_name}")
return folder_match.group(1)
else:
# For movies, check movie folder
movie_folder = os.path.dirname(nfo_file)
folder_name = os.path.basename(movie_folder)
folder_match = re.search(r'\[imdb-(tt\d+)\]', folder_name, re.IGNORECASE)
if folder_match:
print(f"✅ Found IMDb {folder_match.group(1)} in folder: {folder_name}")
return folder_match.group(1)
except ET.ParseError as e:
# Handle malformed XML by trying text-based search
print(f"⚠️ NFO XML parse error in {os.path.basename(nfo_file)}: {e}")
try:
# Fallback: Read as text and search for IMDb patterns
with open(nfo_file, 'r', encoding='utf-8', errors='ignore') as f:
nfo_text = f.read()
# Search for IMDb patterns in raw text
text_match = re.search(r'(tt\d{7,})', nfo_text)
if text_match:
imdb_text = text_match.group(1)
print(f"✅ Found IMDb {imdb_text} in NFO text content: {os.path.basename(nfo_file)}")
return imdb_text
except Exception as text_error:
print(f"⚠️ Error reading NFO as text {nfo_file}: {text_error}")
except Exception as e:
print(f"⚠️ Error parsing NFO for IMDb in {nfo_file}: {e}")
print(f"⚠️ Unexpected error parsing NFO {nfo_file}: {e}")
# Method 4: Fallback - check folder structure
if is_episode:
series_folder = os.path.dirname(os.path.dirname(nfo_file))
folder_name = os.path.basename(series_folder)
folder_match = re.search(r'\[imdb-(tt\d+)\]', folder_name, re.IGNORECASE)
if folder_match:
print(f"✅ Found IMDb {folder_match.group(1)} in folder: {folder_name}")
return folder_match.group(1)
else:
# For movies, check movie folder
movie_folder = os.path.dirname(nfo_file)
folder_name = os.path.basename(movie_folder)
folder_match = re.search(r'\[imdb-(tt\d+)\]', folder_name, re.IGNORECASE)
if folder_match:
print(f"✅ Found IMDb {folder_match.group(1)} in folder: {folder_name}")
return folder_match.group(1)
print(f"❌ No IMDb ID found in {os.path.basename(nfo_file)}")
return "unknown"
@@ -2568,7 +2585,7 @@ def register_routes(app, dependencies: dict):
with db.get_connection() as conn:
cursor = conn.cursor()
cursor.execute("""
SELECT dateadded, source, added_by
SELECT dateadded, source
FROM episodes
WHERE imdb_id = %s AND season = %s AND episode = %s
LIMIT 1
@@ -2578,7 +2595,6 @@ def register_routes(app, dependencies: dict):
if result:
episode["dateadded"] = result["dateadded"]
episode["source"] = result.get("source", "database")
episode["added_by"] = result.get("added_by", "unknown")
else:
print(f"⚠️ No database entry for {episode['imdb_id']} S{episode['season']:02d}E{episode['episode']:02d}")
except Exception as e:
@@ -2591,7 +2607,7 @@ def register_routes(app, dependencies: dict):
with db.get_connection() as conn:
cursor = conn.cursor()
cursor.execute("""
SELECT dateadded, source, added_by
SELECT dateadded, source
FROM movies
WHERE imdb_id = %s
LIMIT 1
@@ -2601,7 +2617,6 @@ def register_routes(app, dependencies: dict):
if result:
movie["dateadded"] = result["dateadded"]
movie["source"] = result.get("source", "database")
movie["added_by"] = result.get("added_by", "unknown")
else:
print(f"⚠️ No database entry for movie {movie['imdb_id']}")
except Exception as e: