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

Update api.py

Browse files
Files changed (1) hide show
  1. api.py +3 -10
api.py CHANGED
@@ -105,34 +105,27 @@ async def execute_py_file(file_name: str,background_tasks: BackgroundTasks):
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(["1removeMask", "2magiDialogCut", "3mergeDialogToVideo"]),
109
  mp4_out_file: str = 'mp4_out/output.mp4',
110
  allow_submit: bool = False, cover_url: str = ''
111
  ):
112
  #cover_url因为本地上传有协程问题,所以采用cover_url然后转换为Picture类型即可->bilibili_api.utls.picture.Picture.from_url(str)->str
113
-
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,background_tasks)
121
  return {"message": "提交成功"}
122
 
123
- async def process_tasks_and_upload(file_list, bili_meta_data, cover_url,allow_submit,background_tasks):
124
 
125
  tasks = []
126
  for file_name in file_list:
127
  tasks.append(file_executer(file_name))
128
 
129
  if allow_submit:
130
- # cover_img = cover_image.file.read()
131
- # cover_img_data = Image.open(io.BytesIO(cover_img)).convert("L").convert("RGB")
132
- # cover_path_to_image = os.path.join(cover_path, "cover.jpg")
133
- # cover_img_data.save(cover_path_to_image)
134
- # print("cover_path_to_image是",cover_path_to_image)
135
- # # background_tasks.add_task(upload_video, bili_meta_data, cover_path_to_image)
136
  #因为采用cover_url上传,所以不需要读取内容然后保存本地->这样也会引起协程问题
137
  print("开始对cover_url是",cover_url,"的提交进程进行加入后台任务")
138
  tasks.append(await upload_video(bili_meta_data, cover_url))
 
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',
110
  allow_submit: bool = False, cover_url: str = ''
111
  ):
112
  #cover_url因为本地上传有协程问题,所以采用cover_url然后转换为Picture类型即可->bilibili_api.utls.picture.Picture.from_url(str)->str
 
113
  print("获取到的用户bili_meta_data是:", bili_meta_data)
114
  #这里需要先转换bili_meta_data从str变成dict才能继续
115
  bili_meta_data = json.loads(bili_meta_data)
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))
127
 
128
  if allow_submit:
 
 
 
 
 
 
129
  #因为采用cover_url上传,所以不需要读取内容然后保存本地->这样也会引起协程问题
130
  print("开始对cover_url是",cover_url,"的提交进程进行加入后台任务")
131
  tasks.append(await upload_video(bili_meta_data, cover_url))