Skip to content

Commit

Permalink
[deviantart] generate filenames (#392, #400)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikf committed Aug 29, 2019
1 parent 0ce9816 commit efb64ad
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 22 deletions.
2 changes: 1 addition & 1 deletion gallery_dl/extractor/8muses.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]"},
}),
)

Expand Down
2 changes: 1 addition & 1 deletion gallery_dl/extractor/adultempire.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class AdultempireGalleryExtractor(GalleryExtractor):
}),
("https://www.adultdvdempire.com/5683/gallery.html", {
"url": "b12cd1a65cae8019d837505adb4d6a2c1ed4d70d",
"keyword": "0fe9a6e3f0a331b95ba77f66a643705ca86e8ec5",
"keyword": "9634eb16cc6dbf347eb9dcdd9b2a499dfd04d167",
}),
)

Expand Down
44 changes: 24 additions & 20 deletions gallery_dl/extractor/deviantart.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -137,18 +137,21 @@ def prepare(self, deviation):
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

Expand Down Expand Up @@ -621,15 +624,13 @@ def _extract(self, data):

# extract download target
target = files[-1]
name = files[0]["src"]

if target["type"] == "gif":
pass
elif target["type"] == "video":
# 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"
Expand All @@ -653,16 +654,19 @@ def _extract(self, data):
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


Expand Down

0 comments on commit efb64ad

Please sign in to comment.