@hyrious/blivec
Advanced tools
Comparing version 0.3.7 to 0.3.8
@@ -26,2 +26,3 @@ #!/usr/bin/env node | ||
quit # quit DD mode | ||
-- [...player_args] # pass args to ffplay or mpv | ||
`.trim(); | ||
@@ -173,3 +174,3 @@ const has_colors = tty.WriteStream.prototype.hasColors(); | ||
} | ||
async function D(id, { interval = 1, mpv = false, on_close = "default" } = {}) { | ||
async function D(id, { interval = 1, mpv = false, on_close = "default", args = [] } = {}) { | ||
log.info(`DD ${id} ${interval > 0 ? `every ${interval} minutes` : "once"}`); | ||
@@ -233,17 +234,19 @@ let con; | ||
} | ||
function play(url, title) { | ||
function play(url, title, extra) { | ||
if (mpv) { | ||
const args = ["--quiet"]; | ||
args.push("--http-header-fields=" + headers.join(",")); | ||
args.push("--title=" + title); | ||
args.push("--geometry=50%"); | ||
args.push(url); | ||
return cp.spawn("mpv", args, { stdio: "ignore", detached: true }); | ||
const args2 = ["--quiet"]; | ||
args2.push("--http-header-fields=" + headers.join(",")); | ||
args2.push("--title=" + title); | ||
args2.push("--geometry=50%"); | ||
args2.push(...extra); | ||
args2.push(url); | ||
return cp.spawn("mpv", args2, { stdio: "ignore", detached: true }); | ||
} else { | ||
const args = ["-hide_banner", "-loglevel", "error"]; | ||
args.push("-headers", headers.map((e) => e + "\r\n").join("")); | ||
args.push("-window_title", title); | ||
args.push("-x", "720", "-y", "405"); | ||
args.push(url); | ||
return cp.spawn("ffplay", args, { stdio: "ignore" }); | ||
const args2 = ["-hide_banner", "-loglevel", "error"]; | ||
args2.push("-headers", headers.map((e) => e + "\r\n").join("")); | ||
args2.push("-window_title", title); | ||
args2.push("-x", "720", "-y", "405"); | ||
args2.push(...extra); | ||
args2.push(url); | ||
return cp.spawn("ffplay", args2, { stdio: "ignore" }); | ||
} | ||
@@ -258,2 +261,5 @@ } | ||
async function replay(initial = true) { | ||
if (!initial && (on_close === "quit" || on_close === "exit")) { | ||
process.exit(0); | ||
} | ||
const info = await poll(); | ||
@@ -277,3 +283,3 @@ if (!info) | ||
log.info(`Now playing: [${selected}] ${info.title}`); | ||
child = play(info.streams[selected].url, info.title); | ||
child = play(info.streams[selected].url, info.title, args); | ||
con ||= listen(id); | ||
@@ -327,2 +333,3 @@ con.resume(); | ||
let on_close = "default"; | ||
let args; | ||
for (const arg of rest) { | ||
@@ -337,4 +344,3 @@ if (arg.startsWith("--interval=")) { | ||
} | ||
} | ||
if (arg.startsWith("--on-close=")) { | ||
} else if (arg.startsWith("--on-close=")) { | ||
const value = arg.slice(11); | ||
@@ -347,7 +353,11 @@ if (["default", "ask", "quit", "exit"].includes(value)) { | ||
} | ||
} else if (arg === "--mpv") { | ||
mpv = true; | ||
} else if (arg === "--") { | ||
args = []; | ||
} else if (args) { | ||
args.push(arg); | ||
} | ||
if (arg === "--mpv") | ||
mpv = true; | ||
} | ||
const con = await D(id, { interval, mpv, on_close }); | ||
const con = await D(id, { interval, mpv, on_close, args }); | ||
con && sigint(con); | ||
@@ -354,0 +364,0 @@ } |
{ | ||
"name": "@hyrious/blivec", | ||
"version": "0.3.7", | ||
"version": "0.3.8", | ||
"description": "bilibili live cli", | ||
@@ -15,7 +15,9 @@ "type": "module", | ||
], | ||
"types": "./src/index.ts", | ||
"types": "./dist/index.d.ts", | ||
"scripts": { | ||
"test": "node dist/bin.js", | ||
"clean": "rimraf dist", | ||
"build": "esbuild src/index.ts src/bin.ts --target=node16.15 --outdir=dist" | ||
"build": "npm run clean && npm run build:js && npm run build:types", | ||
"build:js": "esbuild src/index.ts src/bin.ts --target=node16.15 --outdir=dist", | ||
"build:types": "dts src/index.ts --o dist/index.d.ts" | ||
}, | ||
@@ -34,2 +36,3 @@ "engines": { | ||
"devDependencies": { | ||
"@hyrious/dts": "^0.1.5", | ||
"@hyrious/rimraf": "^0.1.0", | ||
@@ -36,0 +39,0 @@ "@types/node": "^18.13.0", |
@@ -1,6 +0,6 @@ | ||
## <samp>> <ins>b</ins>ilibili-<ins>live</ins>-<ins>c</ins>li</samp> | ||
# <samp>> <ins>b</ins>ilibili-<ins>live</ins>-<ins>c</ins>li</samp> | ||
Personal tool for viewing <ruby>弾幕 <rp>(</rp><rt>danmaku</rt><rp>)</rp></ruby> and other utils in bilibili live streaming. | ||
### Why | ||
## Why | ||
@@ -11,33 +11,60 @@ It will cost too much CPU to open a browser when playing [osu!](https://osu.ppy.sh/users/hyrious), where the performance of CPU matters when the beatmap becomes more difficult and you need at least 240 FPS to play well. | ||
### Usage | ||
## Install | ||
You don't have to install it if you have `npx`, | ||
```bash | ||
# start listening danmaku in room 14917277 | ||
npx @hyrious/blivec 14917277 | ||
[blivc] listening 14917277 | ||
[username] message | ||
^C | ||
npx @hyrious/blivec ...args | ||
``` | ||
# install it globally, which provides a shortcut name "bl" | ||
Or you can choose to install it globally, which will give you a shortcut name `bl`, | ||
```bash | ||
npm i -g @hyrious/blivec | ||
bl 14917277 | ||
bl ...args | ||
``` | ||
# send danmaku (requires cookie to be put at cwd) | ||
bl 14917277 "hello world" | ||
## Usage | ||
# get direct stream url | ||
bl get 14917277 | ||
https://.../a.flv?b=c... | ||
### Listen Danmaku | ||
```bash | ||
bl <room_id> [--json] | ||
``` | ||
### Develop | ||
### Send Danmaku | ||
PR & issues are welcome! | ||
```bash | ||
bl <room_id> <message> | ||
``` | ||
This command requires a cookie file named `cookie.txt` to be put at the current working directory or at your home folder. | ||
### Get Stream URL | ||
```bash | ||
pnpm t 14917277 | ||
bl get <room_id> [--json] | ||
``` | ||
### Credits | ||
### DD Mode | ||
```bash | ||
bl d <room_id> [--mpv] [--interval=1] [--on-close=quit] [-- ...player_args] | ||
``` | ||
Use `ffplay` or `mpv` (if `--mpv` is specified) to play the stream. If it is not available, wait _interval_ minutes and try again. | ||
- `--mpv`: Use `mpv` instead of `ffplay`. | ||
- `--interval=<minutes>`: Wait minutes before trying again. Default is 1 minute. | ||
- `--on-close=<action>`: What to do when the player window is closed. | ||
- `default`: Restart the player. This is super useful when there is network errors and you don't have to touch the keyboard or mouse to keep watching the stream. | ||
- `quit`: Quit the whole program. | ||
- `ask`: Search stream URLs and ask you for a new one to play or just quit. This is useful when you want to switch the stream quality quickly. | ||
## Develop | ||
PR & issues are welcome! | ||
## Credits | ||
- [blivedm](https://github.com/xfgryujk/blivedm) | ||
@@ -48,4 +75,4 @@ - [bilibili-live-ws](https://github.com/simon300000/bilibili-live-ws) | ||
### License | ||
## License | ||
MIT @ [hyrious](https://github.com/hyrious) |
@@ -26,2 +26,3 @@ #!/usr/bin/env node | ||
quit # quit DD mode | ||
-- [...player_args] # pass args to ffplay or mpv | ||
`.trim(); | ||
@@ -190,3 +191,3 @@ | ||
async function D(id: number, { interval = 1, mpv = false, on_close = "default" } = {}) { | ||
async function D(id: number, { interval = 1, mpv = false, on_close = "default", args = <string[]>[] } = {}) { | ||
log.info(`DD ${id} ${interval > 0 ? `every ${interval} minutes` : "once"}`); | ||
@@ -254,3 +255,3 @@ | ||
function play(url: string, title: string) { | ||
function play(url: string, title: string, extra: string[]) { | ||
if (mpv) { | ||
@@ -261,2 +262,3 @@ const args = ["--quiet"]; | ||
args.push("--geometry=50%"); | ||
args.push(...extra); | ||
args.push(url); | ||
@@ -269,2 +271,3 @@ return cp.spawn("mpv", args, { stdio: "ignore", detached: true }); | ||
args.push("-x", "720", "-y", "405"); | ||
args.push(...extra); | ||
args.push(url); | ||
@@ -282,2 +285,6 @@ return cp.spawn("ffplay", args, { stdio: "ignore" }); | ||
async function replay(initial = true) { | ||
if (!initial && (on_close === "quit" || on_close === "exit")) { | ||
process.exit(0); | ||
} | ||
const info = await poll(); | ||
@@ -303,3 +310,3 @@ if (!info) process.exit(0); | ||
log.info(`Now playing: [${selected}] ${info.title}`); | ||
child = play(info.streams[selected].url, info.title); | ||
child = play(info.streams[selected].url, info.title, args); | ||
con ||= listen(id); | ||
@@ -359,2 +366,3 @@ con.resume(); | ||
let on_close = "default"; | ||
let args: string[] | undefined; | ||
for (const arg of rest) { | ||
@@ -369,4 +377,3 @@ if (arg.startsWith("--interval=")) { | ||
} | ||
} | ||
if (arg.startsWith("--on-close=")) { | ||
} else if (arg.startsWith("--on-close=")) { | ||
const value = arg.slice(11); | ||
@@ -379,6 +386,11 @@ if (["default", "ask", "quit", "exit"].includes(value)) { | ||
} | ||
} else if (arg === "--mpv") { | ||
mpv = true; | ||
} else if (arg === "--") { | ||
args = []; | ||
} else if (args) { | ||
args.push(arg); | ||
} | ||
if (arg === "--mpv") mpv = true; | ||
} | ||
const con = await D(id, { interval, mpv, on_close }); | ||
const con = await D(id, { interval, mpv, on_close, args }); | ||
con && sigint(con); | ||
@@ -385,0 +397,0 @@ } |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
52330
8
1480
77
4