Skip to content

Commit

Permalink
[artstation] support video clips (#2566, #3309, #3911)
Browse files Browse the repository at this point in the history
- add 'videos' and 'previews' options
- fix 403 errors for video previews
  • Loading branch information
mikf committed Mar 3, 2024
1 parent 9828806 commit 1a9b9aa
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 17 deletions.
20 changes: 20 additions & 0 deletions docs/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1124,6 +1124,26 @@ Description
Limit the number of posts/projects to download.


extractor.artstation.previews
-----------------------------
Type
``bool``
Default
``false``
Description
Download video previews.


extractor.artstation.videos
---------------------------
Type
``bool``
Default
``true``
Description
Download video clips.


extractor.artstation.search.pro-first
-------------------------------------
Type
Expand Down
41 changes: 30 additions & 11 deletions gallery_dl/extractor/artstation.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,13 @@ def __init__(self, match):
self.user = match.group(1) or match.group(2)

def items(self):
data = self.metadata()

projects = self.projects()
videos = self.config("videos", True)
previews = self.config("previews", False)
external = self.config("external", False)
max_posts = self.config("max-posts")

data = self.metadata()
projects = self.projects()
if max_posts:
projects = itertools.islice(projects, max_posts)

Expand All @@ -45,24 +47,41 @@ def items(self):
asset["num"] = num
yield Message.Directory, asset

if adict["has_embedded_player"] and external:
if adict["has_embedded_player"]:
player = adict["player_embedded"]
url = (text.extr(player, 'src="', '"') or
text.extr(player, "src='", "'"))
if url and not url.startswith(self.root):
asset["extension"] = None
yield Message.Url, "ytdl:" + url, asset
if url.startswith(self.root):
# video clip hosted on artstation
if videos:
page = self.request(url).text
url = text.extr(page, ' src="', '"')
text.nameext_from_url(url, asset)
yield Message.Url, url, asset
elif url:
# external URL
if external:
asset["extension"] = "mp4"
yield Message.Url, "ytdl:" + url, asset
else:
self.log.debug(player)
self.log.warning(
"Failed to extract embedded player URL (%s)",
adict.get("id"))

if not previews:
continue

if adict["has_image"]:
url = adict["image_url"]
text.nameext_from_url(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)
if "/video_clips/" not in url:
lhs, _, rhs = url.partition("/large/")
if rhs:
url = lhs + "/4k/" + rhs
asset["_fallback"] = self._image_fallback(lhs, rhs)

yield Message.Url, url, asset

Expand Down
25 changes: 19 additions & 6 deletions test/results/artstation.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,14 @@
"#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,
"active_projects_count" : 3,
"micro_square_image_url": "https://cdna.artstation.com/p/assets/images/images/005/131/434/micro_square/gaeri-kim-cat-front.jpg?1488720625",
"small_square_image_url": "https://cdna.artstation.com/p/assets/images/images/005/131/434/small_square/gaeri-kim-cat-front.jpg?1488720625",
},
"user": "mikf",
},
Expand All @@ -92,14 +92,14 @@
"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,
"active_projects_count" : int,
"micro_square_image_url": str,
"small_square_image_url": str,
},

{
Expand Down Expand Up @@ -156,6 +156,19 @@
"#count" : 4,
},

{
"#url" : "https://www.artstation.com/artwork/lR8b5k",
"#comment" : "artstation video clips (#2566)",
"#category": ("", "artstation", "image"),
"#class" : artstation.ArtstationImageExtractor,
"#options" : {"videos": True},
"#range" : "2-3",
"#urls" : (
"https://cdn.artstation.com/p/video_sources/000/819/843/infection-4.mp4",
"https://cdn.artstation.com/p/video_sources/000/819/725/infection-veinonly-2.mp4",
),
},

{
"#url" : "https://www.artstation.com/artwork/g4WPK",
"#comment" : "embedded youtube video",
Expand Down

0 comments on commit 1a9b9aa

Please sign in to comment.