diff options
author | Sergey M․ <dstftw@gmail.com> | 2019-11-27 02:26:42 +0700 |
---|---|---|
committer | Sergey M․ <dstftw@gmail.com> | 2019-11-27 02:26:42 +0700 |
commit | 1ced222120c00854865c5b16e89838235ed549ee (patch) | |
tree | 6eede701b3bb29b96f05bb8a131f8fea46af3d9b /youtube_dl | |
parent | 6ddd4bf6ac04ae0b8ba39fb4124e844afc49b5a9 (diff) |
[utils] Add generic caesar cipher and rot47
Diffstat (limited to 'youtube_dl')
-rw-r--r-- | youtube_dl/utils.py | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/youtube_dl/utils.py b/youtube_dl/utils.py index 0d30075aa..b14603d8a 100644 --- a/youtube_dl/utils.py +++ b/youtube_dl/utils.py @@ -5383,6 +5383,19 @@ def decode_packed_codes(code): obfucasted_code) +def caesar(s, alphabet, shift): + if shift == 0: + return s + l = len(alphabet) + return ''.join( + alphabet[(alphabet.index(c) + shift) % l] if c in alphabet else c + for c in s) + + +def rot47(s): + return caesar(s, r'''!"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~''', 47) + + def parse_m3u8_attributes(attrib): info = {} for (key, val) in re.findall(r'(?P<key>[A-Z0-9-]+)=(?P<val>"[^"]+"|[^",]+)(?:,|$)', attrib): |