Skip to content

Commit

Permalink
chore: CRLF to LR
Browse files Browse the repository at this point in the history
  • Loading branch information
yzqzss committed Jun 15, 2024
1 parent 729f035 commit ca0c726
Show file tree
Hide file tree
Showing 9 changed files with 380 additions and 379 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* text=auto eol=lf
14 changes: 7 additions & 7 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"recommendations": [
"charliermarsh.ruff",
"tamasfe.even-better-toml",
"esbenp.prettier-vscode"
]
}
{
"recommendations": [
"charliermarsh.ruff",
"tamasfe.even-better-toml",
"esbenp.prettier-vscode"
]
}
176 changes: 88 additions & 88 deletions biliarchiver/cli_tools/up_command.py
Original file line number Diff line number Diff line change
@@ -1,88 +1,88 @@
from io import TextIOWrapper
import click
import os

from biliarchiver.cli_tools.utils import read_bvids
from biliarchiver.i18n import _


DEFAULT_COLLECTION = "opensource_movies"
"""
开放 collection ,任何人均可上传。
通过 biliarchiver 上传的 item 会在24小时内被自动转移到 bilibili_videos collection
"""
"""
An open collection. Anyone can upload.
Items uploaded by biliarchiver will be automatically moved to bilibili_videos collection within 24 hours.
"""

BILIBILI_VIDEOS_COLLECTION = "bilibili_videos"
""" 由 arkiver 管理。bilibili_videos 属于 social-media-video 的子集 """
""" Managed by arkiver. bilibili_videos is a subset of social-media-video """

BILIBILI_VIDEOS_SUB_1_COLLECTION = "bilibili_videos_sub_1"
""" 由 yzqzss 管理。属于 bilibili_videos 的子集 """
""" Managed by yzqzss. A subset of bilibili_videos """


@click.command(help=click.style(_("上传至互联网档案馆"), fg="cyan"))
@click.option("--bvids", "-i", type=click.STRING, default=None, help=_("bvids 列表的文件路径"))
@click.option(
"--by-storage-home-dir",
"-a",
is_flag=True,
default=False,
help=_("使用 `$storage_home_dir/videos` 目录下的所有视频"),
)
@click.option(
"--update-existing", "-u", is_flag=True, default=False, help=_("更新已存在的 item")
)
@click.option(
"--collection",
"-c",
default=DEFAULT_COLLECTION,
type=click.Choice(
[
DEFAULT_COLLECTION,
BILIBILI_VIDEOS_COLLECTION,
BILIBILI_VIDEOS_SUB_1_COLLECTION,
]
),
help=_("欲上传至的 collection. (非默认值仅限 collection 管理员使用)")
+ f" [default: {DEFAULT_COLLECTION}]",
)
@click.option(
"--delete-after-upload",
"-d",
is_flag=True,
default=False,
help=_("上传后删除视频文件"),
)
def up(
bvids: TextIOWrapper,
by_storage_home_dir: bool,
update_existing: bool,
collection: str,
delete_after_upload: bool,
):
from biliarchiver._biliarchiver_upload_bvid import upload_bvid
from biliarchiver.config import config

ids = []

if by_storage_home_dir:
for bvid_with_upper_part in os.listdir(config.storage_home_dir / "videos"):
bvid = bvid_with_upper_part
if "-" in bvid_with_upper_part:
bvid = bvid_with_upper_part.split("-")[0]
ids.append(bvid)
elif bvids:
ids = read_bvids(bvids)

for id in ids:
upload_bvid(
id,
update_existing=update_existing,
collection=collection,
delete_after_upload=delete_after_upload,
)
from io import TextIOWrapper
import click
import os

from biliarchiver.cli_tools.utils import read_bvids
from biliarchiver.i18n import _


DEFAULT_COLLECTION = "opensource_movies"
"""
开放 collection ,任何人均可上传。
通过 biliarchiver 上传的 item 会在24小时内被自动转移到 bilibili_videos collection
"""
"""
An open collection. Anyone can upload.
Items uploaded by biliarchiver will be automatically moved to bilibili_videos collection within 24 hours.
"""

BILIBILI_VIDEOS_COLLECTION = "bilibili_videos"
""" 由 arkiver 管理。bilibili_videos 属于 social-media-video 的子集 """
""" Managed by arkiver. bilibili_videos is a subset of social-media-video """

BILIBILI_VIDEOS_SUB_1_COLLECTION = "bilibili_videos_sub_1"
""" 由 yzqzss 管理。属于 bilibili_videos 的子集 """
""" Managed by yzqzss. A subset of bilibili_videos """


