Skip to content

Commit

Permalink
[behance] add 'modules' option (#4799)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikf committed Nov 17, 2023
1 parent 6a753d9 commit 07cb584
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 6 deletions.
13 changes: 13 additions & 0 deletions docs/configuration.rst
Expand Up @@ -1110,6 +1110,19 @@ Description
The maximum possible value appears to be ``1920``.


extractor.behance.modules
-------------------------
Type
``list`` of ``strings``
Default
``["image", "video", "mediacollection", "embed"]``
Description
Selects which gallery modules to download from.

Supported module types are
``image``, ``video``, ``mediacollection``, ``embed``, ``text``.


extractor.blogger.videos
------------------------
Type
Expand Down
27 changes: 21 additions & 6 deletions gallery_dl/extractor/behance.py
Expand Up @@ -89,6 +89,17 @@ def __init__(self, match):
BehanceExtractor.__init__(self, match)
self.gallery_id = match.group(1)

def _init(self):
BehanceExtractor._init(self)

modules = self.config("modules")
if modules:
if isinstance(modules, str):
modules = modules.split(",")
self.modules = set(modules)
else:
self.modules = {"image", "video", "mediacollection", "embed"}

def items(self):
data = self.get_gallery_data()
imgs = self.get_images(data)
Expand Down Expand Up @@ -134,13 +145,17 @@ def get_images(self, data):
append = result.append

for module in data["modules"]:
mtype = module["__typename"]
mtype = module["__typename"][:-6].lower()

if mtype not in self.modules:
self.log.debug("Skipping '%s' module", mtype)
continue

if mtype == "ImageModule":
if mtype == "image":
url = module["imageSizes"]["size_original"]["url"]
append((url, module))

elif mtype == "VideoModule":
elif mtype == "video":
try:
renditions = module["videoData"]["renditions"]
except Exception:
Expand All @@ -159,7 +174,7 @@ def get_images(self, data):

append((url, module))

elif mtype == "MediaCollectionModule":
elif mtype == "mediacollection":
for component in module["components"]:
for size in component["imageSizes"].values():
if size:
Expand All @@ -168,14 +183,14 @@ def get_images(self, data):
append(("/".join(parts), module))
break

elif mtype == "EmbedModule":
elif mtype == "embed":
embed = module.get("originalEmbed") or module.get("fluidEmbed")
if embed:
embed = text.unescape(text.extr(embed, 'src="', '"'))
module["extension"] = "mp4"
append(("ytdl:" + embed, module))

elif mtype == "TextModule":
elif mtype == "text":
module["extension"] = "txt"
append(("text:" + module["text"], module))

Expand Down
9 changes: 9 additions & 0 deletions test/results/behance.py
Expand Up @@ -63,6 +63,15 @@
"#count" : 3,
},

{
"#url" : "https://www.behance.net/gallery/89270715/Moevir",
"#comment" : "'text' modules (#4799)",
"#category": ("", "behance", "gallery"),
"#class" : behance.BehanceGalleryExtractor,
"#options" : {"modules": "text"},
"#urls" : """text:<div>Make Shift<br><a href="https://www.moevir.com/News/make-shif?fbclid=IwAR2MXL7mVDskdXHitLs4tv_RQFqB1tpAYix2EMIzea4lOSIPdPOR45wEJMA" target="_blank" rel="nofollow">https://www.moevir.com/News/make-shif</a><br>Moevir Magazine November Issue 2019<br>Photography by Caesar Lima @caephoto <br>Model: Bee @phamhuongbee <br>Makeup by Monica Alvarez @monicaalvarezmakeup <br>Styling by Jessica Boal @jessicaboal <br>Hair by James Gilbert @brandnewjames<br>Shot at Vila Sophia<br></div>""",
},

{
"#url" : "https://www.behance.net/gallery/177464639/Kimori",
"#comment" : "mature content (#4417)",
Expand Down

0 comments on commit 07cb584

Please sign in to comment.