1
0
mirror of https://github.com/mikf/gallery-dl.git synced 2024-11-23 03:02:50 +01:00

[deviantart] generate filenames (#392, #400)

This commit is contained in:
Mike Fährmann 2019-08-29 10:09:21 +02:00
parent 0ce98169b8
commit efb64ad031
No known key found for this signature in database
GPG Key ID: 5680CA389D365A88
3 changed files with 26 additions and 22 deletions

View File

@ -55,7 +55,7 @@ class _8musesAlbumExtractor(Extractor):
}),
("https://www.8muses.com/comics/album/Fakku-Comics/6?sort=az", {
"count": ">= 70",
"keyword": {"name": r"re:^[S-Zs-z]"},
"keyword": {"name": r"re:^[R-Zr-z]"},
}),
)

View File

@ -26,7 +26,7 @@ class AdultempireGalleryExtractor(GalleryExtractor):
}),
("https://www.adultdvdempire.com/5683/gallery.html", {
"url": "b12cd1a65cae8019d837505adb4d6a2c1ed4d70d",
"keyword": "0fe9a6e3f0a331b95ba77f66a643705ca86e8ec5",
"keyword": "9634eb16cc6dbf347eb9dcdd9b2a499dfd04d167",
}),
)

View File

@ -9,7 +9,7 @@
"""Extract images from https://www.deviantart.com/"""
from .common import Extractor, Message
from .. import text, exception
from .. import text, util, exception
from ..cache import cache, memcache
import collections
import itertools
@ -137,18 +137,21 @@ class DeviantartExtractor(Extractor):
deviation["date"] = text.parse_timestamp(
deviation["published_time"])
# filename metadata
alphabet = "0123456789abcdefghijklmnopqrstuvwxyz"
sub = re.compile(r"\W").sub
deviation["filename"] = "".join((
sub("_", deviation["title"].lower()), "_by_",
sub("_", deviation["author"]["username"].lower()), "-d",
util.bencode(deviation["index"], alphabet),
))
@staticmethod
def commit(deviation, target):
url = target["src"]
thumb = deviation["thumbs"][0]["src"] if "thumbs" in deviation else url
target = text.nameext_from_url(thumb, target.copy())
if target["filename"].endswith("-150"):
target["filename"] = target["filename"][:-4]
if not target["filename"].count("-"):
name, _, hid = target["filename"].rpartition("_")
target["filename"] = name + "-" + hid
target = target.copy()
target["filename"] = deviation["filename"]
deviation["target"] = target
deviation["filename"] = target["filename"]
deviation["extension"] = target["extension"] = text.ext_from_url(url)
return Message.Url, url, deviation
@ -621,7 +624,6 @@ class DeviantartExtractorV2(Extractor):
# extract download target
target = files[-1]
name = files[0]["src"]
if target["type"] == "gif":
pass
@ -629,7 +631,6 @@ class DeviantartExtractorV2(Extractor):
# select largest video
target = max(
files, key=lambda x: text.parse_int(x.get("quality", "")[:-1]))
name = target["src"]
elif target["type"] == "flash":
if target["src"].startswith("https://sandbox.deviantart.com"):
# extract SWF file from "sandbox"
@ -653,16 +654,19 @@ class DeviantartExtractorV2(Extractor):
target["src"] = re.sub(
r"q_\d+", self.quality, target["src"])
text.nameext_from_url(name, target)
if target["filename"].endswith("-150"):
target["filename"] = target["filename"][:-4]
if not target["filename"].count("-"):
name, _, hid = target["filename"].rpartition("_")
target["filename"] = name + "-" + hid
deviation["target"] = target
deviation["filename"] = target["filename"]
# filename and extension metadata
alphabet = "0123456789abcdefghijklmnopqrstuvwxyz"
sub = re.compile(r"\W").sub
deviation["filename"] = target["filename"] = "".join((
sub("_", deviation["title"].lower()), "_by_",
sub("_", deviation["author"]["username"].lower()), "-d",
util.bencode(deviation["index"], alphabet),
))
deviation["extension"] = target["extension"] = (
text.ext_from_url(target["src"]))
text.ext_from_url(target["src"])
)
deviation["target"] = target
return deviation