Format code
This commit is contained in:
@@ -32,7 +32,7 @@ def _build(video_id, seektime, topchat_only) -> str:
|
||||
elif seektime == 0:
|
||||
timestamp = 1
|
||||
else:
|
||||
timestamp = int(seektime*1000000)
|
||||
timestamp = int(seektime * 1000000)
|
||||
continuation = Continuation()
|
||||
entity = continuation.entity
|
||||
entity.header = _gen_vid(video_id)
|
||||
|
||||
@@ -36,9 +36,10 @@ def _gen_vid_long(video_id):
|
||||
]
|
||||
|
||||
return urllib.parse.quote(
|
||||
b64enc(reduce(lambda x, y: x+y, item)).decode()
|
||||
b64enc(reduce(lambda x, y: x + y, item)).decode()
|
||||
).encode()
|
||||
|
||||
|
||||
def _gen_vid(video_id):
|
||||
"""generate video_id parameter.
|
||||
Parameter
|
||||
@@ -50,7 +51,7 @@ def _gen_vid(video_id):
|
||||
bytes : base64 encoded video_id parameter.
|
||||
"""
|
||||
header_magic = b'\x0A\x0F\x1A\x0D\x0A'
|
||||
header_id = video_id.encode()
|
||||
header_id = video_id.encode()
|
||||
header_terminator = b'\x20\x01'
|
||||
|
||||
item = [
|
||||
@@ -61,9 +62,10 @@ def _gen_vid(video_id):
|
||||
]
|
||||
|
||||
return urllib.parse.quote(
|
||||
b64enc(reduce(lambda x, y: x+y, item)).decode()
|
||||
b64enc(reduce(lambda x, y: x + y, item)).decode()
|
||||
).encode()
|
||||
|
||||
|
||||
def _nval(val):
|
||||
"""convert value to byte array"""
|
||||
if val < 0:
|
||||
@@ -84,19 +86,19 @@ def _build(video_id, seektime, topchat_only):
|
||||
if seektime == 0:
|
||||
times = b''
|
||||
else:
|
||||
times = _nval(int(seektime*1000))
|
||||
times = _nval(int(seektime * 1000))
|
||||
if seektime > 0:
|
||||
_len_time = b'\x5A' + (len(times)+1).to_bytes(1, 'big') + b'\x10'
|
||||
_len_time = b'\x5A' + (len(times) + 1).to_bytes(1, 'big') + b'\x10'
|
||||
else:
|
||||
_len_time = b''
|
||||
|
||||
|
||||
header_magic = b'\xA2\x9D\xB0\xD3\x04'
|
||||
sep_0 = b'\x1A'
|
||||
vid = _gen_vid(video_id)
|
||||
_tag = b'\x40\x01'
|
||||
timestamp1 = times
|
||||
sep_1 = b'\x60\x04\x72\x02\x08'
|
||||
terminator = b'\x78\x01'
|
||||
sep_0 = b'\x1A'
|
||||
vid = _gen_vid(video_id)
|
||||
_tag = b'\x40\x01'
|
||||
timestamp1 = times
|
||||
sep_1 = b'\x60\x04\x72\x02\x08'
|
||||
terminator = b'\x78\x01'
|
||||
|
||||
body = [
|
||||
sep_0,
|
||||
@@ -110,14 +112,12 @@ def _build(video_id, seektime, topchat_only):
|
||||
terminator
|
||||
]
|
||||
|
||||
body = reduce(lambda x, y: x+y, body)
|
||||
body = reduce(lambda x, y: x + y, body)
|
||||
|
||||
return urllib.parse.quote(
|
||||
b64enc(header_magic +
|
||||
_nval(len(body)) +
|
||||
body
|
||||
).decode()
|
||||
)
|
||||
b64enc(header_magic + _nval(len(body)) + body
|
||||
).decode()
|
||||
)
|
||||
|
||||
|
||||
def getparam(video_id, seektime=0.0, topchat_only=False):
|
||||
|
||||
@@ -68,12 +68,12 @@ def _build(video_id, ts1, ts2, ts3, ts4, ts5, topchat_only) -> str:
|
||||
|
||||
def _times(past_sec):
|
||||
n = int(time.time())
|
||||
_ts1 = n - random.uniform(0, 1*3)
|
||||
_ts1 = n - random.uniform(0, 1 * 3)
|
||||
_ts2 = n - random.uniform(0.01, 0.99)
|
||||
_ts3 = n - past_sec + random.uniform(0, 1)
|
||||
_ts4 = n - random.uniform(10*60, 60*60)
|
||||
_ts4 = n - random.uniform(10 * 60, 60 * 60)
|
||||
_ts5 = n - random.uniform(0.01, 0.99)
|
||||
return list(map(lambda x: int(x*1000000), [_ts1, _ts2, _ts3, _ts4, _ts5]))
|
||||
return list(map(lambda x: int(x * 1000000), [_ts1, _ts2, _ts3, _ts4, _ts5]))
|
||||
|
||||
|
||||
def getparam(video_id, past_sec=0, topchat_only=False) -> str:
|
||||
|
||||
Reference in New Issue
Block a user