Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions JSONParser2.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,67 @@
lan = getdict('JSONParser2', getlan(se, ip))


###########################
## NEW ##
###########################

def getplexinfo(d: dict):
t = d['data']['info']
r = {}
r['id'] = t['id']
r['uid'] = t['upper']['mid']
r['author'] = t['upper']['name']
r['title'] = t['title']
r['count'] = t['media_count']
return r


def getplex(r, f, i, d: dict, logg=None):
"获取订阅夹第i页的视频信息, 一般会一次性获取全部视频信息"
uri = f"https://api.bilibili.com/x/space/fav/season/list?season_id={f}&pn={i}&ps=20"
if logg is not None:
logg.write(f"GET {uri}", currentframe(), "GET PLIEX INFO")
bs = True
while bs:
try:
re = r.get(uri)
bs = False
except:
if logg is not None:
logg.write(format_exc(), currentframe(), "GET PLIEX INFO ERROR")
print(lan['OUTPUT1'].replace('<number>', str(i))) # 获取订阅夹第%s页失败,正在重试……
re.encoding = 'utf8'
if logg is not None:
logg.write(f"status = {re.status_code}\n{re.text}", currentframe(), "GET PLI INFO RESULT")
re = re.json()
if re['code'] != 0:
print('%s %s' % (re['code'], re['message']))
return -1
return re


def getplexiv(i: list, d: dict):
for t in d['data']['medias']:
r = {}
r['id'] = t['id']
r['title'] = t['title']
r['duration'] = t['duration']
r['uid'] = t['upper']['mid']
r['author'] = t['upper']['name']
r['collect'] = t['cnt_info']['collect']
r['danmuku'] = t['cnt_info']['danmaku']
r['play'] = t['cnt_info']['play']
r['bvid'] = t['bvid']
r['pubtime'] = t['pubtime']
i.append(r)


###########################
## END NEW ##
###########################



def getplinfo(d: dict):
t = d['data']['info']
r = {}
Expand All @@ -48,6 +109,7 @@ def getplinfo(d: dict):
return r



def getpli(r, f, i, d: dict, logg=None):
uri = f"https://api.bilibili.com/x/v3/fav/resource/list?media_id={f}&pn={i}&ps=20&keyword={d['k']}&order={d['order']}&type={d['t']}&tid={d['tid']}&jsonp=jsonp"
if logg is not None:
Expand Down
19 changes: 19 additions & 0 deletions PrintInfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,14 @@ def printInfo3(d: dict):
print(f"{lan['O22']}{d['count']}") # 视频数量:


def printInfo3_plex(d: dict):
print(f"{lan['O18']}{d['id']}") # 收藏夹ID:
print(f"{lan['O19']}{d['title']}") # 收藏夹标题:
print(f"{lan['O20']}{d['author']}") # 创建者名字:
print('UID:%s' % (d['uid']))
print(f"{lan['O22']}{d['count']}") # 视频数量:


def printInfo4(l: list): # noqa: E741
ii = 1
for i in l:
Expand All @@ -112,6 +120,17 @@ def printInfo4(l: list): # noqa: E741
ii = ii + 1


def printInfo4_plex(l: list): # noqa: E741
ii = 1
for i in l:
print(lan['O23'].replace('<number>', str(ii))) # 视频<number>:
print(f"{lan['O1']}{i['id']}") # AV号:
print(f"{lan['O2']}{i['bvid']}") # BV号:
print(f"{lan['O4']}{i['title']}") # 标题:
print(f"{lan['O24']}{i['author']}") # UP主名称:
ii = ii + 1


def printInfo5(l: list): # noqa: E741
e = 1
for i in l:
Expand Down
48 changes: 27 additions & 21 deletions biliBv.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,33 @@
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
table = 'fZodR9XQDSUm21yCkr6zBqiveYah8bt4xsWpHnJE7jL5VG3guMTKNPAwcF'
tr = {}
for i in range(58):
tr[table[i]] = i
s = [11, 10, 3, 8, 4, 6]
xor = 177451812
add = 8728348608
#
# This code can Convert bvid into avid CORRECTLY! QwQ -- edited by Evira.

XOR_CODE = 23442827791579
MASK_CODE = 2251799813685247
MAX_AID = 1 << 51
ALPHABET = "FcwAPNKTMug3GV5Lj7EJnHpWsx4tb8haYeviqBz6rkCy12mUSDQX9RdoZf"
ENCODE_MAP = 8, 7, 0, 5, 1, 3, 2, 4, 6
DECODE_MAP = tuple(reversed(ENCODE_MAP))

def debv(x):
if len(x) == 11:
x = "BV1" + x[2:]
r = 0
for i in range(6):
r += tr[x[s[i]]] * 58**i
return (r - add) ^ xor
BASE = len(ALPHABET)
PREFIX = "BV1"
PREFIX_LEN = len(PREFIX)
CODE_LEN = len(ENCODE_MAP)
def debv(x: str) -> int:
assert x[:3] == PREFIX
x = x[3:]
tmp = 0
for i in range(CODE_LEN):
idx = ALPHABET.index(x[DECODE_MAP[i]])
tmp = tmp * BASE + idx
return (tmp & MASK_CODE) ^ XOR_CODE


