fix nfo
This commit is contained in:
+28
-18
@@ -1,27 +1,37 @@
|
|||||||
# NFOGuard Development Summary
|
# 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)
|
### Latest Updates (v1.3.6)
|
||||||
- **🔧 DATABASE**: Fixed comprehensive schema migration for all missing columns
|
- **🔧 NFO MANAGER**: Fixed movie.nfo to preserve existing content instead of overwriting
|
||||||
- **✅ MIGRATION**: Added automatic detection and addition of `path`, `has_video_file`, `last_updated` columns
|
- **✅ PRESERVATION**: Existing movie metadata (title, plot, actors, etc.) now maintained
|
||||||
- **🎯 ROBUST**: Schema introspection ensures all required columns exist
|
- **🎯 TARGETED**: Only updates NFOGuard-managed fields (dateadded, uniqueid, lockdata)
|
||||||
- **🔍 VALIDATION**: Comprehensive column checking for both movies and episodes tables
|
- **🧹 CLEANUP**: Removes old NFOGuard elements before adding new ones to avoid duplicates
|
||||||
|
|
||||||
### Database Migration Strategy
|
### NFO Management Behavior (Fixed)
|
||||||
```
|
**Before (v1.3.5 and earlier):**
|
||||||
✅ Check existing schema with PRAGMA table_info()
|
```xml
|
||||||
✅ Add missing columns: path, has_video_file, last_updated
|
<!-- Full existing NFO with title, plot, cast, etc. -->
|
||||||
✅ Update existing records with default values
|
↓ NFOGuard processing
|
||||||
✅ Handle both movies and episodes tables
|
<movie>
|
||||||
✅ Graceful migration without data loss
|
<!-- Only NFOGuard fields - ALL EXISTING CONTENT LOST -->
|
||||||
|
</movie>
|
||||||
```
|
```
|
||||||
|
|
||||||
### Path Mapping Success (v1.3.2-v1.3.4)
|
**After (v1.3.6):**
|
||||||
- **🐛 CRITICAL**: Fixed substring matching bug (movies/movies6, tv/tv6)
|
```xml
|
||||||
- **🎯 ALGORITHM**: Longest-path-first matching prevents incorrect mappings
|
<!-- Full existing NFO with title, plot, cast, etc. -->
|
||||||
- **📝 DEBUG**: Comprehensive debug logging for troubleshooting
|
↓ NFOGuard processing
|
||||||
- **✅ TESTED**: Annabelle webhook processes correctly through all stageslopment Summary
|
<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
|
## Current Status: v1.3.3 - Database Migration & Path Validation Complete
|
||||||
|
|
||||||
|
|||||||
+41
-10
@@ -37,29 +37,60 @@ class NFOManager:
|
|||||||
def create_movie_nfo(self, movie_dir: Path, imdb_id: str, dateadded: str,
|
def create_movie_nfo(self, movie_dir: Path, imdb_id: str, dateadded: str,
|
||||||
released: Optional[str] = None, source: str = "unknown",
|
released: Optional[str] = None, source: str = "unknown",
|
||||||
lock_metadata: bool = True) -> None:
|
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"
|
nfo_path = movie_dir / "movie.nfo"
|
||||||
|
|
||||||
try:
|
try:
|
||||||
movie = ET.Element("movie")
|
# Try to load existing NFO file
|
||||||
|
if nfo_path.exists():
|
||||||
|
try:
|
||||||
|
tree = ET.parse(nfo_path)
|
||||||
|
movie = tree.getroot()
|
||||||
|
|
||||||
|
# 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 unique ID
|
# 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 = ET.SubElement(movie, "uniqueid", type="imdb", default="true")
|
||||||
uniqueid.text = imdb_id
|
uniqueid.text = imdb_id
|
||||||
|
|
||||||
# Add dates
|
# Add dateadded
|
||||||
if dateadded:
|
if dateadded:
|
||||||
dateadded_elem = ET.SubElement(movie, "dateadded")
|
dateadded_elem = ET.SubElement(movie, "dateadded")
|
||||||
dateadded_elem.text = 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 = ET.SubElement(movie, "premiered")
|
||||||
premiered_elem.text = released[:10] if len(released) >= 10 else released
|
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
|
# Add lockdata if requested
|
||||||
if lock_metadata:
|
if lock_metadata:
|
||||||
lockdata = ET.SubElement(movie, "lockdata")
|
lockdata = ET.SubElement(movie, "lockdata")
|
||||||
@@ -71,7 +102,7 @@ class NFOManager:
|
|||||||
tree.write(nfo_path, encoding="utf-8", xml_declaration=True)
|
tree.write(nfo_path, encoding="utf-8", xml_declaration=True)
|
||||||
|
|
||||||
except Exception as e:
|
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:
|
def create_tvshow_nfo(self, series_dir: Path, imdb_id: str, tvdb_id: Optional[str] = None) -> None:
|
||||||
"""Create tvshow.nfo file"""
|
"""Create tvshow.nfo file"""
|
||||||
|
|||||||
Reference in New Issue
Block a user