mirror of
https://github.com/NanmiCoder/MediaCrawler.git
synced 2026-02-06 23:21:33 +08:00
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>
This commit is contained in:
@@ -197,6 +197,15 @@ async def parse_cmd(argv: Optional[Sequence[str]] = None):
|
|||||||
show_default=True,
|
show_default=True,
|
||||||
),
|
),
|
||||||
] = str(config.ENABLE_GET_SUB_COMMENTS),
|
] = str(config.ENABLE_GET_SUB_COMMENTS),
|
||||||
|
headless: Annotated[
|
||||||
|
str,
|
||||||
|
typer.Option(
|
||||||
|
"--headless",
|
||||||
|
help="是否启用无头模式(对 Playwright 和 CDP 均生效),支持 yes/true/t/y/1 或 no/false/f/n/0",
|
||||||
|
rich_help_panel="运行配置",
|
||||||
|
show_default=True,
|
||||||
|
),
|
||||||
|
] = str(config.HEADLESS),
|
||||||
save_data_option: Annotated[
|
save_data_option: Annotated[
|
||||||
SaveDataOptionEnum,
|
SaveDataOptionEnum,
|
||||||
typer.Option(
|
typer.Option(
|
||||||
@@ -223,13 +232,34 @@ async def parse_cmd(argv: Optional[Sequence[str]] = None):
|
|||||||
rich_help_panel="账号配置",
|
rich_help_panel="账号配置",
|
||||||
),
|
),
|
||||||
] = config.COOKIES,
|
] = config.COOKIES,
|
||||||
|
specified_id: Annotated[
|
||||||
|
str,
|
||||||
|
typer.Option(
|
||||||
|
"--specified_id",
|
||||||
|
help="详情模式下的帖子/视频ID列表,多个ID用逗号分隔(支持完整URL或ID)",
|
||||||
|
rich_help_panel="基础配置",
|
||||||
|
),
|
||||||
|
] = "",
|
||||||
|
creator_id: Annotated[
|
||||||
|
str,
|
||||||
|
typer.Option(
|
||||||
|
"--creator_id",
|
||||||
|
help="创作者模式下的创作者ID列表,多个ID用逗号分隔(支持完整URL或ID)",
|
||||||
|
rich_help_panel="基础配置",
|
||||||
|
),
|
||||||
|
] = "",
|
||||||
) -> SimpleNamespace:
|
) -> SimpleNamespace:
|
||||||
"""MediaCrawler 命令行入口"""
|
"""MediaCrawler 命令行入口"""
|
||||||
|
|
||||||
enable_comment = _to_bool(get_comment)
|
enable_comment = _to_bool(get_comment)
|
||||||
enable_sub_comment = _to_bool(get_sub_comment)
|
enable_sub_comment = _to_bool(get_sub_comment)
|
||||||
|
enable_headless = _to_bool(headless)
|
||||||
init_db_value = init_db.value if init_db else None
|
init_db_value = init_db.value if init_db else None
|
||||||
|
|
||||||
|
# Parse specified_id and creator_id into lists
|
||||||
|
specified_id_list = [id.strip() for id in specified_id.split(",") if id.strip()] if specified_id else []
|
||||||
|
creator_id_list = [id.strip() for id in creator_id.split(",") if id.strip()] if creator_id else []
|
||||||
|
|
||||||
# override global config
|
# override global config
|
||||||
config.PLATFORM = platform.value
|
config.PLATFORM = platform.value
|
||||||
config.LOGIN_TYPE = lt.value
|
config.LOGIN_TYPE = lt.value
|
||||||
@@ -238,9 +268,36 @@ async def parse_cmd(argv: Optional[Sequence[str]] = None):
|
|||||||
config.KEYWORDS = keywords
|
config.KEYWORDS = keywords
|
||||||
config.ENABLE_GET_COMMENTS = enable_comment
|
config.ENABLE_GET_COMMENTS = enable_comment
|
||||||
config.ENABLE_GET_SUB_COMMENTS = enable_sub_comment
|
config.ENABLE_GET_SUB_COMMENTS = enable_sub_comment
|
||||||
|
config.HEADLESS = enable_headless
|
||||||
|
config.CDP_HEADLESS = enable_headless
|
||||||
config.SAVE_DATA_OPTION = save_data_option.value
|
config.SAVE_DATA_OPTION = save_data_option.value
|
||||||
config.COOKIES = cookies
|
config.COOKIES = cookies
|
||||||
|
|
||||||
|
# Set platform-specific ID lists for detail/creator mode
|
||||||
|
if specified_id_list:
|
||||||
|
if platform == PlatformEnum.XHS:
|
||||||
|
config.XHS_SPECIFIED_NOTE_URL_LIST = specified_id_list
|
||||||
|
elif platform == PlatformEnum.BILIBILI:
|
||||||
|
config.BILI_SPECIFIED_ID_LIST = specified_id_list
|
||||||
|
elif platform == PlatformEnum.DOUYIN:
|
||||||
|
config.DY_SPECIFIED_ID_LIST = specified_id_list
|
||||||
|
elif platform == PlatformEnum.WEIBO:
|
||||||
|
config.WEIBO_SPECIFIED_ID_LIST = specified_id_list
|
||||||
|
elif platform == PlatformEnum.KUAISHOU:
|
||||||
|
config.KS_SPECIFIED_ID_LIST = specified_id_list
|
||||||
|
|
||||||
|
if creator_id_list:
|
||||||
|
if platform == PlatformEnum.XHS:
|
||||||
|
config.XHS_CREATOR_ID_LIST = creator_id_list
|
||||||
|
elif platform == PlatformEnum.BILIBILI:
|
||||||
|
config.BILI_CREATOR_ID_LIST = creator_id_list
|
||||||
|
elif platform == PlatformEnum.DOUYIN:
|
||||||
|
config.DY_CREATOR_ID_LIST = creator_id_list
|
||||||
|
elif platform == PlatformEnum.WEIBO:
|
||||||
|
config.WEIBO_CREATOR_ID_LIST = creator_id_list
|
||||||
|
elif platform == PlatformEnum.KUAISHOU:
|
||||||
|
config.KS_CREATOR_ID_LIST = creator_id_list
|
||||||
|
|
||||||
return SimpleNamespace(
|
return SimpleNamespace(
|
||||||
platform=config.PLATFORM,
|
platform=config.PLATFORM,
|
||||||
lt=config.LOGIN_TYPE,
|
lt=config.LOGIN_TYPE,
|
||||||
@@ -249,9 +306,12 @@ async def parse_cmd(argv: Optional[Sequence[str]] = None):
|
|||||||
keywords=config.KEYWORDS,
|
keywords=config.KEYWORDS,
|
||||||
get_comment=config.ENABLE_GET_COMMENTS,
|
get_comment=config.ENABLE_GET_COMMENTS,
|
||||||
get_sub_comment=config.ENABLE_GET_SUB_COMMENTS,
|
get_sub_comment=config.ENABLE_GET_SUB_COMMENTS,
|
||||||
|
headless=config.HEADLESS,
|
||||||
save_data_option=config.SAVE_DATA_OPTION,
|
save_data_option=config.SAVE_DATA_OPTION,
|
||||||
init_db=init_db_value,
|
init_db=init_db_value,
|
||||||
cookies=config.COOKIES,
|
cookies=config.COOKIES,
|
||||||
|
specified_id=specified_id,
|
||||||
|
creator_id=creator_id,
|
||||||
)
|
)
|
||||||
|
|
||||||
command = typer.main.get_command(app)
|
command = typer.main.get_command(app)
|
||||||
|
|||||||
Reference in New Issue
Block a user