Skip to content

Commit

Permalink
[deviantart] work around OAuth API returning empty journal texts
Browse files Browse the repository at this point in the history
  • Loading branch information
mikf committed Sep 27, 2024
1 parent f8f67da commit 928e170
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions gallery_dl/extractor/deviantart.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}

Expand Down Expand Up @@ -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", "<br />")
journal = {"html": html}
elif "body" in deviation:
journal = {"html": deviation.pop("body")}
else:
Expand Down Expand Up @@ -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("<style"):
if not html:
self.log.warning("%s: Empty journal content", deviation["index"])
elif html.startswith("<style"):
html = html.partition("</style>")[2]
head, _, tail = html.rpartition("<script")
content = "\n".join(
Expand Down

0 comments on commit 928e170

Please sign in to comment.