mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2024-11-10 09:07:58 +01:00
[utils] Merge base_n functions
This commit is contained in:
parent
8f4a2124a9
commit
59f898b7a7
3 changed files with 11 additions and 13 deletions
|
@ -18,7 +18,7 @@
|
|||
compat_urllib_parse_urlparse,
|
||||
)
|
||||
from ..utils import (
|
||||
base62,
|
||||
base_n,
|
||||
ExtractorError,
|
||||
ohdave_rsa_encrypt,
|
||||
remove_start,
|
||||
|
@ -143,7 +143,7 @@ def decode_eval_codes(self):
|
|||
|
||||
while count:
|
||||
count -= 1
|
||||
b62count = base62(count)
|
||||
b62count = base_n(count, 62)
|
||||
symbol_table[b62count] = symbols[count] or b62count
|
||||
|
||||
self.sdk_code = re.sub(
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
|
||||
from .jwplatform import JWPlatformBaseIE
|
||||
from ..utils import (
|
||||
base36,
|
||||
base_n,
|
||||
js_to_json,
|
||||
)
|
||||
|
||||
|
@ -42,7 +42,7 @@ def _real_extract(self, url):
|
|||
while count:
|
||||
count -= 1
|
||||
if symbols[count]:
|
||||
code = re.sub(r'\b%s\b' % base36(count), symbols[count], code)
|
||||
code = re.sub(r'\b%s\b' % base_n(count, 36), symbols[count], code)
|
||||
|
||||
code = code.replace('\\\'', '\'')
|
||||
jwplayer_data = self._parse_json(
|
||||
|
|
|
@ -2621,19 +2621,17 @@ def ohdave_rsa_encrypt(data, exponent, modulus):
|
|||
return '%x' % encrypted
|
||||
|
||||
|
||||
def base_n(num, n, table):
|
||||
def base_n(num, n, table=None):
|
||||
if num == 0:
|
||||
return '0'
|
||||
|
||||
FULL_TABLE = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
|
||||
assert n <= len(FULL_TABLE)
|
||||
if not table:
|
||||
table = FULL_TABLE[:n]
|
||||
|
||||
ret = ''
|
||||
while num:
|
||||
ret = table[num % n] + ret
|
||||
num = num // n
|
||||
return ret
|
||||
|
||||
|
||||
def base36(num):
|
||||
return base_n(num, 36, '0123456789abcdefghijklmnopqrstuvwxyz')
|
||||
|
||||
|
||||
def base62(num):
|
||||
return base_n(num, 62, '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ')
|
||||
|
|
Loading…
Reference in a new issue