use date earliest
This commit is contained in:
+19
-11
@@ -235,12 +235,13 @@ class RadarrClient:
|
|||||||
total_processed = 0
|
total_processed = 0
|
||||||
|
|
||||||
while page <= 20: # Safety limit
|
while page <= 20: # Safety limit
|
||||||
|
# Get history in chronological order
|
||||||
data = self._get("/api/v3/history", {
|
data = self._get("/api/v3/history", {
|
||||||
"movieId": str(movie_id), # Ensure it's a string
|
"movieId": str(movie_id),
|
||||||
"page": page,
|
"page": page,
|
||||||
"pageSize": page_size,
|
"pageSize": page_size,
|
||||||
"sortKey": "date",
|
"sortKey": "date",
|
||||||
"sortDirection": "ascending" # Start from oldest
|
"sortDirection": "ascending"
|
||||||
})
|
})
|
||||||
|
|
||||||
if not data:
|
if not data:
|
||||||
@@ -272,18 +273,22 @@ class RadarrClient:
|
|||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
# Only process import events (type 3)
|
# Track the first grab event we find
|
||||||
if event_type != self.EVENT_TYPE_IMPORTED:
|
if event_type == self.EVENT_TYPE_GRABBED and not first_grab:
|
||||||
|
if event.get("date"):
|
||||||
|
try:
|
||||||
|
first_grab = datetime.fromisoformat(event["date"].replace("Z", "+00:00")).astimezone(timezone.utc).isoformat(timespec="seconds")
|
||||||
|
_log("DEBUG", f"Found first grab event at {first_grab}")
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
continue
|
continue
|
||||||
imported_path = None
|
|
||||||
|
# Only process import events
|
||||||
try:
|
try:
|
||||||
data = json.loads(event.get("data", "{}"))
|
data = json.loads(event.get("data", "{}"))
|
||||||
imported_path = data.get("importedPath", "").lower()
|
imported_path = data.get("importedPath", "").lower()
|
||||||
except (json.JSONDecodeError, AttributeError):
|
if not imported_path:
|
||||||
pass
|
continue
|
||||||
|
|
||||||
if not imported_path:
|
|
||||||
continue
|
|
||||||
|
|
||||||
movie_imdb = (movie_info.get("imdbId", "") or "").lower()
|
movie_imdb = (movie_info.get("imdbId", "") or "").lower()
|
||||||
movie_title = (movie_info.get("title", "") or "").lower()
|
movie_title = (movie_info.get("title", "") or "").lower()
|
||||||
@@ -405,7 +410,10 @@ class RadarrClient:
|
|||||||
Returns:
|
Returns:
|
||||||
(date_iso, source_description)
|
(date_iso, source_description)
|
||||||
"""
|
"""
|
||||||
# Try history first
|
# Try history first - we want the earliest event regardless of type
|
||||||
|
import_date = self.earliest_import_event_optimized(movie_id)
|
||||||
|
|
||||||
|
# Try history second
|
||||||
import_date = self.earliest_import_event_optimized(movie_id)
|
import_date = self.earliest_import_event_optimized(movie_id)
|
||||||
if import_date:
|
if import_date:
|
||||||
return import_date, "radarr:history.import"
|
return import_date, "radarr:history.import"
|
||||||
|
|||||||
Reference in New Issue
Block a user