This commit is contained in:
2025-09-14 13:40:22 -04:00
parent 05ba16666e
commit 49266d651a
3 changed files with 70 additions and 29 deletions
+28 -18
View File
@@ -1,27 +1,37 @@
# NFOGuard Development Summary
## Current Status: v1.3.4 - Complete Database Migration Fix
## Current Status: v1.3.6 - NFO Preservation Fix
### Latest Updates (v1.3.4)
- **🔧 DATABASE**: Fixed comprehensive schema migration for all missing columns
- **✅ MIGRATION**: Added automatic detection and addition of `path`, `has_video_file`, `last_updated` columns
- **🎯 ROBUST**: Schema introspection ensures all required columns exist
- **🔍 VALIDATION**: Comprehensive column checking for both movies and episodes tables
### Latest Updates (v1.3.6)
- **🔧 NFO MANAGER**: Fixed movie.nfo to preserve existing content instead of overwriting
- **✅ PRESERVATION**: Existing movie metadata (title, plot, actors, etc.) now maintained
- **🎯 TARGETED**: Only updates NFOGuard-managed fields (dateadded, uniqueid, lockdata)
- **🧹 CLEANUP**: Removes old NFOGuard elements before adding new ones to avoid duplicates
### Database Migration Strategy
```
✅ Check existing schema with PRAGMA table_info()
✅ Add missing columns: path, has_video_file, last_updated
✅ Update existing records with default values
✅ Handle both movies and episodes tables
✅ Graceful migration without data loss
### NFO Management Behavior (Fixed)
**Before (v1.3.5 and earlier):**
```xml
<!-- Full existing NFO with title, plot, cast, etc. -->
↓ NFOGuard processing
<movie>
<!-- Only NFOGuard fields - ALL EXISTING CONTENT LOST -->
</movie>
```
### Path Mapping Success (v1.3.2-v1.3.4)
- **🐛 CRITICAL**: Fixed substring matching bug (movies/movies6, tv/tv6)
- **🎯 ALGORITHM**: Longest-path-first matching prevents incorrect mappings
- **📝 DEBUG**: Comprehensive debug logging for troubleshooting
- **✅ TESTED**: Annabelle webhook processes correctly through all stageslopment Summary
**After (v1.3.6):**
```xml
<!-- Full existing NFO with title, plot, cast, etc. -->
↓ NFOGuard processing
<movie>
<!-- NFOGuard comment and fields added -->
<!-- ALL EXISTING CONTENT PRESERVED -->
<title>Existing Title</title>
<plot>Existing Plot</plot>
<!-- ... existing content ... -->
<dateadded>2025-09-14T13:37:14-04:00</dateadded>
<lockdata>true</lockdata>
</movie>
```lopment Summary
## Current Status: v1.3.3 - Database Migration & Path Validation Complete
+1 -1
View File
@@ -1 +1 @@
1.3.4
1.3.6
+41 -10
View File
@@ -37,29 +37,60 @@ class NFOManager:
def create_movie_nfo(self, movie_dir: Path, imdb_id: str, dateadded: str,
released: Optional[str] = None, source: str = "unknown",
lock_metadata: bool = True) -> None:
"""Create movie.nfo file with proper metadata"""
"""Create or update movie.nfo file preserving existing content"""
nfo_path = movie_dir / "movie.nfo"
try:
movie = ET.Element("movie")
# Try to load existing NFO file
if nfo_path.exists():
try:
tree = ET.parse(nfo_path)
movie = tree.getroot()
# Add unique ID
# Ensure root element is <movie>
if movie.tag != "movie":
raise ValueError("Root element is not <movie>")
# Remove existing NFOGuard elements to avoid duplicates
for elem in movie.findall(".//comment()"):
if elem is not None and "NFOGuard" in str(elem):
movie.remove(elem)
# Remove existing NFOGuard-managed elements
for tag in ["dateadded", "lockdata"]:
existing = movie.find(tag)
if existing is not None:
movie.remove(existing)
# Remove any existing uniqueid with type="imdb"
for uniqueid in movie.findall("uniqueid[@type='imdb']"):
movie.remove(uniqueid)
except (ET.ParseError, ValueError) as e:
print(f"Warning: Could not parse existing NFO {nfo_path}, creating new: {e}")
movie = ET.Element("movie")
else:
# Create new NFO structure
movie = ET.Element("movie")
# Add/update NFOGuard comment
comment = ET.Comment(f" Created by {self.manager_brand} - Source: {source} ")
movie.insert(0, comment)
# Add/update IMDb uniqueid
uniqueid = ET.SubElement(movie, "uniqueid", type="imdb", default="true")
uniqueid.text = imdb_id
# Add dates
# Add dateadded
if dateadded:
dateadded_elem = ET.SubElement(movie, "dateadded")
dateadded_elem.text = dateadded
if released:
# Add premiered if we have release date (only if not already present)
if released and movie.find("premiered") is None:
premiered_elem = ET.SubElement(movie, "premiered")
premiered_elem.text = released[:10] if len(released) >= 10 else released
# Add source comment
comment = ET.Comment(f" Created by {self.manager_brand} - Source: {source} ")
movie.insert(0, comment)
# Add lockdata if requested
if lock_metadata:
lockdata = ET.SubElement(movie, "lockdata")
@@ -71,7 +102,7 @@ class NFOManager:
tree.write(nfo_path, encoding="utf-8", xml_declaration=True)
except Exception as e:
print(f"Error creating movie NFO {nfo_path}: {e}")
print(f"Error creating/updating movie NFO {nfo_path}: {e}")
def create_tvshow_nfo(self, series_dir: Path, imdb_id: str, tvdb_id: Optional[str] = None) -> None:
"""Create tvshow.nfo file"""