Skip to content

Commit eb66e57

Browse files
NanmiCoderclaude
andcommitted
feat(cmd): add --headless, --specified_id, --creator_id CLI options
- Add --headless option to control headless mode for Playwright and CDP - Add --specified_id option for detail mode video/post IDs (comma-separated) - Add --creator_id option for creator mode IDs (comma-separated) - Auto-configure platform-specific ID lists (XHS, Bilibili, Douyin, Weibo, Kuaishou) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent a893055 commit eb66e57

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed

cmd_arg/arg.py

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,15 @@ def main(
197197
show_default=True,
198198
),
199199
] = str(config.ENABLE_GET_SUB_COMMENTS),
200+
headless: Annotated[
201+
str,
202+
typer.Option(
203+
"--headless",
204+
help="是否启用无头模式(对 Playwright 和 CDP 均生效),支持 yes/true/t/y/1 或 no/false/f/n/0",
205+
rich_help_panel="运行配置",
206+
show_default=True,
207+
),
208+
] = str(config.HEADLESS),
200209
save_data_option: Annotated[
201210
SaveDataOptionEnum,
202211
typer.Option(
@@ -223,13 +232,34 @@ def main(
223232
rich_help_panel="账号配置",
224233
),
225234
] = config.COOKIES,
235+
specified_id: Annotated[
236+
str,
237+
typer.Option(
238+
"--specified_id",
239+
help="详情模式下的帖子/视频ID列表,多个ID用逗号分隔(支持完整URL或ID)",
240+
rich_help_panel="基础配置",
241+
),
242+
] = "",
243+
creator_id: Annotated[
244+
str,
245+
typer.Option(
246+
"--creator_id",
247+
help="创作者模式下的创作者ID列表,多个ID用逗号分隔(支持完整URL或ID)",
248+
rich_help_panel="基础配置",
249+
),
250+
] = "",
226251
) -> SimpleNamespace:
227252
"""MediaCrawler 命令行入口"""
228253

229254
enable_comment = _to_bool(get_comment)
230255
enable_sub_comment = _to_bool(get_sub_comment)
256+
enable_headless = _to_bool(headless)
231257
init_db_value = init_db.value if init_db else None
232258

259+
# Parse specified_id and creator_id into lists
260+
specified_id_list = [id.strip() for id in specified_id.split(",") if id.strip()] if specified_id else []
261+
creator_id_list = [id.strip() for id in creator_id.split(",") if id.strip()] if creator_id else []
262+
233263
# override global config
234264
config.PLATFORM = platform.value
235265
config.LOGIN_TYPE = lt.value
@@ -238,9 +268,36 @@ def main(
238268
config.KEYWORDS = keywords
239269
config.ENABLE_GET_COMMENTS = enable_comment
240270
config.ENABLE_GET_SUB_COMMENTS = enable_sub_comment
271+
config.HEADLESS = enable_headless
272+
config.CDP_HEADLESS = enable_headless
241273
config.SAVE_DATA_OPTION = save_data_option.value
242274
config.COOKIES = cookies
243275

276+
# Set platform-specific ID lists for detail/creator mode
277+
if specified_id_list:
278+
if platform == PlatformEnum.XHS:
279+
config.XHS_SPECIFIED_NOTE_URL_LIST = specified_id_list
280+
elif platform == PlatformEnum.BILIBILI:
281+
config.BILI_SPECIFIED_ID_LIST = specified_id_list
282+
elif platform == PlatformEnum.DOUYIN:
283+
config.DY_SPECIFIED_ID_LIST = specified_id_list
284+
elif platform == PlatformEnum.WEIBO:
285+
config.WEIBO_SPECIFIED_ID_LIST = specified_id_list
286+
elif platform == PlatformEnum.KUAISHOU:
287+
config.KS_SPECIFIED_ID_LIST = specified_id_list
288+
289+
if creator_id_list:
290+
if platform == PlatformEnum.XHS:
291+
config.XHS_CREATOR_ID_LIST = creator_id_list
292+
elif platform == PlatformEnum.BILIBILI:
293+
config.BILI_CREATOR_ID_LIST = creator_id_list
294+
elif platform == PlatformEnum.DOUYIN:
295+
config.DY_CREATOR_ID_LIST = creator_id_list
296+
elif platform == PlatformEnum.WEIBO:
297+
config.WEIBO_CREATOR_ID_LIST = creator_id_list
298+
elif platform == PlatformEnum.KUAISHOU:
299+
config.KS_CREATOR_ID_LIST = creator_id_list
300+
244301
return SimpleNamespace(
245302
platform=config.PLATFORM,
246303
lt=config.LOGIN_TYPE,
@@ -249,9 +306,12 @@ def main(
249306
keywords=config.KEYWORDS,
250307
get_comment=config.ENABLE_GET_COMMENTS,
251308
get_sub_comment=config.ENABLE_GET_SUB_COMMENTS,
309+
headless=config.HEADLESS,
252310
save_data_option=config.SAVE_DATA_OPTION,
253311
init_db=init_db_value,
254312
cookies=config.COOKIES,
313+
specified_id=specified_id,
314+
creator_id=creator_id,
255315
)
256316

257317
command = typer.main.get_command(app)

0 commit comments

Comments
 (0)