[deviantart] add "extractor.deviantart.flat" option

Setting this to 'false' downloads images into individual subdirectories
for each gallery-folder or favourite-collection, otherwise it is just
creating a flat list of images.
pull/30/head
Mike Fährmann 7 years ago
parent d075627fd9
commit 9be8f7e106
No known key found for this signature in database
GPG Key ID: 5680CA389D365A88

@ -242,6 +242,22 @@ Description The password belonging to the username.
Extractor-specific Options Extractor-specific Options
========================== ==========================
extractor.deviantart.flat
-------------------------
=========== =====
Type ``bool``
Default ``true``
Description Select the directory structure created by the Gallery- and
Favorite-Extractors.
* ``true``: Use a flat directory structure.
* ``false``: Collect a list of all gallery-folders or
favorites-collections and defere any further work to other
extractors (``folder`` or ``collection``), which will then
create individual subdirectories for each of them.
=========== =====
extractor.deviantart.mature extractor.deviantart.mature
--------------------------- ---------------------------
=========== ===== =========== =====
@ -261,7 +277,7 @@ extractor.exhentai.original
Type ``bool`` Type ``bool``
Default ``true`` Default ``true``
Description | Always download the original image or Description | Always download the original image or
| download the down-sampled version for larger images. | download the down-sampled version of larger images.
=========== ===== =========== =====

@ -135,6 +135,10 @@ class DeviantartExtractor(Extractor):
deviation["extension"] = "htm" deviation["extension"] = "htm"
return Message.Url, html, deviation return Message.Url, html, deviation
@property
def flat(self):
return self.config("flat", True)
@staticmethod @staticmethod
def _find_folder(folders, name): def _find_folder(folders, name):
regex = re.compile("[^\w]*" + name.replace("-", "[^\w]+") + "[^\w]*$") regex = re.compile("[^\w]*" + name.replace("-", "[^\w]+") + "[^\w]*$")
@ -143,6 +147,13 @@ class DeviantartExtractor(Extractor):
return folder return folder
raise exception.NotFoundError("folder") raise exception.NotFoundError("folder")
def _folder_urls(self, folders, category):
urlfmt = "https://{}.deviantart.com/{}/0/{}"
return [
urlfmt.format(self.user, category, folder["name"])
for folder in folders
]
class DeviantartGalleryExtractor(DeviantartExtractor): class DeviantartGalleryExtractor(DeviantartExtractor):
"""Extractor for all deviations from an artist's gallery""" """Extractor for all deviations from an artist's gallery"""
@ -154,21 +165,18 @@ class DeviantartGalleryExtractor(DeviantartExtractor):
"url": "63bfa8efba199e27181943c9060f6770f91a8441", "url": "63bfa8efba199e27181943c9060f6770f91a8441",
"keyword": "9342c2a7a2bd6eb9f4a6ea539d04d75248ebe05f", "keyword": "9342c2a7a2bd6eb9f4a6ea539d04d75248ebe05f",
}), }),
("http://shimoda7.deviantart.com/gallery/?catpath=/", None),
("https://yakuzafc.deviantart.com/", { ("https://yakuzafc.deviantart.com/", {
"url": "fa6ecb2c3aa78872f762d43f7809b7f0580debc1", "url": "fa6ecb2c3aa78872f762d43f7809b7f0580debc1",
}), }),
("http://shimoda7.deviantart.com/gallery/?catpath=/", None),
] ]
def deviations(self): def deviations(self):
if self.api.user_profile(self.user): if self.api.user_profile(self.user) and self.flat:
return self.api.gallery_all(self.user, self.offset) return self.api.gallery_all(self.user, self.offset)
else: else:
urlfmt = "https://{}.deviantart.com/gallery/0/{}" folders = self.api.gallery_folders(self.user)
return [ return self._folder_urls(folders, "gallery")
urlfmt.format(self.user, folder["name"])
for folder in self.api.gallery_folders(self.user)
]
class DeviantartFolderExtractor(DeviantartExtractor): class DeviantartFolderExtractor(DeviantartExtractor):
@ -257,10 +265,14 @@ class DeviantartFavoriteExtractor(DeviantartExtractor):
] ]
def deviations(self): def deviations(self):
return itertools.chain.from_iterable([ folders = self.api.collections_folders(self.user)
self.api.collections(self.user, folder["folderid"]) if self.flat:
for folder in self.api.collections_folders(self.user) return itertools.chain.from_iterable([
]) self.api.collections(self.user, folder["folderid"])
for folder in folders
])
else:
return self._folder_urls(folders, "favourites")
class DeviantartCollectionExtractor(DeviantartExtractor): class DeviantartCollectionExtractor(DeviantartExtractor):

Loading…
Cancel
Save