-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* bundle tiny.en as whisper default model * improve download-whisper-model script * improve download-ffmpeg-wasm script
- Loading branch information
Showing
4 changed files
with
81 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,9 +35,7 @@ await Promise.all( | |
console.info(chalk.green(`✅ File ${file.name} valid`)); | ||
} else { | ||
console.warn( | ||
chalk.yellow( | ||
`❌ File ${file.name} not valid, start to redownload` | ||
) | ||
chalk.yellow(`❌ File ${file.name} not valid, start to redownload`) | ||
); | ||
fs.removeSync(path.join(dir, file.name)); | ||
pendingFiles.push(file); | ||
|
@@ -81,6 +79,8 @@ if (proxyUrl) { | |
} | ||
|
||
const download = async (url, dest, md5) => { | ||
console.info(chalk.blue(`=> Start to download ${url} to ${dest}`)); | ||
|
||
return spinner(async () => { | ||
console.info(chalk.blue(`=> Start to download file ${url}`)); | ||
await axios | ||
|
@@ -89,22 +89,27 @@ const download = async (url, dest, md5) => { | |
}) | ||
.then(async (response) => { | ||
const data = Buffer.from(response.data, "binary"); | ||
console.info(chalk.green(`✅ ${dest} downloaded successfully`)); | ||
|
||
fs.writeFileSync(dest, data); | ||
const hash = await hashFile(dest, { algo: "md5" }); | ||
if (hash === md5) { | ||
console.info(chalk.green(`✅ ${dest} downloaded successfully`)); | ||
console.info(chalk.green(`✅ ${dest} valid`)); | ||
} else { | ||
console.error( | ||
chalk.red( | ||
`❌ Error: ${dest} MD5 not match, ${hash} should be ${md5}` | ||
`❌ Error: ${dest} not valid. \nPlease try again using the command "yarn workspace enjoy download-ffmpeg-wasm"` | ||
) | ||
); | ||
process.exit(1); | ||
} | ||
}) | ||
.catch((err) => { | ||
console.error(chalk.red(`❌ Error: ${err}`)); | ||
console.error( | ||
chalk.red( | ||
`❌ Failed to download(${err}). \nPlease try again using the command "yarn workspace enjoy download-ffmpeg-wasm"` | ||
) | ||
); | ||
process.exit(1); | ||
}); | ||
}); | ||
|
@@ -126,20 +131,29 @@ const cleanup = () => { | |
try { | ||
fs.removeSync(path.join(dir, file.name)); | ||
} catch (err) { | ||
console.error(chalk.red(`❌ Error: ${err}`)); | ||
console.error( | ||
chalk.red( | ||
`❌ Failed to download(${err}). \nPlease try again using the command "yarn workspace enjoy download-ffmpeg-wasm"` | ||
) | ||
); | ||
} | ||
}); | ||
}; | ||
|
||
const baseURL = "https://unpkg.com/@ffmpeg/[email protected]/dist/esm"; | ||
// const baseURL = "https://unpkg.com/@ffmpeg/[email protected]/dist/esm"; | ||
const baseURL = "https://enjoy-storage.baizhiheizi.com"; | ||
try { | ||
await Promise.all( | ||
pendingFiles.map((file) => | ||
download(`${baseURL}/${file.name}`, path.join(dir, file.name), file.md5) | ||
) | ||
); | ||
} catch (err) { | ||
console.error(chalk.red(`❌ Error: ${err}`)); | ||
console.error( | ||
chalk.red( | ||
`❌ Failed to download(${err}). \nPlease try again using the command "yarn workspace enjoy download-ffmpeg-wasm"` | ||
) | ||
); | ||
cleanup(); | ||
process.exit(1); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters