dev #63
+30
-12
@@ -2418,7 +2418,7 @@ def register_routes(app, dependencies: dict):
|
||||
print(f"📊 Found {len(missing_tv_nfo_files)} TV NFO files missing dateadded elements")
|
||||
|
||||
# Convert TV file paths to episode information with direct NFO parsing
|
||||
def extract_imdb_from_nfo_content(nfo_file, is_episode=True):
|
||||
def extract_imdb_from_nfo_content(nfo_file, is_episode=True, verbose_logging=True):
|
||||
"""Extract IMDb ID directly from NFO file content - we already know the file exists"""
|
||||
imdb_id = "unknown"
|
||||
|
||||
@@ -2432,7 +2432,8 @@ def register_routes(app, dependencies: dict):
|
||||
if imdb_elem is not None and imdb_elem.text:
|
||||
imdb_text = imdb_elem.text.strip()
|
||||
if imdb_text.startswith('tt'):
|
||||
print(f"✅ Found IMDb {imdb_text} in <imdb> tag: {os.path.basename(nfo_file)}")
|
||||
if verbose_logging:
|
||||
print(f"✅ Found IMDb {imdb_text} in <imdb> tag: {os.path.basename(nfo_file)}")
|
||||
return imdb_text
|
||||
|
||||
# Method 2: Check <uniqueid type="imdb"> tags
|
||||
@@ -2440,7 +2441,8 @@ def register_routes(app, dependencies: dict):
|
||||
if uniqueid.get("type") == "imdb" and uniqueid.text:
|
||||
imdb_text = uniqueid.text.strip()
|
||||
if imdb_text.startswith('tt'):
|
||||
print(f"✅ Found IMDb {imdb_text} in <uniqueid type='imdb'>: {os.path.basename(nfo_file)}")
|
||||
if verbose_logging:
|
||||
print(f"✅ Found IMDb {imdb_text} in <uniqueid type='imdb'>: {os.path.basename(nfo_file)}")
|
||||
return imdb_text
|
||||
|
||||
# Method 3: Check for IMDb pattern anywhere in NFO content
|
||||
@@ -2448,12 +2450,14 @@ def register_routes(app, dependencies: dict):
|
||||
content_match = re.search(r'(tt\d{7,})', nfo_content)
|
||||
if content_match:
|
||||
imdb_text = content_match.group(1)
|
||||
print(f"✅ Found IMDb {imdb_text} in NFO content: {os.path.basename(nfo_file)}")
|
||||
if verbose_logging:
|
||||
print(f"✅ Found IMDb {imdb_text} in NFO content: {os.path.basename(nfo_file)}")
|
||||
return imdb_text
|
||||
|
||||
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}")
|
||||
if verbose_logging:
|
||||
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:
|
||||
@@ -2463,13 +2467,16 @@ def register_routes(app, dependencies: dict):
|
||||
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)}")
|
||||
if verbose_logging:
|
||||
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}")
|
||||
if verbose_logging:
|
||||
print(f"⚠️ Error reading NFO as text {nfo_file}: {text_error}")
|
||||
|
||||
except Exception as e:
|
||||
print(f"⚠️ Unexpected error parsing NFO {nfo_file}: {e}")
|
||||
if verbose_logging:
|
||||
print(f"⚠️ Unexpected error parsing NFO {nfo_file}: {e}")
|
||||
|
||||
# Method 4: Fallback - check folder structure
|
||||
if is_episode:
|
||||
@@ -2477,7 +2484,8 @@ def register_routes(app, dependencies: dict):
|
||||
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}")
|
||||
if verbose_logging:
|
||||
print(f"✅ Found IMDb {folder_match.group(1)} in folder: {folder_name}")
|
||||
return folder_match.group(1)
|
||||
else:
|
||||
# For movies, check movie folder
|
||||
@@ -2485,10 +2493,12 @@ def register_routes(app, dependencies: dict):
|
||||
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}")
|
||||
if verbose_logging:
|
||||
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)}")
|
||||
if verbose_logging:
|
||||
print(f"❌ No IMDb ID found in {os.path.basename(nfo_file)}")
|
||||
return "unknown"
|
||||
|
||||
for nfo_file in missing_tv_nfo_files:
|
||||
@@ -2600,11 +2610,19 @@ def register_routes(app, dependencies: dict):
|
||||
movie_folder_name = os.path.basename(movie_dir)
|
||||
|
||||
# Extract IMDb ID from NFO content
|
||||
imdb_id = extract_imdb_from_nfo_content(nfo_file, is_episode=False)
|
||||
imdb_id = extract_imdb_from_nfo_content(nfo_file, is_episode=False, verbose_logging=False)
|
||||
|
||||
# Clean movie title (remove year and imdb parts)
|
||||
clean_movie_title = re.sub(r'\s*\(\d{4}\)\s*\[imdb-[^]]+\]', '', movie_folder_name).strip()
|
||||
|
||||
# Log detailed movie information
|
||||
if imdb_id != "unknown":
|
||||
print(f"✅ Found IMDb {imdb_id} for movie: {clean_movie_title} ({movie_folder_name})")
|
||||
else:
|
||||
print(f"❌ No IMDb ID found for movie: {clean_movie_title} ({movie_folder_name})")
|
||||
print(f" 📁 Path: {movie_dir}")
|
||||
print(f" 📄 NFO: {os.path.basename(nfo_file)}")
|
||||
|
||||
missing_items["movies"].append({
|
||||
"imdb_id": imdb_id,
|
||||
"title": clean_movie_title,
|
||||
|
||||
Reference in New Issue
Block a user