rogerxavier
commited on
Commit
•
0fb176f
1
Parent(s):
22f62ea
Update api.py
Browse files
api.py
CHANGED
@@ -109,35 +109,7 @@ async def execute_py_file(file_name: str,background_tasks: BackgroundTasks):
|
|
109 |
|
110 |
|
111 |
#保证既要提交队列后返回给用户,又要先完成前面的video生成步骤再执行后面的submit函数,还有兼顾allow_submit的值
|
112 |
-
|
113 |
-
# @app.get("/execute_all_task")
|
114 |
-
# async def execute_all_task(background_tasks: BackgroundTasks, bili_meta_data,file_list: List[str] = Query(["0filterImage","1removeMask", "2magiDialogCut", "3mergeDialogToVideo"]),
|
115 |
-
# mp4_out_file: str = 'mp4_out/output.mp4',
|
116 |
-
# allow_submit: bool = False, cover_url: str = ''
|
117 |
-
# ):
|
118 |
-
# #cover_url因为本地上传有协程问题,所以采用cover_url然后转换为Picture类型即可->bilibili_api.utls.picture.Picture.from_url(str)->str
|
119 |
-
# print("获取到的用户bili_meta_data是:", bili_meta_data)
|
120 |
-
# #这里需要先转换bili_meta_data从str变成dict才能继续
|
121 |
-
# bili_meta_data = json.loads(bili_meta_data)
|
122 |
-
# print("获取到的file_list是",file_list)
|
123 |
-
# print("获取到的allow_submit是",allow_submit)
|
124 |
-
|
125 |
-
# background_tasks.add_task(process_tasks_and_upload, file_list, bili_meta_data, cover_url,allow_submit)
|
126 |
-
# return {"message": "提交成功"}
|
127 |
-
|
128 |
-
# async def process_tasks_and_upload(file_list, bili_meta_data, cover_url,allow_submit):
|
129 |
-
|
130 |
-
# tasks = []
|
131 |
-
# for file_name in file_list:
|
132 |
-
# tasks.append(file_executer(file_name))
|
133 |
-
|
134 |
-
# if allow_submit:
|
135 |
-
# #因为采用cover_url上传,所以不需要读取内容然后保存本地->这样也会引起协程问题
|
136 |
-
# print("开始对cover_url是",cover_url,"的提交进程进行加入后台任务")
|
137 |
-
# tasks.append(await upload_video(bili_meta_data, cover_url))
|
138 |
-
|
139 |
-
|
140 |
-
##尝试能立刻返回的
|
141 |
@app.get("/execute_all_task")
|
142 |
async def execute_all_task(background_tasks: BackgroundTasks, bili_meta_data,file_list: List[str] = Query(["0filterImage","1removeMask", "2magiDialogCut", "3mergeDialogToVideo"]),
|
143 |
mp4_out_file: str = 'mp4_out/output.mp4',
|
@@ -207,3 +179,16 @@ async def upload_video(meta:dict,cover_url:str):
|
|
207 |
|
208 |
await uploader.start()
|
209 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
109 |
|
110 |
|
111 |
#保证既要提交队列后返回给用户,又要先完成前面的video生成步骤再执行后面的submit函数,还有兼顾allow_submit的值
|
112 |
+
##能立刻返回的
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
113 |
@app.get("/execute_all_task")
|
114 |
async def execute_all_task(background_tasks: BackgroundTasks, bili_meta_data,file_list: List[str] = Query(["0filterImage","1removeMask", "2magiDialogCut", "3mergeDialogToVideo"]),
|
115 |
mp4_out_file: str = 'mp4_out/output.mp4',
|
|
|
179 |
|
180 |
await uploader.start()
|
181 |
|
182 |
+
|
183 |
+
#检测output.mp4下载查看生成效果(b不过审时用)
|
184 |
+
@app.get("/get_video")
|
185 |
+
async def get_video(dir:str = "/mp4_out/output.mp4")->"video file in header":
|
186 |
+
video_file_path = dir
|
187 |
+
video_file = open(video_file_path, "rb")
|
188 |
+
video_data = video_file.read()
|
189 |
+
video_file.close()
|
190 |
+
|
191 |
+
response = Response(content=video_data, media_type="video/mp4")
|
192 |
+
response.headers["Content-Disposition"] = "attachment; filename=output.mp4"
|
193 |
+
|
194 |
+
return response
|