feat: make exception for voice 043 in kr and en

This commit is contained in:
Haoyu Xu
2025-08-02 21:16:13 +08:00
parent 57d5cac582
commit 8ad0aba8cf
6 changed files with 66 additions and 13 deletions

View File

@@ -251,10 +251,16 @@ export default class Voice {
#nextVoice() { #nextVoice() {
const getVoiceId = () => { const getVoiceId = () => {
const id = let list = this.#voice.list
this.#voice.list[ if (
Math.floor(Math.random() * this.#voice.list.length) this.#config.language === 'EN' ||
] this.#config.language === 'KR'
) {
// filter out CN_043 as this voice is not available in en and kr
list = list.filter((item) => item !== 'CN_043')
}
const id = list[Math.floor(Math.random() * list.length)]
console.log(id, list, this.#config.language)
return id === this.#voice.id.last ? getVoiceId() : id return id === this.#voice.id.last ? getVoiceId() : id
} }
this.#playVoice(getVoiceId()) this.#playVoice(getVoiceId())

View File

@@ -7,3 +7,6 @@ item_to_download:
- char_128 - char_128
additional_regex: additional_regex:
- ^(?!(avg|charpack))(.*)$ - ^(?!(avg|charpack))(.*)$
servers:
- name: cn
url: https://ak-conf.hypergryph.com/config/prod/official/network_config

View File

@@ -7,21 +7,43 @@ import config from '../index.ts'
import type { UpdateList, ItemToDownload, AbInfosItem } from '../types.ts' import type { UpdateList, ItemToDownload, AbInfosItem } from '../types.ts'
export default async (dataDir: string) => { export default async (dataDir: string) => {
const pidSet: Set<string> = new Set() await Promise.all(
const versionRes: Response = await fetch( config.servers.map(async (server) => {
'https://ak-conf.hypergryph.com/config/prod/official/Android/version' const networkConfResp = await fetch(server.url)
const networkConf = JSON.parse(
(await networkConfResp.json()).content.replace('\\', '')
) )
const funcVer = networkConf.funcVer
const networkConfUrls = networkConf.configs[funcVer].network
await download(dataDir, {
hv: networkConfUrls.hv.replace('{0}', 'Android'),
hu: networkConfUrls.hu,
})
})
)
}
const download = async (
dataDir: string,
urls: {
hv: string
hu: string
}
) => {
const pidSet: Set<string> = new Set()
const versionRes: Response = await fetch(urls.hv)
const version: string = (await versionRes.json()).resVersion const version: string = (await versionRes.json()).resVersion
const lpacksRes: Response = await fetch( const lpacksRes: Response = await fetch(
`https://ak.hycdn.cn/assetbundle/official/Android/assets/${version}/hot_update_list.json` `${urls.hu}/Android/assets/${version}/hot_update_list.json`
) )
const updateList: UpdateList = await lpacksRes.json() const updateList: UpdateList = await lpacksRes.json()
const itemToDownload: Set<ItemToDownload> = new Set(config.item_to_download) const itemToDownload: Set<ItemToDownload> = new Set(config.item_to_download)
updateList.abInfos.map((item: AbInfosItem) => { updateList.abInfos.map((item: AbInfosItem) => {
if (item.name.includes(config.dynchars)) { if (item.name.includes(config.dynchars)) {
const id = getOperatorId(item.name).replace('.ab', '') const id = getOperatorId(item.name).replace('.ab', '')
const alternativeId = getOperatorAlternativeId(id)
itemToDownload.add(id) itemToDownload.add(id)
itemToDownload.add(getOperatorAlternativeId(id)) itemToDownload.add(alternativeId)
} }
}) })
mapping.musicFiles.map((item) => { mapping.musicFiles.map((item) => {
@@ -42,7 +64,7 @@ export default async (dataDir: string) => {
pidSet.forEach((item) => { pidSet.forEach((item) => {
lpacksToDownload.push({ lpacksToDownload.push({
name: item, name: item,
url: `https://ak.hycdn.cn/assetbundle/official/Android/assets/${version}/${item}.dat`, url: `${urls.hu}/Android/assets/${version}/${item}.dat`,
}) })
}) })
const regexs = [] const regexs = []

View File

@@ -2,6 +2,10 @@ export type Config = {
dynchars: string dynchars: string
item_to_download: ItemToDownload[] item_to_download: ItemToDownload[]
additional_regex: string[] additional_regex: string[]
servers: {
name: 'cn' | 'jp' | 'en' | 'kr'
url: string
}[]
} }
export type ItemToDownload = string export type ItemToDownload = string

View File

@@ -156,10 +156,26 @@ export const build = async (namesToBuild: string[]) => {
) )
const voiceFileList = file.readdirSync(voiceSubFolder) const voiceFileList = file.readdirSync(voiceSubFolder)
voiceList[voiceSubFolderMapping.lookup_region].map((item) => { voiceList[voiceSubFolderMapping.lookup_region].map((item) => {
if (!voiceFileList.includes(`${item}.ogg`)) // an exception for detecting file existence
if (
item.endsWith('043') &&
voiceFileList.includes(`${item}.ogg`) &&
(voiceSubFolderMapping.name === 'kr' ||
voiceSubFolderMapping.name === 'en')
) {
console.log(
`Voice folder ${voiceSubFolderMapping.name} for ${name} has ${item}.ogg`
)
}
if (
!voiceFileList.includes(`${item}.ogg`) &&
// make an exception
!item.endsWith('043')
) {
err.push( err.push(
`Voice folder ${voiceSubFolderMapping.name} for ${name} is missing ${item}.ogg` `Voice folder ${voiceSubFolderMapping.name} for ${name} is missing ${item}.ogg`
) )
}
}) })
} }
} }

View File

@@ -70,7 +70,7 @@ export const unzipDownload = async (
retry.map( retry.map(
throttle(async (item) => { throttle(async (item) => {
const name = item.name const name = item.name
console.log(`Downloading ${name}`) console.log(`Downloading ${name} to ${targetDir}`)
const zip = await fetch(item.url) const zip = await fetch(item.url)
.then((resp) => { .then((resp) => {
const status = resp.status const status = resp.status
@@ -114,7 +114,9 @@ export const unzipDownload = async (
const readStream = await entry.openReadStream() const readStream = await entry.openReadStream()
const writeStream = fs.createWriteStream(filePath) const writeStream = fs.createWriteStream(filePath)
await pipeline(readStream, writeStream) await pipeline(readStream, writeStream)
console.log(`Finish Writing to ${entry.filename}`) console.log(
`Finish Writing to ${targetDir}/${entry.filename}`
)
} }
} finally { } finally {
await zip.close() await zip.close()