Skip to content

Commit

Permalink
[deviantart] add 'previews' option (#3782, #6124)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikf committed Sep 27, 2024
1 parent 928e170 commit bc11dc0
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 1 deletion.
15 changes: 14 additions & 1 deletion docs/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1989,7 +1989,7 @@ Description

Setting this option to ``"images"`` only downloads original
files if they are images and falls back to preview versions for
everything else (archives, etc.).
everything else (archives, videos, etc.).


extractor.deviantart.pagination
Expand All @@ -2005,6 +2005,19 @@ Description
* ``"manual"``: Disregard ``has_more`` and only stop when a batch of results is empty.


extractor.deviantart.previews
-----------------------------
Type
``bool``
Default
``false``
Description
For non-image files (archives, videos, etc.),
also download the file's preview image.

Set this option to ``"all"`` to download previews for all files.


extractor.deviantart.public
---------------------------
Type
Expand Down
18 changes: 18 additions & 0 deletions gallery_dl/extractor/deviantart.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ def _init(self):
self.extra = self.config("extra", False)
self.quality = self.config("quality", "100")
self.original = self.config("original", True)
self.previews = self.config("previews", False)
self.intermediary = self.config("intermediary", True)
self.comments_avatars = self.config("comments-avatars", False)
self.comments = self.comments_avatars or self.config("comments", False)
Expand Down Expand Up @@ -77,6 +78,11 @@ def _init(self):
else:
self._update_content = self._update_content_default

if self.previews == "all":
self.previews_images = self.previews = True
else:
self.previews_images = False

journals = self.config("journals", "html")
if journals == "html":
self.commit_journal = self._commit_journal_html
Expand Down Expand Up @@ -209,6 +215,18 @@ def items(self):
comment["_extractor"] = DeviantartAvatarExtractor
yield Message.Queue, url, comment

if self.previews and "preview" in deviation:
preview = deviation["preview"]
deviation["is_preview"] = True
if self.previews_images:
yield self.commit(deviation, preview)
else:
mtype = mimetypes.guess_type(
"a." + deviation["extension"], False)[0]
if mtype and not mtype.startswith("image/"):
yield self.commit(deviation, preview)
del deviation["is_preview"]

if not self.extra:
continue

Expand Down
11 changes: 11 additions & 0 deletions test/results/deviantart.py
Original file line number Diff line number Diff line change
Expand Up @@ -689,6 +689,17 @@
"#exception": exception.NotFoundError,
},

{
"#url" : "https://www.deviantart.com/justatest235723/art/archive-1103129101",
"#comment": "ZIP archive + preview image (#3782)",
"#class" : deviantart.DeviantartDeviationExtractor,
"#options": {"previews": True},
"#pattern": [
r"/f/940f2d05-c5eb-4917-8192-7eb6a2d508c6/di8rvv1-afe65948-16e1-4eca-b08d-9e6aaa9ed344\.zip",
r"/i/940f2d05-c5eb-4917-8192-7eb6a2d508c6/di8rvv1-bb9d891f-4374-4203-acd3-aea34b29a6a1\.png",
],
},

{
"#url" : "https://www.deviantart.com/myria-moon/art/Aime-Moi-261986576",
"#category": ("", "deviantart", "deviation"),
Expand Down

0 comments on commit bc11dc0

Please sign in to comment.