Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add --encoding argument #9

Merged
merged 1 commit into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ You can test code with the `txt` file included in the test directory :

```sh
node dist/index.js test/jojo.txt
node dist/index.js test/la_despedida.txt --encoding=latin1
```

## License
Expand Down
11 changes: 10 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,22 @@ async function mainCLI() {
if (!process.argv[2]) {
throw `Ultrastar2ass - Convert Ultrastar karaoke to ASS file
Usage: ultrastar2ass myfile.txt
Options:
--encoding=input-file-encoding (default: utf8)
Output goes to stdout
`;
}
const txtFile = process.argv[2];
let encoding = 'utf8'
if (process.argv[3] && process.argv[3].startsWith('--encoding=')) {
encoding = process.argv[3].replace('--encoding=', '')
if (!['utf8', 'utf-8', 'utf16le', 'utf-16le', 'latin1'].includes(encoding)) {
throw 'Only utf8, utf16le, and latin1 encodings are supported.'
}
}

if (!await asyncExists(txtFile)) throw `File ${txtFile} does not exist`;
const txt = await asyncReadFile(txtFile, 'utf8');
const txt = await asyncReadFile(txtFile, encoding);
return convertToASS(txt, { syllable_precision: true });
}

Expand Down
Loading