|
@@ -30,6 +30,27 @@ def _summary(generated: dict[str, Any]) -> dict[str, Any]:
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+LIGHT_ITEM_METADATA_KEYS = {
|
|
|
|
|
+ "page_index",
|
|
|
|
|
+ "page_rank",
|
|
|
|
|
+ "source_cursor",
|
|
|
|
|
+ "content_mode",
|
|
|
|
|
+ "search_provider",
|
|
|
|
|
+ "detail_provider",
|
|
|
|
|
+ "acquisition_match_status",
|
|
|
|
|
+ "matched_unique_key",
|
|
|
|
|
+ "skip_reason",
|
|
|
|
|
+ "unsupported_raw_type",
|
|
|
|
|
+ "video_url_missing",
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+def _light_metadata(metadata: dict[str, Any] | None) -> dict[str, Any]:
|
|
|
|
|
+ if not isinstance(metadata, dict):
|
|
|
|
|
+ return {}
|
|
|
|
|
+ return {key: metadata[key] for key in LIGHT_ITEM_METADATA_KEYS if key in metadata}
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
def _normalize_light_query_detail(detail: dict[str, Any]) -> dict[str, Any]:
|
|
def _normalize_light_query_detail(detail: dict[str, Any]) -> dict[str, Any]:
|
|
|
media_by_item = {media["item_id"]: media for media in detail.get("media_assets") or []}
|
|
media_by_item = {media["item_id"]: media for media in detail.get("media_assets") or []}
|
|
|
classification_by_item = {row["item_id"]: row for row in detail.get("classifications") or []}
|
|
classification_by_item = {row["item_id"]: row for row in detail.get("classifications") or []}
|
|
@@ -49,7 +70,8 @@ def _normalize_light_query_detail(detail: dict[str, Any]) -> dict[str, Any]:
|
|
|
"display_limit": job.get("display_limit"),
|
|
"display_limit": job.get("display_limit"),
|
|
|
"search_limit": job.get("search_limit"),
|
|
"search_limit": job.get("search_limit"),
|
|
|
"error_message": job.get("error_message"),
|
|
"error_message": job.get("error_message"),
|
|
|
- "items": [],
|
|
|
|
|
|
|
+ "item_ids": [],
|
|
|
|
|
+ "item_count": 0,
|
|
|
},
|
|
},
|
|
|
)
|
|
)
|
|
|
|
|
|
|
@@ -65,7 +87,7 @@ def _normalize_light_query_detail(detail: dict[str, Any]) -> dict[str, Any]:
|
|
|
"raw_summary": item.get("raw_summary"),
|
|
"raw_summary": item.get("raw_summary"),
|
|
|
"status": item.get("status"),
|
|
"status": item.get("status"),
|
|
|
"content_mode": item.get("content_mode"),
|
|
"content_mode": item.get("content_mode"),
|
|
|
- "metadata": item.get("metadata") or {},
|
|
|
|
|
|
|
+ "metadata": _light_metadata(item.get("metadata")),
|
|
|
"classification": _model_dump(classification) if classification else None,
|
|
"classification": _model_dump(classification) if classification else None,
|
|
|
"decode_summary": _model_dump(decode_by_item[item_id]) if item_id in decode_by_item else None,
|
|
"decode_summary": _model_dump(decode_by_item[item_id]) if item_id in decode_by_item else None,
|
|
|
"media_assets": [],
|
|
"media_assets": [],
|
|
@@ -76,11 +98,12 @@ def _normalize_light_query_detail(detail: dict[str, Any]) -> dict[str, Any]:
|
|
|
platform = payload["platform"]
|
|
platform = payload["platform"]
|
|
|
group = platforms.setdefault(
|
|
group = platforms.setdefault(
|
|
|
platform,
|
|
platform,
|
|
|
- {"platform": platform, "status": "done", "items": []},
|
|
|
|
|
|
|
+ {"platform": platform, "status": "done", "item_ids": [], "item_count": 0},
|
|
|
)
|
|
)
|
|
|
if group.get("status") in {None, "pending"}:
|
|
if group.get("status") in {None, "pending"}:
|
|
|
group["status"] = "done"
|
|
group["status"] = "done"
|
|
|
- group["items"].append(payload)
|
|
|
|
|
|
|
+ group.setdefault("item_ids", []).append(item_id)
|
|
|
|
|
+ group["item_count"] = len(group["item_ids"])
|
|
|
|
|
|
|
|
return {
|
|
return {
|
|
|
"query": QuerySchema.model_validate(detail["query"]).model_dump(mode="json"),
|
|
"query": QuerySchema.model_validate(detail["query"]).model_dump(mode="json"),
|