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
This commit is contained in:
2025-09-14 10:41:43 -04:00
parent d8754e41a7
commit e188706001
3 changed files with 56 additions and 14 deletions
+35 -1
View File
@@ -293,6 +293,40 @@ sonarr-nfo-cache | [2025-09-14T09:37:00-04:00] INFO: Batched movie webhook...
---
---
### 🆕 v0.6.7 Webhook Episode Import History Fix (September 2025)
**🎯 Critical Webhook Processing Fix:**
- **Problem**: Webhook episodes used current time instead of actual Sonarr import history
- **Issue**: `<dateadded>2025-09-14T12:40:07+00:00</dateadded>` showed webhook time (UTC) instead of real import time (local)
- **Root Cause**: `_get_webhook_episode_date()` wasn't querying Sonarr import history like manual scans
**⚡ Enhanced Webhook Episode Processing:**
- **Sonarr History Lookup**: Webhooks now query Sonarr import history for real import dates
- **Local Timezone Conversion**: Import dates converted to container timezone (Eastern Time)
- **Proper Source Attribution**: Episodes now show `sonarr:history.import` instead of `webhook:new_download` when history exists
- **Fallback Logic**: Only uses current time when no Sonarr history found (true new downloads)
**📋 Expected Results:**
```xml
<!-- Before (Wrong) -->
<dateadded>2025-09-14T12:40:07+00:00</dateadded> <!-- Current webhook time in UTC -->
<!-- source: TV Episode; webhook:new_download -->
<!-- After (Correct) -->
<dateadded>2025-09-14T08:40:07-04:00</dateadded> <!-- Real import time in Eastern -->
<!-- source: TV Episode; sonarr:history.import -->
```
**🛠️ Technical Implementation:**
- **Enhanced Logic**: Webhooks now follow same import history priority as manual scans
- **Timezone Consistency**: All import dates converted to local timezone before NFO generation
- **Better Logging**: Shows whether import history was found or current time used as fallback
- **Upgrade Handling**: Episodes downloaded multiple times now preserve original import dates
---
**Last Updated:** September 14, 2025
**Version:** v0.6.6
**Version:** v0.6.7
**Status:** Enhanced Production Ready