Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance Video Download and Batch Save Capabilities #5

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ python3 -m vistopia.main --token [token] [subcommand]
- `search`: 搜索节目
- `subscriptions`: 列出所有已订阅节目
- `show-content`: 节目章节信息
- `save-show`: 保存节目至本地,并添加封面和 ID3 信息
- `save-show`: 保存节目至本地,并添加封面和 ID3 信息(安装 ffmpeg 后可保存视频节目)
- `save-transcript`: 保存节目文稿至本地
- `batch-save`: 批量保存专辑节目及文稿

### 使用 SingleFile 将文稿网页保存为纯本地文件

Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ authors = [{ name = "Chenxing Luo", email = "[email protected]" }]
readme = "README.md"
license = { file = "LICENSE" }
dynamic = ["version"]
dependencies = ["requests", "mutagen", "click", "tabulate", "wcwidth"]
dependencies = ["requests", "mutagen", "click", "tabulate", "wcwidth", "pathvalidate"]
requires-python = ">=3.6"

[project.scripts]
Expand All @@ -17,4 +17,4 @@ Repository = "https://github.com/chazeon/python-vistopia.git"
include = ["vistopia"]

[tool.setuptools.dynamic]
version = {attr = "vistopia.__version__"}
version = {attr = "vistopia.__version__"}
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ mutagen
click
tabulate
wcwidth
pathvalidate
54 changes: 54 additions & 0 deletions vistopia/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,63 @@ def show_content(ctx: click.Context, **argv):
article["duration_str"],
))

click.echo(f"Title: {catalog['title']}")
click.echo(f"Author: {catalog['author']}")
click.echo(f"Type: {catalog['type']}")
click.echo(tabulate(table))


@main.command("batch-save", help="批量下载专辑节目及文稿")
@click.option("--id", required=True, help="Show ID in the form '1-3,4,8'")
@click.option("--single-file-exec-path", type=click.Path(),
help="Path to the single-file CLI tool")
@click.option("--cookie-file-path", type=click.Path(),
help=(
"Path to the browser cookie file "
"(only needed in single-file mode)"))
@click.pass_context
def batch_save(ctx: click.Context, **argv):
visitor: Visitor = ctx.obj.visitor

album_id = argv.pop("id")
single_file_exec_path = argv.pop("single_file_exec_path")
cookie_file_path = argv.pop("cookie_file_path")

albums = set(range_expand(album_id) if album_id else [])
logger.debug(f"albums: {albums}")

for content_id in albums:
logger.debug(f"album: {content_id}")
logger.debug(visitor.get_content_show(content_id))
logger.debug(json.dumps(
visitor.get_catalog(content_id), indent=2, ensure_ascii=False))

catalog = visitor.get_catalog(content_id)
if catalog is None or catalog["type"] == "free":
continue
print(f"Saving show: [{content_id}]-{catalog['title']}")

ctx.obj.visitor.save_show(
content_id,
no_tag=False,
episodes=None
)

if single_file_exec_path and cookie_file_path:
ctx.obj.visitor.save_transcript_with_single_file(
content_id,
episodes=None,
single_file_exec_path=single_file_exec_path,
cookie_file_path=cookie_file_path
)
else:
ctx.obj.visitor.save_transcript(
content_id,
episodes=None
)
return


@main.command("save-show", help="保存节目至本地,并添加封面和 ID3 信息")
@click.option("--id", type=click.INT, required=True)
@click.option("--no-tag", is_flag=True, default=False,
Expand Down
Loading
Loading