Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
nicks96432 committed Aug 10, 2021
0 parents commit 978927a
Show file tree
Hide file tree
Showing 14 changed files with 2,647 additions and 0 deletions.
118 changes: 118 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
.pnpm-debug.log*

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage
*.lcov

# nyc test coverage
.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# Snowpack dependency directory (https://snowpack.dev/)
web_modules/

# TypeScript cache
*.tsbuildinfo

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env
.env.test
.env.production

# parcel-bundler cache (https://parceljs.org/)
.cache
.parcel-cache

# Next.js build output
.next
out

# Nuxt.js build / generate output
.nuxt
dist

# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and not Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public

# vuepress build output
.vuepress/dist

# Serverless directories
.serverless/

# FuseBox cache
.fusebox/

# DynamoDB Local files
.dynamodb/

# TernJS port file
.tern-port

# Stores VSCode versions used for testing VSCode extensions
.vscode-test

# yarn v2
.yarn/cache
.yarn/unplugged
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2021 我可能很廢

Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
43 changes: 43 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# MLTD-asset-downloader

English | [繁體中文](README.zh-TW.md)

JavaScript based Game asset downloader for THE IDOLM@STER MILLION LIVE! Theater Days (MLTD).

## Usage

sorry for my poor English translation

```console
$ ./mltd-asset-downloader --help
Usage: mltd-asset-downloader [options]

asset downloader for THE IDOLM@STER MILLION LIVE! Theater Days (MLTD)

Options:
-V, --version output the version number
--latest skip all interactive prompts and download latest assets directly
--dry-run don't download to disk. This may be helpful to test your network speed ¯\_(ツ)_/¯
--checksum don't download any file and check all downloaded files
-b, --batch-size <size> batch size of downloading file, default CPU cores count (default: 8)
-o, --output-path <path> downloaded path (default: "assets")
-h, --help display this help
```

## Build

```shell
npm install
npm run build
```

or

```shell
yarn
yarn build
```

## License

Licensed under [MIT](LICENSE).
43 changes: 43 additions & 0 deletions README.zh-TW.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# MLTD遊戲資源下載器

[English](README.md) | 繁體中文

使用Javascript製作的偶像大師 百萬人演唱會! 劇場時光 (MLTD) 遊戲資源下載器

## 用法

英文渣翻抱歉

```console
$ ./mltd-asset-downloadeer --help
Usage: mltd-asset-downloader [選項]

偶像大師 百萬人演唱會! 劇場時光 (MLTD) 遊戲檔案下載器

Options:
-V, --version 印出版本號
--latest 跳過所有選項並直接下載最新版遊戲檔案
--dry-run 不要把檔案存到硬碟裡。這個功能可能在測網速的時候有用 ¯\_(ツ)_/¯
--checksum 不下載任何檔案,只檢查已下載的檔案是否正確
-b, --batch-size <size> 一次要下載幾個檔案,預設為CPU核心數 (default: 8)
-o, --output-path <path> 存檔路徑 (default: "assets")
-h, --help 顯示這個說明
```

## 編譯

```shell
npm install
npm run build
```


```shell
yarn
yarn build
```

## 授權條款

本軟體遵守[MIT](LICENSE)授權條款。
28 changes: 28 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"name": "mltd-asset-downloader",
"version": "1.0.0",
"license": "MIT",
"private": true,
"scripts": {
"build": "webpack --mode production",
"postbuild": "pkg -t node16-linux-x64,node16-macos-x64,node16-win-x64 -C brotli --out-path dist dist/mltd-asset-downloader.js",
"dev": "webpack --mode development --watch",
"start": "node build/mltd-asset-downloader"
},
"dependencies": {
"@msgpack/msgpack": "^2.7.0",
"bluebird": "^3.7.2",
"chalk": "^4.1.2",
"cli-progress": "^3.9.0",
"commander": "^8.1.0",
"inquirer": "^8.1.2",
"log-update": "^4.0.0",
"node-fetch": "^2.6.1",
"sprintf-js": "^1.1.2"
},
"devDependencies": {
"pkg": "^5.3.1",
"webpack": "^5.48.0",
"webpack-cli": "^4.7.2"
}
}
91 changes: 91 additions & 0 deletions src/downloadAssets.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
import path from "path";
import chalk from "chalk";
import fs from "fs/promises";
import Promise from "bluebird";
import logUpdate from "log-update";
import { sprintf } from "sprintf-js";
import { Presets, SingleBar } from "cli-progress";
import getDownloadList from "./getDownloadList.js";
import {
fetchWithRetry,
getBufferChecksum,
getResponseAssetHash
} from "./utils.js";

const downloadAssets = async (assetList, args, i18n) => {
const downloadList = await getDownloadList(assetList, args, i18n);
const bar = new SingleBar(
{
clearOnComplete: true,
format: `${chalk.blue("{bar}")} {file} | {value}/{total}`,
stopOnComplete: true
},
Presets.shades_classic
);
if (!args.dryRun && !args.checksum)
try {
await fs.mkdir(args.outputPath, { recursive: true });
} catch (e) {}
for (const assetVersion of downloadList) {
const outputPath = path.join(args.outputPath, assetVersion);
logUpdate(sprintf(i18n.downloadAssets, outputPath));
if (!args.dryRun && !args.checksum)
try {
await fs.mkdir(outputPath, { recursive: true });
} catch (e) {
if (e.code === "EACCES") {
console.error(sprintf(i18n.eaccesText, args.outputPath));
process.exit(1);
}
}
bar.start(assetList[assetVersion].length, 0);
await Promise.map(
assetList[assetVersion],
async assetListItem => {
let dataURL = `https://d3k5923sb1sy5k.cloudfront.net/${assetVersion}/production/`;
assetVersion < 70000
? (dataURL += `2017v1`)
: (dataURL += `2018v1`);
dataURL += `/Android/${assetListItem.file}`;
if (!args.dryRun || args.checksum)
try {
const res = await fetchWithRetry(dataURL, "HEAD");
const buf = await fs.readFile(
`./${args.outputPath}/${assetVersion}/${assetListItem.name}`
);
if (
getResponseAssetHash(res) === getBufferChecksum(buf)
) {
bar.increment(1, { file: assetListItem.name });
return;
} else if (args.checksum) {
console.error(
sprintf(i18n.checksumFailed, manifest.indexName)
);
process.exit(1);
}
} catch (e) {}
const res = await fetchWithRetry(dataURL);
const buf = await res.buffer();
if (getResponseAssetHash(res) !== getBufferChecksum(buf)) {
console.error(
sprintf(i18n.checksumFailed, manifest.indexName)
);
process.exit(1);
}
if (!args.dryRun)
await fs.writeFile(
path.join(outputPath, assetListItem.name),
buf
);
bar.increment(1, { file: assetListItem.name });
},
{ concurrency: parseInt(args.batchSize, 10) }
);
bar.stop();
logUpdate(sprintf(`${i18n.downloadAssets} ${i18n.done}`, outputPath));
logUpdate.done();
}
};

export default downloadAssets;
Loading

0 comments on commit 978927a

Please sign in to comment.