Skip to content

Commit

Permalink
[artstation] download /4k/ images (#1422)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikf committed Apr 7, 2021
1 parent 3794019 commit 52a7913
Showing 1 changed file with 23 additions and 12 deletions.
35 changes: 23 additions & 12 deletions gallery_dl/extractor/artstation.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# -*- coding: utf-8 -*-

# Copyright 2018-2019 Mike Fährmann
# Copyright 2018-2021 Mike Fährmann
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 as
# published by the Free Software Foundation.

"""Extract images from https://www.artstation.com/"""
"""Extractors for https://www.artstation.com/"""

from .common import Extractor, Message
from .. import text, util, exception
Expand All @@ -29,7 +29,6 @@ def __init__(self, match):

def items(self):
data = self.metadata()
yield Message.Version, 1
yield Message.Directory, data

for project in self.projects():
Expand All @@ -49,7 +48,20 @@ def items(self):
if adict["has_image"]:
url = adict["image_url"]
text.nameext_from_url(url, asset)
yield Message.Url, self._no_cache(url), asset

url = self._no_cache(url)
lhs, _, rhs = url.partition("/large/")
if rhs:
url = lhs + "/4k/" + rhs
asset["_fallback"] = self._image_fallback(lhs, rhs)

yield Message.Url, url, asset

@staticmethod
def _image_fallback(lhs, rhs):
yield lhs + "/large/" + rhs
yield lhs + "/medium/" + rhs
yield lhs + "/small/" + rhs

def metadata(self):
"""Return general metadata"""
Expand Down Expand Up @@ -135,8 +147,8 @@ class ArtstationUserExtractor(ArtstationExtractor):
r"|((?!www)\w+)\.artstation\.com(?:/projects)?)/?$")
test = (
("https://www.artstation.com/gaerikim/", {
"pattern": r"https://\w+\.artstation\.com/p/assets"
r"/images/images/\d+/\d+/\d+/large/[^/]+",
"pattern": r"https://\w+\.artstation\.com/p/assets/images"
r"/images/\d+/\d+/\d+/(4k|large|medium|small)/[^/]+",
"count": ">= 6",
}),
("https://www.artstation.com/gaerikim/albums/all/"),
Expand Down Expand Up @@ -202,8 +214,8 @@ class ArtstationLikesExtractor(ArtstationExtractor):
r"/(?!artwork|projects|search)([^/?#]+)/likes/?")
test = (
("https://www.artstation.com/mikf/likes", {
"pattern": r"https://\w+\.artstation\.com/p/assets"
r"/images/images/\d+/\d+/\d+/large/[^/]+",
"pattern": r"https://\w+\.artstation\.com/p/assets/images"
r"/images/\d+/\d+/\d+/(4k|large|medium|small)/[^/]+",
"count": 6,
}),
# no likes
Expand Down Expand Up @@ -250,7 +262,6 @@ def items(self):
self.root)

challenge = self.request(challenge_url).json()
yield Message.Version, 1
yield Message.Directory, {"challenge": challenge}

params = {"sorting": self.sorting}
Expand Down Expand Up @@ -344,10 +355,10 @@ class ArtstationImageExtractor(ArtstationExtractor):
test = (
("https://www.artstation.com/artwork/LQVJr", {
"pattern": r"https?://\w+\.artstation\.com/p/assets"
r"/images/images/008/760/279/large/.+",
"content": "1f645ce7634e44675ebde8f6b634d36db0617d3c",
r"/images/images/008/760/279/4k/.+",
"content": "7b113871465fdc09d127adfdc2767d51cf45a7e9",
# SHA1 hash without _no_cache()
# "content": "2e8aaf6400aeff2345274f45e90b6ed3f2a0d946",
# "content": "44b80f9af36d40efc5a2668cdd11d36d6793bae9",
}),
# multiple images per project
("https://www.artstation.com/artwork/Db3dy", {
Expand Down

0 comments on commit 52a7913

Please sign in to comment.