From 293abb8921c43720023ca13985456c8356d53b42 Mon Sep 17 00:00:00 2001 From: ClosedPort22 <44864697+ClosedPort22@users.noreply.github.com> Date: Mon, 23 Jan 2023 17:37:57 +0800 Subject: [PATCH 1/3] [deviantart] add support for /deviation/ URLs --- gallery_dl/extractor/deviantart.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/gallery_dl/extractor/deviantart.py b/gallery_dl/extractor/deviantart.py index aeb2d0a16e..cbe54ca59a 100644 --- a/gallery_dl/extractor/deviantart.py +++ b/gallery_dl/extractor/deviantart.py @@ -867,7 +867,8 @@ class DeviantartDeviationExtractor(DeviantartExtractor): archive_fmt = "g_{_username}_{index}.{extension}" pattern = (BASE_PATTERN + r"/(art|journal)/(?:[^/?#]+-)?(\d+)" r"|(?:https?://)?(?:www\.)?deviantart\.com/" - r"(?:view/|view(?:-full)?\.php/*\?(?:[^#]+&)?id=)(\d+)") + r"(?:view/|deviation/|view(?:-full)?\.php/*\?(?:[^#]+&)?id=)" + r"(\d+)") test = ( (("https://www.deviantart.com/shimoda7/art/For-the-sake-10073852"), { "options": (("original", 0),), @@ -940,6 +941,8 @@ class DeviantartDeviationExtractor(DeviantartExtractor): ("https://www.deviantart.com/view/1", { "exception": exception.NotFoundError, }), + # /deviation/ (#3558) + ("https://www.deviantart.com/deviation/817215762"), # old-style URLs ("https://shimoda7.deviantart.com" "/art/For-the-sake-of-a-memory-10073852"), From 674c71964629161e76639176c46368e4918fe93e Mon Sep 17 00:00:00 2001 From: ClosedPort22 <44864697+ClosedPort22@users.noreply.github.com> Date: Mon, 23 Jan 2023 17:59:55 +0800 Subject: [PATCH 2/3] [deviantart] refactor base36 conversion --- gallery_dl/extractor/deviantart.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/gallery_dl/extractor/deviantart.py b/gallery_dl/extractor/deviantart.py index cbe54ca59a..bc4210e4ec 100644 --- a/gallery_dl/extractor/deviantart.py +++ b/gallery_dl/extractor/deviantart.py @@ -175,8 +175,7 @@ def prepare(self, deviation): ) # 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 ############################################################# From c90b4ea8d9b8cfc771e5d85332066c5ed059d6fd Mon Sep 17 00:00:00 2001 From: ClosedPort22 <44864697+ClosedPort22@users.noreply.github.com> Date: Mon, 23 Jan 2023 18:14:39 +0800 Subject: [PATCH 3/3] [deviantart] add support for fav.me URLs --- gallery_dl/extractor/deviantart.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/gallery_dl/extractor/deviantart.py b/gallery_dl/extractor/deviantart.py index bc4210e4ec..257e4fabef 100644 --- a/gallery_dl/extractor/deviantart.py +++ b/gallery_dl/extractor/deviantart.py @@ -867,7 +867,8 @@ class DeviantartDeviationExtractor(DeviantartExtractor): pattern = (BASE_PATTERN + r"/(art|journal)/(?:[^/?#]+-)?(\d+)" r"|(?:https?://)?(?:www\.)?deviantart\.com/" r"(?:view/|deviation/|view(?:-full)?\.php/*\?(?:[^#]+&)?id=)" - r"(\d+)") + r"(\d+)" # bare deviation ID without slug + r"|(?:https?://)?fav\.me/d([0-9a-z]+)") # base36 test = ( (("https://www.deviantart.com/shimoda7/art/For-the-sake-10073852"), { "options": (("original", 0),), @@ -942,6 +943,13 @@ class DeviantartDeviationExtractor(DeviantartExtractor): }), # /deviation/ (#3558) ("https://www.deviantart.com/deviation/817215762"), + # fav.me (#3558) + ("https://fav.me/ddijrpu", { + "count": 1, + }), + ("https://fav.me/dddd", { + "exception": exception.NotFoundError, + }), # old-style URLs ("https://shimoda7.deviantart.com" "/art/For-the-sake-of-a-memory-10073852"), @@ -958,7 +966,8 @@ class DeviantartDeviationExtractor(DeviantartExtractor): def __init__(self, match): DeviantartExtractor.__init__(self, match) self.type = match.group(3) - self.deviation_id = match.group(4) or match.group(5) + self.deviation_id = \ + match.group(4) or match.group(5) or id_from_base36(match.group(6)) def deviations(self): url = "{}/{}/{}/{}".format(