查询视频生成状态 Args: at: Access Token operations: 内部操作列表;当前上游状态查询仅使用其中抽取出的 media 引用 Returns: { "operations": [{ "operation": { "name": "task_id", "metadata": {...} # 完
(self, at: str, operations: List[Dict])
| 3864 | # ========== 任务轮询 (使用AT) ========== |
| 3865 | |
| 3866 | async def check_video_status(self, at: str, operations: List[Dict]) -> dict: |
| 3867 | """查询视频生成状态 |
| 3868 | |
| 3869 | Args: |
| 3870 | at: Access Token |
| 3871 | operations: 内部操作列表;当前上游状态查询仅使用其中抽取出的 media 引用 |
| 3872 | |
| 3873 | Returns: |
| 3874 | { |
| 3875 | "operations": [{ |
| 3876 | "operation": { |
| 3877 | "name": "task_id", |
| 3878 | "metadata": {...} # 完成时包含视频信息 |
| 3879 | }, |
| 3880 | "status": "MEDIA_GENERATION_STATUS_SUCCESSFUL" |
| 3881 | }] |
| 3882 | } |
| 3883 | """ |
| 3884 | url = f"{self.api_base_url}/video:batchCheckAsyncVideoGenerationStatus" |
| 3885 | |
| 3886 | media_refs = self._operations_to_media_refs(operations) |
| 3887 | if not media_refs: |
| 3888 | raise ValueError("视频状态查询缺少 media 引用,无法按当前上游结构发起查询") |
| 3889 | |
| 3890 | json_data = {"media": media_refs} |
| 3891 | max_retries = config.flow_max_retries |
| 3892 | last_error: Optional[Exception] = None |
| 3893 | |
| 3894 | for retry_attempt in range(max_retries): |
| 3895 | try: |
| 3896 | result = await self._make_video_api_request( |
| 3897 | url=url, |
| 3898 | json_data=json_data, |
| 3899 | at=at, |
| 3900 | timeout=self._get_video_poll_timeout() |
| 3901 | ) |
| 3902 | try: |
| 3903 | media_preview = result.get("media") if isinstance(result, dict) else None |
| 3904 | operations_preview = result.get("operations") if isinstance(result, dict) else None |
| 3905 | preview_payload = { |
| 3906 | "top_keys": list(result.keys()) if isinstance(result, dict) else [], |
| 3907 | "media_count": len(media_preview) if isinstance(media_preview, list) else 0, |
| 3908 | "operations_count": len(operations_preview) if isinstance(operations_preview, list) else 0, |
| 3909 | "first_media": media_preview[0] if isinstance(media_preview, list) and media_preview else None, |
| 3910 | "first_operation": operations_preview[0] if isinstance(operations_preview, list) and operations_preview else None, |
| 3911 | } |
| 3912 | print( |
| 3913 | "[VIDEO POLL RAW] " |
| 3914 | + json.dumps( |
| 3915 | self._truncate_large_debug_value(preview_payload), |
| 3916 | ensure_ascii=False, |
| 3917 | )[:4000] |
| 3918 | ) |
| 3919 | except Exception: |
| 3920 | pass |
| 3921 | return self._normalize_video_generation_response(result) |
| 3922 | except Exception as e: |
| 3923 | last_error = e |