🔨 修复下载脚本

This commit is contained in:
‘KimigaiiWuyi’ 2024-05-07 20:19:11 +08:00
parent 1e162d58fd
commit dc1c0f0d24
3 changed files with 53 additions and 25 deletions

View File

@ -66,6 +66,9 @@ BETA_CHAR = {
'10000091': '娜维娅', '10000091': '娜维娅',
'10000092': '嘉明', '10000092': '嘉明',
'10000093': '闲云', '10000093': '闲云',
'10000095': '希格雯',
'10000097': '赛索斯',
'10000098': '克洛琳德',
} }

View File

@ -1,42 +1,51 @@
import json import json
from io import BytesIO
from typing import Dict from typing import Dict
from pathlib import Path from pathlib import Path
import httpx import httpx
from PIL import Image
MAP_PATH = Path(__file__).parent.parent / 'utils' / 'map' / 'data' MAP_PATH = Path(__file__).parent.parent / 'utils' / 'map' / 'data'
with open(MAP_PATH / 'enName2AvatarID_mapping_4.5.0.json') as f: with open(MAP_PATH / 'enName2AvatarID_mapping_4.6.0.json') as f:
enmap: Dict[str, str] = json.load(f) enmap: Dict[str, str] = json.load(f)
char_list = ['Arlecchino'] suffix = 'webp'
base = 'https://api.ambr.top/assets/UI'
char_list = ['Sigewinne', 'Sethos', 'Clorinde']
base = 'https://api.hakush.in/gi/UI/'
# title = 'https://enka.network/ui/{}' # title = 'https://enka.network/ui/{}'
# hakush = 'https://api.hakush.in/gi/UI/'
# ambr = 'https://api.ambr.top/assets/UI'
icon_list = [ icon_list = [
'Skill_E_{}_01.png', 'Skill_E_{}_01.' + suffix,
'Skill_E_{}_02.png', 'Skill_E_{}_02.' + suffix,
'Skill_S_{}_01.png', 'Skill_S_{}_01.' + suffix,
'Skill_S_{}_02.png', 'Skill_S_{}_02.' + suffix,
'UI_Talent_S_{}_01.png', 'UI_Talent_S_{}_01.' + suffix,
'UI_Talent_S_{}_02.png', 'UI_Talent_S_{}_02.' + suffix,
'UI_Talent_S_{}_03.png', 'UI_Talent_S_{}_03.' + suffix,
'UI_Talent_S_{}_04.png', 'UI_Talent_S_{}_04.' + suffix,
'UI_Talent_S_{}_05.png', 'UI_Talent_S_{}_05.' + suffix,
'UI_Talent_S_{}_06.png', 'UI_Talent_S_{}_06.' + suffix,
'UI_Talent_S_{}_07.png', 'UI_Talent_S_{}_07.' + suffix,
'UI_Talent_U_{}_01.png', 'UI_Talent_U_{}_01.' + suffix,
'UI_Talent_U_{}_02.png', 'UI_Talent_U_{}_02.' + suffix,
'UI_Talent_C_{}_01.png', 'UI_Talent_C_{}_01.' + suffix,
'UI_Talent_C_{}_02.png', 'UI_Talent_C_{}_02.' + suffix,
'UI_Gacha_AvatarImg_{}.png', 'UI_Gacha_AvatarImg_{}.' + suffix,
'UI_NameCardIcon_{}.png', 'UI_NameCardIcon_{}.' + suffix,
'UI_AvatarIcon_{}.png', 'UI_AvatarIcon_{}.' + suffix,
'UI_NameCardPic_{}_P.png', 'UI_NameCardPic_{}_P.' + suffix,
] ]
is_download = True is_download = True
def download(icon_name: str, url: str): def download(icon_name: str, url: str):
icon_name = icon_name.split('.')[0] + '.png'
path = Path(__file__).parent / icon_name path = Path(__file__).parent / icon_name
if path.exists(): if path.exists():
print(f'{icon_name}已经存在!,跳过!') print(f'{icon_name}已经存在!,跳过!')
@ -45,10 +54,17 @@ def download(icon_name: str, url: str):
char_data = httpx.get(url, follow_redirects=True, timeout=80) char_data = httpx.get(url, follow_redirects=True, timeout=80)
if char_data.headers['Content-Type'] == 'image/png': if char_data.headers['Content-Type'] == 'image/png':
char_bytes = char_data.content char_bytes = char_data.content
elif char_data.headers['Content-Type'] == 'image/webp':
webp_image = BytesIO(char_data.content)
img = Image.open(webp_image)
png_bytes = BytesIO()
img.save(png_bytes, 'PNG')
png_bytes.seek(0)
char_bytes = png_bytes.read()
else: else:
print(f'{icon_name}不存在,跳过!') print(f'{icon_name}不存在,跳过!')
return return
# img_data = httpx.get(url).content
with open(path, '+wb') as handler: with open(path, '+wb') as handler:
handler.write(char_bytes) handler.write(char_bytes)
print('下载成功!') print('下载成功!')
@ -102,8 +118,8 @@ def download_namecard_pic():
en = 'Hutao' en = 'Hutao'
elif en == 'Thoma': elif en == 'Thoma':
en = 'Tohma' en = 'Tohma'
url = f'{base}/namecard/UI_NameCardPic_{en}_P.png' url = f'{base}/namecard/UI_NameCardPic_{en}_P.' + suffix
download(f'{avatar_id}.png', url) download(f'{avatar_id}.' + suffix, url)
# download_namecard_pic() # download_namecard_pic()

View File

@ -0,0 +1,9 @@
from typing import Union, Optional
from .ambr_to_minigg import ConvertWeapon
async def convert_hakush_to_weapon(
weapon_id: Union[int, str]
) -> Optional[ConvertWeapon]:
return None