mirror of
https://github.com/saveweb/biliarchiver.git
synced 2024-09-19 11:05:28 -07:00
自定义要上传到的 collection
This commit is contained in:
parent
3a7a74c179
commit
a456e4f1fa
@ -13,12 +13,12 @@ from biliarchiver.config import BILIBILI_IDENTIFIER_PERFIX, config
|
||||
from biliarchiver.utils.dirLock import UploadLock, AlreadyRunningError
|
||||
from biliarchiver.version import BILI_ARCHIVER_VERSION
|
||||
|
||||
def upload_bvid(bvid: str, *, update_existing: bool = False):
|
||||
def upload_bvid(bvid: str, *, update_existing: bool = False, collection: str):
|
||||
try:
|
||||
lock_dir = config.storage_home_dir / '.locks' / bvid
|
||||
os.makedirs(lock_dir, exist_ok=True)
|
||||
with UploadLock(lock_dir): # type: ignore
|
||||
_upload_bvid(bvid, update_existing=update_existing)
|
||||
_upload_bvid(bvid, update_existing=update_existing, collection=collection)
|
||||
except AlreadyRunningError:
|
||||
print(f'已经有一个上传 {bvid} 的进程在运行,跳过')
|
||||
except VideosBasePathNotFoundError:
|
||||
@ -27,7 +27,7 @@ def upload_bvid(bvid: str, *, update_existing: bool = False):
|
||||
print(f'上传 {bvid} 时出错:')
|
||||
raise e
|
||||
|
||||
def _upload_bvid(bvid: str, *, update_existing: bool = False):
|
||||
def _upload_bvid(bvid: str, *, update_existing: bool = False, collection: str):
|
||||
access_key, secret_key = read_ia_keys(config.ia_key_file)
|
||||
|
||||
# identifier format: BiliBili-{bvid}_p{pid}-{upper_part}
|
||||
@ -134,7 +134,7 @@ def _upload_bvid(bvid: str, *, update_existing: bool = False):
|
||||
|
||||
md = {
|
||||
"mediatype": "movies",
|
||||
"collection": 'opensource_movies',
|
||||
"collection": collection,
|
||||
"title": bv_info['data']['View']['title'] + f' P{pid} ' + p_part ,
|
||||
"description": remote_identifier + ' uploading...',
|
||||
'creator': creators if len(creators) > 1 else owner_creator, # type: list[str] | str
|
||||
|
@ -6,27 +6,40 @@ from pathlib import Path
|
||||
from biliarchiver._biliarchiver_upload_bvid import upload_bvid
|
||||
from biliarchiver.config import config
|
||||
|
||||
DEFAULT_COLLECTION = "opensource_movies"
|
||||
"""
|
||||
开放 collection ,任何人均可上传。
|
||||
通过 biliarchiver 上传的 item 会在24小时内被自动转移到 bilibili_videos collection
|
||||
"""
|
||||
BILIBILI_VIDEOS_COLLECTION = "bilibili_videos"
|
||||
""" 由 arkiver 管理。bilibili_videos 属于 social-media-video 的子集 """
|
||||
BILIBILI_VIDEOS_SUB_1_COLLECTION = "bilibili_videos_sub_1"
|
||||
""" 由 yzqzss 管理。属于 bilibili_videos 的子集 """
|
||||
|
||||
|
||||
@dataclass
|
||||
class Args:
|
||||
bvids: str
|
||||
by_storage_home_dir: bool
|
||||
update_existing: bool
|
||||
collection: str
|
||||
|
||||
|
||||
def parse_args():
|
||||
parser = argparse.ArgumentParser()
|
||||
bvids_file_group = parser.add_argument_group()
|
||||
bvids_file_group.title = 'bvids'
|
||||
bvids_file_group.add_argument('--bvids', type=str, dest='bvids',
|
||||
source_group = parser.add_argument_group()
|
||||
source_group.title = '视频来源'
|
||||
source_group.description = "$storage_home_dir 由 config.json 定义"
|
||||
source_group.add_argument('--bvids', type=str, dest='bvids',
|
||||
help='bvids 列表的文件路径')
|
||||
storage_home_dir_group = parser.add_argument_group()
|
||||
storage_home_dir_group.title = 'storage_home_dir'
|
||||
storage_home_dir_group.add_argument('--by-storage_home_dir', action='store_true', dest='by_storage_home_dir',
|
||||
help='从 config.json 中读取 storage_home_dir,然后上传 storage_home_dir/videos 下的所有视频')
|
||||
update_existing_group = parser.add_argument_group()
|
||||
update_existing_group.title = 'update_existing'
|
||||
update_existing_group.add_argument('--update_existing', action='store_true', dest='update_existing',
|
||||
help='更新已存在的 item')
|
||||
source_group.add_argument('--by-storage_home_dir', action='store_true', dest='by_storage_home_dir',
|
||||
help="使用 $storage_home_dir/videos 目录下的所有视频 ")
|
||||
parser.add_argument('--update_existing', action='store_true', dest='update_existing',
|
||||
help='更新 IA 上已存在的 item')
|
||||
parser.add_argument("--collection", default=DEFAULT_COLLECTION, dest='collection',
|
||||
choices=[DEFAULT_COLLECTION, BILIBILI_VIDEOS_COLLECTION, BILIBILI_VIDEOS_SUB_1_COLLECTION],
|
||||
help=f"Collection to upload to. (非默认值仅限 collection 管理员使用) [default: {DEFAULT_COLLECTION}]"
|
||||
)
|
||||
|
||||
args = Args(**vars(parser.parse_args()))
|
||||
|
||||
@ -40,14 +53,14 @@ def main():
|
||||
if '-' in bvid_with_upper_part:
|
||||
bvid = bvid_with_upper_part.split('-')[0]
|
||||
|
||||
upload_bvid(bvid, update_existing=args.update_existing)
|
||||
upload_bvid(bvid, update_existing=args.update_existing, collection=args.collection)
|
||||
|
||||
if args.bvids:
|
||||
elif args.bvids:
|
||||
with open(args.bvids, 'r', encoding='utf-8') as f:
|
||||
bvids_from_file = f.read().splitlines()
|
||||
for bvid in bvids_from_file:
|
||||
|
||||
upload_bvid(bvid, update_existing=args.update_existing)
|
||||
upload_bvid(bvid, update_existing=args.update_existing, collection=args.collection)
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
Loading…
Reference in New Issue
Block a user