[chzzk] add 'comment' and 'community' extractors (#7735 #7741)

* [chzzk] add 'comment' and 'community' extractors
* [chzzk] update
* [chzzk] add tests
* [chzzk] update docs/supportedsites
* [chzzk] add 'offset' option
* [docs] add 'offset' option to gallery-dl.conf
This commit is contained in:
enduser420
2025-06-28 18:57:19 +05:30
committed by GitHub
parent c8e4a2f8d1
commit f77e98b57d
6 changed files with 184 additions and 1 deletions

View File

@@ -38,6 +38,7 @@ modules = [
"bunkr",
"catbox",
"chevereto",
"chzzk",
"cien",
"civitai",
"comick",

View File

@@ -0,0 +1,81 @@
# -*- coding: utf-8 -*-
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 as
# published by the Free Software Foundation.
"""Extractors for https://chzzk.naver.com"""
from .common import Extractor, Message
from .. import text, util
class ChzzkExtractor(Extractor):
"""Base class for chzzk extractors"""
category = "chzzk"
filename_fmt = "{uid}_{id}_{num}.{extension}"
directory_fmt = ("{category}", "{user[userNickname]}")
archive_fmt = "{uid}_{id}_{num}"
def request_api(self, uid, id=None, params=None):
return self.request_json(
f"https://apis.naver.com/nng_main/nng_comment_api/v1/type"
f"/CHANNEL_POST/id/{uid}/comments/{id or ''}",
params=params)["content"]
def items(self):
for comment in self.comments():
data = comment["comment"]
files = data.pop("attaches") or ()
data["id"] = data["commentId"]
data["uid"] = data["objectId"]
data["user"] = comment["user"]
data["count"] = len(files)
data["date"] = text.parse_datetime(
data["createdDate"], "%Y%m%d%H%M%S")
yield Message.Directory, data
for data["num"], file in enumerate(files, 1):
if extra := file.get("extraJson"):
file.update(util.json_loads(extra))
file["date"] = text.parse_datetime(
file["createdDate"], "%Y-%m-%dT%H:%M:%S.%f%z")
file["date_updated"] = text.parse_datetime(
file["updatedDate"], "%Y-%m-%dT%H:%M:%S.%f%z")
data["file"] = file
url = file["attachValue"]
yield Message.Url, url, text.nameext_from_url(url, data)
class ChzzkCommentExtractor(ChzzkExtractor):
"""Extractor for individual comment from chzzk.naver.com"""
subcategory = "comment"
pattern = r"(?:https?://)?chzzk\.naver\.com/(\w+)/community/detail/(\d+)"
example = "https://chzzk.naver.com/0123456789abcdef/community/detail/12345"
def comments(self):
uid, id = self.groups
res = self.request_api(uid, id)
return ({"comment": res["comment"], "user": res["user"]},)
class ChzzkCommunityExtractor(ChzzkExtractor):
"""Extractor for comments from chzzk.naver.com"""
subcategory = "community"
pattern = r"(?:https?://)?chzzk\.naver\.com/(\w+)/community"
example = "https://chzzk.naver.com/0123456789abcdef/community"
request_interval = (0.5, 1.5)
def comments(self):
uid = self.match[1]
params = {
"limit": 10,
"offset": text.parse_int(self.config("offset")),
"pagingType": "PAGE",
}
while True:
comments = self.request_api(uid, params=params)["comments"]
yield from comments["data"]
if not comments["page"]["next"]:
return
params["offset"] += params["limit"]