Commit Graph

82 Commits

Author SHA1 Message Date
sbcrumb e188706001 fix: webhook episode processing now uses real Sonarr import history
Critical Fix for Episode Import Dates:
- Webhook episodes now query Sonarr import history instead of using current time
- Fix _get_webhook_episode_date() to follow same logic as manual scans
- Convert import dates from UTC to local timezone for NFO dateadded fields
- Episodes now show 'sonarr:history.import' source instead of 'webhook:new_download'

Before: <dateadded>2025-09-14T12:40:07+00:00</dateadded> (current webhook time)
After:  <dateadded>2025-09-14T08:40:07-04:00</dateadded> (real import time in local timezone)

This fixes the issue where episodes downloaded at 8:40am EST were showing
12:40pm UTC webhook time instead of the actual import timestamp.

Enhanced webhook processing now:
1. Checks database for existing entries (prevents duplicates)
2. Queries Sonarr import history for real import dates
3. Converts UTC import dates to local timezone
4. Only uses current time as last resort for true new downloads
2025-09-14 10:41:43 -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 1bf2725a5b iupdate 2025-09-13 19:15:22 -04:00
sbcrumb 4ef28c3021 updates 2025-09-12 13:54:29 -04:00
sbcrumb ac2753509d Add configurable TV webhook processing modes (targeted vs series)
⚙️ New Configuration Option:
• Added TV_WEBHOOK_PROCESSING_MODE environment variable
• targeted = Only process episodes mentioned in webhook (efficient, default)
• series = Process entire series directory (comprehensive, previous behavior)

🎯 Targeted Episode Processing:
• New process_webhook_episodes() method for precise processing
• Only updates NFOs for downloaded episodes (e.g., just S41E07)
• Reduces unnecessary file operations and Emby notifications
• Falls back to series processing if no episode data in webhook

🔧 Implementation Details:
• Modified Sonarr webhook handler to pass episode data
• Enhanced batch processor with mode detection
• Maintains backward compatibility with existing behavior
• Added comprehensive logging for processing mode selection

 Benefits:
• Efficient: 1 download = 1 episode processed (not entire series)
• Configurable: Users can choose preferred behavior via .env
• Compatible: Works with existing autoscan/Emby refresh systems
• Smart: Falls back gracefully when episode data unavailable
2025-09-11 11:22:36 -04:00
sbcrumb 03bdf2bf9f Fix TV endpoints to use proper JSON request models
🐛 API Fix:
• Add TVSeasonRequest and TVEpisodeRequest Pydantic models
• Update /tv/scan-season and /tv/scan-episode to accept JSON body
• Fix query parameter validation errors

 Now Works:
• curl -X POST "/tv/scan-season" -H "Content-Type: application/json" -d '{...}'
• curl -X POST "/tv/scan-episode" -H "Content-Type: application/json" -d '{...}'
2025-09-11 09:52:26 -04:00
sbcrumb c705fb4d6d Add comprehensive TV show enhancements and URL-safe endpoints
 Features Added:
• Single season/episode processing capability via new endpoints
• Enhanced NFO generation with full Sonarr API metadata (titles, plots, ratings)
• NFOGuard timestamp tracking in all NFO source comments
• URL-safe /tv/scan-season and /tv/scan-episode endpoints

🔧 Technical Improvements:
• Fixed URL encoding issues for paths with spaces and special characters
• Enhanced TVProcessor with process_season() and process_episode_file() methods
• Rich metadata extraction from Sonarr API (episode titles, plots, runtime, ratings)
• XML escaping for special characters in metadata
• Comprehensive episode parsing (SxxExx and numeric formats)

📚 Documentation:
• Updated README with new TV processing endpoints
• Added enhanced NFO generation examples showing before/after
• Documented URL-safe alternatives to manual scan paths

