Skip to content

Commit

Permalink
[deviantart] extend functionality of 'original' option
Browse files Browse the repository at this point in the history
  • Loading branch information
mikf committed Oct 11, 2018
1 parent c00dce2 commit d8492df
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
10 changes: 5 additions & 5 deletions docs/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -407,13 +407,13 @@ Description Enable mature content.
extractor.deviantart.original
-----------------------------
=========== =====
Type ``bool``
Type ``bool`` or ``string``
Default ``true``
Description Download full-sized original images if available.
Description Download original files if available.

Some of DeviantArt's images require an additional API call to get
their actual original version, which is being hosted on
Amazon Web Services (AWS) servers.
Setting this option to ``"images"`` only downloads original
files if they are images and falls back to preview versions for
everything else (archives, etc.).
=========== =====


Expand Down
13 changes: 11 additions & 2 deletions gallery_dl/extractor/deviantart.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from .. import text, exception
from ..cache import cache, memcache
import itertools
import mimetypes
import datetime
import time
import math
Expand Down Expand Up @@ -70,8 +71,7 @@ def items(self):
content = deviation["content"]
if (self.original and deviation["is_downloadable"] and
content["filesize"] != deviation["download_filesize"]):
content.update(
self.api.deviation_download(deviation["deviationid"]))
self._update_content(deviation, content)
yield self.commit(deviation, content)

if "videos" in deviation:
Expand Down Expand Up @@ -194,6 +194,15 @@ def _folder_urls(self, folders, category):
url = "{}/{}/{}/0/".format(self.root, self.user, category)
return [(url + folder["name"], folder) for folder in folders]

def _update_content(self, deviation, content):
data = self.api.deviation_download(deviation["deviationid"])
if self.original == "images":
url = data["src"].partition("?")[0]
mtype = mimetypes.guess_type(url, False)[0]
if not mtype or not mtype.startswith("image/"):
return
content.update(data)


class DeviantartGalleryExtractor(DeviantartExtractor):
"""Extractor for all deviations from an artist's gallery"""
Expand Down

0 comments on commit d8492df

Please sign in to comment.