feat: use click-option-group

This commit is contained in:
OverflowCat 2023-08-10 03:32:45 +08:00
parent d4f61dc3f3
commit ba180b530f
4 changed files with 104 additions and 13 deletions

View File

@ -4,7 +4,34 @@ from biliarchiver.cli_tools.down_command import down
from biliarchiver.cli_tools.get_command import get
@click.group()
class HelpCommand(click.Group):
def format_help(self, ctx, formatter):
click.echo(
"""
<_-^-_>
<%&&&&&&&&&&&&&&&&&&&&%*>
<&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&> > __ __ __ __ <
/<&&&> <&&&>/ .<&&&> <&&&> > / / /_/ / / /_/ <
(<&&&>,(/(/<&&&>%(/(/(/(<&&&>(/(// <&&&> > / /_ __ / / __ <
%<&&&>(( <&&&#> <#&&&> (((<&&&(> > / __ \ / / / / / / <
<&&&&>/* <&&&#>, .<#&&&> .//<&&&(> > / /_/ / / / / / / / __ __ <
<&&&&>(* ,(<&&&#>% %<#&&&>%( ((<&&&(> > /_.___/ /_/ /_/ /_/ / / /_/ <
<&&&&>/* .<&&&#> <#&&&>% (/<&&&(> > ____ _ ____ _____ / /_ __ _ __ ___ ____ <
(<&&&>(* <&&&>#,,-w-,#<&&&> ((<&&&(> > / __ `/ / __/ / ___/ / __ \ / / | | / / / _ \ / __/ <
(<&&&>/* <&&&>, <&&&> .//<&&&)> > / /_/ / / / / /__ / / / / / / | |/ / / __/ / / <
<&&&>((/((<&&&>((((((((<&&&>(((/((<&&&> > \__,_/ /_/ \___/ /_/ /_/ /_/ |___/ \___/ /_/ <
<&&&> ,,(<&&&> <&&&>(,, <&&&>
<&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&>
<&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&><""".replace(
"<", "\u001b[0m"
).replace(
">", "\u001b[96m"
),
)
click.echo(super().format_help(ctx, formatter))
@click.group(cls=HelpCommand)
def biliarchiver():
pass

View File

@ -7,6 +7,7 @@ from httpx import AsyncClient
import requests
import json
import click
from click_option_group import optgroup
from bilix.sites.bilibili import api
from rich import print
@ -260,14 +261,16 @@ async def by_favlist(url_or_fid: str):
async def main(
series: str,
ranking: str,
rid: str,
up_videos: str,
popular_precious: bool,
popular_series: bool,
popular_series_number: int,
all_popular_series: bool,
favlist: str,
):
if ranking:
by_ranking(ranking)
by_ranking(rid)
if up_videos:
await by_up_videos(up_videos)
if popular_precious:
@ -303,20 +306,61 @@ class URLorIntParamType(click.ParamType):
@click.command(help=click.style("批量获取 BV 号", fg="cyan"))
@click.option("--series", help="获取合集或视频列表内视频", type=URLorIntParamType("sid"))
@click.option(
@optgroup.group("合集")
@optgroup.option(
"--series", help=click.style("合集或视频列表内视频", fg="red"), type=URLorIntParamType("sid")
)
@optgroup.group("排行榜")
@optgroup.option(
"--ranking",
help="""排行榜全站榜非个性推荐榜。0 为全站排行榜。rid 等于分区的 tid。""",
type=URLorIntParamType("rid"),
"-r",
help=click.style("排行榜(全站榜,非个性推荐榜)", fg="yellow"),
is_flag=True,
)
@optgroup.option(
"--rid",
"--ranking-id",
default=0,
show_default=True,
help=click.style("目标排行 rid0 为全站排行榜。rid 等于分区的 tid", fg="yellow"),
type=int,
)
@click.option("--up-videos", help="UP 主用户页投稿", type=URLorIntParamType("mid"))
@click.option("--popular-precious", help="入站必刷,更新频率低", is_flag=True)
@click.option(
"--popular-series", help="每周必看每周五晚18:00更新", type=int, default=1, show_default=True
@optgroup.group("UP 主")
@optgroup.option(
"--up-videos",
"-u",
help=click.style("UP 主用户页投稿", fg="cyan"),
type=URLorIntParamType("mid"),
)
@optgroup.group("入站必刷")
@optgroup.option(
"--popular-precious", help=click.style("入站必刷,更新频率低", fg="bright_red"), is_flag=True
)
@optgroup.group("每周必看")
@optgroup.option(
"--popular-series",
"-p",
help=click.style("每周必看,每周五晚 18:00 更新", fg="magenta"),
is_flag=True,
)
@optgroup.option(
"--popular-series-number",
default=1,
type=int,
show_default=True,
help=click.style("获取第几期(周)", fg="magenta"),
)
@optgroup.option(
"--all-popular-series",
help=click.style("自动获取全部的每周必看(增量)", fg="magenta"),
is_flag=True,
)
@optgroup.group("收藏夹")
@optgroup.option(
"--favlist", help=click.style("收藏夹", fg="green"), type=URLorIntParamType("fid")
)
@click.option("--all-popular-series", help="自动获取全部的每周必看(增量)", is_flag=True)
@click.option("--favlist", help="收藏夹", type=URLorIntParamType("fid"))
def get(**kwargs):
if not any(kwargs.values()):
click.echo(get.get_help(click.Context(get)))
return
asyncio.run(main(**kwargs))

21
poetry.lock generated
View File

@ -217,6 +217,25 @@ files = [
[package.dependencies]
colorama = {version = "*", markers = "platform_system == \"Windows\""}
[[package]]
name = "click-option-group"
version = "0.5.6"
description = "Option groups missing in Click"
optional = false
python-versions = ">=3.6,<4"
files = [
{file = "click-option-group-0.5.6.tar.gz", hash = "sha256:97d06703873518cc5038509443742b25069a3c7562d1ea72ff08bfadde1ce777"},
{file = "click_option_group-0.5.6-py3-none-any.whl", hash = "sha256:38a26d963ee3ad93332ddf782f9259c5bdfe405e73408d943ef5e7d0c3767ec7"},
]
[package.dependencies]
Click = ">=7.0,<9"
[package.extras]
docs = ["Pallets-Sphinx-Themes", "m2r2", "sphinx"]
tests = ["pytest"]
tests-cov = ["coverage", "coveralls", "pytest", "pytest-cov"]
[[package]]
name = "colorama"
version = "0.4.6"
@ -928,4 +947,4 @@ zstd = ["zstandard (>=0.18.0)"]
[metadata]
lock-version = "2.0"
python-versions = "^3.9"
content-hash = "e8531f61b2a71d84b258dee3d741822f1eff73b22aa7658e9b4505d9bdad3b64"
content-hash = "e4300e1d250f776c84a8b16a34ad793d919c4f896370cdd258e33721990ed78a"

View File

@ -13,6 +13,7 @@ internetarchive = "^3.5.0"
danmakuc = "^0.3.6"
browser-cookie3 = "^0.19.1"
click = "^8.1.6"
click-option-group = "^0.5.6"
[tool.poetry.scripts]
biliarchiver = "biliarchiver.cli_tools.biliarchiver:biliarchiver"