@click.command(help=click.style(_("上传至互联网档案馆"), fg="cyan"))
@click.option("--bvids", "-i", type=click.STRING, default=None, help=_("bvids 列表的文件路径"))
@click.option(
"--by-storage-home-dir",
"-a",
is_flag=True,
default=False,
help=_("使用 `$storage_home_dir/videos` 目录下的所有视频"),
)
@click.option(
"--update-existing", "-u", is_flag=True, default=False, help=_("更新已存在的 item")
)
@click.option(
"--collection",
"-c",
default=DEFAULT_COLLECTION,
type=click.Choice(
[
DEFAULT_COLLECTION,
BILIBILI_VIDEOS_COLLECTION,
BILIBILI_VIDEOS_SUB_1_COLLECTION,
]
),
help=_("欲上传至的 collection. (非默认值仅限 collection 管理员使用)")
+ f" [default: {DEFAULT_COLLECTION}]",
)
@click.option(
"--delete-after-upload",
"-d",
is_flag=True,
default=False,
help=_("上传后删除视频文件"),
)
def up(
bvids: TextIOWrapper,
by_storage_home_dir: bool,
update_existing: bool,
collection: str,
delete_after_upload: bool,
):
from biliarchiver._biliarchiver_upload_bvid import upload_bvid
from biliarchiver.config import config

ids = []

if by_storage_home_dir:
for bvid_with_upper_part in os.listdir(config.storage_home_dir / "videos"):
bvid = bvid_with_upper_part
if "-" in bvid_with_upper_part:
bvid = bvid_with_upper_part.split("-")[0]
ids.append(bvid)
elif bvids:
ids = read_bvids(bvids)

for id in ids:
upload_bvid(
id,
update_existing=update_existing,
collection=collection,
delete_after_upload=delete_after_upload,
)
46 changes: 23 additions & 23 deletions biliarchiver/cli_tools/utils.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
from pathlib import Path
from biliarchiver.utils.identifier import is_bvid
from biliarchiver.i18n import _


def read_bvids(bvids: str) -> list[str]:
bvids_list = None

file = Path(bvids)
if file.exists() and file.is_file():
with open(file, "r", encoding="utf-8") as f:
bvids_list = f.read().split()
else:
bvids_list = bvids.split()

del bvids

for bvid in bvids_list:
assert is_bvid(bvid), _("bvid {} 不合法").format(bvid)

assert bvids_list is not None and len(bvids_list) > 0, _("bvids 为空")

return bvids_list
from pathlib import Path
from biliarchiver.utils.identifier import is_bvid
from biliarchiver.i18n import _


def read_bvids(bvids: str) -> list[str]:
bvids_list = None

file = Path(bvids)
if file.exists() and file.is_file():
with open(file, "r", encoding="utf-8") as f:
bvids_list = f.read().split()
else:
bvids_list = bvids.split()

del bvids

for bvid in bvids_list:
assert is_bvid(bvid), _("bvid {} 不合法").format(bvid)

assert bvids_list is not None and len(bvids_list) > 0, _("bvids 为空")

return bvids_list
40 changes: 20 additions & 20 deletions biliarchiver/i18n.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import gettext
import locale
from pathlib import Path
import warnings

default_lang, default_enc = locale.getdefaultlocale()
default_lang = default_lang or "en"
languages = ["en"] if not default_lang.lower().startswith("zh") else ["zh_CN"]
appname = "biliarchiver"

localedir = Path(__file__).parent / "locales"
if not localedir.exists():
warnings.warn("Locales directory not found, i18n will not work.", RuntimeWarning)

i18n = gettext.translation(
appname, localedir=localedir, fallback=True, languages=languages
)

_ = i18n.gettext
ngettext = i18n.ngettext
import gettext
import locale
from pathlib import Path
import warnings

default_lang, default_enc = locale.getdefaultlocale()
default_lang = default_lang or "en"
languages = ["en"] if not default_lang.lower().startswith("zh") else ["zh_CN"]
appname = "biliarchiver"

localedir = Path(__file__).parent / "locales"
if not localedir.exists():
warnings.warn("Locales directory not found, i18n will not work.", RuntimeWarning)

i18n = gettext.translation(
appname, localedir=localedir, fallback=True, languages=languages
)

_ = i18n.gettext
ngettext = i18n.ngettext
2 changes: 1 addition & 1 deletion biliarchiver/locales/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1 @@
*.mo
*.mo
Loading

0 comments on commit ca0c726

Please sign in to comment.