修复删除已上传视频的逻辑,添加 追加上传功能
This commit is contained in:
parent
50216dc3e7
commit
cf8cbaae8c
140
bilibili.py
140
bilibili.py
@ -18,8 +18,10 @@ class VideoPart:
|
||||
self.title = title
|
||||
self.desc = desc
|
||||
|
||||
|
||||
class Bilibili:
|
||||
def __init__(self, cookie=None):
|
||||
self.files = []
|
||||
self.videos = []
|
||||
self.session = requests.session()
|
||||
if cookie:
|
||||
@ -137,7 +139,6 @@ class Bilibili:
|
||||
)
|
||||
json = r.json()
|
||||
|
||||
|
||||
if json['code'] is not 0:
|
||||
return r.text
|
||||
|
||||
@ -154,7 +155,6 @@ class Bilibili:
|
||||
|
||||
return True
|
||||
|
||||
|
||||
def upload(self,
|
||||
parts,
|
||||
title,
|
||||
@ -192,32 +192,17 @@ class Bilibili:
|
||||
"""
|
||||
:param parts: e.g. VideoPart('part path', 'part title', 'part desc'), or [VideoPart(...), VideoPart(...)]
|
||||
:type parts: VideoPart or list<VideoPart>
|
||||
:param title: video's title
|
||||
:type title: str
|
||||
:param tid: video type, see: https://member.bilibili.com/x/web/archive/pre
|
||||
or https://github.com/uupers/BiliSpider/wiki/%E8%A7%86%E9%A2%91%E5%88%86%E5%8C%BA%E5%AF%B9%E5%BA%94%E8%A1%A8
|
||||
:type tid: int
|
||||
:param tag: video's tag
|
||||
:type tag: list<str>
|
||||
:param desc: video's description
|
||||
:type desc: str
|
||||
:param source: (optional) 转载地址
|
||||
:type source: str
|
||||
:param cover: (optional) cover's URL, use method *cover_up* to get
|
||||
:type cover: str
|
||||
:param no_reprint: (optional) 0=可以转载, 1=禁止转载(default)
|
||||
:type no_reprint: int
|
||||
"""
|
||||
|
||||
self.session.headers['Content-Type'] = 'application/json; charset=utf-8'
|
||||
if not isinstance(parts, list):
|
||||
parts = [parts]
|
||||
|
||||
videos = []
|
||||
for part in parts:
|
||||
filepath = part.path
|
||||
filename = os.path.basename(filepath)
|
||||
filesize = os.path.getsize(filepath)
|
||||
self.files.append(part)
|
||||
r = self.session.get('https://member.bilibili.com/preupload?'
|
||||
'os=upos&upcdn=ws&name={name}&size={size}&r=upos&profile=ugcupos%2Fyb&ssl=0'
|
||||
.format(name=filename, size=filesize))
|
||||
@ -303,6 +288,24 @@ class Bilibili:
|
||||
cover='',
|
||||
no_reprint=1,
|
||||
):
|
||||
"""
|
||||
:param title: video's title
|
||||
:type title: str
|
||||
:param tid: video type, see: https://member.bilibili.com/x/web/archive/pre
|
||||
or https://github.com/uupers/BiliSpider/wiki/%E8%A7%86%E9%A2%91%E5%88%86%E5%8C%BA%E5%AF%B9%E5%BA%94%E8%A1%A8
|
||||
:type tid: int
|
||||
:param tag: video's tag
|
||||
:type tag: list<str>
|
||||
:param desc: video's description
|
||||
:type desc: str
|
||||
:param source: (optional) 转载地址
|
||||
:type source: str
|
||||
:param cover: (optional) cover's URL, use method *cover_up* to get
|
||||
:type cover: str
|
||||
:param no_reprint: (optional) 0=可以转载, 1=禁止转载(default)
|
||||
:type no_reprint: int
|
||||
"""
|
||||
self.session.headers['Content-Type'] = 'application/json; charset=utf-8'
|
||||
copyright = 2 if source else 1
|
||||
r = self.session.post('https://member.bilibili.com/x/vu/web/add?csrf=' + self.csrf,
|
||||
json={
|
||||
@ -319,10 +322,108 @@ class Bilibili:
|
||||
"videos": self.videos}
|
||||
)
|
||||
print(r.text)
|
||||
for _p in self.videos:
|
||||
for _p in self.files:
|
||||
os.remove(_p.path)
|
||||
|
||||
def appendUpload(self,
|
||||
aid,
|
||||
parts,
|
||||
title="",
|
||||
tid="",
|
||||
tag="",
|
||||
desc="",
|
||||
source='',
|
||||
cover='',
|
||||
no_reprint=1,
|
||||
):
|
||||
"""
|
||||
:param aid: just aid
|
||||
:type aid: int
|
||||
:param parts: e.g. VideoPart('part path', 'part title', 'part desc'), or [VideoPart(...), VideoPart(...)]
|
||||
:type parts: VideoPart or list<VideoPart>
|
||||
:param title: video's title
|
||||
:type title: str
|
||||
:param tid: video type, see: https://member.bilibili.com/x/web/archive/pre
|
||||
or https://github.com/uupers/BiliSpider/wiki/%E8%A7%86%E9%A2%91%E5%88%86%E5%8C%BA%E5%AF%B9%E5%BA%94%E8%A1%A8
|
||||
:type tid: int
|
||||
:param tag: video's tag
|
||||
:type tag: list<str>
|
||||
:param desc: video's description
|
||||
:type desc: str
|
||||
:param source: (optional) 转载地址
|
||||
:type source: str
|
||||
:param cover: (optional) cover's URL, use method *cover_up* to get
|
||||
:type cover: str
|
||||
:param no_reprint: (optional) 0=可以转载, 1=禁止转载(default)
|
||||
:type no_reprint: int
|
||||
"""
|
||||
self.session.headers['Content-Type'] = 'application/json; charset=utf-8'
|
||||
p = self.session.get("https://member.bilibili.com/x/web/archive/view?aid={}&history=".format(aid))
|
||||
j = p.json()
|
||||
if len(self.videos) == 0:
|
||||
for i in j['data']['videos']:
|
||||
self.videos.append({'filename': i['filename'],
|
||||
'title': i["title"],
|
||||
'desc': i["desc"]})
|
||||
if (title == ""): title = j["data"]["archive"]['title']
|
||||
if (tag == ""): tag = j["data"]["archive"]['tag']
|
||||
if (no_reprint == ""): no_reprint = j["data"]["archive"]['no_reprint']
|
||||
if (desc == ""): desc = j["data"]["archive"]['desc']
|
||||
if (source == ""): source = j["data"]["archive"]['source']
|
||||
if (tid == ""): tid = j["data"]["archive"]['tid']
|
||||
self.preUpload(parts)
|
||||
self.editUpload(aid, title, tid, tag, desc, source, cover, no_reprint)
|
||||
|
||||
def editUpload(self,
|
||||
aid,
|
||||
title,
|
||||
tid,
|
||||
tag,
|
||||
desc,
|
||||
source='',
|
||||
cover='',
|
||||
no_reprint=1,
|
||||
):
|
||||
"""
|
||||
:param aid: just aid
|
||||
:type aid: int
|
||||
:param parts: e.g. VideoPart('part path', 'part title', 'part desc'), or [VideoPart(...), VideoPart(...)]
|
||||
:type parts: VideoPart or list<VideoPart>
|
||||
:param title: video's title
|
||||
:type title: str
|
||||
:param tid: video type, see: https://member.bilibili.com/x/web/archive/pre
|
||||
or https://github.com/uupers/BiliSpider/wiki/%E8%A7%86%E9%A2%91%E5%88%86%E5%8C%BA%E5%AF%B9%E5%BA%94%E8%A1%A8
|
||||
:type tid: int
|
||||
:param tag: video's tag
|
||||
:type tag: list<str>
|
||||
:param desc: video's description
|
||||
:type desc: str
|
||||
:param source: (optional) 转载地址
|
||||
:type source: str
|
||||
:param cover: (optional) cover's URL, use method *cover_up* to get
|
||||
:type cover: str
|
||||
:param no_reprint: (optional) 0=可以转载, 1=禁止转载(default)
|
||||
:type no_reprint: int
|
||||
"""
|
||||
copyright = 2 if source else 1
|
||||
r = self.session.post('https://member.bilibili.com/x/vu/web/edit?csrf=' + self.csrf,
|
||||
json={
|
||||
"aid": aid,
|
||||
"copyright": copyright,
|
||||
"source": source,
|
||||
"title": title,
|
||||
"tid": tid,
|
||||
"tag": ','.join(tag),
|
||||
"no_reprint": no_reprint,
|
||||
"desc": desc,
|
||||
"cover": cover,
|
||||
"mission_id": 0,
|
||||
"order_id": 0,
|
||||
"videos": self.videos}
|
||||
)
|
||||
print(r.text)
|
||||
for _p in self.files:
|
||||
os.remove(_p.path)
|
||||
|
||||
def addChannel(self, name, intro=''):
|
||||
"""
|
||||
@ -389,4 +490,3 @@ class Bilibili:
|
||||
# print(r.text)
|
||||
# {"code":0,"data":{"url":"http://i0.hdslb.com/bfs/archive/67db4a6eae398c309244e74f6e85ae8d813bd7c9.jpg"},"message":"","ttl":1}
|
||||
return r.json()['data']['url']
|
||||
|
||||
|
Reference in New Issue
Block a user