From 7f6a53c3475f357bd0c77a95b94bb91bcf81f9b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20F=C3=A4hrmann?= Date: Sat, 14 Dec 2024 20:16:28 +0100 Subject: [PATCH] [cohost] add 'avatar' and 'background' options (#6656) --- docs/configuration.rst | 20 ++++++++++++++++++++ docs/gallery-dl.conf | 2 ++ gallery_dl/extractor/cohost.py | 30 +++++++++++++++++++++++++++++- test/results/cohost.py | 12 ++++++++++++ 4 files changed, 63 insertions(+), 1 deletion(-) diff --git a/docs/configuration.rst b/docs/configuration.rst index f4ff7aab5f..a35968abfa 100644 --- a/docs/configuration.rst +++ b/docs/configuration.rst @@ -1755,6 +1755,26 @@ Description Extract ``ask`` posts. +extractor.cohost.avatar +----------------------- +Type + ``bool`` +Default + ``false`` +Description + Download ``avatar`` images. + + +extractor.cohost.background +--------------------------- +Type + ``bool`` +Default + ``false`` +Description + Download ``background``/``banner``/``header`` images. + + extractor.cohost.pinned ----------------------- Type diff --git a/docs/gallery-dl.conf b/docs/gallery-dl.conf index 4dc2e14e67..3d7386981c 100644 --- a/docs/gallery-dl.conf +++ b/docs/gallery-dl.conf @@ -176,6 +176,8 @@ "cohost": { "asks" : true, + "avatar" : false, + "background": false, "pinned" : false, "replies": true, "shares" : true diff --git a/gallery_dl/extractor/cohost.py b/gallery_dl/extractor/cohost.py index 0524239b4f..6a43224d2b 100644 --- a/gallery_dl/extractor/cohost.py +++ b/gallery_dl/extractor/cohost.py @@ -19,7 +19,7 @@ class CohostExtractor(Extractor): category = "cohost" root = "https://cohost.org" directory_fmt = ("{category}", "{postingProject[handle]}") - filename_fmt = ("{postId}_{headline:?/_/[b:200]}{num}.{extension}") + filename_fmt = ("{postId}{headline:?_//[b:200]}{num:?_//}.{extension}") archive_fmt = "{postId}_{num}" def _init(self): @@ -28,6 +28,14 @@ def _init(self): self.shares = self.config("shares", False) self.asks = self.config("asks", True) + self.avatar = self.config("avatar", False) + if self.avatar: + self._urls_avatar = {None, ""} + + self.background = self.config("background", False) + if self.background: + self._urls_background = {None, ""} + def items(self): for post in self.posts(): reason = post.get("limitedVisibilityReason") @@ -43,6 +51,26 @@ def items(self): post["publishedAt"], "%Y-%m-%dT%H:%M:%S.%fZ") yield Message.Directory, post + + project = post["postingProject"] + if self.avatar: + url = project.get("avatarURL") + if url not in self._urls_avatar: + self._urls_avatar.add(url) + p = post.copy() + p["postId"] = p["kind"] = "avatar" + p["headline"] = p["num"] = "" + yield Message.Url, url, text.nameext_from_url(url, p) + + if self.background: + url = project.get("headerURL") + if url not in self._urls_background: + self._urls_background.add(url) + p = post.copy() + p["postId"] = p["kind"] = "background" + p["headline"] = p["num"] = "" + yield Message.Url, url, text.nameext_from_url(url, p) + for post["num"], file in enumerate(files, 1): url = file["fileURL"] post.update(file) diff --git a/test/results/cohost.py b/test/results/cohost.py index 1184f21c0d..aaef294226 100644 --- a/test/results/cohost.py +++ b/test/results/cohost.py @@ -16,6 +16,18 @@ "#count" : 20, }, +{ + "#url" : "https://cohost.org/infinitebrians", + "#category": ("", "cohost", "user"), + "#class" : cohost.CohostUserExtractor, + "#options" : {"avatar": True, "background": True}, + "#range" : "1-2", + "#urls" : ( + "https://staging.cohostcdn.org/avatar/3281-abb43502-4c48-407d-9778-2bed7722d3d7-profile.gif", + "https://staging.cohostcdn.org/header/3281-b29dbf4d-45b2-417b-b03b-0f7f07595e66-profile.png", + ), +}, + { "#url" : "https://cohost.org/infinitebrians/post/4957017-thank-you-akira-tori", "#category": ("", "cohost", "post"),