From c1f51947f263107c1989df6a3995e28723ab83b9 Mon Sep 17 00:00:00 2001 From: yzqzss Date: Fri, 4 Aug 2023 19:44:26 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BD=BF=E7=94=A8=E8=A7=86=E9=A2=91?= =?UTF-8?q?=E5=B0=81=E9=9D=A2=E5=9B=BE=E4=BD=9C=E4=B8=BA=20IA=20item=20ite?= =?UTF-8?q?mimage?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- biliarchiver/_biliarchiver_upload_bvid.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/biliarchiver/_biliarchiver_upload_bvid.py b/biliarchiver/_biliarchiver_upload_bvid.py index 2d74eef..00b7afb 100644 --- a/biliarchiver/_biliarchiver_upload_bvid.py +++ b/biliarchiver/_biliarchiver_upload_bvid.py @@ -1,8 +1,9 @@ import json import os -from pathlib import Path +from pathlib import Path, PurePath import time from typing import List +from urllib.parse import urlparse from internetarchive import get_item from requests import Response from rich import print @@ -74,6 +75,12 @@ def _upload_bvid(bvid: str, *, update_existing: bool = False, collection: str): with open(f'{videos_basepath}/{local_identifier}/_uploaded.mark', 'w', encoding='utf-8') as f: f.write('') continue + with open(f'{videos_basepath}/{local_identifier}/extra/{file_basename}.info.json', 'r', encoding='utf-8') as f: + bv_info = json.load(f) + + cover_url: str = bv_info['data']['pic'] + cover_suffix = PurePath(urlparse(cover_url).path).suffix + filedict = {} # "remote filename": "local filename" for filename in os.listdir(f'{videos_basepath}/{local_identifier}/extra'): file = f'{videos_basepath}/{local_identifier}/extra/{filename}' @@ -81,6 +88,10 @@ def _upload_bvid(bvid: str, *, update_existing: bool = False, collection: str): if file.startswith('_'): continue filedict[filename] = file + + # 复制一份 cover 作为 itemimage + if filename == f'{bvid}_p{pid}{cover_suffix}': + filedict[f'{bvid}_p{pid}_itemimage{cover_suffix}'] = file for filename in os.listdir(f'{videos_basepath}/{local_identifier}'): file = f'{videos_basepath}/{local_identifier}/{filename}' @@ -93,6 +104,7 @@ def _upload_bvid(bvid: str, *, update_existing: bool = False, collection: str): assert (f'{file_basename}.mp4' in filedict) or (f'{file_basename}.flv' in filedict) + # IA 去重 for file_in_item in item.files: if file_in_item["name"] in filedict: @@ -100,8 +112,6 @@ def _upload_bvid(bvid: str, *, update_existing: bool = False, collection: str): print(f"File {file_in_item['name']} already exists in {remote_identifier}.") - with open(f'{videos_basepath}/{local_identifier}/extra/{file_basename}.info.json', 'r', encoding='utf-8') as f: - bv_info = json.load(f) # with open(f'{videos_basepath}/_videos_info.json', 'r', encoding='utf-8') as f: # videos_info = json.load(f)