[utils] Merge base_n functions
[youtube-dl] / youtube_dl / utils.py
index 8ec70f93cd51ee6c05d43dedd8a1962f57a7f40e..900e07a8ec74f529e7bca0eec8b6bafb39ff5faf 100644 (file)
@@ -905,9 +905,9 @@ def unified_strdate(date_str, day_first=True):
         '%d %b %Y',
         '%B %d %Y',
         '%b %d %Y',
-        '%b %dst %Y %I:%M%p',
-        '%b %dnd %Y %I:%M%p',
-        '%b %dth %Y %I:%M%p',
+        '%b %dst %Y %I:%M',
+        '%b %dnd %Y %I:%M',
+        '%b %dth %Y %I:%M',
         '%Y %m %d',
         '%Y-%m-%d',
         '%Y/%m/%d',
@@ -2619,3 +2619,19 @@ def ohdave_rsa_encrypt(data, exponent, modulus):
     payload = int(binascii.hexlify(data[::-1]), 16)
     encrypted = pow(payload, exponent, modulus)
     return '%x' % encrypted
+
+
+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