Modify bytes combination
This commit is contained in:
@@ -12,6 +12,7 @@ Author: taizan-hokuto (2019) @taizan205
|
||||
ver 0.0.1 2019.10.05
|
||||
'''
|
||||
|
||||
|
||||
def _gen_vid(video_id):
|
||||
"""generate video_id parameter.
|
||||
Parameter
|
||||
@@ -40,9 +41,11 @@ def _gen_vid(video_id):
|
||||
b64enc(reduce(lambda x, y: x+y, item)).decode()
|
||||
).encode()
|
||||
|
||||
|
||||
def _nval(val):
|
||||
"""convert value to byte array"""
|
||||
if val<0: raise ValueError
|
||||
if val < 0:
|
||||
raise ValueError
|
||||
buf = b''
|
||||
while val >> 7:
|
||||
m = val & 0xFF | 0x80
|
||||
@@ -51,6 +54,7 @@ def _nval(val):
|
||||
buf += val.to_bytes(1, 'big')
|
||||
return buf
|
||||
|
||||
|
||||
def _build(video_id, seektime, topchat_only):
|
||||
switch_01 = b'\x04' if topchat_only else b'\x01'
|
||||
if seektime < 0:
|
||||
@@ -75,7 +79,8 @@ def _build(video_id, seektime, topchat_only):
|
||||
sep_3 = b'\x00\x58\x03\x60'
|
||||
sep_4 = b'\x68' + parity + b'\x72\x04\x08'
|
||||
sep_5 = b'\x10' + parity + b'\x78\x00'
|
||||
body = [
|
||||
|
||||
body = b''.join([
|
||||
sep_0,
|
||||
_nval(len(vid)),
|
||||
vid,
|
||||
@@ -90,9 +95,7 @@ def _build(video_id, seektime, topchat_only):
|
||||
sep_4,
|
||||
switch_01,
|
||||
sep_5
|
||||
]
|
||||
|
||||
body = reduce(lambda x, y: x+y, body)
|
||||
])
|
||||
|
||||
return urllib.parse.quote(
|
||||
b64enc(header_magic +
|
||||
@@ -101,6 +104,7 @@ def _build(video_id, seektime, topchat_only):
|
||||
).decode()
|
||||
)
|
||||
|
||||
|
||||
def getparam(video_id, seektime=0, topchat_only=False):
|
||||
'''
|
||||
Parameter
|
||||
|
||||
@@ -11,6 +11,8 @@ Author: taizan-hokuto (2019) @taizan205
|
||||
|
||||
ver 0.0.1 2019.10.05
|
||||
'''
|
||||
|
||||
|
||||
def _gen_vid(video_id):
|
||||
"""generate video_id parameter.
|
||||
Parameter
|
||||
@@ -44,6 +46,7 @@ def _gen_vid(video_id):
|
||||
b64enc(reduce(lambda x, y: x+y, item)).decode()
|
||||
).encode()
|
||||
|
||||
|
||||
def _tzparity(video_id, times):
|
||||
t = 0
|
||||
for i, s in enumerate(video_id):
|
||||
@@ -55,9 +58,11 @@ def _tzparity(video_id,times):
|
||||
|
||||
return ((times ^ t) % 2).to_bytes(1, 'big')
|
||||
|
||||
|
||||
def _nval(val):
|
||||
"""convert value to byte array"""
|
||||
if val<0: raise ValueError
|
||||
if val < 0:
|
||||
raise ValueError
|
||||
buf = b''
|
||||
while val >> 7:
|
||||
m = val & 0xFF | 0x80
|
||||
@@ -66,6 +71,7 @@ def _nval(val):
|
||||
buf += val.to_bytes(1, 'big')
|
||||
return buf
|
||||
|
||||
|
||||
def _build(video_id, _ts1, _ts2, _ts3, _ts4, _ts5, topchat_only):
|
||||
# _short_type2
|
||||
switch_01 = b'\x04' if topchat_only else b'\x01'
|
||||
@@ -99,7 +105,7 @@ def _build(video_id, _ts1, _ts2, _ts3, _ts4, _ts5, topchat_only):
|
||||
sep_9 = b'\x88\x01\x00\xA0\x01'
|
||||
timestamp5 = _nval(_ts5)
|
||||
|
||||
body = [
|
||||
body = b''.join([
|
||||
sep_0,
|
||||
_nval(len(vid)),
|
||||
vid,
|
||||
@@ -121,15 +127,13 @@ def _build(video_id, _ts1, _ts2, _ts3, _ts4, _ts5, topchat_only):
|
||||
ts_3_end,
|
||||
timestamp4,
|
||||
sep_6,
|
||||
switch_01,#
|
||||
switch_01,
|
||||
sep_7,
|
||||
switch_01,#
|
||||
switch_01,
|
||||
sep_8,
|
||||
sep_9,
|
||||
timestamp5
|
||||
]
|
||||
|
||||
body = reduce(lambda x, y: x+y, body)
|
||||
])
|
||||
|
||||
return urllib.parse.quote(
|
||||
b64enc(header_magic +
|
||||
@@ -161,4 +165,3 @@ def getparam(video_id, past_sec = 0, topchat_only = False):
|
||||
if True, fetch only 'top chat'
|
||||
'''
|
||||
return _build(video_id, *_times(past_sec), topchat_only)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user