🎯 User Benefits:
• Can now process single seasons: Chicago Fire Season 13
• Can now process single episodes: S13E21 files
• Enhanced NFO files with full episode metadata for better Emby/Plex experience
• Timestamps show when NFOGuard processed each file
2025-09-11 09:39:42 -04:00
sbcrumb 5df4db5878 Comprehensive fallback enhancement: Accept any TMDB type + Radarr NFO premiered dates
- TMDB now accepts ANY release type (1-6+) for maximum coverage
- Added Radarr NFO <premiered> date extraction as additional fallback
- For rename-first movies: Import → Any TMDB → Radarr NFO → File dates
- Much more aggressive about using ANY reasonable date over bad file dates
- Covers edge cases where TMDB has unusual release types

Version bumped to 0.2.20
2025-09-10 10:01:20 -04:00
sbcrumb 47a2286953 Add detailed logging to debug TMDB API fallback issues
- Enhanced _get_digital_release_date with comprehensive logging
- Added external clients configuration check in debug endpoint
- Will show if TMDB API key is configured and external clients initialized
- Added error handling for external client calls
2025-09-10 09:13:12 -04:00
sbcrumb f586185a4f Fix debug endpoint to use global movie_processor instance
- Corrected debug endpoint to use global movie_processor variable
- Was incorrectly trying to access batcher.movie_processor (doesn't exist)
- Now properly tests full TMDB fallback pipeline for rename-first movies
2025-09-10 09:08:09 -04:00
sbcrumb fc983ed472 Fix private repo authentication and enhance debug endpoint
- Add authentication to git clone commands in CI workflows for private repo support
- Enhanced debug endpoint to test FULL movie processing pipeline (not just database)
- Debug now shows both database result AND final TMDB fallback decision
- Will reveal if TMDB API calls are working correctly for rename-first scenarios
2025-09-10 09:04:26 -04:00
sbcrumb bf7fb27fdb Fix dev workflow hanging and implement runtime branch detection
- Fix duplicate Dockerfile sections that were causing build hangs
- Replace complex build args with simple runtime git branch detection
- Revert CI workflows to working state (remove build args and debug code)
- Add automatic version tagging: dev branch shows "0.2.15-dev"
- Enhanced movie fallback logic for rename-first scenarios
- Improved logging to trace movie date decision process
2025-09-10 08:54:47 -04:00
sbcrumb 6f356b1942 versions 2025-09-10 08:29:04 -04:00
sbcrumb 4e786d775b Add configurable TV season directory naming
Features:
- TV_SEASON_DIR_FORMAT: Configurable season folder creation (Season {season:02d})
- TV_SEASON_DIR_PATTERN: Configurable season folder detection (season )
- Support for different naming conventions (Season 01, S01, Season01, etc.)
- Updated .env.template with TV configuration examples

Fixes hardcoded 'Season ' patterns for better flexibility
2025-09-09 20:25:03 -04:00
sbcrumb afe93b4a8a imdb updates 2025-09-09 17:13:14 -04:00
sbcrumb 4a9aecbc22 updates 2025-09-09 10:59:45 -04:00
sbcrumb 4685c970af add api secrets seperate from .env 2025-09-09 10:20:46 -04:00
sbcrumb b2938758e2 fix file date release to option not required 2025-09-09 10:03:54 -04:00
sbcrumb 0aa9655d25 digital logic updates 2025-09-09 09:52:55 -04:00
sbcrumb d75016bbf2 tmdb debuging 2025-09-09 09:39:43 -04:00
sbcrumb fed82a9e13 digital release logic 2025-09-09 09:30:20 -04:00
sbcrumb bbbf4b63cc digital release date 2025-09-09 09:18:33 -04:00
sbcrumb 149bf9acd3 added back tmdb 2025-09-09 08:55:02 -04:00
sbcrumb dd215d2f38 db updates 2025-09-09 08:50:21 -04:00
sbcrumb 19b40c0fd5 update to db call 2025-09-08 18:00:50 -04:00
sbcrumb 6f47df201d db error 2025-09-08 17:45:06 -04:00
sbcrumb e618b71620 updates again 2025-09-08 17:42:02 -04:00
sbcrumb f942b4c253 radarr date troubshooting 2025-09-08 10:29:28 -04:00
sbcrumb 5cc237461c updates for debug scan 2025-09-08 10:21:38 -04:00
sbcrumb f73875acdd refactor 2025-09-08 10:05:04 -04:00