From 928e170721897e0d67fd803febc182a43f5dd8e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20F=C3=A4hrmann?= Date: Thu, 26 Sep 2024 17:54:41 +0200 Subject: [PATCH] [deviantart] work around OAuth API returning empty journal texts (#6196, #6207, #5916) --- gallery_dl/extractor/deviantart.py | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/gallery_dl/extractor/deviantart.py b/gallery_dl/extractor/deviantart.py index 0027c4f826..b92f33c127 100644 --- a/gallery_dl/extractor/deviantart.py +++ b/gallery_dl/extractor/deviantart.py @@ -51,6 +51,7 @@ def _init(self): self.comments = self.comments_avatars or self.config("comments", False) self.api = DeviantartOAuthAPI(self) + self.eclipse_api = None self.group = False self._premium_cache = {} @@ -171,8 +172,19 @@ def items(self): if self.commit_journal: if "excerpt" in deviation: - journal = self.api.deviation_content( - deviation["deviationid"]) + # journal = self.api.deviation_content( + # deviation["deviationid"]) + if not self.eclipse_api: + self.eclipse_api = DeviantartEclipseAPI(self) + content = self.eclipse_api.deviation_extended_fetch( + deviation["index"], + deviation["author"]["username"], + "journal", + )["deviation"]["textContent"] + html = content["html"]["markup"] + if html.startswith("{"): + html = content["excerpt"].replace("\n", "
") + journal = {"html": html} elif "body" in deviation: journal = {"html": deviation.pop("body")} else: @@ -324,10 +336,11 @@ def _commit_journal_html(self, deviation, journal): deviation["extension"] = "htm" return Message.Url, html, deviation - @staticmethod - def _commit_journal_text(deviation, journal): + def _commit_journal_text(self, deviation, journal): html = journal["html"] - if html.startswith("")[2] head, _, tail = html.rpartition("