@autorecord/douyin-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/LICENSE ADDED
@@ -0,0 +1,165 @@
1
+ GNU LESSER GENERAL PUBLIC LICENSE
2
+ Version 3, 29 June 2007
3
+
4
+ Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
5
+ Everyone is permitted to copy and distribute verbatim copies
6
+ of this license document, but changing it is not allowed.
7
+
8
+
9
+ This version of the GNU Lesser General Public License incorporates
10
+ the terms and conditions of version 3 of the GNU General Public
11
+ License, supplemented by the additional permissions listed below.
12
+
13
+ 0. Additional Definitions.
14
+
15
+ As used herein, "this License" refers to version 3 of the GNU Lesser
16
+ General Public License, and the "GNU GPL" refers to version 3 of the GNU
17
+ General Public License.
18
+
19
+ "The Library" refers to a covered work governed by this License,
20
+ other than an Application or a Combined Work as defined below.
21
+
22
+ An "Application" is any work that makes use of an interface provided
23
+ by the Library, but which is not otherwise based on the Library.
24
+ Defining a subclass of a class defined by the Library is deemed a mode
25
+ of using an interface provided by the Library.
26
+
27
+ A "Combined Work" is a work produced by combining or linking an
28
+ Application with the Library. The particular version of the Library
29
+ with which the Combined Work was made is also called the "Linked
30
+ Version".
31
+
32
+ The "Minimal Corresponding Source" for a Combined Work means the
33
+ Corresponding Source for the Combined Work, excluding any source code
34
+ for portions of the Combined Work that, considered in isolation, are
35
+ based on the Application, and not on the Linked Version.
36
+
37
+ The "Corresponding Application Code" for a Combined Work means the
38
+ object code and/or source code for the Application, including any data
39
+ and utility programs needed for reproducing the Combined Work from the
40
+ Application, but excluding the System Libraries of the Combined Work.
41
+
42
+ 1. Exception to Section 3 of the GNU GPL.
43
+
44
+ You may convey a covered work under sections 3 and 4 of this License
45
+ without being bound by section 3 of the GNU GPL.
46
+
47
+ 2. Conveying Modified Versions.
48
+
49
+ If you modify a copy of the Library, and, in your modifications, a
50
+ facility refers to a function or data to be supplied by an Application
51
+ that uses the facility (other than as an argument passed when the
52
+ facility is invoked), then you may convey a copy of the modified
53
+ version:
54
+
55
+ a) under this License, provided that you make a good faith effort to
56
+ ensure that, in the event an Application does not supply the
57
+ function or data, the facility still operates, and performs
58
+ whatever part of its purpose remains meaningful, or
59
+
60
+ b) under the GNU GPL, with none of the additional permissions of
61
+ this License applicable to that copy.
62
+
63
+ 3. Object Code Incorporating Material from Library Header Files.
64
+
65
+ The object code form of an Application may incorporate material from
66
+ a header file that is part of the Library. You may convey such object
67
+ code under terms of your choice, provided that, if the incorporated
68
+ material is not limited to numerical parameters, data structure
69
+ layouts and accessors, or small macros, inline functions and templates
70
+ (ten or fewer lines in length), you do both of the following:
71
+
72
+ a) Give prominent notice with each copy of the object code that the
73
+ Library is used in it and that the Library and its use are
74
+ covered by this License.
75
+
76
+ b) Accompany the object code with a copy of the GNU GPL and this license
77
+ document.
78
+
79
+ 4. Combined Works.
80
+
81
+ You may convey a Combined Work under terms of your choice that,
82
+ taken together, effectively do not restrict modification of the
83
+ portions of the Library contained in the Combined Work and reverse
84
+ engineering for debugging such modifications, if you also do each of
85
+ the following:
86
+
87
+ a) Give prominent notice with each copy of the Combined Work that
88
+ the Library is used in it and that the Library and its use are
89
+ covered by this License.
90
+
91
+ b) Accompany the Combined Work with a copy of the GNU GPL and this license
92
+ document.
93
+
94
+ c) For a Combined Work that displays copyright notices during
95
+ execution, include the copyright notice for the Library among
96
+ these notices, as well as a reference directing the user to the
97
+ copies of the GNU GPL and this license document.
98
+
99
+ d) Do one of the following:
100
+
101
+ 0) Convey the Minimal Corresponding Source under the terms of this
102
+ License, and the Corresponding Application Code in a form
103
+ suitable for, and under terms that permit, the user to
104
+ recombine or relink the Application with a modified version of
105
+ the Linked Version to produce a modified Combined Work, in the
106
+ manner specified by section 6 of the GNU GPL for conveying
107
+ Corresponding Source.
108
+
109
+ 1) Use a suitable shared library mechanism for linking with the
110
+ Library. A suitable mechanism is one that (a) uses at run time
111
+ a copy of the Library already present on the user's computer
112
+ system, and (b) will operate properly with a modified version
113
+ of the Library that is interface-compatible with the Linked
114
+ Version.
115
+
116
+ e) Provide Installation Information, but only if you would otherwise
117
+ be required to provide such information under section 6 of the
118
+ GNU GPL, and only to the extent that such information is
119
+ necessary to install and execute a modified version of the
120
+ Combined Work produced by recombining or relinking the
121
+ Application with a modified version of the Linked Version. (If
122
+ you use option 4d0, the Installation Information must accompany
123
+ the Minimal Corresponding Source and Corresponding Application
124
+ Code. If you use option 4d1, you must provide the Installation
125
+ Information in the manner specified by section 6 of the GNU GPL
126
+ for conveying Corresponding Source.)
127
+
128
+ 5. Combined Libraries.
129
+
130
+ You may place library facilities that are a work based on the
131
+ Library side by side in a single library together with other library
132
+ facilities that are not Applications and are not covered by this
133
+ License, and convey such a combined library under terms of your
134
+ choice, if you do both of the following:
135
+
136
+ a) Accompany the combined library with a copy of the same work based
137
+ on the Library, uncombined with any other library facilities,
138
+ conveyed under the terms of this License.
139
+
140
+ b) Give prominent notice with the combined library that part of it
141
+ is a work based on the Library, and explaining where to find the
142
+ accompanying uncombined form of the same work.
143
+
144
+ 6. Revised Versions of the GNU Lesser General Public License.
145
+
146
+ The Free Software Foundation may publish revised and/or new versions
147
+ of the GNU Lesser General Public License from time to time. Such new
148
+ versions will be similar in spirit to the present version, but may
149
+ differ in detail to address new problems or concerns.
150
+
151
+ Each version is given a distinguishing version number. If the
152
+ Library as you received it specifies that a certain numbered version
153
+ of the GNU Lesser General Public License "or any later version"
154
+ applies to it, you have the option of following the terms and
155
+ conditions either of that published version or of any later version
156
+ published by the Free Software Foundation. If the Library as you
157
+ received it does not specify a version number of the GNU Lesser
158
+ General Public License, you may choose any version of the GNU Lesser
159
+ General Public License ever published by the Free Software Foundation.
160
+
161
+ If the Library as you received it specifies that a proxy can decide
162
+ whether future versions of the GNU Lesser General Public License shall
163
+ apply, that proxy's public statement of acceptance of any version is
164
+ permanent authorization for you to choose that version for the
165
+ Library.
package/README.md ADDED
@@ -0,0 +1,3 @@
1
+ # Intro
2
+
3
+ 这是 [LiveAutoRecord](https://github.com/WhiteMinds/LiveAutoRecord) 的一个平台插件,为其支持了抖音平台
@@ -0,0 +1,33 @@
1
+ export declare function getRoomInfo(webRoomId: string, retryOnSpecialCode?: boolean): Promise<{
2
+ living: boolean;
3
+ roomId: string;
4
+ owner: string;
5
+ title: string;
6
+ streams: StreamProfile[];
7
+ sources: SourceProfile[];
8
+ }>;
9
+ export interface StreamProfile {
10
+ desc: string;
11
+ key: string;
12
+ bitRate: number;
13
+ }
14
+ export interface SourceProfile {
15
+ name: string;
16
+ streamMap: StreamData['data'];
17
+ }
18
+ interface StreamData {
19
+ common: unknown;
20
+ data: Record<string, {
21
+ main: {
22
+ flv: string;
23
+ hls: string;
24
+ cmaf: string;
25
+ dash: string;
26
+ lls: string;
27
+ tsl: string;
28
+ tile: string;
29
+ sdk_params: string;
30
+ };
31
+ }>;
32
+ }
33
+ export {};
@@ -0,0 +1,82 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.getRoomInfo = void 0;
16
+ const axios_1 = __importDefault(require("axios"));
17
+ const axios_cookiejar_support_1 = require("axios-cookiejar-support");
18
+ const tough_cookie_1 = require("tough-cookie");
19
+ const utils_1 = require("./utils");
20
+ const jar = new tough_cookie_1.CookieJar();
21
+ const requester = (0, axios_cookiejar_support_1.wrapper)(axios_1.default.create({
22
+ timeout: 10e3,
23
+ jar,
24
+ }));
25
+ function getRoomInfo(webRoomId, retryOnSpecialCode = true) {
26
+ return __awaiter(this, void 0, void 0, function* () {
27
+ const res = yield requester.get('https://live.douyin.com/webcast/web/enter/', {
28
+ params: {
29
+ aid: 6383,
30
+ live_id: 1,
31
+ device_platform: 'web',
32
+ language: 'zh-CN',
33
+ enter_from: 'web_live',
34
+ cookie_enabled: 'true',
35
+ screen_width: 1920,
36
+ screen_height: 1080,
37
+ browser_language: 'zh-CN',
38
+ browser_platform: 'MacIntel',
39
+ browser_name: 'Chrome',
40
+ browser_version: '108.0.0.0',
41
+ web_rid: webRoomId,
42
+ // enter_source:,
43
+ 'Room-Enter-User-Login-Ab': 0,
44
+ is_need_double_stream: 'false',
45
+ },
46
+ });
47
+ // 无 cookie 时 code 为 10037
48
+ if (res.data.status_code === 10037 && retryOnSpecialCode) {
49
+ // resp 自动设置 cookie
50
+ yield requester.get('https://live.douyin.com/favicon.ico');
51
+ return getRoomInfo(webRoomId, false);
52
+ }
53
+ (0, utils_1.assert)(res.data.status_code === 0, `Unexpected resp, code ${res.data.status_code}, msg ${res.data.data}`);
54
+ const data = res.data.data;
55
+ const room = data.data[0];
56
+ const { options: { qualities }, stream_data, } = room.stream_url.live_core_sdk_data.pull_data;
57
+ const streamData = JSON.parse(stream_data).data;
58
+ const streams = qualities.map((info) => ({
59
+ desc: info.name,
60
+ key: info.sdk_key,
61
+ bitRate: info.v_bit_rate,
62
+ }));
63
+ // 看起来抖音是自动切换 cdn 的,所以这里固定返回一个默认的 source。
64
+ const sources = [
65
+ {
66
+ name: '自动切换线路',
67
+ streamMap: streamData,
68
+ },
69
+ ];
70
+ return {
71
+ living: data.room_status === 0,
72
+ // 接口里不会再返回 web room id,只能直接用入参原路返回了。
73
+ roomId: webRoomId,
74
+ owner: data.user.nickname,
75
+ title: room.title,
76
+ streams,
77
+ sources,
78
+ };
79
+ });
80
+ }
81
+ exports.getRoomInfo = getRoomInfo;
82
+ //# sourceMappingURL=douyin_api.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"douyin_api.js","sourceRoot":"","sources":["../src/douyin_api.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,kDAAyB;AACzB,qEAAiD;AACjD,+CAAwC;AACxC,mCAAgC;AAEhC,MAAM,GAAG,GAAG,IAAI,wBAAS,EAAE,CAAA;AAC3B,MAAM,SAAS,GAAG,IAAA,iCAAO,EACvB,eAAK,CAAC,MAAM,CAAC;IACX,OAAO,EAAE,IAAI;IACb,GAAG;CACJ,CAAC,CACH,CAAA;AAED,SAAsB,WAAW,CAC/B,SAAiB,EACjB,kBAAkB,GAAG,IAAI;;QASzB,MAAM,GAAG,GAAG,MAAM,SAAS,CAAC,GAAG,CAC7B,4CAA4C,EAC5C;YACE,MAAM,EAAE;gBACN,GAAG,EAAE,IAAI;gBACT,OAAO,EAAE,CAAC;gBACV,eAAe,EAAE,KAAK;gBACtB,QAAQ,EAAE,OAAO;gBACjB,UAAU,EAAE,UAAU;gBACtB,cAAc,EAAE,MAAM;gBACtB,YAAY,EAAE,IAAI;gBAClB,aAAa,EAAE,IAAI;gBACnB,gBAAgB,EAAE,OAAO;gBACzB,gBAAgB,EAAE,UAAU;gBAC5B,YAAY,EAAE,QAAQ;gBACtB,eAAe,EAAE,WAAW;gBAC5B,OAAO,EAAE,SAAS;gBAClB,iBAAiB;gBACjB,0BAA0B,EAAE,CAAC;gBAC7B,qBAAqB,EAAE,OAAO;aAC/B;SACF,CACF,CAAA;QAED,0BAA0B;QAC1B,IAAI,GAAG,CAAC,IAAI,CAAC,WAAW,KAAK,KAAK,IAAI,kBAAkB,EAAE;YACxD,mBAAmB;YACnB,MAAM,SAAS,CAAC,GAAG,CAAC,qCAAqC,CAAC,CAAA;YAC1D,OAAO,WAAW,CAAC,SAAS,EAAE,KAAK,CAAC,CAAA;SACrC;QAED,IAAA,cAAM,EACJ,GAAG,CAAC,IAAI,CAAC,WAAW,KAAK,CAAC,EAC1B,yBAAyB,GAAG,CAAC,IAAI,CAAC,WAAW,SAAS,GAAG,CAAC,IAAI,CAAC,IAAI,EAAE,CACtE,CAAA;QAED,MAAM,IAAI,GAAG,GAAG,CAAC,IAAI,CAAC,IAAI,CAAA;QAC1B,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;QACzB,MAAM,EACJ,OAAO,EAAE,EAAE,SAAS,EAAE,EACtB,WAAW,GACZ,GAAG,IAAI,CAAC,UAAU,CAAC,kBAAkB,CAAC,SAAS,CAAA;QAChD,MAAM,UAAU,GAAI,IAAI,CAAC,KAAK,CAAC,WAAW,CAAgB,CAAC,IAAI,CAAA;QAE/D,MAAM,OAAO,GAAoB,SAAS,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;YACxD,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,GAAG,EAAE,IAAI,CAAC,OAAO;YACjB,OAAO,EAAE,IAAI,CAAC,UAAU;SACzB,CAAC,CAAC,CAAA;QAEH,yCAAyC;QACzC,MAAM,OAAO,GAAoB;YAC/B;gBACE,IAAI,EAAE,QAAQ;gBACd,SAAS,EAAE,UAAU;aACtB;SACF,CAAA;QAED,OAAO;YACL,MAAM,EAAE,IAAI,CAAC,WAAW,KAAK,CAAC;YAC9B,qCAAqC;YACrC,MAAM,EAAE,SAAS;YACjB,KAAK,EAAE,IAAI,CAAC,IAAI,CAAC,QAAQ;YACzB,KAAK,EAAE,IAAI,CAAC,KAAK;YACjB,OAAO;YACP,OAAO;SACR,CAAA;IACH,CAAC;CAAA;AA9ED,kCA8EC"}
package/lib/index.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ import { RecorderProvider } from '@autorecord/manager';
2
+ export declare const provider: RecorderProvider<{}>;
package/lib/index.js ADDED
@@ -0,0 +1,187 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.provider = void 0;
16
+ const path_1 = __importDefault(require("path"));
17
+ const mitt_1 = __importDefault(require("mitt"));
18
+ const manager_1 = require("@autorecord/manager");
19
+ const stream_1 = require("./stream");
20
+ const utils_1 = require("./utils");
21
+ function createRecorder(opts) {
22
+ var _a, _b;
23
+ // 内部实现时,应该只有 proxy 包裹的那一层会使用这个 recorder 标识符,不应该有直接通过
24
+ // 此标志来操作这个对象的地方,不然会跳过 proxy 的拦截。
25
+ const recorder = Object.assign(Object.assign(Object.assign({ id: (_a = opts.id) !== null && _a !== void 0 ? _a : (0, manager_1.genRecorderUUID)(), extra: (_b = opts.extra) !== null && _b !== void 0 ? _b : {} }, (0, mitt_1.default)()), opts), { availableStreams: [], availableSources: [], state: 'idle', getChannelURL() {
26
+ return `https://live.bilibili.com/${this.channelId}`;
27
+ }, checkLiveStatusAndRecord: (0, utils_1.singleton)(checkLiveStatusAndRecord), toJSON() {
28
+ return (0, manager_1.defaultToJSON)(exports.provider, this);
29
+ } });
30
+ const recorderWithSupportUpdatedEvent = new Proxy(recorder, {
31
+ set(obj, prop, value) {
32
+ Reflect.set(obj, prop, value);
33
+ if (typeof prop === 'string') {
34
+ obj.emit('Updated', [prop]);
35
+ }
36
+ return true;
37
+ },
38
+ });
39
+ return recorderWithSupportUpdatedEvent;
40
+ }
41
+ const ffmpegOutputOptions = [
42
+ '-c',
43
+ 'copy',
44
+ '-movflags',
45
+ 'frag_keyframe',
46
+ '-min_frag_duration',
47
+ '60000000',
48
+ ];
49
+ const checkLiveStatusAndRecord = function ({ getSavePath }) {
50
+ return __awaiter(this, void 0, void 0, function* () {
51
+ if (this.recordHandle != null)
52
+ return this.recordHandle;
53
+ const { living, owner, title, roomId } = yield (0, stream_1.getInfo)(this.channelId);
54
+ if (!living)
55
+ return null;
56
+ this.state = 'recording';
57
+ let res;
58
+ // TODO: 先不做什么错误处理,就简单包一下预期上会有错误的地方
59
+ try {
60
+ res = yield (0, stream_1.getStream)({
61
+ channelId: this.channelId,
62
+ quality: this.quality,
63
+ streamPriorities: this.streamPriorities,
64
+ sourcePriorities: this.sourcePriorities,
65
+ });
66
+ }
67
+ catch (err) {
68
+ this.state = 'idle';
69
+ throw err;
70
+ }
71
+ const { currentStream: stream, sources: availableSources, streams: availableStreams, } = res;
72
+ this.availableStreams = availableStreams.map((s) => s.desc);
73
+ this.availableSources = availableSources.map((s) => s.name);
74
+ this.usedStream = stream.name;
75
+ this.usedSource = stream.source;
76
+ // TODO: emit update event
77
+ const savePath = getSavePath({ owner, title });
78
+ // TODO: 之后可能要结合 disableRecordMeta 之类的来确认是否要创建文件。
79
+ const extraDataSavePath = (0, utils_1.replaceExtName)(savePath, '.json');
80
+ // TODO: 这个 ensure 或许应该放在 createRecordExtraDataController 里实现?
81
+ (0, utils_1.ensureFolderExist)(extraDataSavePath);
82
+ const extraDataController = (0, manager_1.createRecordExtraDataController)(extraDataSavePath);
83
+ extraDataController.setMeta({ title });
84
+ // TODO: 弹幕录制
85
+ const recordSavePath = savePath;
86
+ (0, utils_1.ensureFolderExist)(recordSavePath);
87
+ const callback = (...args) => {
88
+ var _a;
89
+ console.log('cb', ...args);
90
+ (_a = this.recordHandle) === null || _a === void 0 ? void 0 : _a.stop();
91
+ };
92
+ // TODO: 主播重新开关播后原来的直播流地址会失效,这可能会导致录制出现问题,需要处理。
93
+ /**
94
+ * FragmentMP4 可以边录边播(浏览器原生支持),具有一定的抗损坏能力,录制中 KILL 只会
95
+ * 丢失最后一个片段,而 FLV 格式如果录制中 KILL 了需要手动修复下 keyframes。
96
+ */
97
+ const command = (0, manager_1.createFFMPEGBuilder)()
98
+ .input(stream.url)
99
+ .addInputOptions('-user_agent', 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:107.0) Gecko/20100101 Firefox/107.0', '-headers', 'Referer: https://live.bilibili.com/')
100
+ .outputOptions(ffmpegOutputOptions)
101
+ .output(recordSavePath)
102
+ .on('error', callback)
103
+ .on('end', () => callback())
104
+ .on('stderr', (stderrLine) => {
105
+ this.emit('DebugLog', { type: 'ffmpeg', text: stderrLine });
106
+ // if (stderrLine.startsWith('frame=')) {
107
+ // if (waitFirstFrame) {
108
+ // waitFirstFrame = false
109
+ // // 发出通知
110
+ // if (config.record.notice && !isSwitching)
111
+ // createNotice(channel.profile, channelInfo.title)
112
+ // }
113
+ // // TODO: 在此处对长时间无frame时的情况做检查。
114
+ // }
115
+ });
116
+ const ffmpegArgs = command._getArguments();
117
+ extraDataController.setMeta({
118
+ recordStartTimestamp: Date.now(),
119
+ ffmpegArgs,
120
+ });
121
+ command.run();
122
+ // TODO: 需要一个机制防止空录制,比如检查文件的大小变化、ffmpeg 的输出、直播状态等
123
+ const stop = (0, utils_1.singleton)(() => __awaiter(this, void 0, void 0, function* () {
124
+ if (!this.recordHandle)
125
+ return;
126
+ this.state = 'stopping-record';
127
+ // TODO: emit update event
128
+ // 如果给 SIGKILL 信号会非正常退出,SIGINT 可以被 ffmpeg 正常处理。
129
+ // TODO: fluent-ffmpeg 好像没处理好这个 SIGINT 导致的退出信息,会抛一个错。
130
+ command.kill('SIGINT');
131
+ // TODO: 这里可能会有内存泄露,因为事件还没清,之后再检查下看看。
132
+ // client?.close()
133
+ extraDataController.setMeta({ recordStopTimestamp: Date.now() });
134
+ extraDataController.flush();
135
+ this.usedStream = undefined;
136
+ this.usedSource = undefined;
137
+ // TODO: other codes
138
+ // TODO: emit update event
139
+ this.emit('RecordStop', this.recordHandle);
140
+ this.recordHandle = undefined;
141
+ this.state = 'idle';
142
+ }));
143
+ this.recordHandle = {
144
+ id: (0, manager_1.genRecordUUID)(),
145
+ stream: stream.name,
146
+ source: stream.source,
147
+ url: stream.url,
148
+ ffmpegArgs,
149
+ savePath: recordSavePath,
150
+ stop,
151
+ };
152
+ this.emit('RecordStart', this.recordHandle);
153
+ return this.recordHandle;
154
+ });
155
+ };
156
+ exports.provider = {
157
+ id: 'DouYin',
158
+ name: '抖音',
159
+ siteURL: 'https://live.douyin.com/',
160
+ matchURL(channelURL) {
161
+ // TODO: 暂时不支持 v.douyin.com
162
+ return /https?:\/\/live\.douyin\.com\//.test(channelURL);
163
+ },
164
+ resolveChannelInfoFromURL(channelURL) {
165
+ return __awaiter(this, void 0, void 0, function* () {
166
+ if (!this.matchURL(channelURL))
167
+ return null;
168
+ const id = path_1.default.basename(new URL(channelURL).pathname);
169
+ const info = yield (0, stream_1.getInfo)(id);
170
+ return {
171
+ id: info.roomId,
172
+ title: info.title,
173
+ owner: info.owner,
174
+ };
175
+ });
176
+ },
177
+ createRecorder(opts) {
178
+ return createRecorder(Object.assign({ providerId: exports.provider.id }, opts));
179
+ },
180
+ fromJSON(recorder) {
181
+ return (0, manager_1.defaultFromJSON)(this, recorder);
182
+ },
183
+ setFFMPEGOutputArgs(args) {
184
+ ffmpegOutputOptions.splice(0, ffmpegOutputOptions.length, ...args);
185
+ },
186
+ };
187
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,gDAAuB;AACvB,gDAAuB;AACvB,iDAa4B;AAC5B,qCAA6C;AAC7C,mCAAsE;AAEtE,SAAS,cAAc,CAAC,IAAwB;;IAC9C,qDAAqD;IACrD,iCAAiC;IACjC,MAAM,QAAQ,+CACZ,EAAE,E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AAO,gCAAgC,CAAC,IAAI,CAAC,UAAU,CAAC,CAAA;IAC1D,CAAC;IAEK,yBAAyB,CAAC,UAAU;;YACxC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC;gBAAE,OAAO,IAAI,CAAA;YAE3C,MAAM,EAAE,GAAG,cAAI,CAAC,QAAQ,CAAC,IAAI,GAAG,CAAC,UAAU,CAAC,CAAC,QAAQ,CAAC,CAAA;YACtD,MAAM,IAAI,GAAG,MAAM,IAAA,gBAAO,EAAC,EAAE,CAAC,CAAA;YAE9B,OAAO;gBACL,EAAE,EAAE,IAAI,CAAC,MAAM;gBACf,KAAK,EAAE,IAAI,CAAC,KAAK;gBACjB,KAAK,EAAE,IAAI,CAAC,KAAK;aAClB,CAAA;QACH,CAAC;KAAA;IAED,cAAc,CAAC,IAAI;QACjB,OAAO,cAAc,iBAAG,UAAU,EAAE,gBAAQ,CAAC,EAAE,IAAK,IAAI,EAAG,CAAA;IAC7D,CAAC;IAED,QAAQ,CAAC,QAAQ;QACf,OAAO,IAAA,yBAAe,EAAC,IAAI,EAAE,QAAQ,CAAC,CAAA;IACxC,CAAC;IAED,mBAAmB,CAAC,IAAI;QACtB,mBAAmB,CAAC,MAAM,CAAC,CAAC,EAAE,mBAAmB,CAAC,MAAM,EAAE,GAAG,IAAI,CAAC,CAAA;IACpE,CAAC;CACF,CAAA"}
@@ -0,0 +1,23 @@
1
+ import { Recorder } from '@autorecord/manager';
2
+ import { SourceProfile, StreamProfile } from './douyin_api';
3
+ export declare function getInfo(channelId: string): Promise<{
4
+ living: boolean;
5
+ owner: string;
6
+ title: string;
7
+ roomId: string;
8
+ }>;
9
+ export declare function getStream(opts: Pick<Recorder, 'channelId' | 'quality' | 'streamPriorities' | 'sourcePriorities'> & {
10
+ rejectCache?: boolean;
11
+ }): Promise<{
12
+ currentStream: {
13
+ name: string;
14
+ source: string;
15
+ url: string;
16
+ };
17
+ living: boolean;
18
+ roomId: string;
19
+ owner: string;
20
+ title: string;
21
+ streams: StreamProfile[];
22
+ sources: SourceProfile[];
23
+ }>;
package/lib/stream.js ADDED
@@ -0,0 +1,109 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
+ return new (P || (P = Promise))(function (resolve, reject) {
28
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
32
+ });
33
+ };
34
+ Object.defineProperty(exports, "__esModule", { value: true });
35
+ exports.getStream = exports.getInfo = void 0;
36
+ const manager_1 = require("@autorecord/manager");
37
+ const douyin_api_1 = require("./douyin_api");
38
+ const R = __importStar(require("ramda"));
39
+ const utils_1 = require("./utils");
40
+ function getInfo(channelId) {
41
+ return __awaiter(this, void 0, void 0, function* () {
42
+ const info = yield (0, douyin_api_1.getRoomInfo)(channelId);
43
+ return {
44
+ living: info.living,
45
+ owner: info.owner,
46
+ title: info.title,
47
+ roomId: info.roomId,
48
+ };
49
+ });
50
+ }
51
+ exports.getInfo = getInfo;
52
+ function getStream(opts) {
53
+ return __awaiter(this, void 0, void 0, function* () {
54
+ const info = yield (0, douyin_api_1.getRoomInfo)(opts.channelId);
55
+ if (!info.living) {
56
+ throw new Error('It must be called getStream when living');
57
+ }
58
+ let expectStream;
59
+ const streamsWithPriority = sortAndFilterStreamsByPriority(info.streams, opts.streamPriorities);
60
+ if (streamsWithPriority.length > 0) {
61
+ // 通过优先级来选择对应流
62
+ expectStream = streamsWithPriority[0];
63
+ }
64
+ else {
65
+ // 通过设置的画质选项来选择对应流
66
+ const flexedStreams = (0, utils_1.getValuesFromArrayLikeFlexSpaceBetween)(info.streams, manager_1.Qualities.length);
67
+ expectStream = flexedStreams[manager_1.Qualities.indexOf(opts.quality)];
68
+ }
69
+ let expectSource = null;
70
+ const sourcesWithPriority = sortAndFilterSourcesByPriority(info.sources, opts.sourcePriorities);
71
+ if (sourcesWithPriority.length > 0) {
72
+ expectSource = sourcesWithPriority[0];
73
+ }
74
+ else {
75
+ expectSource = info.sources[0];
76
+ }
77
+ return Object.assign(Object.assign({}, info), { currentStream: {
78
+ name: expectStream.desc,
79
+ source: expectSource.name,
80
+ url: expectSource.streamMap[expectStream.key].main.flv,
81
+ } });
82
+ });
83
+ }
84
+ exports.getStream = getStream;
85
+ /**
86
+ * 按提供的流优先级去给流列表排序,并过滤掉不在优先级配置中的流
87
+ */
88
+ function sortAndFilterStreamsByPriority(streams, streamPriorities) {
89
+ if (streamPriorities.length === 0)
90
+ return [];
91
+ return R.sortBy(R.prop('priority'),
92
+ // 分配优先级属性,数字越大优先级越高
93
+ streams
94
+ .map((stream) => (Object.assign(Object.assign({}, stream), { priority: R.reverse(streamPriorities).indexOf(stream.desc) })))
95
+ .filter(({ priority }) => priority !== -1));
96
+ }
97
+ /**
98
+ * 按提供的源优先级去给源列表排序,并过滤掉不在优先级配置中的源
99
+ */
100
+ function sortAndFilterSourcesByPriority(sources, sourcePriorities) {
101
+ if (sourcePriorities.length === 0)
102
+ return [];
103
+ return R.sortBy(R.prop('priority'),
104
+ // 分配优先级属性,数字越大优先级越高
105
+ sources
106
+ .map((source) => (Object.assign(Object.assign({}, source), { priority: R.reverse(sourcePriorities).indexOf(source.name) })))
107
+ .filter(({ priority }) => priority !== -1));
108
+ }
109
+ //# sourceMappingURL=stream.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stream.js","sourceRoot":"","sources":["../src/stream.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iDAAyD;AACzD,6CAAwE;AACxE,yCAA0B;AAC1B,mCAAwE;AAExE,SAAsB,OAAO,CAAC,SAAiB;;QAM7C,MAAM,IAAI,GAAG,MAAM,IAAA,wBAAW,EAAC,SAAS,CAAC,CAAA;QAEzC,OAAO;YACL,MAAM,EAAE,IAAI,CAAC,MAAM;YACnB,KAAK,EAAE,IAAI,CAAC,KAAK;YACjB,KAAK,EAAE,IAAI,CAAC,KAAK;YACjB,MAAM,EAAE,IAAI,CAAC,MAAM;SACpB,CAAA;IACH,CAAC;CAAA;AAdD,0BAcC;AAED,SAAsB,SAAS,CAC7B,IAG6B;;QAE7B,MAAM,IAAI,GAAG,MAAM,IAAA,wBAAW,EAAC,IAAI,CAAC,SAAS,CAAC,CAAA;QAC9C,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE;YAChB,MAAM,IAAI,KAAK,CAAC,yCAAyC,CAAC,CAAA;SAC3D;QAED,IAAI,YAA2B,CAAA;QAC/B,MAAM,mBAAmB,GAAG,8BAA8B,CACxD,IAAI,CAAC,OAAO,EACZ,IAAI,CAAC,gBAAgB,CACtB,CAAA;QACD,IAAI,mBAAmB,CA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AAM,CAAC,IAAI,CAAC,IAC1D,CAAC;SACF,MAAM,CAAC,CAAC,EAAE,QAAQ,EAAE,EAAE,EAAE,CAAC,QAAQ,KAAK,CAAC,CAAC,CAAC,CAC7C,CAAA;AACH,CAAC;AAED;;GAEG;AACH,SAAS,8BAA8B,CACrC,OAAwB,EACxB,gBAA8C;IAI9C,IAAI,gBAAgB,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,EAAE,CAAA;IAE5C,OAAO,CAAC,CAAC,MAAM,CACb,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC;IAClB,oBAAoB;IACpB,OAAO;SACJ,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,iCACZ,MAAM,KACT,QAAQ,EAAE,CAAC,CAAC,OAAO,CAAC,gBAAgB,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,IAC1D,CAAC;SACF,MAAM,CAAC,CAAC,EAAE,QAAQ,EAAE,EAAE,EAAE,CAAC,QAAQ,KAAK,CAAC,CAAC,CAAC,CAC7C,CAAA;AACH,CAAC"}
package/lib/test.d.ts ADDED
@@ -0,0 +1 @@
1
+ export {};
package/lib/test.js ADDED
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ // execute in shell `ts-node src/test.ts` to run test
4
+ // TODO: add to scripts
5
+ const manager_1 = require("@autorecord/manager");
6
+ const _1 = require(".");
7
+ const manager = (0, manager_1.createRecorderManager)({ providers: [_1.provider] });
8
+ manager.addRecorder({
9
+ providerId: _1.provider.id,
10
+ channelId: '317590520822',
11
+ quality: 'medium',
12
+ streamPriorities: [],
13
+ sourcePriorities: [],
14
+ });
15
+ manager.startCheckLoop();
16
+ //# 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,iDAA2D;AAC3D,wBAA4B;AAE5B,MAAM,OAAO,GAAG,IAAA,+BAAqB,EAAC,EAAE,SAAS,EAAE,CAAC,WAAQ,CAAC,EAAE,CAAC,CAAA;AAChE,OAAO,CAAC,WAAW,CAAC;IAClB,UAAU,EAAE,WAAQ,CAAC,EAAE;IACvB,SAAS,EAAE,cAAc;IACzB,OAAO,EAAE,QAAQ;IACjB,gBAAgB,EAAE,EAAE;IACpB,gBAAgB,EAAE,EAAE;CACrB,CAAC,CAAA;AACF,OAAO,CAAC,cAAc,EAAE,CAAA"}
package/lib/utils.d.ts ADDED
@@ -0,0 +1,28 @@
1
+ /**
2
+ * 接收 fn ,返回一个和 fn 签名一致的函数 fn'。当已经有一个 fn' 在运行时,再调用
3
+ * fn' 会直接返回运行中 fn' 的 Promise,直到 Promise 结束 pending 状态
4
+ */
5
+ export declare function singleton<Fn extends (...args: any) => Promise<any>>(fn: Fn): Fn;
6
+ /**
7
+ * 从数组中按照特定算法提取一些值(允许同个索引重复提取)。
8
+ * 算法的行为类似 flex 的 space-between。
9
+ *
10
+ * examples:
11
+ * ```
12
+ * console.log(getValuesFromArrayLikeFlexSpaceBetween([1, 2, 3, 4, 5, 6, 7], 1))
13
+ * // [1]
14
+ * console.log(getValuesFromArrayLikeFlexSpaceBetween([1, 2, 3, 4, 5, 6, 7], 3))
15
+ * // [1, 4, 7]
16
+ * console.log(getValuesFromArrayLikeFlexSpaceBetween([1, 2, 3, 4, 5, 6, 7], 4))
17
+ * // [1, 3, 5, 7]
18
+ * console.log(getValuesFromArrayLikeFlexSpaceBetween([1, 2, 3, 4, 5, 6, 7], 11))
19
+ * // [1, 1, 2, 3, 3, 4, 5, 5, 6, 7, 7]
20
+ * ```
21
+ */
22
+ export declare function getValuesFromArrayLikeFlexSpaceBetween<T>(array: T[], columnCount: number): T[];
23
+ export declare function ensureFolderExist(fileOrFolderPath: string): void;
24
+ export declare function assert(assertion: unknown, msg?: string): asserts assertion;
25
+ export declare function assertStringType(data: unknown, msg?: string): asserts data is string;
26
+ export declare function assertNumberType(data: unknown, msg?: string): asserts data is number;
27
+ export declare function assertObjectType(data: unknown, msg?: string): asserts data is object;
28
+ export declare function replaceExtName(filePath: string, newExtName: string): string;
package/lib/utils.js ADDED
@@ -0,0 +1,121 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __importDefault = (this && this.__importDefault) || function (mod) {
26
+ return (mod && mod.__esModule) ? mod : { "default": mod };
27
+ };
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ exports.replaceExtName = exports.assertObjectType = exports.assertNumberType = exports.assertStringType = exports.assert = exports.ensureFolderExist = exports.getValuesFromArrayLikeFlexSpaceBetween = exports.singleton = void 0;
30
+ const fs_1 = __importDefault(require("fs"));
31
+ const path_1 = __importDefault(require("path"));
32
+ const R = __importStar(require("ramda"));
33
+ /**
34
+ * 接收 fn ,返回一个和 fn 签名一致的函数 fn'。当已经有一个 fn' 在运行时,再调用
35
+ * fn' 会直接返回运行中 fn' 的 Promise,直到 Promise 结束 pending 状态
36
+ */
37
+ function singleton(fn) {
38
+ let latestPromise = null;
39
+ return function (...args) {
40
+ if (latestPromise)
41
+ return latestPromise;
42
+ const promise = fn.apply(this, args);
43
+ promise.finally(() => {
44
+ if (promise === latestPromise) {
45
+ latestPromise = null;
46
+ }
47
+ });
48
+ latestPromise = promise;
49
+ return promise;
50
+ };
51
+ }
52
+ exports.singleton = singleton;
53
+ /**
54
+ * 从数组中按照特定算法提取一些值(允许同个索引重复提取)。
55
+ * 算法的行为类似 flex 的 space-between。
56
+ *
57
+ * examples:
58
+ * ```
59
+ * console.log(getValuesFromArrayLikeFlexSpaceBetween([1, 2, 3, 4, 5, 6, 7], 1))
60
+ * // [1]
61
+ * console.log(getValuesFromArrayLikeFlexSpaceBetween([1, 2, 3, 4, 5, 6, 7], 3))
62
+ * // [1, 4, 7]
63
+ * console.log(getValuesFromArrayLikeFlexSpaceBetween([1, 2, 3, 4, 5, 6, 7], 4))
64
+ * // [1, 3, 5, 7]
65
+ * console.log(getValuesFromArrayLikeFlexSpaceBetween([1, 2, 3, 4, 5, 6, 7], 11))
66
+ * // [1, 1, 2, 3, 3, 4, 5, 5, 6, 7, 7]
67
+ * ```
68
+ */
69
+ function getValuesFromArrayLikeFlexSpaceBetween(array, columnCount) {
70
+ if (columnCount < 1)
71
+ return [];
72
+ if (columnCount === 1)
73
+ return [array[0]];
74
+ const spacingCount = columnCount - 1;
75
+ const spacingLength = array.length / spacingCount;
76
+ const columns = R.range(1, columnCount + 1);
77
+ const columnValues = columns.map((column, idx, columns) => {
78
+ // 首个和最后的列是特殊的,因为它们不在范围内,而是在两端
79
+ if (idx === 0) {
80
+ return array[0];
81
+ }
82
+ else if (idx === columns.length - 1) {
83
+ return array[array.length - 1];
84
+ }
85
+ const beforeSpacingCount = column - 1;
86
+ const colPos = beforeSpacingCount * spacingLength;
87
+ return array[Math.floor(colPos)];
88
+ });
89
+ return columnValues;
90
+ }
91
+ exports.getValuesFromArrayLikeFlexSpaceBetween = getValuesFromArrayLikeFlexSpaceBetween;
92
+ function ensureFolderExist(fileOrFolderPath) {
93
+ const folder = path_1.default.dirname(fileOrFolderPath);
94
+ if (!fs_1.default.existsSync(folder)) {
95
+ fs_1.default.mkdirSync(folder, { recursive: true });
96
+ }
97
+ }
98
+ exports.ensureFolderExist = ensureFolderExist;
99
+ function assert(assertion, msg) {
100
+ if (!assertion) {
101
+ throw new Error(msg);
102
+ }
103
+ }
104
+ exports.assert = assert;
105
+ function assertStringType(data, msg) {
106
+ assert(typeof data === 'string', msg);
107
+ }
108
+ exports.assertStringType = assertStringType;
109
+ function assertNumberType(data, msg) {
110
+ assert(typeof data === 'number', msg);
111
+ }
112
+ exports.assertNumberType = assertNumberType;
113
+ function assertObjectType(data, msg) {
114
+ assert(typeof data === 'object', msg);
115
+ }
116
+ exports.assertObjectType = assertObjectType;
117
+ function replaceExtName(filePath, newExtName) {
118
+ return path_1.default.join(path_1.default.dirname(filePath), path_1.default.basename(filePath, path_1.default.extname(filePath)) + newExtName);
119
+ }
120
+ exports.replaceExtName = replaceExtName;
121
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,4CAAmB;AACnB,gDAAuB;AACvB,yCAA0B;AAE1B;;;GAGG;AACH,SAAgB,SAAS,CACvB,EAAM;IAEN,IAAI,aAAa,GAA4B,IAAI,CAAA;IAEjD,OAAO,UAAU,GAAG,IAAI;QACtB,IAAI,aAAa;YAAE,OAAO,aAAa,CAAA;QAEvC,MAAM,OAAO,GAAG,EAAE,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,CAAA;QACpC,OAAO,CAAC,OAAO,CAAC,GAAG,EAAE;YACnB,IAAI,OAAO,KAAK,aAAa,EAAE;gBAC7B,aAAa,GAAG,IAAI,CAAA;aACrB;QACH,CAAC,CAAC,CAAA;QAEF,aAAa,GAAG,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AAE;QAC1B,YAAE,CAAC,SAAS,CAAC,MAAM,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAA;KAC1C;AACH,CAAC;AALD,8CAKC;AAED,SAAgB,MAAM,CAAC,SAAkB,EAAE,GAAY;IACrD,IAAI,CAAC,SAAS,EAAE;QACd,MAAM,IAAI,KAAK,CAAC,GAAG,CAAC,CAAA;KACrB;AACH,CAAC;AAJD,wBAIC;AAED,SAAgB,gBAAgB,CAC9B,IAAa,EACb,GAAY;IAEZ,MAAM,CAAC,OAAO,IAAI,KAAK,QAAQ,EAAE,GAAG,CAAC,CAAA;AACvC,CAAC;AALD,4CAKC;AAED,SAAgB,gBAAgB,CAC9B,IAAa,EACb,GAAY;IAEZ,MAAM,CAAC,OAAO,IAAI,KAAK,QAAQ,EAAE,GAAG,CAAC,CAAA;AACvC,CAAC;AALD,4CAKC;AAED,SAAgB,gBAAgB,CAC9B,IAAa,EACb,GAAY;IAEZ,MAAM,CAAC,OAAO,IAAI,KAAK,QAAQ,EAAE,GAAG,CAAC,CAAA;AACvC,CAAC;AALD,4CAKC;AAED,SAAgB,cAAc,CAAC,QAAgB,EAAE,UAAkB;IACjE,OAAO,cAAI,CAAC,IAAI,CACd,cAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,EACtB,cAAI,CAAC,QAAQ,CAAC,QAAQ,EAAE,cAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,GAAG,UAAU,CAC7D,CAAA;AACH,CAAC;AALD,wCAKC"}
package/package.json ADDED
@@ -0,0 +1,37 @@
1
+ {
2
+ "name": "@autorecord/douyin-recorder",
3
+ "version": "1.0.0",
4
+ "description": "LAR douyin recorder implemention",
5
+ "main": "./lib/index.js",
6
+ "publishConfig": {
7
+ "access": "public"
8
+ },
9
+ "scripts": {
10
+ "build": "tsc",
11
+ "watch": "tsc -w"
12
+ },
13
+ "files": [
14
+ "lib"
15
+ ],
16
+ "repository": "https://github.com/WhiteMinds/DouYinRecorder",
17
+ "author": "WhiteMind",
18
+ "license": "LGPL",
19
+ "dependencies": {
20
+ "axios": "^0.27.2",
21
+ "axios-cookiejar-support": "^4.0.3",
22
+ "mitt": "^3.0.0",
23
+ "ramda": "^0.28.0",
24
+ "tough-cookie": "^4.1.2"
25
+ },
26
+ "devDependencies": {
27
+ "@autorecord/manager": "^1.0.3",
28
+ "@types/lodash": "^4.14.190",
29
+ "@types/node": "*",
30
+ "@types/ramda": "^0.28.16",
31
+ "@types/tough-cookie": "^4.0.2",
32
+ "typescript": "^4.8.4"
33
+ },
34
+ "peerDependencies": {
35
+ "@autorecord/manager": "*"
36
+ }
37
+ }