例行更新
This commit is contained in:
parent
3ae8176abb
commit
0260fce845
71
bilibili.py
71
bilibili.py
@ -49,8 +49,8 @@ class Bilibili:
|
|||||||
APPKEY = '4409e2ce8ffd12b8'
|
APPKEY = '4409e2ce8ffd12b8'
|
||||||
ACTIONKEY = 'appkey'
|
ACTIONKEY = 'appkey'
|
||||||
BUILD = 101800
|
BUILD = 101800
|
||||||
DEVICE = 'android'
|
DEVICE = 'android_tv_yst'
|
||||||
MOBI_APP = 'android'
|
MOBI_APP = 'android_tv_yst'
|
||||||
PLATFORM = 'android'
|
PLATFORM = 'android'
|
||||||
APPSECRET = '59b43e04ad6965f34319062b478f83dd'
|
APPSECRET = '59b43e04ad6965f34319062b478f83dd'
|
||||||
|
|
||||||
@ -94,11 +94,16 @@ class Bilibili:
|
|||||||
data = json['data']
|
data = json['data']
|
||||||
return data['hash'], data['key']
|
return data['hash'], data['key']
|
||||||
|
|
||||||
def cnn_captcha(img):
|
def access_token_2_cookie(access_token):
|
||||||
url = "http://47.95.255.188:5000/code"
|
r = self.session.get(
|
||||||
data = {"image": img}
|
'https://passport.bilibili.com/api/login/sso?' + \
|
||||||
r = requests.post(url, data=data)
|
signed_body(
|
||||||
return r.text
|
'access_key={access_token}&appkey={appkey}&gourl=https%3A%2F%2Faccount.bilibili.com%2Faccount%2Fhome'
|
||||||
|
.format(access_token=access_token, appkey=APPKEY),
|
||||||
|
),
|
||||||
|
allow_redirects=False,
|
||||||
|
)
|
||||||
|
return r.cookies.get_dict(domain=".bilibili.com")
|
||||||
|
|
||||||
self.session.headers['Content-Type'] = 'application/x-www-form-urlencoded; charset=UTF-8'
|
self.session.headers['Content-Type'] = 'application/x-www-form-urlencoded; charset=UTF-8'
|
||||||
h, k = getkey()
|
h, k = getkey()
|
||||||
@ -112,9 +117,13 @@ class Bilibili:
|
|||||||
pwd = parse.quote_plus(pwd)
|
pwd = parse.quote_plus(pwd)
|
||||||
|
|
||||||
r = self.session.post(
|
r = self.session.post(
|
||||||
'https://passport.bilibili.com/api/v2/oauth2/login',
|
'https://passport.snm0516.aisee.tv/api/tv/login',
|
||||||
signed_body('appkey={appkey}&password={password}&username={username}'
|
signed_body(
|
||||||
.format(appkey=APPKEY, username=user, password=pwd))
|
'appkey={appkey}&build={build}&captcha=&channel=master&'
|
||||||
|
'guid=XYEBAA3E54D502E37BD606F0589A356902FCF&mobi_app={mobi_app}&'
|
||||||
|
'password={password}&platform={platform}&token=5598158bcd8511e2&ts=0&username={username}'
|
||||||
|
.format(appkey=APPKEY, build=BUILD, platform=PLATFORM, mobi_app=MOBI_APP, username=user,
|
||||||
|
password=pwd)),
|
||||||
)
|
)
|
||||||
try:
|
try:
|
||||||
json = r.json()
|
json = r.json()
|
||||||
@ -123,32 +132,17 @@ class Bilibili:
|
|||||||
|
|
||||||
if json['code'] == -105:
|
if json['code'] == -105:
|
||||||
# need captcha
|
# need captcha
|
||||||
self.session.headers['cookie'] = 'sid=xxxxxxxx'
|
raise Exception('TODO: login with captcha')
|
||||||
r = self.session.get('https://passport.bilibili.com/captcha')
|
|
||||||
captcha = cnn_captcha(base64.b64encode(r.content))
|
|
||||||
r = self.session.post(
|
|
||||||
'https://passport.bilibili.com/api/v2/oauth2/login',
|
|
||||||
signed_body('actionKey={actionKey}&appkey={appkey}&build={build}&captcha={captcha}&device={device}'
|
|
||||||
'&mobi_app={mobi_app}&password={password}&platform={platform}&username={username}'
|
|
||||||
.format(actionKey=ACTIONKEY,
|
|
||||||
appkey=APPKEY,
|
|
||||||
build=BUILD,
|
|
||||||
captcha=captcha,
|
|
||||||
device=DEVICE,
|
|
||||||
mobi_app=MOBI_APP,
|
|
||||||
password=pwd,
|
|
||||||
platform=PLATFORM,
|
|
||||||
username=user)),
|
|
||||||
)
|
|
||||||
json = r.json()
|
|
||||||
|
|
||||||
if json['code'] != 0:
|
if json['code'] != 0:
|
||||||
return r.text
|
return r.text
|
||||||
|
|
||||||
ls = []
|
access_token = json['data']['token_info']['access_token']
|
||||||
for item in json['data']['cookie_info']['cookies']:
|
cookie_dict = access_token_2_cookie(access_token)
|
||||||
ls.append(item['name'] + '=' + item['value'])
|
cookie = '; '.join(
|
||||||
cookie = '; '.join(ls)
|
'%s=%s' % (k, v)
|
||||||
|
for k, v in cookie_dict.items()
|
||||||
|
)
|
||||||
self.session.headers["cookie"] = cookie
|
self.session.headers["cookie"] = cookie
|
||||||
|
|
||||||
self.csrf = re.search('bili_jct=(.*?);', cookie).group(1)
|
self.csrf = re.search('bili_jct=(.*?);', cookie).group(1)
|
||||||
@ -244,7 +238,8 @@ class Bilibili:
|
|||||||
chunks_num = math.ceil(filesize / chunk_size)
|
chunks_num = math.ceil(filesize / chunk_size)
|
||||||
chunks_index = 0
|
chunks_index = 0
|
||||||
chunks_data = f.read(chunk_size)
|
chunks_data = f.read(chunk_size)
|
||||||
Common.modifyLastUploadStatus("Uploading >{}< @ {:.2f}%".format(filepath, 100.0 * chunks_index / chunks_num))
|
Common.modifyLastUploadStatus(
|
||||||
|
"Uploading >{}< @ {:.2f}%".format(filepath, 100.0 * chunks_index / chunks_num))
|
||||||
while True:
|
while True:
|
||||||
_d = datetime.now()
|
_d = datetime.now()
|
||||||
if not chunks_data:
|
if not chunks_data:
|
||||||
@ -268,8 +263,9 @@ class Bilibili:
|
|||||||
continue
|
continue
|
||||||
chunks_data = f.read(chunk_size)
|
chunks_data = f.read(chunk_size)
|
||||||
chunks_index += 1 # start with 0
|
chunks_index += 1 # start with 0
|
||||||
Common.modifyLastUploadStatus("Uploading >{}< @ {:.2f}%".format(filepath, 100.0*chunks_index/chunks_num))
|
Common.modifyLastUploadStatus(
|
||||||
if (datetime.now()-_d).seconds < 2:
|
"Uploading >{}< @ {:.2f}%".format(filepath, 100.0 * chunks_index / chunks_num))
|
||||||
|
if (datetime.now() - _d).seconds < 2:
|
||||||
sleep(1)
|
sleep(1)
|
||||||
|
|
||||||
# NOT DELETE! Refer to https://github.com/comwrg/bilibiliupload/issues/15#issuecomment-424379769
|
# NOT DELETE! Refer to https://github.com/comwrg/bilibiliupload/issues/15#issuecomment-424379769
|
||||||
@ -287,10 +283,9 @@ class Bilibili:
|
|||||||
'title': part.title,
|
'title': part.title,
|
||||||
'desc': part.desc})
|
'desc': part.desc})
|
||||||
Common.modifyLastUploadStatus("Upload >{}< Finished".format(filepath))
|
Common.modifyLastUploadStatus("Upload >{}< Finished".format(filepath))
|
||||||
__f = open("uploaded.json","w")
|
__f = open("uploaded.json", "w")
|
||||||
JSON.dump(self.videos, __f)
|
JSON.dump(self.videos, __f)
|
||||||
|
|
||||||
|
|
||||||
def finishUpload(self,
|
def finishUpload(self,
|
||||||
title,
|
title,
|
||||||
tid,
|
tid,
|
||||||
@ -356,7 +351,7 @@ class Bilibili:
|
|||||||
def clear(self):
|
def clear(self):
|
||||||
self.files.clear()
|
self.files.clear()
|
||||||
self.videos.clear()
|
self.videos.clear()
|
||||||
if(os.path.exists("uploaded.json")):
|
if (os.path.exists("uploaded.json")):
|
||||||
os.remove("uploaded.json")
|
os.remove("uploaded.json")
|
||||||
|
|
||||||
def appendUpload(self,
|
def appendUpload(self,
|
||||||
|
Reference in New Issue
Block a user