@bililive-tools/manager 1.4.0 → 1.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/manager.d.ts +1 -0
- package/lib/manager.js +4 -2
- package/lib/recorder.d.ts +2 -0
- package/lib/utils.d.ts +2 -0
- package/lib/utils.js +48 -0
- package/package.json +1 -1
package/lib/manager.d.ts
CHANGED
|
@@ -13,6 +13,7 @@ export interface RecorderProvider<E extends AnyObject> {
|
|
|
13
13
|
title: string;
|
|
14
14
|
owner: string;
|
|
15
15
|
uid?: number;
|
|
16
|
+
avatar?: string;
|
|
16
17
|
} | null>;
|
|
17
18
|
createRecorder: (this: RecorderProvider<E>, opts: Omit<RecorderCreateOpts<E>, "providerId">) => Recorder<E>;
|
|
18
19
|
fromJSON: <T extends SerializedRecorder<E>>(this: RecorderProvider<E>, json: T) => Recorder<E>;
|
package/lib/manager.js
CHANGED
|
@@ -4,7 +4,7 @@ import ejs from "ejs";
|
|
|
4
4
|
import { omit, range } from "lodash-es";
|
|
5
5
|
import { parseArgsStringToArgv } from "string-argv";
|
|
6
6
|
import { getBiliStatusInfoByRoomIds } from "./api.js";
|
|
7
|
-
import { formatDate, removeSystemReservedChars, formatTemplate, replaceExtName, downloadImage, } from "./utils.js";
|
|
7
|
+
import { formatDate, removeSystemReservedChars, formatTemplate, replaceExtName, downloadImage, isBetweenTimeRange, } from "./utils.js";
|
|
8
8
|
import { StreamManager } from "./streamManager.js";
|
|
9
9
|
const configurableProps = [
|
|
10
10
|
"savePathRule",
|
|
@@ -39,7 +39,9 @@ export function createRecorderManager(opts) {
|
|
|
39
39
|
const maxThreadCount = 3;
|
|
40
40
|
// 这里暂时不打算用 state == recording 来过滤,provider 必须内部自己处理录制过程中的 check,
|
|
41
41
|
// 这样可以防止一些意外调用 checkLiveStatusAndRecord 时出现重复录制。
|
|
42
|
-
let needCheckRecorders = recorders
|
|
42
|
+
let needCheckRecorders = recorders
|
|
43
|
+
.filter((r) => !r.disableAutoCheck)
|
|
44
|
+
.filter((r) => isBetweenTimeRange(r.handleTime));
|
|
43
45
|
let threads = [];
|
|
44
46
|
if (manager.biliBatchQuery) {
|
|
45
47
|
const biliNeedCheckRecorders = needCheckRecorders
|
package/lib/recorder.d.ts
CHANGED
|
@@ -47,6 +47,8 @@ export interface RecorderCreateOpts<E extends AnyObject = UnknownObject> {
|
|
|
47
47
|
formatriorities?: Array<"flv" | "hls">;
|
|
48
48
|
/** 只录制音频 */
|
|
49
49
|
onlyAudio?: boolean;
|
|
50
|
+
/** 监控时间段 */
|
|
51
|
+
handleTime?: [string | null, string | null];
|
|
50
52
|
/** 控制弹幕是否使用服务端时间戳 */
|
|
51
53
|
useServerTimestamp?: boolean;
|
|
52
54
|
extra?: Partial<E>;
|
package/lib/utils.d.ts
CHANGED
|
@@ -61,6 +61,7 @@ export declare function sortByKeyOrder<T, K extends keyof T>(objects: T[], order
|
|
|
61
61
|
* @returns Promise
|
|
62
62
|
*/
|
|
63
63
|
export declare function retry<T>(fn: () => Promise<T>, retries?: number, delay?: number): Promise<T>;
|
|
64
|
+
export declare const isBetweenTimeRange: (range: undefined | [] | [string | null, string | null]) => boolean;
|
|
64
65
|
declare const _default: {
|
|
65
66
|
replaceExtName: typeof replaceExtName;
|
|
66
67
|
singleton: typeof singleton;
|
|
@@ -79,5 +80,6 @@ declare const _default: {
|
|
|
79
80
|
uuid: () => `${string}-${string}-${string}-${string}-${string}`;
|
|
80
81
|
sortByKeyOrder: typeof sortByKeyOrder;
|
|
81
82
|
retry: typeof retry;
|
|
83
|
+
isBetweenTimeRange: (range: undefined | [] | [string | null, string | null]) => boolean;
|
|
82
84
|
};
|
|
83
85
|
export default _default;
|
package/lib/utils.js
CHANGED
|
@@ -159,6 +159,10 @@ export function createInvalidStreamChecker(count = 15) {
|
|
|
159
159
|
let prevFrame = 0;
|
|
160
160
|
let frameUnchangedCount = 0;
|
|
161
161
|
return (ffmpegLogLine) => {
|
|
162
|
+
// B站某些cdn在直播结束后仍会返回一些数据 https://github.com/renmu123/biliLive-tools/issues/123
|
|
163
|
+
if (ffmpegLogLine.includes("New subtitle stream with index")) {
|
|
164
|
+
return true;
|
|
165
|
+
}
|
|
162
166
|
const streamInfo = ffmpegLogLine.match(/frame=\s*(\d+) fps=.*? q=.*? size=.*? time=.*? bitrate=.*? speed=.*?/);
|
|
163
167
|
if (streamInfo != null) {
|
|
164
168
|
const [, frameText] = streamInfo;
|
|
@@ -257,6 +261,49 @@ export async function retry(fn, retries = 3, delay = 1000) {
|
|
|
257
261
|
return retry(fn, retries - 1, delay);
|
|
258
262
|
}
|
|
259
263
|
}
|
|
264
|
+
export const isBetweenTimeRange = (range) => {
|
|
265
|
+
if (!range)
|
|
266
|
+
return true;
|
|
267
|
+
if (range.length !== 2)
|
|
268
|
+
return true;
|
|
269
|
+
if (range[0] === null || range[1] === null)
|
|
270
|
+
return true;
|
|
271
|
+
try {
|
|
272
|
+
const status = isBetweenTime(new Date(), range);
|
|
273
|
+
return status;
|
|
274
|
+
}
|
|
275
|
+
catch (error) {
|
|
276
|
+
return true;
|
|
277
|
+
}
|
|
278
|
+
};
|
|
279
|
+
/**
|
|
280
|
+
* 当前时间是否在两个时间'HH:mm:ss'之间,如果是["22:00:00","05:00:00"],当前时间是凌晨3点,返回true
|
|
281
|
+
* @param {string} currentTime 当前时间
|
|
282
|
+
* @param {string[]} timeRange 时间范围
|
|
283
|
+
*/
|
|
284
|
+
function isBetweenTime(currentTime, timeRange) {
|
|
285
|
+
const [startTime, endTime] = timeRange;
|
|
286
|
+
if (!startTime || !endTime)
|
|
287
|
+
return true;
|
|
288
|
+
const [startHour, startMinute, startSecond] = startTime.split(":").map(Number);
|
|
289
|
+
const [endHour, endMinute, endSecond] = endTime.split(":").map(Number);
|
|
290
|
+
const [currentHour, currentMinute, currentSecond] = [
|
|
291
|
+
currentTime.getHours(),
|
|
292
|
+
currentTime.getMinutes(),
|
|
293
|
+
currentTime.getSeconds(),
|
|
294
|
+
];
|
|
295
|
+
const start = startHour * 3600 + startMinute * 60 + startSecond;
|
|
296
|
+
let end = endHour * 3600 + endMinute * 60 + endSecond;
|
|
297
|
+
let current = currentHour * 3600 + currentMinute * 60 + currentSecond;
|
|
298
|
+
// 如果结束时间小于开始时间,说明跨越了午夜
|
|
299
|
+
if (end < start) {
|
|
300
|
+
end += 24 * 3600; // 将结束时间加上24小时
|
|
301
|
+
if (current < start) {
|
|
302
|
+
current += 24 * 3600; // 如果当前时间小于开始时间,也加上24小时
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
return start <= current && current <= end;
|
|
306
|
+
}
|
|
260
307
|
export default {
|
|
261
308
|
replaceExtName,
|
|
262
309
|
singleton,
|
|
@@ -275,4 +322,5 @@ export default {
|
|
|
275
322
|
uuid,
|
|
276
323
|
sortByKeyOrder,
|
|
277
324
|
retry,
|
|
325
|
+
isBetweenTimeRange,
|
|
278
326
|
};
|