[artstation] fix & update 'challenge' extractor

This commit is contained in:
Mike Fährmann
2026-02-05 20:05:42 +01:00
parent 04442e262e
commit d3adfd603b
2 changed files with 36 additions and 14 deletions

View File

@@ -319,9 +319,9 @@ class ArtstationChallengeExtractor(ArtstationExtractor):
"{challenge[id]} - {challenge[title]}")
archive_fmt = "c_{challenge[id]}_{asset_id}"
pattern = (r"(?:https?://)?(?:www\.)?artstation\.com"
r"/contests/[^/?#]+/challenges/(\d+)"
r"/c(?:hallenges|ontests)/[^/?#]+/c(?:ategori|halleng)es/(\d+)"
r"/?(?:\?sorting=([a-z]+))?")
example = "https://www.artstation.com/contests/NAME/challenges/12345"
example = "https://www.artstation.com/challenges/NAME/categories/12345"
def __init__(self, match):
ArtstationExtractor.__init__(self, match)
@@ -329,24 +329,28 @@ class ArtstationChallengeExtractor(ArtstationExtractor):
self.sorting = match[2] or "popular"
def items(self):
base = f"{self.root}/contests/_/challenges/{self.challenge_id}"
challenge_url = base + ".json"
submission_url = base + "/submissions.json"
update_url = self.root + "/contests/submission_updates.json"
base = self.root + "/api/v2/competition/"
challenge_url = f"{base}challenges/{self.challenge_id}.json"
submission_url = base + "submissions.json"
challenge = self.request_json(challenge_url)
yield Message.Directory, "", {"challenge": challenge}
params = {"sorting": self.sorting}
params = {
"page" : 1,
"per_page" : 50,
"challenge_id": self.challenge_id,
"sort_by" : self.sorting,
}
for submission in self._pagination(submission_url, params):
params = {"submission_id": submission["id"]}
update_url = (f"{base}submissions/{submission['id']}"
f"/submission_updates.json")
params = {"page": 1, "per_page": 50}
for update in self._pagination(update_url, params=params):
del update["replies"]
update["challenge"] = challenge
for url in text.extract_iter(
update["body_presentation_html"], ' href="', '"'):
for url in util.unique_sequence(text.extract_iter(
update["body"], ' href="', '"')):
update["asset_id"] = self._id_from_url(url)
text.nameext_from_url(url, update)
yield Message.Url, self._no_cache(url), update

View File

@@ -108,10 +108,28 @@ __tests__ = (
},
{
"#url" : "https://www.artstation.com/contests/beyond-human/challenges/23?sorting=winners",
"#url" : "https://www.artstation.com/challenges/beyond-human/categories/23/submissions",
"#class" : artstation.ArtstationChallengeExtractor,
},
{
"#url" : "https://www.artstation.com/contests/beyond-human/challenges/23?sorting=popular",
"#class" : artstation.ArtstationChallengeExtractor,
"#range" : "1-30",
"#count" : 30,
"challenge": {
"id" : 23,
"headline" : "Imagining Where Future Humans Live",
"created_at": "2017-06-26T14:45:43+00:00",
"contest" : {
"archived" : True,
"published": True,
"slug" : "beyond-human",
"title" : "Beyond Human",
"submissions_count": 4258,
},
},
},
{