|
@@ -49,10 +49,41 @@ def submit_job(cookie, prompt, user_id, mode):
|
|
|
response = requests.post(url=url, headers=nec_headers(cookie), impersonate="chrome101", json=request_data)
|
|
|
return response_catch(response)
|
|
|
|
|
|
+
|
|
|
+# 提交任务 mode: relaxed/fast
|
|
|
+def submit_video_job(cookie, prompt, user_id, mode):
|
|
|
+ mode = mode or "fast"
|
|
|
+ request_data = {
|
|
|
+ "f": {
|
|
|
+ "mode": mode,
|
|
|
+ "private": False
|
|
|
+ },
|
|
|
+ "channelId": f"singleplayer_{user_id}",
|
|
|
+ "roomId": None,
|
|
|
+ "metadata": {
|
|
|
+ "isMobile": None,
|
|
|
+ "imagePrompts": None,
|
|
|
+ "imageReferences": None,
|
|
|
+ "characterReferences": None,
|
|
|
+ "depthReferences": None,
|
|
|
+ "lightboxOpen": None
|
|
|
+ },
|
|
|
+ "t": "video",
|
|
|
+ "videoType": "vid_1.1_i2v_480",
|
|
|
+ "newPrompt": prompt,
|
|
|
+ "parentJob": None,
|
|
|
+ "animateMode": "manual"
|
|
|
+ }
|
|
|
+ url = "https://www.midjourney.com/api/app/submit-jobs"
|
|
|
+ response = requests.post(url=url, headers=nec_headers(cookie), impersonate="chrome101", json=request_data)
|
|
|
+ return response_catch(response)
|
|
|
+
|
|
|
+
|
|
|
def generate_random_string(length=15):
|
|
|
characters = string.ascii_letters + string.digits
|
|
|
return ''.join(random.choice(characters) for _ in range(length))
|
|
|
|
|
|
+
|
|
|
def upload_image_to_oss(job_id, image_num=4):
|
|
|
OSS_ACCESS_KEY_ID = 'LTAI5tEYvefc4U3fyU5du225'
|
|
|
OSS_ACCESS_KEY_SECRET = 'Z1gZtAGe8NwRtXgPzVgRMkRez4Ex4K'
|
|
@@ -78,6 +109,31 @@ def upload_image_to_oss(job_id, image_num=4):
|
|
|
|
|
|
return results
|
|
|
|
|
|
+def upload_video_to_oss(job_id, image_num=4):
|
|
|
+ OSS_ACCESS_KEY_ID = 'LTAI5tEYvefc4U3fyU5du225'
|
|
|
+ OSS_ACCESS_KEY_SECRET = 'Z1gZtAGe8NwRtXgPzVgRMkRez4Ex4K'
|
|
|
+ OSS_ENDPOINT = 'oss-ap-southeast-1-internal.aliyuncs.com'
|
|
|
+ OSS_BUCKET_NAME = 'aigc-admin'
|
|
|
+
|
|
|
+ results = []
|
|
|
+ for i in range(image_num):
|
|
|
+ object_name = 'saas/mjVideo/' + generate_random_string(32) + ".mp4"
|
|
|
+ # 下载网络视频
|
|
|
+ response = requests.get(f"https://cdn.midjourney.com/video/{job_id}/{i}.mp4",
|
|
|
+ headers=nec_headers(""),
|
|
|
+ impersonate="chrome101")
|
|
|
+ if response.ok:
|
|
|
+ # 连接OSS
|
|
|
+ auth = oss2.Auth(OSS_ACCESS_KEY_ID, OSS_ACCESS_KEY_SECRET)
|
|
|
+ bucket = oss2.Bucket(auth, OSS_ENDPOINT, OSS_BUCKET_NAME)
|
|
|
+ # 上传视频到OSS
|
|
|
+ bucket.put_object(object_name, response.content)
|
|
|
+ # 构造OSS文件URL
|
|
|
+ oss_url = f"https://res.aiddit.com/{object_name}"
|
|
|
+ results.append(oss_url)
|
|
|
+
|
|
|
+ return results
|
|
|
+
|
|
|
|
|
|
def response_catch(response):
|
|
|
if response.ok:
|