Skip to content

Commit

Permalink
[artstation] support collections (#146)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikf committed Mar 1, 2024
1 parent 32ec695 commit cf9e99c
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 2 deletions.
2 changes: 1 addition & 1 deletion docs/supportedsites.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ Consider all listed sites to potentially be NSFW.
<tr>
<td>ArtStation</td>
<td>https://www.artstation.com/</td>
<td>Albums, Artwork Listings, Challenges, Followed Users, individual Images, Likes, Search Results, User Profiles</td>
<td>Albums, Artwork Listings, Challenges, Collections, Followed Users, individual Images, Likes, Search Results, User Profiles</td>
<td></td>
</tr>
<tr>
Expand Down
50 changes: 49 additions & 1 deletion gallery_dl/extractor/artstation.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,14 +226,62 @@ class ArtstationLikesExtractor(ArtstationExtractor):
directory_fmt = ("{category}", "{userinfo[username]}", "Likes")
archive_fmt = "f_{userinfo[id]}_{asset[id]}"
pattern = (r"(?:https?://)?(?:www\.)?artstation\.com"
r"/(?!artwork|projects|search)([^/?#]+)/likes/?")
r"/(?!artwork|projects|search)([^/?#]+)/likes")
example = "https://www.artstation.com/USER/likes"

def projects(self):
url = "{}/users/{}/likes.json".format(self.root, self.user)
return self._pagination(url)


class ArtstationCollectionExtractor(ArtstationExtractor):
"""Extractor for an artstation collection"""
subcategory = "collection"
directory_fmt = ("{category}", "{user}",
"{collection[id]} {collection[name]}")
archive_fmt = "c_{collection[id]}_{asset[id]}"
pattern = (r"(?:https?://)?(?:www\.)?artstation\.com"
r"/(?!artwork|projects|search)([^/?#]+)/collections/(\d+)")
example = "https://www.artstation.com/USER/collections/12345"

def __init__(self, match):
ArtstationExtractor.__init__(self, match)
self.collection_id = match.group(2)

def metadata(self):
url = "{}/collections/{}.json".format(
self.root, self.collection_id)
params = {"username": self.user}
collection = self.request(
url, params=params, notfound="collection").json()
return {"collection": collection, "user": self.user}

def projects(self):
url = "{}/collections/{}/projects.json".format(
self.root, self.collection_id)
params = {"collection_id": self.collection_id}
return self._pagination(url, params)


class ArtstationCollectionsExtractor(ArtstationExtractor):
"""Extractor for an artstation user's collections"""
subcategory = "collections"
pattern = (r"(?:https?://)?(?:www\.)?artstation\.com"
r"/(?!artwork|projects|search)([^/?#]+)/collections/?$")
example = "https://www.artstation.com/USER/collections"

def items(self):
url = self.root + "/collections.json"
params = {"username": self.user}

for collection in self.request(
url, params=params, notfound="collections").json():
url = "{}/{}/collections/{}".format(
self.root, self.user, collection["id"])
collection["_extractor"] = ArtstationCollectionExtractor
yield Message.Queue, url, collection


class ArtstationChallengeExtractor(ArtstationExtractor):
"""Extractor for submissions of artstation challenges"""
subcategory = "challenge"
Expand Down
1 change: 1 addition & 0 deletions scripts/supportedsites.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@

"artstation": {
"artwork": "Artwork Listings",
"collections": "",
},
"bluesky": {
"posts": "",
Expand Down
38 changes: 38 additions & 0 deletions test/results/artstation.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,44 @@
"#count" : 6,
},

{
"#url" : "https://www.artstation.com/mikf/collections/2647023",
"#category": ("", "artstation", "collection"),
"#class" : artstation.ArtstationCollectionExtractor,
"#count" : 10,

"collection": {
"active_projects_count": 3,
"id" : 2647023,
"is_private" : False,
"micro_square_image_url": "https://cdna.artstation.com/p/assets/images/images/005/131/434/micro_square/gaeri-kim-cat-front.jpg?1488720625",
"name" : "テスト",
"projects_count": 3,
"small_square_image_url": "https://cdna.artstation.com/p/assets/images/images/005/131/434/small_square/gaeri-kim-cat-front.jpg?1488720625",
"user_id" : 697975,
},
"user": "mikf",
},

{
"#url" : "https://www.artstation.com/mikf/collections",
"#category": ("", "artstation", "collections"),
"#class" : artstation.ArtstationCollectionsExtractor,
"#urls" : (
"https://www.artstation.com/mikf/collections/2647023",
"https://www.artstation.com/mikf/collections/2647719",
),

"active_projects_count": int,
"id" : range(2647023, 2647719),
"is_private" : False,
"micro_square_image_url": str,
"name" : r"re:テスト|empty",
"projects_count": int,
"small_square_image_url": str,
"user_id" : 697975,
},

{
"#url" : "https://www.artstation.com/sungchoi/likes",
"#comment" : "no likes",
Expand Down

0 comments on commit cf9e99c

Please sign in to comment.