@bililive-tools/douyu-recorder 1.0.0

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/test.d.ts ADDED
@@ -0,0 +1 @@
1
+ export {};
package/lib/test.js ADDED
@@ -0,0 +1,14 @@
1
+ // execute in shell `ts-node src/test.ts` to run test
2
+ // TODO: add to scripts
3
+ import { createRecorderManager } from "@bililive-tools/manager";
4
+ import { provider } from "./index.js";
5
+ const manager = createRecorderManager({ providers: [provider] });
6
+ manager.addRecorder({
7
+ providerId: provider.id,
8
+ channelId: "74751",
9
+ quality: "highest",
10
+ streamPriorities: [],
11
+ sourcePriorities: [],
12
+ });
13
+ manager.startCheckLoop();
14
+ //# sourceMappingURL=test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"test.js","sourceRoot":"","sources":["../src/test.ts"],"names":[],"mappings":"AAAA,qDAAqD;AACrD,uBAAuB;AACvB,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAChE,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAEtC,MAAM,OAAO,GAAG,qBAAqB,CAAC,EAAE,SAAS,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;AACjE,OAAO,CAAC,WAAW,CAAC;IAClB,UAAU,EAAE,QAAQ,CAAC,EAAE;IACvB,SAAS,EAAE,OAAO;IAClB,OAAO,EAAE,SAAS;IAClB,gBAAgB,EAAE,EAAE;IACpB,gBAAgB,EAAE,EAAE;CACrB,CAAC,CAAC;AACH,OAAO,CAAC,cAAc,EAAE,CAAC"}
package/lib/utils.d.ts ADDED
@@ -0,0 +1,19 @@
1
+ /**
2
+ * 从数组中按照特定算法提取一些值(允许同个索引重复提取)。
3
+ * 算法的行为类似 flex 的 space-between。
4
+ *
5
+ * examples:
6
+ * ```
7
+ * console.log(getValuesFromArrayLikeFlexSpaceBetween([1, 2, 3, 4, 5, 6, 7], 1))
8
+ * // [1]
9
+ * console.log(getValuesFromArrayLikeFlexSpaceBetween([1, 2, 3, 4, 5, 6, 7], 3))
10
+ * // [1, 4, 7]
11
+ * console.log(getValuesFromArrayLikeFlexSpaceBetween([1, 2, 3, 4, 5, 6, 7], 4))
12
+ * // [1, 3, 5, 7]
13
+ * console.log(getValuesFromArrayLikeFlexSpaceBetween([1, 2, 3, 4, 5, 6, 7], 11))
14
+ * // [1, 1, 2, 3, 3, 4, 5, 5, 6, 7, 7]
15
+ * ```
16
+ */
17
+ export declare function getValuesFromArrayLikeFlexSpaceBetween<T>(array: T[], columnCount: number): T[];
18
+ export declare function ensureFolderExist(fileOrFolderPath: string): void;
19
+ export declare function assert(assertion: unknown, msg?: string): asserts assertion;
package/lib/utils.js ADDED
@@ -0,0 +1,53 @@
1
+ import fs from "node:fs";
2
+ import path from "node:path";
3
+ import { range } from "lodash-es";
4
+ /**
5
+ * 从数组中按照特定算法提取一些值(允许同个索引重复提取)。
6
+ * 算法的行为类似 flex 的 space-between。
7
+ *
8
+ * examples:
9
+ * ```
10
+ * console.log(getValuesFromArrayLikeFlexSpaceBetween([1, 2, 3, 4, 5, 6, 7], 1))
11
+ * // [1]
12
+ * console.log(getValuesFromArrayLikeFlexSpaceBetween([1, 2, 3, 4, 5, 6, 7], 3))
13
+ * // [1, 4, 7]
14
+ * console.log(getValuesFromArrayLikeFlexSpaceBetween([1, 2, 3, 4, 5, 6, 7], 4))
15
+ * // [1, 3, 5, 7]
16
+ * console.log(getValuesFromArrayLikeFlexSpaceBetween([1, 2, 3, 4, 5, 6, 7], 11))
17
+ * // [1, 1, 2, 3, 3, 4, 5, 5, 6, 7, 7]
18
+ * ```
19
+ */
20
+ export function getValuesFromArrayLikeFlexSpaceBetween(array, columnCount) {
21
+ if (columnCount < 1)
22
+ return [];
23
+ if (columnCount === 1)
24
+ return [array[0]];
25
+ const spacingCount = columnCount - 1;
26
+ const spacingLength = array.length / spacingCount;
27
+ const columns = range(1, columnCount + 1);
28
+ const columnValues = columns.map((column, idx, columns) => {
29
+ // 首个和最后的列是特殊的,因为它们不在范围内,而是在两端
30
+ if (idx === 0) {
31
+ return array[0];
32
+ }
33
+ else if (idx === columns.length - 1) {
34
+ return array[array.length - 1];
35
+ }
36
+ const beforeSpacingCount = column - 1;
37
+ const colPos = beforeSpacingCount * spacingLength;
38
+ return array[Math.floor(colPos)];
39
+ });
40
+ return columnValues;
41
+ }
42
+ export function ensureFolderExist(fileOrFolderPath) {
43
+ const folder = path.dirname(fileOrFolderPath);
44
+ if (!fs.existsSync(folder)) {
45
+ fs.mkdirSync(folder, { recursive: true });
46
+ }
47
+ }
48
+ export function assert(assertion, msg) {
49
+ if (!assertion) {
50
+ throw new Error(msg);
51
+ }
52
+ }
53
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,KAAK,EAAE,MAAM,WAAW,CAAC;AAElC;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,sCAAsC,CAAI,KAAU,EAAE,WAAmB;IACvF,IAAI,WAAW,GAAG,CAAC;QAAE,OAAO,EAAE,CAAC;IAC/B,IAAI,WAAW,KAAK,CAAC;QAAE,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;IAEzC,MAAM,YAAY,GAAG,WAAW,GAAG,CAAC,CAAC;IACrC,MAAM,aAAa,GAAG,KAAK,CAAC,MAAM,GAAG,YAAY,CAAC;IAElD,MAAM,OAAO,GAAG,KAAK,CAAC,CAAC,EAAE,WAAW,GAAG,CAAC,CAAC,CAAC;IAC1C,MAAM,YAAY,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,GAAG,EAAE,OAAO,EAAE,EAAE;QACxD,8BAA8B;QAC9B,IAAI,GAAG,KAAK,CAAC,EAAE,CAAC;YACd,OAAO,KAAK,CAAC,CAAC,CAAC,CAAC;QAClB,CAAC;aAAM,IAAI,GAAG,KAAK,OAAO,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACtC,OAAO,KAAK,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;QACjC,CAAC;QAED,MAAM,kBAAkB,GAAG,MAAM,GAAG,CAAC,CAAC;QACtC,MAAM,MAAM,GAAG,kBAAkB,GAAG,aAAa,CAAC;QAElD,OAAO,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC;IACnC,CAAC,CAAC,CAAC;IAEH,OAAO,YAAY,CAAC;AACtB,CAAC;AAED,MAAM,UAAU,iBAAiB,CAAC,gBAAwB;IACxD,MAAM,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC,gBAAgB,CAAC,CAAC;IAC9C,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE,CAAC;QAC3B,EAAE,CAAC,SAAS,CAAC,MAAM,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IAC5C,CAAC;AACH,CAAC;AAED,MAAM,UAAU,MAAM,CAAC,SAAkB,EAAE,GAAY;IACrD,IAAI,CAAC,SAAS,EAAE,CAAC;QACf,MAAM,IAAI,KAAK,CAAC,GAAG,CAAC,CAAC;IACvB,CAAC;AACH,CAAC"}
package/package.json ADDED
@@ -0,0 +1,50 @@
1
+ {
2
+ "name": "@bililive-tools/douyu-recorder",
3
+ "version": "1.0.0",
4
+ "description": "LAR douyu recorder implemention",
5
+ "main": "./lib/index.js",
6
+ "type": "module",
7
+ "exports": {
8
+ ".": {
9
+ "types": "./src/index.ts",
10
+ "development": "./src/index.ts",
11
+ "default": "./lib/index.js"
12
+ },
13
+ "./*.js": {
14
+ "types": "./src/*.ts",
15
+ "development": "./src/*.ts",
16
+ "default": "./lib/*.js"
17
+ }
18
+ },
19
+ "publishConfig": {
20
+ "access": "public"
21
+ },
22
+ "files": [
23
+ "lib"
24
+ ],
25
+ "repository": "https://github.com/renmu123/biliLive-tools/tree/master/packages/DouYuRecorder",
26
+ "author": "renmu123",
27
+ "license": "LGPL",
28
+ "dependencies": {
29
+ "mitt": "^3.0.1",
30
+ "query-string": "^9.1.1",
31
+ "safe-eval": "^0.4.1",
32
+ "ws": "^8.18.0",
33
+ "@bililive-tools/manager": "1.0.0"
34
+ },
35
+ "devDependencies": {
36
+ "@types/ws": "^8.5.13",
37
+ "@biliLive-tools/types": "1.8.0"
38
+ },
39
+ "peerDependencies": {
40
+ "@bililive-tools/manager": "*"
41
+ },
42
+ "optionalDependencies": {
43
+ "bufferutil": "^4.0.8",
44
+ "utf-8-validate": "^6.0.5"
45
+ },
46
+ "scripts": {
47
+ "build": "tsc",
48
+ "watch": "tsc -w"
49
+ }
50
+ }