rogerxavier
commited on
Commit
•
251d42c
1
Parent(s):
df02735
Update api.py
Browse files
api.py
CHANGED
@@ -15,6 +15,7 @@ from bilibili_api import sync, video_uploader, Credential#bili上传部分
|
|
15 |
import asyncio #保证后台任务的先后
|
16 |
import json #对bili_meta_data进行dumps ->str和loads—>dict
|
17 |
import bilibili_api
|
|
|
18 |
import requests #用于请求其他space的图片api
|
19 |
|
20 |
sessdata = os.getenv('sessdata')
|
@@ -178,6 +179,8 @@ async def upload_video(meta:dict,cover_url:str):
|
|
178 |
await uploader.start()
|
179 |
|
180 |
|
|
|
|
|
181 |
#检测output.mp4下载查看生成效果(b不过审时用)
|
182 |
@app.get("/get_video")
|
183 |
async def get_video(dir:str = "/mp4_out/output.mp4")->"video file in header":
|
@@ -194,6 +197,53 @@ async def get_video(dir:str = "/mp4_out/output.mp4")->"video file in header":
|
|
194 |
|
195 |
|
196 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
197 |
|
198 |
|
199 |
|
|
|
15 |
import asyncio #保证后台任务的先后
|
16 |
import json #对bili_meta_data进行dumps ->str和loads—>dict
|
17 |
import bilibili_api
|
18 |
+
import random #随机获取cover
|
19 |
import requests #用于请求其他space的图片api
|
20 |
|
21 |
sessdata = os.getenv('sessdata')
|
|
|
179 |
await uploader.start()
|
180 |
|
181 |
|
182 |
+
|
183 |
+
|
184 |
#检测output.mp4下载查看生成效果(b不过审时用)
|
185 |
@app.get("/get_video")
|
186 |
async def get_video(dir:str = "/mp4_out/output.mp4")->"video file in header":
|
|
|
197 |
|
198 |
|
199 |
|
200 |
+
# 补零函数,将数字部分补齐为指定长度
|
201 |
+
def zero_pad(s, length):
|
202 |
+
return s.zfill(length)
|
203 |
+
|
204 |
+
|
205 |
+
#如果默认的cover不能过审,那么随机选取无水印的manga1下面的随便一个作为cover重新上传
|
206 |
+
async def upload_video(meta:dict,cover_url:str):
|
207 |
+
credential = Credential(sessdata=sessdata,
|
208 |
+
bili_jct=bili_jct,
|
209 |
+
buvid3=buvid3)
|
210 |
+
|
211 |
+
# 获取存放去水印漫画图片的路径
|
212 |
+
img_path = 'manga1'
|
213 |
+
#获取漫画原图无水印的加入image_files,并排序
|
214 |
+
subdir_path = os.path.join(os.getcwd(), img_path)
|
215 |
+
# 对话图片经过加入list并补0确定顺序
|
216 |
+
image_files = []
|
217 |
+
for root, dirs, files in os.walk(subdir_path):
|
218 |
+
for file in files:
|
219 |
+
if file.endswith(".jpg") or file.endswith(".png"):
|
220 |
+
image_files.append(os.path.relpath(os.path.join(root, file)))
|
221 |
+
# 对对话框文件名中的数字部分进行补零操作-这样顺序会正常
|
222 |
+
image_files.sort(
|
223 |
+
key=lambda x: zero_pad(''.join(filter(str.isdigit, os.path.splitext(os.path.basename(x))[0])), 3))
|
224 |
+
|
225 |
+
# 获取随机一张图片图片存入cover/0.jpg作为cover图片
|
226 |
+
random_image = Image.open(random.choice(image_files))
|
227 |
+
# 定义要保存的文件路径
|
228 |
+
save_path = os.path.join("cover", "0.jpg")
|
229 |
+
# 保存图片文件
|
230 |
+
random_image.save(save_path)
|
231 |
+
|
232 |
+
with open("cover/0.jpg", "rb") as f:
|
233 |
+
cover_data = f.read()
|
234 |
+
cover = bilibili_api.utils.picture.Picture.from_content(cover_data,"jpg")#直接读取本地图片content
|
235 |
+
|
236 |
+
|
237 |
+
|
238 |
+
page = video_uploader.VideoUploaderPage(path='mp4_out/output_video.mp4', title=meta['title'], description=meta['desc'])
|
239 |
+
|
240 |
+
uploader = video_uploader.VideoUploader([page], meta, credential, cover=cover)
|
241 |
+
|
242 |
+
@uploader.on("__ALL__")
|
243 |
+
async def ev(data):
|
244 |
+
print(data)
|
245 |
+
|
246 |
+
await uploader.start()
|
247 |
|
248 |
|
249 |
|