-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1f1eb2b
commit 7724645
Showing
8 changed files
with
137 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"baha-anime-dl-cli": patch | ||
--- | ||
|
||
cli tool |
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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# Bahamut Anime Downloader CLI | ||
|
||
``` | ||
baha-anime-dl <sn> [options] | ||
``` | ||
|
||
## Options | ||
|
||
- `-o, --output <path>`: Output path | ||
- `-c, --cookie <cookie>`: Cookie string `KEY=VALUE` |
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 |
---|---|---|
@@ -0,0 +1,35 @@ | ||
{ | ||
"name": "baha-anime-dl-cli", | ||
"description": "This tool is used to download low quality Anime from Bahamut.", | ||
"version": "0.0.0", | ||
"author": "JacobLinCool <jacoblincool@gmail.com> (https://jacoblin.cool)", | ||
"license": "AGPL-3.0", | ||
"keywords": [], | ||
"bin": { | ||
"baha-anime-dl": "dist/index.js" | ||
}, | ||
"files": [ | ||
"dist" | ||
], | ||
"scripts": { | ||
"build": "tsup" | ||
}, | ||
"dependencies": { | ||
"baha-anime-dl": "workspace:*", | ||
"baha-anime-dl-ext": "workspace:*", | ||
"yargs": "^17.7.2" | ||
}, | ||
"devDependencies": { | ||
"@types/yargs": "^17.0.32", | ||
"tsup": "^7.2.0", | ||
"typescript": "^5.2.2" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/JacobLinCool/baha-anime-dl.git" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/JacobLinCool/baha-anime-dl/issues" | ||
}, | ||
"homepage": "https://jacoblincool.github.io/baha-anime-dl" | ||
} |
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 |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import { Downloader, default_config } from "baha-anime-dl"; | ||
import { build, merge } from "baha-anime-dl-ext"; | ||
import fs from "node:fs"; | ||
import path from "node:path"; | ||
import { hideBin } from "yargs/helpers"; | ||
import yargs from "yargs/yargs"; | ||
|
||
main(); | ||
|
||
async function main() { | ||
const argv = await yargs(hideBin(process.argv)) | ||
.command("<sn>", "Download media with the given serial number or ID", (yargs) => { | ||
yargs.positional("sn", { | ||
type: "string", | ||
describe: "The serial number or ID of the media to download", | ||
}); | ||
}) | ||
.option("output", { | ||
alias: "o", | ||
type: "string", | ||
describe: "Output path for the downloaded media", | ||
}) | ||
.option("cookie", { | ||
alias: "c", | ||
type: "array", | ||
describe: "Cookie to be set. This will be set to the cookie jar at the beginning.", | ||
}) | ||
.demandCommand(1).argv; | ||
|
||
const sn = parseInt(argv._[0].toString()); | ||
if (isNaN(sn)) { | ||
console.error("Invalid serial number"); | ||
process.exit(1); | ||
} | ||
|
||
const output = argv.output || `${sn}.mp4`; | ||
|
||
console.log(`Downloading media with serial number ${sn} to ${output}`); | ||
|
||
const config = { | ||
...default_config(), | ||
fetcher: build({ | ||
headers: { | ||
"User-Agent": "Mozilla/5.0 Baha LowRes Anime Downloader", | ||
}, | ||
cookies: argv.cookie | ||
? Object.fromEntries(argv.cookie.map((c) => c.toString().split("=", 2))) | ||
: {}, | ||
}), | ||
}; | ||
|
||
const downloader = new Downloader(config); | ||
const download = downloader.download(sn); | ||
const merged = await merge(download); | ||
|
||
const dir = path.dirname(output); | ||
if (!fs.existsSync(dir)) { | ||
fs.mkdirSync(dir, { recursive: true }); | ||
} | ||
fs.writeFileSync(output, Buffer.from(merged)); | ||
} |
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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
#!/usr/bin/env node | ||
import "./cli"; |
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"extends": "../../tsconfig.json", | ||
"compilerOptions": { | ||
"paths": { | ||
"@/*": ["./src/*"] | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { defineConfig } from "tsup"; | ||
|
||
export default defineConfig(() => ({ | ||
entry: ["src/index.ts"], | ||
outDir: "dist", | ||
target: "node16", | ||
format: ["esm", "cjs"], | ||
shims: true, | ||
clean: true, | ||
splitting: false, | ||
dts: true, | ||
})); |
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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"includeVersion": true, | ||
"entryPoints": ["src/index.ts"] | ||
} |