def enbv(x):
x = (x ^ xor) + add
r = list('BV1 4 1 7 ')
for i in range(6):
r[s[i]] = table[x // 58**i % 58]
return ''.join(r)
def enbv(x: int) -> str:
bvid = [""] * 9
tmp = (MAX_AID | x) ^ XOR_CODE
for i in range(CODE_LEN):
bvid[ENCODE_MAP[i]] = ALPHABET[tmp % BASE]
tmp //= BASE
return PREFIX + "".join(bvid)
88 changes: 65 additions & 23 deletions start.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def main(ip={}, menuInfo=None):
log = logg is not None
global se
global lan
uc = True # 是否检测更新
uc = False # 是否检测更新
if JSONParser.getset(se, 'uc') is True:
uc = False
if 'uc' in ip:
Expand Down Expand Up @@ -137,6 +137,7 @@ def main(ip={}, menuInfo=None):
ss = False
ep = False
pl = False # 收藏夹
plex = True # 订阅夹(与收藏夹不同ctype,不然会fid冲突)
hd = False # 互动视频
ch = False # 频道
uv = False # 投稿
Expand All @@ -149,7 +150,7 @@ def main(ip={}, menuInfo=None):
au = False # 音频区音乐
ac = False # 音频区收藏夹/专辑/歌单
uid = -1 # 收藏夹/频道主人id
fid = -1 # 收藏夹id
fid = -1 # 收藏夹id/订阅夹id
cid = -1 # 频道id
uvd = {} # 投稿查询信息
pld = {} # 收藏夹扩展信息
Expand Down Expand Up @@ -183,7 +184,7 @@ def main(ip={}, menuInfo=None):
if log and not logg.hasf():
logg.openf(f"log/AV{inp[2:]}_{round(time())}.log")
elif inp[0:2].lower() == 'bv':
inp = str(biliBv.debv(inp))
inp = str(biliBv.bv2av(inp))
s = "https://www.bilibili.com/video/av" + inp
av = True
if log and not logg.hasf():
Expand Down Expand Up @@ -395,6 +396,12 @@ def main(ip={}, menuInfo=None):
if s.isnumeric():
fid = int(s)
break
if 'ctype' in sl:
for s in sl['ctype']:
if s.isnumeric():
if int(s)==21:
plex=True # 订阅夹
break
if 'keyword' in sl:
pld['k'] = sl['keyword'][0]
if 'type' in sl:
Expand Down Expand Up @@ -782,31 +789,66 @@ def main(ip={}, menuInfo=None):
else:
print(lan['PLITIDNUL'])
return 0
i = 1
re = JSONParser2.getpli(section, fid, i, pld, logg)
if re == -1:
return -1
pli = JSONParser2.getplinfo(re)
if log:
logg.write(f"pli = {pli}", currentframe(), "PL INFO RESULT")
if ns:
PrintInfo.printInfo3(pli)
n = ceil(pli['count'] / 20)

plv = []
JSONParser2.getpliv(plv, re)
while i < n:
i = i + 1
if plex:
#使用订阅链接,而非收藏夹链接
if log:
logg.write(f"GET https://api.bilibili.com/x/space/fav/season/list?season_id={fid}", currentframe(), "PLEX PARAMETERS & GET LIST")
i = 0
page = 1
re = JSONParser2.getplex(section, fid, page, pld, logg)
if re == -1:
return -1
pli = JSONParser2.getplexinfo(re)
if log:
logg.write(f"plexi = {pli}", currentframe(), "PLEX INFO RESULT")
if ns:
PrintInfo.printInfo3_plex(pli)
n = pli['count']
JSONParser2.getplexiv(plv, re)
i += len(re['data']['medias'])
while i < n:
page += 1
re = JSONParser2.getplex(section, fid, page, pld, logg)
if re == -1:
return -1
i += len(re['data']['medias'])
JSONParser2.getplexiv(plv, re)
if log:
logg.write(f"plv = {plv}", currentframe(), "PL VIDEO LIST RESULT")
if len(plv) != pli['count']:
print(lan['ERROR8']) # 视频数量与预计数量不符,貌似BUG了。
return -1
if ns:
PrintInfo.printInfo4_plex(plv)

else:
i = 1
re = JSONParser2.getpli(section, fid, i, pld, logg)
if re == -1:
return -1
pli = JSONParser2.getplinfo(re)
if log:
logg.write(f"pli = {pli}", currentframe(), "PL INFO RESULT")
if ns:
PrintInfo.printInfo3(pli)
n = ceil(pli['count'] / 20)
JSONParser2.getpliv(plv, re)
if log:
logg.write(f"plv = {plv}", currentframe(), "PL VIDEO LIST RESULT")
if len(plv) != pli['count']:
print(lan['ERROR8']) # 视频数量与预计数量不符,貌似BUG了。
return -1
if ns:
PrintInfo.printInfo4(plv)
while i < n:
i = i + 1
re = JSONParser2.getpli(section, fid, i, pld, logg)
if re == -1:
return -1
JSONParser2.getpliv(plv, re)
if log:
logg.write(f"plv = {plv}", currentframe(), "PL VIDEO LIST RESULT")
if len(plv) != pli['count']:
print(lan['ERROR8']) # 视频数量与预计数量不符,貌似BUG了。
return -1
if ns:
PrintInfo.printInfo4(plv)

bs = True
f = True
while bs:
Expand Down