rogerxavier commited on
Commit
be2a33b
1 Parent(s): 2d851c4

Update api.py

Browse files
Files changed (1) hide show
  1. api.py +33 -6
api.py CHANGED
@@ -104,6 +104,35 @@ async def execute_py_file(file_name: str,background_tasks: BackgroundTasks):
104
 
105
 
106
  #保证既要提交队列后返回给用户,又要先完成前面的video生成步骤再执行后面的submit函数,还有兼顾allow_submit的值
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
107
  @app.get("/execute_all_task")
108
  async def execute_all_task(background_tasks: BackgroundTasks, bili_meta_data,file_list: List[str] = Query(["0filterImage","1removeMask", "2magiDialogCut", "3mergeDialogToVideo"]),
109
  mp4_out_file: str = 'mp4_out/output.mp4',
@@ -116,11 +145,10 @@ async def execute_all_task(background_tasks: BackgroundTasks, bili_meta_data,fil
116
  print("获取到的file_list是",file_list)
117
  print("获取到的allow_submit是",allow_submit)
118
 
119
- background_tasks.add_task(process_tasks_and_upload, file_list, bili_meta_data, cover_url,allow_submit)
120
  return {"message": "提交成功"}
121
 
122
- async def process_tasks_and_upload(file_list, bili_meta_data, cover_url,allow_submit):
123
-
124
  tasks = []
125
  for file_name in file_list:
126
  tasks.append(file_executer(file_name))
@@ -128,9 +156,8 @@ async def process_tasks_and_upload(file_list, bili_meta_data, cover_url,allow_s
128
  if allow_submit:
129
  #因为采用cover_url上传,所以不需要读取内容然后保存本地->这样也会引起协程问题
130
  print("开始对cover_url是",cover_url,"的提交进程进行加入后台任务")
131
- tasks.append(await upload_video(bili_meta_data, cover_url))
132
-
133
-
134
 
135
 
136
 
 
104
 
105
 
106
  #保证既要提交队列后返回给用户,又要先完成前面的video生成步骤再执行后面的submit函数,还有兼顾allow_submit的值
107
+ ##成功示例,可惜不能立刻返回
108
+ # @app.get("/execute_all_task")
109
+ # async def execute_all_task(background_tasks: BackgroundTasks, bili_meta_data,file_list: List[str] = Query(["0filterImage","1removeMask", "2magiDialogCut", "3mergeDialogToVideo"]),
110
+ # mp4_out_file: str = 'mp4_out/output.mp4',
111
+ # allow_submit: bool = False, cover_url: str = ''
112
+ # ):
113
+ # #cover_url因为本地上传有协程问题,所以采用cover_url然后转换为Picture类型即可->bilibili_api.utls.picture.Picture.from_url(str)->str
114
+ # print("获取到的用户bili_meta_data是:", bili_meta_data)
115
+ # #这里需要先转换bili_meta_data从str变成dict才能继续
116
+ # bili_meta_data = json.loads(bili_meta_data)
117
+ # print("获取到的file_list是",file_list)
118
+ # print("获取到的allow_submit是",allow_submit)
119
+
120
+ # background_tasks.add_task(process_tasks_and_upload, file_list, bili_meta_data, cover_url,allow_submit)
121
+ # return {"message": "提交成功"}
122
+
123
+ # async def process_tasks_and_upload(file_list, bili_meta_data, cover_url,allow_submit):
124
+
125
+ # tasks = []
126
+ # for file_name in file_list:
127
+ # tasks.append(file_executer(file_name))
128
+
129
+ # if allow_submit:
130
+ # #因为采用cover_url上传,所以不需要读取内容然后保存本地->这样也会引起协程问题
131
+ # print("开始对cover_url是",cover_url,"的提交进程进行加入后台任务")
132
+ # tasks.append(await upload_video(bili_meta_data, cover_url))
133
+
134
+
135
+ ##尝试能立刻返回的
136
  @app.get("/execute_all_task")
137
  async def execute_all_task(background_tasks: BackgroundTasks, bili_meta_data,file_list: List[str] = Query(["0filterImage","1removeMask", "2magiDialogCut", "3mergeDialogToVideo"]),
138
  mp4_out_file: str = 'mp4_out/output.mp4',
 
145
  print("获取到的file_list是",file_list)
146
  print("获取到的allow_submit是",allow_submit)
147
 
148
+ background_tasks.add_task(process_tasks_and_upload, file_list, bili_meta_data, cover_url,allow_submit,background_tasks)
149
  return {"message": "提交成功"}
150
 
151
+ def process_tasks_and_upload(file_list, bili_meta_data, cover_url,allow_submit,background_tasks):
 
152
  tasks = []
153
  for file_name in file_list:
154
  tasks.append(file_executer(file_name))
 
156
  if allow_submit:
157
  #因为采用cover_url上传,所以不需要读取内容然后保存本地->这样也会引起协程问题
158
  print("开始对cover_url是",cover_url,"的提交进程进行加入后台任务")
159
+ background_tasks.add_task(upload_video,bili_meta_data, cover_url)
160
+ ##尝试能立刻返回的
 
161
 
162
 
163