From 013733c9e9e5d8196fc280641b2cbe940cc8ac5a Mon Sep 17 00:00:00 2001 From: ClosedPort22 <44864697+ClosedPort22@users.noreply.github.com> Date: Thu, 19 Jan 2023 12:00:20 +0800 Subject: [PATCH] [deviantart] fix index fields for embedded/shared images --- gallery_dl/extractor/deviantart.py | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/gallery_dl/extractor/deviantart.py b/gallery_dl/extractor/deviantart.py index e188f485..13ec4d8d 100644 --- a/gallery_dl/extractor/deviantart.py +++ b/gallery_dl/extractor/deviantart.py @@ -155,12 +155,23 @@ class DeviantartExtractor(Extractor): def prepare(self, deviation): """Adjust the contents of a Deviation-object""" + alphabet = "0123456789abcdefghijklmnopqrstuvwxyz" if "index" not in deviation: try: - deviation["index"] = text.parse_int( - deviation["url"].rpartition("-")[2]) + if deviation["url"].startswith("https://sta.sh"): + filename = deviation["content"]["src"].split("/")[5] + deviation["index_base36"] = filename.partition("-")[0][1:] + deviation["index"] = \ + util.bdecode(deviation["index_base36"], alphabet) + else: + deviation["index"] = text.parse_int( + deviation["url"].rpartition("-")[2]) except KeyError: deviation["index"] = 0 + deviation["index_base36"] = "0" + if "index_base36" not in deviation: + deviation["index_base36"] = \ + util.bencode(deviation["index"], alphabet) if self.user: deviation["username"] = self.user @@ -182,8 +193,6 @@ class DeviantartExtractor(Extractor): ) # filename metadata - alphabet = "0123456789abcdefghijklmnopqrstuvwxyz" - deviation["index_base36"] = util.bencode(deviation["index"], alphabet) sub = re.compile(r"\W").sub deviation["filename"] = "".join(( sub("_", deviation["title"].lower()), "_by_", @@ -777,6 +786,10 @@ class DeviantartStatusExtractor(DeviantartExtractor): "count": 1, "pattern": r"https://images-wixmp-\w+\.wixmp\.com/f" r"/[^/]+/[^.]+\.jpg\?token=", + "keyword": { + "index": int, + "index_base36": "re:^[0-9a-z]+$", + }, }), ("https://www.deviantart.com/justgalym/posts/statuses", { "options": (("journals", "text"),),