diff options
author | Yen Chi Hsuan <yan12125@gmail.com> | 2016-02-26 14:58:29 +0800 |
---|---|---|
committer | Yen Chi Hsuan <yan12125@gmail.com> | 2016-02-26 14:58:29 +0800 |
commit | f52354a88927eb66bcb1f603d2d91162b5bd2b5f (patch) | |
tree | 82c74cfcd7f572e5d70547035fbf62960b8114a0 /youtube_dl/utils.py | |
parent | 59f898b7a72284efb994a8c6baee7771046226dd (diff) |
[utils] Move codes for handling eval() from iqiyi.py
Diffstat (limited to 'youtube_dl/utils.py')
-rw-r--r-- | youtube_dl/utils.py | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/youtube_dl/utils.py b/youtube_dl/utils.py index 900e07a8e..fc7e2fb7f 100644 --- a/youtube_dl/utils.py +++ b/youtube_dl/utils.py @@ -2635,3 +2635,23 @@ def base_n(num, n, table=None): ret = table[num % n] + ret num = num // n return ret + + +def decode_packed_codes(code): + mobj = re.search( + r"'([^']+)',(\d+),(\d+),'([^']+)'\.split\('\|'\),[^,]+,{}", + code) + obfucasted_code, base, count, symbols = mobj.groups() + base = int(base) + count = int(count) + symbols = symbols.split('|') + symbol_table = {} + + while count: + count -= 1 + base_n_count = base_n(count, base) + symbol_table[base_n_count] = symbols[count] or base_n_count + + return re.sub( + r'\b(\w+)\b', lambda mobj: symbol_table[mobj.group(0)], + obfucasted_code) |