ai_admin/WebAdmin/create_music_video.py
2024-09-20 04:29:09 +00:00

72 lines
2.8 KiB
Python
Executable File
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import os
import requests
from .base import logger
VIDEO_API_KEY = 'c4c0f516-33c0-4f5c-9d29-3b1d4e6a93c3'
VIDEO_API_URL = 'https://www.typeframes.com/api/public/v2/render'
WEBHOOK_URL = 'https://www.typeframes.cc/api/webhook/'
def create_music_video_payload(audio_url,generationPreset, media_type, text, ratio, voice_name, style, rate, user_id, slug, disableCaptions,caption_preset, caption_position, video_id):
"""
构建生成视频的请求体(用于 create-music-video
"""
try:
video_headers = {
'Content-Type': 'application/json',
'key': VIDEO_API_KEY
}
# 配置 webhook URL包含 video_id
webhook_url = f"{WEBHOOK_URL}?userid={user_id}&videoid={video_id}"
hasToGenerateVideos = media_type == "movingImage"
# 构建请求体
payload = {
"frameRate": 60,
"resolution": "1080p",
"frameDurationMultiplier": 18,
"webhook": webhook_url,
"creationParams": {
"mediaType": media_type,
"hasSoundWave": False,
"origin": "/create",
"flowType": "file-to-video",
"slug": slug,
"hasToGenerateVoice": False,
"hasToTranscript": False,
"hasToSearchMedia": True,
"hasAvatar": False,
"hasWebsiteRecorder": False,
"hasTextSmallAtBottom": False,
"ratio": ratio,
"selectedAudio": "Stomp",
"disableCaptions": disableCaptions,
"selectedVoice": voice_name,
"captionPresetName": caption_preset,
"captionPositionName": caption_position,
"sourceType": "contentScraping",
"selectedStoryStyle": {
"value": "custom",
"label": "Custom"
},
"generationPreset": generationPreset,
"selectedRecording": audio_url,
"selectedRecordingType": "audio",
"useQualityTranscript": False,
"hasEnhancedGeneration": False,
"disableAudio": False,
"hasToGenerateVideos": hasToGenerateVideos,
"audioUrl": "https://cdn.tfrv.xyz/audio/_bladerunner-2049.mp3"
}
}
logger.info(payload)
response = requests.post(VIDEO_API_URL, headers=video_headers, json=payload)
if response.status_code == 200:
return {"code": 200, "data": response.json()}
else:
return {"code": response.status_code, "message": response.text}
except Exception as e:
return {"code": 500, "message": str(e)}