[deviantart] refactor base36 conversion

This commit is contained in:
ClosedPort22
2023-01-23 17:59:55 +08:00
parent 293abb8921
commit 674c719646

View File

@@ -175,8 +175,7 @@ class DeviantartExtractor(Extractor):
)
# filename metadata
alphabet = "0123456789abcdefghijklmnopqrstuvwxyz"
deviation["index_base36"] = util.bencode(deviation["index"], alphabet)
deviation["index_base36"] = base36_from_id(deviation["index"])
sub = re.compile(r"\W").sub
deviation["filename"] = "".join((
sub("_", deviation["title"].lower()), "_by_",
@@ -1564,6 +1563,17 @@ def _login_impl(extr, username, password):
}
def id_from_base36(base36):
return util.bdecode(base36, _ALPHABET)
def base36_from_id(deviation_id):
return util.bencode(int(deviation_id), _ALPHABET)
_ALPHABET = "0123456789abcdefghijklmnopqrstuvwxyz"
###############################################################################
# Journal Formats #############################################################