rogerxavier commited on
Commit
c242b8c
1 Parent(s): 67734fe

Update api.py

Browse files
Files changed (1) hide show
  1. api.py +33 -1
api.py CHANGED
@@ -12,6 +12,7 @@ from fastapi.responses import PlainTextResponse #执行其他py的plaintext返
12
  import subprocess
13
  from fastapi import BackgroundTasks
14
  import time
 
15
  app = FastAPI()
16
 
17
  @app.get("/inference")
@@ -123,4 +124,35 @@ def returnRandomSubscribeUrl(background_tasks: BackgroundTasks)->str:
123
  background_tasks.add_task(someTask)
124
  return result
125
  ##########异步样例
126
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12
  import subprocess
13
  from fastapi import BackgroundTasks
14
  import time
15
+ from bilibili_api import sync, video_uploader, Credential#bili上传部分
16
  app = FastAPI()
17
 
18
  @app.get("/inference")
 
124
  background_tasks.add_task(someTask)
125
  return result
126
  ##########异步样例
127
+
128
+
129
+
130
+
131
+ sessdata = os.getenv('sessdata')
132
+ bili_jct = os.getenv('bili_jct')
133
+ buvid3 = os.getenv('buvid3')
134
+ async def upload_video():
135
+ credential = Credential(sessdata=sessdata,
136
+ bili_jct=bili_jct,
137
+ buvid3=buvid3)
138
+
139
+
140
+ page = video_uploader.VideoUploaderPage(path='mp4_out/output_video.mp4', title=meta['title'], description=meta['desc'])
141
+
142
+ uploader = video_uploader.VideoUploader([page], meta, credential, cover='cover.jpg')
143
+
144
+ @uploader.on("__ALL__")
145
+ async def ev(data):
146
+ print(data)
147
+
148
+ await uploader.start()
149
+
150
+ @app.post("/upload_video")
151
+ async def run_upload_video(meta: dict = Body(...),cover_image: UploadFile = File(...), save_path: str = "/cover"):
152
+ cover_img = cover_image.file.read()
153
+ cover_img_data = Image.open(io.BytesIO(img)).convert("L").convert("RGB")
154
+ path_to_image = os.path.join(save_path, f"cover.jpg")
155
+ cover_img_data.save(path_to_image)
156
+ #video数据从meta用户请求获取,至于
157
+ await upload_video(meta)
158
+ return {"message": "Video upload completed"}