Commit Graph

57 Commits

Author SHA1 Message Date
sbcrumb 27430a7ead fix: nfo
Local Docker Build (Dev) / build-dev (pull_request) Successful in 23s
2025-09-24 19:35:39 -04:00
sbcrumb 210af8ac4b tv-nfo (#4)
Local Docker Build (Dev) / build-dev (push) Successful in 23s
Reviewed-on: #4
Co-authored-by: SBCrumb <sbcrumb@kickthetree.com>
Co-committed-by: SBCrumb <sbcrumb@kickthetree.com>
2025-09-24 18:53:48 -04:00
sbcrumb 830c1d9ae4 fix: Use tolerant XML parser for TMDB ID detection in NFO files
Local Docker Build (Dev) / build-dev (push) Successful in 20s
- Replace ET.parse() with _parse_nfo_with_tolerance() in parse_imdb_from_nfo
- Handles NFO files with URLs appended after </movie> tag
- Should resolve For the One (2024) TMDB ID detection issue
- NFO had TMDB ID 1339758 but trailing URLs prevented XML parsing
2025-09-24 13:53:52 -04:00
sbcrumb bfdf02ebd1 fix: Improve TMDB fallback detection and logging for movies without IMDb IDs
Local Docker Build (Dev) / build-dev (push) Successful in 21s
- Update find_movie_imdb_id to properly log TMDB vs IMDb ID detection
- Fix error message to indicate search for both IMDb AND TMDB IDs
- Add critical workflow reminder to SUMMARY.md for code-only development
- Should resolve For the One (2024) processing with TMDB ID 1339758
2025-09-24 13:49:54 -04:00
sbcrumb 994f430d45 feat: Implement comprehensive three-tier optimization system for movies and TV episodes
Local Docker Build (Dev) / build-dev (push) Successful in 24s
- Add NFO file extraction for TV episodes with dateadded detection
- Extend three-tier optimization (NFO cache, DB cache, full processing) to TV episodes
- Add TMDB ID fallback support for movies without IMDb IDs
- Implement Tier 1.5 processing for TMDB-only movies using premiered dates
- Update documentation with complete TV episode optimization details
- Add database rebuild capabilities for both movies and TV content
- Performance improvements eliminate 90%+ of processing time on warm systems
2025-09-24 13:37:01 -04:00
sbcrumb ea661bcd45 feat: Add TMDB ID detection for movies without IMDb IDs
Local Docker Build (Dev) / build-dev (push) Successful in 23s
Added fallback detection for movies that only have TMDB IDs in NFO files.
When no IMDb ID is found, the system now:

- Detects TMDB ID from <uniqueid type="tmdb"> elements
- Logs a helpful warning with the TMDB ID for manual lookup
- Provides clear guidance that manual IMDb lookup may be needed

This helps identify movies like "For the One (2024)" that have TMDB data
but are missing IMDb identifiers, allowing users to manually add IMDb IDs
to directory names or filenames when available.

Future enhancement: Could implement TMDB->IMDb API conversion.
2025-09-24 12:36:16 -04:00
sbcrumb d6d24e8840 feat: Add three-tier optimization for TV episodes
Local Docker Build (Dev) / build-dev (push) Successful in 24s
Extended the revolutionary three-tier performance system to TV episodes:

TIER 1 (Fastest): Episode NFO File Check
- Detects existing NFOGuard data in episode NFO files (dateadded + lockdata)
- Skips all database queries AND Sonarr API calls
- Perfect for database rebuilds from existing episode NFO files

TIER 2 (Fast): Episode Database Check
- Uses complete episode database entries when available
- Skips expensive Sonarr API calls for series/episode metadata
- Creates NFO from cached data only

TIER 3 (Normal): Full Episode Processing
- Only when neither NFO nor database have data
- Queries Sonarr APIs, processes dates, enhanced metadata

TV shows now benefit from same performance improvements as movies:
- Database rebuilds from existing NFO files (instant)
- Subsequent scans 90%+ faster for processed episodes
- Large TV libraries process efficiently with intelligent caching

This completes the performance optimization system across all media types.
2025-09-24 11:29:20 -04:00
sbcrumb 3889d3a31c feat: Add three-tier optimization for maximum performance
Local Docker Build (Dev) / build-dev (push) Successful in 19s
Implemented smart caching system that dramatically reduces processing time:

TIER 1 (Fastest): NFO File Check
- If NFO already has NFOGuard dateadded + lockdata, use it directly
- Skips both database queries AND API calls
- Perfect for movies already processed by NFOGuard

TIER 2 (Fast): Database Check
- If database has complete dateadded data, use it
- Skips expensive API calls to TMDB/OMDB/Radarr
- Creates NFO from cached data

TIER 3 (Slowest): Full Processing
- Only when neither NFO nor database have data
- Queries all APIs, processes dates, saves to database

This should dramatically improve full scan performance, especially
on subsequent runs where most movies already have NFOGuard data.

Expected speedup: 90%+ reduction in processing time for warm scans.
2025-09-24 11:21:38 -04:00
sbcrumb 172a364e6e debug: Add IMDb ID detection logging and database-first optimization
Local Docker Build (Dev) / build-dev (push) Successful in 18s
Added comprehensive debugging for IMDb ID detection to identify issues
with directories that don't have IMDb IDs in folder names but do have
them in filenames (like Adulthood (2025) [tt26657977]).

Also added database-first optimization that skips expensive API calls
when we already have complete data in the database. This should:
- Speed up full rescans significantly
- Reduce unnecessary API calls to TMDB/OMDB/Radarr
- Keep database size appropriate by not re-querying known movies

This should resolve both the small database size issue and improve
performance for movies that already have valid dateadded entries.
2025-09-24 11:16:56 -04:00
sbcrumb ed03f23272 fix: Move NFOGuard comment to bottom with other fields
Local Docker Build (Dev) / build-dev (push) Successful in 24s
Moved the NFOGuard source comment from the top of the XML file to
just before our field additions at the bottom. This creates a clear
separation showing where NFOGuard's modifications begin.

Expected structure:
[existing rich metadata]
<!-- NFOGuard - Source: tmdb:digital -->
<uniqueid type="imdb" default="true">tt123</uniqueid>
<premiered>2024-08-20</premiered>
<dateadded>2024-08-20T00:00:00+00:00</dateadded>
<lockdata>true</lockdata>
2025-09-24 10:08:10 -04:00
sbcrumb fc3c190c1b fix: Ensure NFOGuard fields are appended at bottom of NFO files
Local Docker Build (Dev) / build-dev (push) Successful in 24s
Changed from ET.SubElement() to ET.Element() + explicit append() to
guarantee that NFOGuard-managed fields appear at the very bottom of
NFO files after all existing content.

This is critical because:
- Emby plugin specifically looks for dateadded field
- All NFOGuard fields should be grouped together at the bottom
- Preserves existing rich metadata while clearly marking our additions

Added debug logging for dateadded field to confirm it's being written.
2025-09-24 10:06:29 -04:00
sbcrumb 17914ff8f4 debug: Add NFO creation debugging for Inside Out 2 issue
Local Docker Build (Dev) / build-dev (push) Successful in 22s
Added debug logging to understand why rich existing NFO metadata
isn't being preserved when NFOGuard updates files.

This will show:
- Parameters passed to create_movie_nfo
- Whether existing premiered dates are being preserved
- Why NFOGuard fields aren't being added to the bottom

This should help diagnose why Inside Out 2 NFO isn't getting
NFOGuard's dateadded and lockdata fields appended.
2025-09-24 10:02:52 -04:00
sbcrumb c04fe8d083 debug optional 2025-09-22 12:18:40 -04:00
sbcrumb 3e5c80279f fix: nfo logic long vs shortname 2025-09-22 11:02:12 -04:00
sbcrumb de3896b8c3 fix: add debug for .nfo ussues 2025-09-22 10:54:22 -04:00
sbcrumb a74feeb67e udpates to flow and nfo manager for TV 2025-09-22 10:03:59 -04:00
sbcrumb f563c67405 update sonarr .nfo flow 2025-09-22 09:25:03 -04:00
sbcrumb b881c7944c initial updates to mirror github files 2025-09-21 09:30:12 -04:00
sbcrumb c6d5d2e6dc updates 2025-09-21 09:28:06 -04:00
sbcrumb 22483717c4 initial update 2025-09-21 09:25:36 -04:00
sbcrumb 532ea02a5b update to docker 2025-09-17 15:23:29 -04:00
sbcrumb 1353b53cc8 CRITICAL: Fix database upsert bug preventing manual scan date persistence
**Root Cause**: upsert_movie_dates() was UPDATE-only, not proper upsert
- Manual scans failed to save dateadded to database (NULL values)
- Webhooks found database entries but with NULL dateadded
- Fell back to current timestamp instead of using proper import dates

**Database Fix**:
- Changed core/database.py upsert_movie_dates() from UPDATE to INSERT OR REPLACE
- Now properly saves dateadded during manual scans
- Preserves existing path with COALESCE fallback

**Webhook Enhancement**:
- Added comprehensive debug logging for database lookups
- Enhanced webhook date decision logic with proper fallback chain
- Only uses current timestamp as absolute last resort

**Impact**:
- Movies: Manual scans now persist dates, webhooks find existing entries 
- TV Shows: Not affected - already using proper INSERT OR REPLACE 
- Version: 1.5.5
2025-09-15 12:18:53 -04:00
sbcrumb 1dae7df3d2 updates to paths again 2025-09-14 14:23:25 -04:00
sbcrumb 1a562f7b41 missing path 2025-09-14 14:21:09 -04:00
sbcrumb f5ae8c7768 cleanup 2025-09-14 14:19:39 -04:00
sbcrumb a9c90d2939 remove debug 2025-09-14 14:15:19 -04:00
sbcrumb 2657729975 dates for TV shows 2025-09-14 13:56:31 -04:00
sbcrumb d7db924510 dates at bottom 2025-09-14 13:54:04 -04:00
sbcrumb 179f8f51d7 nfo dates to the bottom 2025-09-14 13:49:15 -04:00
sbcrumb e7b65cfed6 nfo fix again 2025-09-14 13:44:56 -04:00
sbcrumb 49266d651a fix nfo 2025-09-14 13:40:22 -04:00
sbcrumb 05ba16666e another DB table 2025-09-14 13:31:54 -04:00
sbcrumb b1f670415d database fix 2025-09-14 13:29:02 -04:00
sbcrumb 609f17713a fix path mapping wrong with smartstring 2025-09-14 13:25:32 -04:00
sbcrumb d168cc8317 path helper 2025-09-14 13:21:05 -04:00
sbcrumb 7b72d2d20b update DB tables 2025-09-14 13:15:48 -04:00
sbcrumb 04b0202903 removal of hard codeing 2025-09-14 13:13:13 -04:00
sbcrumb c20cefb571 fix hardcoded paths 2025-09-14 13:07:50 -04:00
sbcrumb bbe5f8c892 push updates to paths again 2025-09-14 13:03:41 -04:00
sbcrumb e741e4b046 fix: isolate movie and TV webhook processing to prevent cross-contamination
- Add prefixed batch keys (movie:imdbid, tv:imdbid) to prevent IMDb ID collisions
- Add path existence validation for Radarr webhooks to reject invalid mappings early
- Remove duplicate Radarr webhook handler code
- Add debug scripts for troubleshooting webhook and path mapping issues
- Create corrected .env template with fixed TV_PATHS and SONARR_ROOT_FOLDERS

This fixes the issue where TV path mapping failures caused movie webhooks
to process wrong movies due to shared batch queue corruption.
2025-09-14 12:43:07 -04:00
sbcrumb 5b7d4cdbd0 feat: improve NFO file organization by moving NFOGuard elements to bottom
NFO Organization Enhancement:
- Move all NFOGuard elements (dateadded, lockdata, comments) to bottom of NFO files
- Remove existing NFOGuard elements and re-add at bottom for clean organization
- Provides better separation between media metadata and NFOGuard management
- Easier to read NFO files when Radarr/Sonarr has already populated extensive metadata

Before: NFOGuard elements mixed throughout existing metadata
After: All media metadata first, then NFOGuard elements grouped at bottom

This addresses user feedback about NFO readability when files already contain
extensive metadata from Radarr, making it easier to see both media info and
NFOGuard management details in a logical order.
2025-09-14 11:21:44 -04:00
sbcrumb d8754e41a7 fix: NFO timestamp consistency and enhanced episode processing debug
NFO Management Timestamp Fix:
- Fix NFO management comments to use local timezone instead of UTC
- Both movie and TV episode NFO files now show consistent local timezone
- Comments now show: <!-- managed by NFOGuard at 2025-09-14T09:29:06-04:00 -->

Enhanced Episode Processing Debug:
- Add comprehensive debug logging for webhook episode database lookups
- Track IMDb ID and season/episode info throughout processing pipeline
- Add database write verification to catch storage issues immediately
- Enhanced logging will help identify duplicate processing root causes

This addresses the issue where episodes were being treated as new downloads
instead of finding existing database entries, helping prevent duplicate processing.
2025-09-14 10:27:05 -04:00
sbcrumb 7af7b1c43e feat: complete timezone support for NFO dateadded fields
- Fix NFO dateadded timestamps to use local timezone instead of UTC
- Convert Radarr/Sonarr import dates from UTC to local timezone for NFO files
- Update webhook episode processing to use local time for new downloads
- Convert file modification time fallbacks to local timezone
- Preserve historical dates (aired, premiered) in original UTC format
- Replace all placeholder logging functions with centralized timezone-aware logging
- Add convert_utc_to_local() utility function for timestamp conversion
- Now all logs AND NFO files show consistent local timezone formatting

Users with TZ=America/New_York will now see:
- Logs: [2025-09-14T09:37:00-04:00]
- NFO files: <dateadded>2025-09-14T09:37:00-04:00</dateadded>
2025-09-14 09:56:27 -04:00
sbcrumb 17ef94ec4f feat: implement timezone-aware logging system
- Fix inconsistent timestamp formats in logs for easier troubleshooting
- All logging systems now respect Docker TZ environment variable (e.g., TZ=America/New_York)
- Add TimezoneAwareFormatter for Python's standard logging module
- Enhance _log function with robust timezone support and fallbacks
- Replace placeholder logging functions with centralized core.logging._log
- Support both zoneinfo (Python 3.9+) and pytz (older versions)
- Users now see consistent timezone formatting across all log outputs
2025-09-14 09:45:32 -04:00
sbcrumb f4c56f6cbe feat: smart NFO management and correct episode date field mapping
💾 Smart NFO File Management:
- Add intelligent content comparison to prevent unnecessary file overwrites
- Only update NFO files when content actually changes (ignoring timestamp differences)
- Dramatically reduce file system writes and improve scan performance
- Applied to both TV episodes and movies for comprehensive efficiency
- New _nfo_content_matches() method for smart content comparison

🗓️ Fix Episode Date Field Mapping:
- BREAKING: Correct date field usage in episode NFOs
- <aired> and <premiered>: Now use historical air dates (e.g., 1951-10-15)
- <dateadded>: Correctly shows actual download/import date (e.g., 2025-09-13)
- Resolves confusion between when show aired vs when user downloaded it
- Media servers now show historically accurate metadata with working "Recently Added"

🎯 Technical Changes:
- Enhanced create_episode_nfo() with content comparison logic
- Enhanced create_movie_nfo() with content comparison logic
- Separated historical date logic from import date logic
- Added comprehensive debug logging for file skip/update decisions

🏆 User Experience:
- Faster scans with fewer unnecessary file operations
- Correct historical context in media servers
- "Recently Added" functionality preserved and working
- No more metadata confusion between air dates and import dates

Example NFO output:
- <aired>1951-10-15</aired> (historical)
- <dateadded>2025-09-13T21:39:28+00:00</dateadded> (when downloaded)
- <premiered>1951-10-15</premiered> (historical)
2025-09-13 19:52:43 -04:00
sbcrumb f998a64cdb update f string 2025-09-13 19:23:16 -04:00
sbcrumb 4ef28c3021 updates 2025-09-12 13:54:29 -04:00
sbcrumb dcbb25ca9e Fix Emby TV episode date handling by using <aired> field for import dates
- Issue: Emby displays DateCreated field which gets updated on metadata refresh
- Root cause: Emby ignores <dateadded> but reads <aired> for TV episodes
- Solution: Write import date to <aired> field instead of actual air date
- Emby will now display import date (Feb 19) instead of scan date (Sep 11)
- Maintains backward compatibility with fallback to actual air date
2025-09-11 16:45:36 -04:00
sbcrumb 52fa0b6060 Add missing get_episode_date method and bump version to v0.6.0
🐛 Database Fix:
• Add missing get_episode_date() method to NFOGuardDatabase
• Fixes: 'NFOGuardDatabase' object has no attribute 'get_episode_date'

🔄 Version Update:
• Bump VERSION from 0.2.22 to 0.6.0
• Major feature release with comprehensive TV enhancements

 Now Works:
• Single season processing via /tv/scan-season
• Single episode processing via /tv/scan-episode
• Enhanced NFO generation with Sonarr API metadata
• Database queries for existing episode dates
2025-09-11 09:59:15 -04:00
sbcrumb aff6179ddb Fix missing typing imports in NFOManager
🐛 Fix:
• Add missing Dict, Any imports from typing module
• Resolves NameError: name 'Dict' is not defined
2025-09-11 09:46:23 -04:00