mirror of
https://github.com/saveweb/biliarchiver.git
synced 2024-09-19 11:05:28 -07:00
fix: use click.File()
This commit is contained in:
parent
447399361b
commit
d4f61dc3f3
@ -178,7 +178,7 @@ def _upload_bvid(bvid: str, *, update_existing: bool = False, collection: str):
|
||||
md = xml_chars_legalize(obj=md)
|
||||
assert isinstance(md, dict)
|
||||
if hash(json.dumps(md)) != _md_before:
|
||||
print(f"Removed XML illegal characters from metadata, cleaned metadata:")
|
||||
print("Removed XML illegal characters from metadata, cleaned metadata:")
|
||||
print(md)
|
||||
|
||||
if filedict:
|
||||
@ -212,7 +212,7 @@ def _upload_bvid(bvid: str, *, update_existing: bool = False, collection: str):
|
||||
if item.metadata.get("external-identifier") != md['external-identifier']:
|
||||
new_md["external-identifier"] = md['external-identifier']
|
||||
if new_md:
|
||||
print(f"Updating metadata:")
|
||||
print("Updating metadata:")
|
||||
print(new_md)
|
||||
|
||||
# remove XML illegal characters
|
||||
@ -220,7 +220,7 @@ def _upload_bvid(bvid: str, *, update_existing: bool = False, collection: str):
|
||||
new_md = xml_chars_legalize(obj=new_md)
|
||||
assert isinstance(new_md, dict)
|
||||
if hash(json.dumps(new_md)) != _md_before:
|
||||
print(f"Removed XML illegal characters from metadata, cleaned metadata:")
|
||||
print("Removed XML illegal characters from metadata, cleaned metadata:")
|
||||
print(new_md)
|
||||
|
||||
r = item.modify_metadata(
|
||||
|
@ -25,7 +25,7 @@ async def new_get_subtitle_info(client: httpx.AsyncClient, bvid, cid):
|
||||
res = await req_retry(client, 'https://api.bilibili.com/x/player/v2', params=params)
|
||||
info = json.loads(res.text)
|
||||
if info['code'] == -400:
|
||||
raise APIError(f'未找到字幕信息', params)
|
||||
raise APIError('未找到字幕信息', params)
|
||||
|
||||
# 这里 monkey patch 一下把返回 lan_doc 改成返回 lan,这样生成的字幕文件名就是 语言代码 而不是 中文名 了
|
||||
# 例如
|
||||
|
@ -1,8 +1,8 @@
|
||||
import asyncio
|
||||
from io import TextIOWrapper
|
||||
import os
|
||||
from pathlib import Path
|
||||
from typing import List, Union
|
||||
import click
|
||||
|
||||
from biliarchiver.archive_bvid import archive_bvid
|
||||
from biliarchiver.config import config
|
||||
@ -61,7 +61,7 @@ def check_ia_item_exist(client: Client, identifier: str) -> bool:
|
||||
|
||||
|
||||
def _down(
|
||||
bvids: click.File(),
|
||||
bvids: TextIOWrapper,
|
||||
skip_ia_check: bool,
|
||||
from_browser: str | None,
|
||||
min_free_space_gb: int,
|
||||
@ -69,9 +69,7 @@ def _down(
|
||||
):
|
||||
assert check_ffmpeg() is True, "ffmpeg 未安装"
|
||||
|
||||
assert bvids is not None, "必须指定 bvids 列表的文件路径"
|
||||
with open(bvids, "r", encoding="utf-8") as f:
|
||||
bvids_from_file = f.read().splitlines()
|
||||
bvids_from_file = bvids.read().splitlines()
|
||||
|
||||
check_outdated_version(
|
||||
pypi_project="biliarchiver", self_version=BILI_ARCHIVER_VERSION
|
||||
|
@ -1,10 +1,9 @@
|
||||
from genericpath import exists
|
||||
import click
|
||||
from rich.console import Console
|
||||
|
||||
|
||||
@click.command(help=click.style("从哔哩哔哩下载", fg="cyan"))
|
||||
@click.option("--bvids", required=True, type=str, help="bvids 列表的文件路径")
|
||||
@click.option("--bvids", type=click.File(), required=True, help="bvids 列表的文件路径")
|
||||
@click.option(
|
||||
"--skip-ia-check",
|
||||
"-s",
|
||||
@ -27,12 +26,8 @@ from rich.console import Console
|
||||
help="最小剩余空间 (GB),用超退出",
|
||||
show_default=True,
|
||||
)
|
||||
@click.option(
|
||||
"--skip", type=int, default=0, show_default=True, help="跳过文件开头 bvid 的个数"
|
||||
)
|
||||
def down(
|
||||
**kwargs
|
||||
):
|
||||
@click.option("--skip", type=int, default=0, show_default=True, help="跳过文件开头 bvid 的个数")
|
||||
def down(**kwargs):
|
||||
from biliarchiver.cli_tools.bili_archive_bvids import _down
|
||||
|
||||
try:
|
||||
|
@ -1,6 +1,8 @@
|
||||
from io import TextIOWrapper
|
||||
import click
|
||||
import os
|
||||
|
||||
|
||||
DEFAULT_COLLECTION = "opensource_movies"
|
||||
"""
|
||||
开放 collection ,任何人均可上传。
|
||||
@ -13,9 +15,7 @@ BILIBILI_VIDEOS_SUB_1_COLLECTION = "bilibili_videos_sub_1"
|
||||
|
||||
|
||||
@click.command(help=click.style("上传至互联网档案馆", fg="cyan"))
|
||||
@click.option(
|
||||
"--bvids", type=click.Path(exists=True), default=None, help="bvids 列表的文件路径"
|
||||
)
|
||||
@click.option("--bvids", type=click.File(), default=None, help="bvids 列表的文件路径")
|
||||
@click.option(
|
||||
"--by-storage-home-dir",
|
||||
is_flag=True,
|
||||
@ -35,7 +35,12 @@ BILIBILI_VIDEOS_SUB_1_COLLECTION = "bilibili_videos_sub_1"
|
||||
),
|
||||
help=f"Collection to upload to. (非默认值仅限 collection 管理员使用) [default: {DEFAULT_COLLECTION}]",
|
||||
)
|
||||
def up(bvids, by_storage_home_dir, update_existing, collection):
|
||||
def up(
|
||||
bvids: TextIOWrapper,
|
||||
by_storage_home_dir: bool,
|
||||
update_existing: bool,
|
||||
collection,
|
||||
):
|
||||
from biliarchiver._biliarchiver_upload_bvid import upload_bvid
|
||||
from biliarchiver.config import config
|
||||
|
||||
@ -49,8 +54,7 @@ def up(bvids, by_storage_home_dir, update_existing, collection):
|
||||
collection=collection)
|
||||
|
||||
elif bvids:
|
||||
with open(bvids, "r", encoding="utf-8") as f:
|
||||
bvids_from_file = f.read().splitlines()
|
||||
bvids_from_file = bvids.read().splitlines()
|
||||
for bvid in bvids_from_file:
|
||||
upload_bvid(bvid, update_existing=update_existing,
|
||||
collection=collection)
|
||||
|
@ -1,5 +1,4 @@
|
||||
import os
|
||||
import sys
|
||||
import importlib.util
|
||||
|
||||
class AlreadyRunningError(Exception):
|
||||
|
Loading…
Reference in New Issue
Block a user