[deviantart] extend functionality of 'original' option
This commit is contained in:
@@ -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.).
|
||||
=========== =====
|
||||
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@ from .common import Extractor, Message
|
||||
from .. import text, exception
|
||||
from ..cache import cache, memcache
|
||||
import itertools
|
||||
import mimetypes
|
||||
import datetime
|
||||
import time
|
||||
import math
|
||||
@@ -70,8 +71,7 @@ class DeviantartExtractor(Extractor):
|
||||
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:
|
||||
@@ -194,6 +194,15 @@ class DeviantartExtractor(Extractor):
|
||||
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"""
|
||||
|
||||
Reference in New Issue
Block a user