bilibili-API-collect
bilibili-API-collect copied to clipboard
修改B站视频标题
我想实时修改b站视频标题,比如每分钟刷新显示当前投币数。 参见: https://www.youtube.com/watch?v=BxV14h0kFs0&t=248s 获取数据没什么问题,但关于修改标题,我查阅了很多资料和办法,好像都不奏效,在这里好像也没有相关API。 我知道B站需要人工审核,但还是想尽量完成这个概念
这么玩早晚封号😀
这么玩早晚封号😀
我也大概觉得这样,国内这些平台水平和格局还是差远了,当然有审核的因素。
我正巧在做类似的事情 非要硬怼api的话,看https://www.bilibili.com/read/cv5420339 用控制台测测,https://member.bilibili.com/x/vu/web/edit?t={}&csrf={} 这个api还是正确的。 对我来讲这个api太难用了。我的解决方法是云端挂了个selenium-chrome的docker,用python控制。控制函数如下供参考。 b站修改投稿偶尔会抽风,务必要挂个重试包装。我用了一个来月很稳定,运行时大概花300M内存左右。
@retry(times=10, timeout=60, exceptions=(IndexError))
def bili_tag_fix_selenium(bvid: str, tags: dict, driver: webdriver.Remote) -> None:
'''
tags format:
{
video_index: video_title,
1: 'title1',
2: 'title2',
}
'''
if len(tags.keys()) == 0: return
logging.info(f'now processing {bvid}')
driver.get(f'https://member.bilibili.com/platform/upload/video/frame?type=edit&bvid={bvid}')
time.sleep(10)
video_eps = driver.find_element(By.ID, 'video-up').find_elements(By.CLASS_NAME, 'item-title')
for index in tags:
if tags[index] is None: continue
title_element = video_eps[int(index) - 1]
# now click on the title:
try:
title_element.click()
except ElementClickInterceptedException:
# always happen in docker not locally. but this still works
driver.execute_script("arguments[0].click();", title_element)
# input will show up;
time.sleep(2)
video_ep_input = driver.find_element(
By.ID,
'video-up'
).find_elements(
By.CLASS_NAME,
'video-title-edit'
)[0].find_elements(By.TAG_NAME, 'input')[0]
video_ep_input.send_keys(Keys.CONTROL + "a")
video_ep_input.send_keys(Keys.DELETE)
video_ep_input.send_keys(f'{str(int(index) - 1).zfill(2)}_{tags[index]}')
time.sleep(0.5)
driver.find_elements(By.CLASS_NAME, 'submit-add')[0].click()
time.sleep(10)
花了点时间搞出来了API
https://github.com/lovegaoshi/azusa-player/issues/8#issuecomment-1880083106
import requests
import json
def load_cookies(fn="cookies.json"):
with open(fn) as f:
loaded_cookies = json.load(f)
cookies = {}
for cookie in loaded_cookies["cookie_info"]["cookies"]:
cookies[cookie["name"]] = cookie["value"]
return cookies
def get_bv_info(bvid, cookies=load_cookies()):
url = (
f"https://member.bilibili.com/x/vupre/web/archive/view?topic_grey=1&bvid={bvid}"
)
r = requests.get(url, cookies={"SESSDATA": cookies["SESSDATA"]}, timeout=100)
rjson = r.json()["data"]
result = {
"cover": rjson["archive"]["cover"],
"title": rjson["archive"]["title"],
"copyright": rjson["archive"]["copyright"],
"source": rjson["archive"]["source"],
"tid": rjson["archive"]["tid"],
"tag": rjson["archive"]["tag"],
"desc_format_id": rjson["archive"]["desc_format_id"],
"desc": rjson["archive"]["desc"],
"recreate": -1,
"dynamic": rjson["archive"]["dynamic"],
"interactive": rjson["archive"]["interactive"],
"aid": rjson["archive"]["aid"],
"new_web_edit": 1,
"videos": [],
"act_reserve_create": 0, # false is 0? true is what?
"handle_staff": False,
"topic_grey": 1,
"mission_id": 0,
"subtitle": {"open": 0, "lan": ""},
"is_360": -1,
"web_os": 1,
"csrf": cookies["bili_jct"],
}
for video in rjson["videos"]:
result["videos"].append(
{
"filename": video["filename"],
"title": video["title"],
"desc": video["desc"],
"cid": video["cid"],
}
)
return result
def post_bvid_edit(payload, cookies=load_cookies()):
return requests.post(
f'https://member.bilibili.com/x/vu/web/edit?csrf={payload["csrf"]}',
json=payload,
cookies={"SESSDATA": cookies["SESSDATA"]},
timeout=100,
)
eg.
info = get_by_info('BV123456789')
info['videos'][0]['title'] = "船新标题"
post_bvid_edit(info)
cookies需要SESSDATA和bili_jct
api 其实早就有了...这边没收录而已
https://github.com/Nemo2011/bilibili-api/blob/11c33b16003f3111684421fb9ad4cbea5833ef18/bilibili_api/data/api/video_uploader.json#L83-L116
理论简单但实际抽象,不清楚会不会触发验证码风控