1
0
mirror of https://github.com/mikf/gallery-dl.git synced 2024-11-22 02:32:33 +01:00

[deviantart] add 'previews' option (#3782, #6124)

This commit is contained in:
Mike Fährmann 2024-09-26 21:47:26 +02:00
parent 928e170721
commit bc11dc0de2
No known key found for this signature in database
GPG Key ID: 5680CA389D365A88
3 changed files with 43 additions and 1 deletions

View File

@ -1989,7 +1989,7 @@ Description
Setting this option to ``"images"`` only downloads original Setting this option to ``"images"`` only downloads original
files if they are images and falls back to preview versions for files if they are images and falls back to preview versions for
everything else (archives, etc.). everything else (archives, videos, etc.).
extractor.deviantart.pagination extractor.deviantart.pagination
@ -2005,6 +2005,19 @@ Description
* ``"manual"``: Disregard ``has_more`` and only stop when a batch of results is empty. * ``"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 extractor.deviantart.public
--------------------------- ---------------------------
Type Type

View File

@ -46,6 +46,7 @@ class DeviantartExtractor(Extractor):
self.extra = self.config("extra", False) self.extra = self.config("extra", False)
self.quality = self.config("quality", "100") self.quality = self.config("quality", "100")
self.original = self.config("original", True) self.original = self.config("original", True)
self.previews = self.config("previews", False)
self.intermediary = self.config("intermediary", True) self.intermediary = self.config("intermediary", True)
self.comments_avatars = self.config("comments-avatars", False) self.comments_avatars = self.config("comments-avatars", False)
self.comments = self.comments_avatars or self.config("comments", False) self.comments = self.comments_avatars or self.config("comments", False)
@ -77,6 +78,11 @@ class DeviantartExtractor(Extractor):
else: else:
self._update_content = self._update_content_default 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") journals = self.config("journals", "html")
if journals == "html": if journals == "html":
self.commit_journal = self._commit_journal_html self.commit_journal = self._commit_journal_html
@ -209,6 +215,18 @@ class DeviantartExtractor(Extractor):
comment["_extractor"] = DeviantartAvatarExtractor comment["_extractor"] = DeviantartAvatarExtractor
yield Message.Queue, url, comment 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: if not self.extra:
continue continue

View File

@ -689,6 +689,17 @@ __tests__ = (
"#exception": exception.NotFoundError, "#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", "#url" : "https://www.deviantart.com/myria-moon/art/Aime-Moi-261986576",
"#category": ("", "deviantart", "deviation"), "#category": ("", "deviantart", "deviation"),