Skip to content

Commit

Permalink
[deviantart] allow selecting source for 'extra' (#1356)
Browse files Browse the repository at this point in the history
Setting 'extra' to "stash" or "deviations" will only download embedded
sta.sh content or deviations. 'true' still downloads both.
  • Loading branch information
mikf committed Mar 6, 2021
1 parent a677123 commit 5c32a7b
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 16 deletions.
9 changes: 6 additions & 3 deletions docs/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -745,14 +745,18 @@ Description
extractor.deviantart.extra
--------------------------
Type
``bool``
``bool`` or ``string``
Default
``false``
Description
Download embedded Deviations and Sta.sh resources from
description texts and journals.

Note: Enabling this option also enables deviantart.metadata_.
Set this option to ``"stash"`` or ``"deviations"``
to select only one of them as a source.

Note: Enabling this option also enables
`deviantart.metadata <extractor.deviantart.metadata_>`_.


extractor.deviantart.flat
Expand Down Expand Up @@ -2760,7 +2764,6 @@ Description

.. _base-directory: `extractor.*.base-directory`_
.. _date-format: `extractor.*.date-format`_
.. _deviantart.metadata: `extractor.deviantart.metadata`_
.. _postprocessors: `extractor.*.postprocessors`_
.. _download archive: `extractor.*.archive`_

Expand Down
37 changes: 24 additions & 13 deletions gallery_dl/extractor/deviantart.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,18 @@ def items(self):
else:
self.user = profile["user"]["username"]

if self.extra:
finditer_stash = DeviantartStashExtractor.pattern.finditer
finditer_deviation = DeviantartDeviationExtractor.pattern.finditer
extra = self.extra
if extra:
if extra == "stash":
extra_stash = DeviantartStashExtractor.pattern.finditer
extra_deviation = None
elif extra == "deviations":
extra_deviation = DeviantartDeviationExtractor.pattern.finditer
extra_stash = None
else:
extra_stash = DeviantartStashExtractor.pattern.finditer
extra_deviation = DeviantartDeviationExtractor.pattern.finditer
extra = True

yield Message.Version, 1
for deviation in self.deviations():
Expand Down Expand Up @@ -131,21 +140,23 @@ def items(self):

if "excerpt" in deviation and self.commit_journal:
journal = self.api.deviation_content(deviation["deviationid"])
if self.extra:
if extra:
deviation["_journal"] = journal["html"]
yield self.commit_journal(deviation, journal)

if self.extra:
if extra:
txt = (deviation.get("description", "") +
deviation.get("_journal", ""))
for match in finditer_stash(txt):
url = text.ensure_http_scheme(match.group(0))
deviation["_extractor"] = DeviantartStashExtractor
yield Message.Queue, url, deviation
for match in finditer_deviation(txt):
url = text.ensure_http_scheme(match.group(0))
deviation["_extractor"] = DeviantartDeviationExtractor
yield Message.Queue, url, deviation
if extra_stash:
for match in extra_stash(txt):
url = text.ensure_http_scheme(match.group(0))
deviation["_extractor"] = DeviantartStashExtractor
yield Message.Queue, url, deviation
if extra_deviation:
for match in extra_deviation(txt):
url = text.ensure_http_scheme(match.group(0))
deviation["_extractor"] = DeviantartDeviationExtractor
yield Message.Queue, url, deviation

def deviations(self):
"""Return an iterable containing all relevant Deviation-objects"""
Expand Down

0 comments on commit 5c32a7b

Please sign in to comment.