nfo: improvments to processing
This commit is contained in:
+59
-24
@@ -2317,9 +2317,9 @@ def register_routes(app, dependencies: dict):
|
|||||||
import subprocess
|
import subprocess
|
||||||
import re
|
import re
|
||||||
|
|
||||||
# Find all NFO files and check which ones are missing dateadded
|
# Separate tracking for TV and movie missing files
|
||||||
# This is much faster than database-driven approach
|
missing_tv_nfo_files = []
|
||||||
missing_nfo_files = []
|
missing_movie_nfo_files = []
|
||||||
|
|
||||||
# Find all NFO files in TV directory
|
# Find all NFO files in TV directory
|
||||||
if os.path.exists(tv_path):
|
if os.path.exists(tv_path):
|
||||||
@@ -2342,7 +2342,7 @@ def register_routes(app, dependencies: dict):
|
|||||||
|
|
||||||
if i % 1000 == 0 and i > 0:
|
if i % 1000 == 0 and i > 0:
|
||||||
elapsed = time.time() - scan_start_time
|
elapsed = time.time() - scan_start_time
|
||||||
print(f"📊 Progress: {i}/{len(tv_nfo_files)} TV NFO files checked in {elapsed:.1f}s, {len(missing_nfo_files)} missing found")
|
print(f"📊 Progress: {i}/{len(tv_nfo_files)} TV NFO files checked in {elapsed:.1f}s, {len(missing_tv_nfo_files)} missing found")
|
||||||
|
|
||||||
# Timeout check
|
# Timeout check
|
||||||
if time.time() - scan_start_time > 180: # 3 minutes
|
if time.time() - scan_start_time > 180: # 3 minutes
|
||||||
@@ -2358,7 +2358,7 @@ def register_routes(app, dependencies: dict):
|
|||||||
|
|
||||||
# If grep returns non-zero, dateadded is missing
|
# If grep returns non-zero, dateadded is missing
|
||||||
if grep_result.returncode != 0:
|
if grep_result.returncode != 0:
|
||||||
missing_nfo_files.append(nfo_file)
|
missing_tv_nfo_files.append(nfo_file)
|
||||||
|
|
||||||
# Log specific files we're looking for
|
# Log specific files we're looking for
|
||||||
if 'Hudson' in nfo_file and 'S08E05' in nfo_file:
|
if 'Hudson' in nfo_file and 'S08E05' in nfo_file:
|
||||||
@@ -2383,9 +2383,9 @@ def register_routes(app, dependencies: dict):
|
|||||||
else:
|
else:
|
||||||
print(f"❌ TV path does not exist: {tv_path}")
|
print(f"❌ TV path does not exist: {tv_path}")
|
||||||
|
|
||||||
print(f"📊 Found {len(missing_nfo_files)} NFO files missing dateadded elements")
|
print(f"📊 Found {len(missing_tv_nfo_files)} TV NFO files missing dateadded elements")
|
||||||
|
|
||||||
# Convert file paths to episode/movie information with direct NFO parsing
|
# 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):
|
||||||
"""Extract IMDb ID directly from NFO file content - we already know the file exists"""
|
"""Extract IMDb ID directly from NFO file content - we already know the file exists"""
|
||||||
imdb_id = "unknown"
|
imdb_id = "unknown"
|
||||||
@@ -2459,7 +2459,7 @@ def register_routes(app, dependencies: dict):
|
|||||||
print(f"❌ No IMDb ID found in {os.path.basename(nfo_file)}")
|
print(f"❌ No IMDb ID found in {os.path.basename(nfo_file)}")
|
||||||
return "unknown"
|
return "unknown"
|
||||||
|
|
||||||
for nfo_file in missing_nfo_files:
|
for nfo_file in missing_tv_nfo_files:
|
||||||
try:
|
try:
|
||||||
# Parse episode info from file path
|
# Parse episode info from file path
|
||||||
# Example: /media/TV/tv/Hudson & Rex (2019) [imdb-tt9111220]/Season 08/Hudson & Rex (2019)-S08E05-Episode.nfo
|
# Example: /media/TV/tv/Hudson & Rex (2019) [imdb-tt9111220]/Season 08/Hudson & Rex (2019)-S08E05-Episode.nfo
|
||||||
@@ -2522,7 +2522,7 @@ def register_routes(app, dependencies: dict):
|
|||||||
|
|
||||||
if i % 500 == 0 and i > 0:
|
if i % 500 == 0 and i > 0:
|
||||||
elapsed = time.time() - scan_start_time
|
elapsed = time.time() - scan_start_time
|
||||||
print(f"📊 Progress: {i}/{len(movie_nfo_files)} Movie NFO files checked in {elapsed:.1f}s, {len(missing_items['movies'])} missing found")
|
print(f"📊 Progress: {i}/{len(movie_nfo_files)} Movie NFO files checked in {elapsed:.1f}s, {len(missing_movie_nfo_files)} missing found")
|
||||||
|
|
||||||
# Timeout check
|
# Timeout check
|
||||||
if time.time() - scan_start_time > 300: # 5 minutes total
|
if time.time() - scan_start_time > 300: # 5 minutes total
|
||||||
@@ -2538,6 +2538,30 @@ def register_routes(app, dependencies: dict):
|
|||||||
|
|
||||||
# If grep returns non-zero, dateadded is missing
|
# If grep returns non-zero, dateadded is missing
|
||||||
if grep_result.returncode != 0:
|
if grep_result.returncode != 0:
|
||||||
|
missing_movie_nfo_files.append(nfo_file)
|
||||||
|
|
||||||
|
except subprocess.TimeoutExpired:
|
||||||
|
print(f"⏰ Timeout checking {nfo_file}")
|
||||||
|
continue
|
||||||
|
except Exception as e:
|
||||||
|
print(f"⚠️ Error checking {nfo_file}: {e}")
|
||||||
|
continue
|
||||||
|
|
||||||
|
else:
|
||||||
|
print(f"❌ Error finding Movie NFO files: {find_result.stderr}")
|
||||||
|
|
||||||
|
except subprocess.TimeoutExpired:
|
||||||
|
print("⏰ Find command timeout for Movie files")
|
||||||
|
except Exception as e:
|
||||||
|
print(f"❌ Error scanning Movie directory: {e}")
|
||||||
|
else:
|
||||||
|
print(f"❌ Movie path does not exist: {movie_path}")
|
||||||
|
|
||||||
|
# Process missing movie NFO files
|
||||||
|
print(f"📊 Found {len(missing_movie_nfo_files)} Movie NFO files missing dateadded elements")
|
||||||
|
|
||||||
|
for nfo_file in missing_movie_nfo_files:
|
||||||
|
try:
|
||||||
# Extract movie info from file path
|
# Extract movie info from file path
|
||||||
# Example: /media/Movies/movies/Knives Out (2019) [imdb-tt8946378]/movie.nfo
|
# Example: /media/Movies/movies/Knives Out (2019) [imdb-tt8946378]/movie.nfo
|
||||||
movie_dir = os.path.dirname(nfo_file)
|
movie_dir = os.path.dirname(nfo_file)
|
||||||
@@ -2557,24 +2581,10 @@ def register_routes(app, dependencies: dict):
|
|||||||
"nfo_path": nfo_file,
|
"nfo_path": nfo_file,
|
||||||
"reason": "NFO missing dateadded element (filesystem scan)"
|
"reason": "NFO missing dateadded element (filesystem scan)"
|
||||||
})
|
})
|
||||||
|
|
||||||
except subprocess.TimeoutExpired:
|
|
||||||
print(f"⏰ Timeout checking {nfo_file}")
|
|
||||||
continue
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"⚠️ Error checking {nfo_file}: {e}")
|
print(f"⚠️ Error parsing movie NFO file path {nfo_file}: {e}")
|
||||||
continue
|
continue
|
||||||
|
|
||||||
else:
|
|
||||||
print(f"❌ Error finding Movie NFO files: {find_result.stderr}")
|
|
||||||
|
|
||||||
except subprocess.TimeoutExpired:
|
|
||||||
print("⏰ Find command timeout for Movie files")
|
|
||||||
except Exception as e:
|
|
||||||
print(f"❌ Error scanning Movie directory: {e}")
|
|
||||||
else:
|
|
||||||
print(f"❌ Movie path does not exist: {movie_path}")
|
|
||||||
|
|
||||||
# Database lookup to get actual dateadded values for missing items
|
# Database lookup to get actual dateadded values for missing items
|
||||||
print("🔍 Looking up dateadded values from database for missing items...")
|
print("🔍 Looking up dateadded values from database for missing items...")
|
||||||
|
|
||||||
@@ -2765,6 +2775,19 @@ def register_routes(app, dependencies: dict):
|
|||||||
dateadded_elem = ET.SubElement(root, "dateadded")
|
dateadded_elem = ET.SubElement(root, "dateadded")
|
||||||
dateadded_elem.text = nfo_dateadded
|
dateadded_elem.text = nfo_dateadded
|
||||||
|
|
||||||
|
# Add source attribution (similar to what NFOGuard normally adds)
|
||||||
|
# Check if source element exists, if not create it
|
||||||
|
source_elem = root.find("source")
|
||||||
|
if source_elem is None:
|
||||||
|
source_elem = ET.SubElement(root, "source")
|
||||||
|
source_elem.text = f"NFOGuard repair - {episode.get('source', 'database')}"
|
||||||
|
|
||||||
|
# Add addedby attribution if not present
|
||||||
|
addedby_elem = root.find("addedby")
|
||||||
|
if addedby_elem is None:
|
||||||
|
addedby_elem = ET.SubElement(root, "addedby")
|
||||||
|
addedby_elem.text = "NFOGuard"
|
||||||
|
|
||||||
# Write back to file
|
# Write back to file
|
||||||
tree.write(nfo_path, encoding='utf-8', xml_declaration=True)
|
tree.write(nfo_path, encoding='utf-8', xml_declaration=True)
|
||||||
|
|
||||||
@@ -2851,6 +2874,18 @@ def register_routes(app, dependencies: dict):
|
|||||||
dateadded_elem = ET.SubElement(root, "dateadded")
|
dateadded_elem = ET.SubElement(root, "dateadded")
|
||||||
dateadded_elem.text = nfo_dateadded
|
dateadded_elem.text = nfo_dateadded
|
||||||
|
|
||||||
|
# Add source attribution (similar to what NFOGuard normally adds)
|
||||||
|
source_elem = root.find("source")
|
||||||
|
if source_elem is None:
|
||||||
|
source_elem = ET.SubElement(root, "source")
|
||||||
|
source_elem.text = f"NFOGuard repair - {movie.get('source', 'database')}"
|
||||||
|
|
||||||
|
# Add addedby attribution if not present
|
||||||
|
addedby_elem = root.find("addedby")
|
||||||
|
if addedby_elem is None:
|
||||||
|
addedby_elem = ET.SubElement(root, "addedby")
|
||||||
|
addedby_elem.text = "NFOGuard"
|
||||||
|
|
||||||
# Write back to file
|
# Write back to file
|
||||||
tree.write(nfo_path, encoding='utf-8', xml_declaration=True)
|
tree.write(nfo_path, encoding='utf-8', xml_declaration=True)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user