|
16 | 16 | PLEX_URL = os.environ.get("PLEX_URL") |
17 | 17 | PLEX_TOKEN = os.environ.get("PLEX_TOKEN") |
18 | 18 | MAINTAINERR_URL = os.environ.get("MAINTAINERR_URL") |
19 | | -CURRENT_VERSION = "2.0.1" |
| 19 | +CURRENT_VERSION = "2.0.2" |
20 | 20 |
|
21 | 21 | def load_config(): |
22 | 22 | try: |
@@ -164,15 +164,36 @@ def sync_collections(): |
164 | 164 | delete_days = coll.get("deleteAfterDays", 30) |
165 | 165 | media_list = coll.get("media", []) |
166 | 166 |
|
167 | | - logging.info(f"✅ Kollektion '{coll_title}' in Maintainerr gefunden. Verarbeite {len(media_list)} Items...") |
| 167 | + # --- NEU: Paginierung / Media-Server Workaround --- |
| 168 | + media_count = coll.get("mediaCount", len(media_list)) |
| 169 | + plex_collection_id = coll.get("mediaServerId") |
| 170 | + |
| 171 | + if media_count > len(media_list) and plex_collection_id: |
| 172 | + logging.info(f"🔍 API-Limit erkannt ({len(media_list)}/{media_count} geliefert). Lade komplette Liste für '{coll_title}' via Media-Server Endpoint...") |
| 173 | + try: |
| 174 | + children_api = f"{MAINTAINERR_URL}/api/media-server/collection/{plex_collection_id}/children" |
| 175 | + c_resp = requests.get(children_api, headers={"Accept": "application/json"}) |
| 176 | + c_resp.raise_for_status() |
| 177 | + |
| 178 | + # Die kurze Liste mit der vollständigen überschreiben |
| 179 | + media_list = c_resp.json() |
| 180 | + logging.info(f"✅ Erfolgreich {len(media_list)} Items nachgeladen.") |
| 181 | + except Exception as e: |
| 182 | + logging.error(f"❌ Fehler beim Nachladen der Items für '{coll_title}': {e}") |
| 183 | + # -------------------------------------------------- |
| 184 | + |
| 185 | + logging.info(f"▶️ Verarbeite {len(media_list)} Items aus Kollektion '{coll_title}'...") |
168 | 186 |
|
169 | 187 | sortable_items = [] |
170 | 188 | for item in media_list: |
171 | | - plex_id = item.get("mediaServerId") |
172 | | - add_date = item.get("addDate") |
| 189 | + # Flexibel auf Maintainerr- und Media-Server-Datenstruktur reagieren |
| 190 | + plex_id = item.get("mediaServerId") or item.get("ratingKey") |
| 191 | + add_date = item.get("addDate") or item.get("addedAt") |
| 192 | + |
173 | 193 | if not plex_id or not add_date: continue |
174 | 194 |
|
175 | | - days_left = calculate_days_left(add_date, delete_days) |
| 195 | + # Dank unserer Normalisierung von vorhin frisst er hier jedes Format! |
| 196 | + days_left = calculate_days_left(str(add_date), delete_days) |
176 | 197 | sortable_items.append({"plex_id": int(plex_id), "days_left": days_left}) |
177 | 198 |
|
178 | 199 | sortable_items.sort(key=lambda x: x["days_left"]) |
|
0 commit comments