obs-scheduler 0.0.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/.gitattributes ADDED
@@ -0,0 +1,2 @@
1
+ # Auto detect text files and perform LF normalization
2
+ * text=auto
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Edon
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,36 @@
1
+ # obs-scheduler
2
+
3
+ A CLI for scheduling actions in OBS.
4
+
5
+ ## Usage
6
+
7
+ ```shell
8
+ obs-scheduler -c scheduler-config.json -p
9
+ ```
10
+
11
+ ## Examples
12
+
13
+ ### Configuration File
14
+
15
+ ```json
16
+ {
17
+ "events": [
18
+ {
19
+ "name": "Example Event",
20
+ "schedule_type": "date",
21
+ "date": "2026-01-06T10:00",
22
+ "action": "start_recording"
23
+ },
24
+ {
25
+ "name": "Example Event 2",
26
+ "schedule_type": "recurring",
27
+ "schedule": "* * * * * *",
28
+ "action": "start_recording"
29
+ }
30
+ ]
31
+ }
32
+ ```
33
+
34
+ ## Notes
35
+
36
+ `config-schema.json` takes advantage of options and syntax from [`json-editor`](https://github.com/json-editor/json-editor) to allow for easy integration into a visual editor.
package/cli.js ADDED
@@ -0,0 +1,23 @@
1
+ #!/usr/bin/env node
2
+
3
+ import { run } from "./dist/index.js";
4
+
5
+ import { program } from "commander";
6
+
7
+ program
8
+ .name('obs-scheduler')
9
+ .version('0.0.1')
10
+ .option('-c, --config <file-path>', 'config file path')
11
+ .option(
12
+ '-i, --ip-address [address:port]',
13
+ 'OBS Websocket IP address and port',
14
+ undefined,
15
+ )
16
+ .option(
17
+ '-p, --password [password]',
18
+ 'OBS Websocket password',
19
+ undefined,
20
+ )
21
+ .action(run);
22
+
23
+ await program.parseAsync(process.argv);
@@ -0,0 +1,216 @@
1
+ {
2
+ "$schema": "http://json-schema.org/draft-07/schema#",
3
+ "title": "OBS Scheduler Config File Schema",
4
+ "type": "object",
5
+ "required": [
6
+ "events"
7
+ ],
8
+ "properties": {
9
+ "events": {
10
+ "title": "Events",
11
+ "description": "A list of events for triggering an action within OBS.",
12
+ "type": "array",
13
+ "format": "tabs",
14
+ "items": {
15
+ "title": "Event",
16
+ "description": "A scheduled event for triggering a set action in OBS.",
17
+ "type": "object",
18
+ "required": [
19
+ "schedule_type",
20
+ "action"
21
+ ],
22
+ "properties": {
23
+ "name": {
24
+ "title": "Name",
25
+ "description": "An optional name for the event.",
26
+ "propertyOrder": 1,
27
+ "type": "string"
28
+ },
29
+ "enabled": {
30
+ "title": "Enabled",
31
+ "description": "Whether or not this event should be considered \"active\".",
32
+ "propertyOrder": 2,
33
+ "type": "boolean",
34
+ "default": true,
35
+ "format": "checkbox"
36
+ },
37
+ "schedule_type": {
38
+ "title": "Schedule Type",
39
+ "propertyOrder": 3,
40
+ "$ref": "#/definitions/ScheduleType"
41
+ },
42
+ "date": {
43
+ "title": "Date",
44
+ "description": "A date/time for when the action should trigger.",
45
+ "propertyOrder": 4,
46
+ "type": "string",
47
+ "format": "datetime-local",
48
+ "options": {
49
+ "dependencies": {
50
+ "schedule_type": "date"
51
+ }
52
+ }
53
+ },
54
+ "schedule": {
55
+ "title": "Schedule",
56
+ "description": "[WIP] A schedule for a recurring event.",
57
+ "propertyOrder": 4,
58
+ "type": "string",
59
+ "options": {
60
+ "dependencies": {
61
+ "schedule_type": "recurring"
62
+ }
63
+ }
64
+ },
65
+ "action": {
66
+ "title": "Action",
67
+ "propertyOrder": 5,
68
+ "$ref": "#/definitions/EventAction"
69
+ },
70
+ "switcher_message": {
71
+ "title": "Advanced Scene Switcher Message",
72
+ "description": "A message to send to Advanced Scene Switcher.",
73
+ "type": "string",
74
+ "options": {
75
+ "dependencies": {
76
+ "action": "advanced_scene_switcher"
77
+ }
78
+ }
79
+ },
80
+ "ws_request": {
81
+ "title": "OBS Websocket Message",
82
+ "$ref": "#/definitions/OBSWSRequest"
83
+ }
84
+ },
85
+ "allOf": [
86
+ {
87
+ "oneOf": [
88
+ {
89
+ "required": [
90
+ "date"
91
+ ],
92
+ "properties": {
93
+ "schedule_type": {
94
+ "const": "date"
95
+ }
96
+ }
97
+ },
98
+ {
99
+ "required": [
100
+ "schedule"
101
+ ],
102
+ "properties": {
103
+ "schedule_type": {
104
+ "const": "recurring"
105
+ }
106
+ }
107
+ }
108
+ ]
109
+ },
110
+ {
111
+ "oneOf": [
112
+ {
113
+ "not": {
114
+ "properties": {
115
+ "action": {
116
+ "enum": [
117
+ "advanced_scene_switcher",
118
+ "obs_ws"
119
+ ]
120
+ }
121
+ }
122
+ }
123
+ },
124
+ {
125
+ "required": [
126
+ "switcher_message"
127
+ ],
128
+ "properties": {
129
+ "action": {
130
+ "const": "advanced_scene_switcher"
131
+ }
132
+ }
133
+ },
134
+ {
135
+ "required": [
136
+ "ws_request"
137
+ ],
138
+ "properties": {
139
+ "action": {
140
+ "const": "obs_ws"
141
+ }
142
+ }
143
+ }
144
+ ]
145
+ }
146
+ ],
147
+ "options": {
148
+ "switcher": false
149
+ }
150
+ }
151
+ }
152
+ },
153
+ "additionalProperties": false,
154
+ "definitions": {
155
+ "ScheduleType": {
156
+ "description": "The type of schedule for an event.",
157
+ "type": "string",
158
+ "enum": [
159
+ "date",
160
+ "recurring"
161
+ ],
162
+ "options": {
163
+ "enum_titles": [
164
+ "Specific Date/Time",
165
+ "Recurring Event"
166
+ ]
167
+ }
168
+ },
169
+ "EventAction": {
170
+ "description": "An action to trigger in OBS.",
171
+ "type": "string",
172
+ "enum": [
173
+ "start_stream",
174
+ "stop_stream",
175
+ "start_recording",
176
+ "pause_recording",
177
+ "stop_recording",
178
+ "advanced_scene_switcher",
179
+ "obs_ws"
180
+ ],
181
+ "options": {
182
+ "enum_titles": [
183
+ "Start Stream",
184
+ "Stop Stream",
185
+ "Start Recording",
186
+ "Pause Recording",
187
+ "Stop Recording",
188
+ "Advanced Scene Switcher",
189
+ "Raw Websocket"
190
+ ]
191
+ }
192
+ },
193
+ "OBSWSRequest": {
194
+ "description": "A message to send to OBS as a raw Websocket message.",
195
+ "type": "object",
196
+ "required": [
197
+ "type",
198
+ "data"
199
+ ],
200
+ "additionalProperties": false,
201
+ "properties": {
202
+ "type": {
203
+ "type": "string"
204
+ },
205
+ "data": {
206
+ "type": "object"
207
+ }
208
+ },
209
+ "options": {
210
+ "dependencies": {
211
+ "action": "obs_ws"
212
+ }
213
+ }
214
+ }
215
+ }
216
+ }
package/dist/config.js ADDED
@@ -0,0 +1,53 @@
1
+ import { DateTime } from "luxon";
2
+
3
+ /** @typedef {'date'|'recurring'} ConfigEventType */
4
+
5
+ /**
6
+ * @typedef {'start_stream'|'stop_stream'|'start_recording'|'pause_recording'|'stop_recording'|'advanced_scene_switcher'|'obs_ws'} ConfigEventAction
7
+ */
8
+
9
+ /**
10
+ * @typedef {Object} OBSWSRequest
11
+ * @property {string} type
12
+ * @property {Object} data
13
+ */
14
+
15
+ /**
16
+ * @typedef {Object} ConfigEvent
17
+ * @property {string} [name]
18
+ * @property {boolean} [enabled=true]
19
+ * @property {ConfigEventType} schedule_type
20
+ * @property {string} [date] Only present if `schedule_type` is `'date'`.
21
+ * @property {string} [schedule] Only present if `schedule_type` is `'recurring'`.
22
+ * @property {ConfigEventAction} action
23
+ * @property {string} [switcher_message] Only present if `action` is `'advanced_scene_switcher'`.
24
+ * @property {OBSWSRequest} [ws_request] Only present if `action` is `'obs_ws'`.
25
+ */
26
+
27
+ /**
28
+ * @typedef {Object} Config
29
+ * @property {ConfigEvent[]} events
30
+ */
31
+
32
+ /**
33
+ *
34
+ * @param {DateTime} date
35
+ * @param {ConfigEvent} event
36
+ * @returns {boolean}
37
+ */
38
+ export function checkEventSchedule(date, event) {
39
+ if (event.enabled == false) {
40
+ return false;
41
+ }
42
+
43
+ if (event.date) {
44
+ const eventDate = DateTime.fromISO(event.date);
45
+ // console.log(eventDate.getTime(), date.getTime())
46
+ return eventDate.startOf('second').toMillis() == date.toMillis();
47
+ } else if (event.schedule) {
48
+ // TODO: match `schedule` field
49
+ return false;
50
+ } else {
51
+ return false;
52
+ }
53
+ }
package/dist/index.js ADDED
@@ -0,0 +1,64 @@
1
+ import * as fs from 'node:fs';
2
+ import { setInterval } from 'node:timers/promises';
3
+
4
+ import { checkEventSchedule } from './config.js';
5
+ import { convertEventToWebsocketRequest } from './obs.js';
6
+
7
+ import { OBSWebSocket } from "obs-websocket-js";
8
+ import { DateTime } from 'luxon';
9
+
10
+ /** @typedef {import('./config.js').Config} Config */
11
+
12
+ /**
13
+ * @this {import("commander").Command}
14
+ */
15
+ export async function run() {
16
+ const {
17
+ ipAddress,
18
+ password,
19
+ config: configPath
20
+ } = this.opts();
21
+
22
+ // Connect to OBS-WS
23
+ const obs = new OBSWebSocket();
24
+
25
+ try {
26
+ await obs.connect(
27
+ ipAddress ? `ws://${ipAddress}` : undefined,
28
+ password,
29
+ );
30
+ } catch (error) {
31
+ console.error('Failed to connect to OBS.', error.code, error.message);
32
+ process.exit(1);
33
+ }
34
+
35
+ /** @type {Config} */
36
+ let config = {};
37
+
38
+ function updateConfigFromFile() {
39
+ const fileContents = fs.readFileSync(configPath, "utf8")
40
+ .replace(/^[ \t]*\/\/.+$\n/gm, '');
41
+ config = JSON.parse(fileContents);
42
+ }
43
+
44
+ // Read config file for initial value
45
+ updateConfigFromFile();
46
+
47
+ // Watch config file for changes
48
+ fs.watchFile(configPath, { interval: 1000 }, updateConfigFromFile);
49
+
50
+ // Forever, every second, check if current time matches an event in the config
51
+ for await (const start of setInterval(1000, Date.now())) {
52
+ const date = DateTime.now().startOf('second');
53
+
54
+ const matchingEvents = config.events
55
+ .filter(e => checkEventSchedule(date, e));
56
+
57
+ const wsRequests = matchingEvents
58
+ .flatMap(convertEventToWebsocketRequest);
59
+
60
+ await obs.callBatch(wsRequests, {
61
+ haltOnFailure: false,
62
+ });
63
+ }
64
+ }
package/dist/obs.js ADDED
@@ -0,0 +1,64 @@
1
+ /** @typedef {import('./config.js').ConfigEvent} ConfigEvent */
2
+
3
+ /**
4
+ * Maps a `ConfigEvent` to an OBS Websocket request.
5
+ * @param {ConfigEvent} event
6
+ * @returns {import("obs-websocket-js").RequestBatchRequest[]}
7
+ */
8
+ export function convertEventToWebsocketRequest(event) {
9
+ const requestID = `${event.name ? event.name + '.' : ''}${event.action}`;
10
+
11
+ switch (event.action) {
12
+ case "start_stream":
13
+ return [{
14
+ requestID,
15
+ requestType: 'StartStream',
16
+ }];
17
+ case "stop_stream":
18
+ return [{
19
+ requestID,
20
+ requestType: 'StopStream',
21
+ }];
22
+ case "start_recording":
23
+ return [{
24
+ requestID,
25
+ requestType: 'StartRecord',
26
+ }];
27
+ case "pause_recording":
28
+ return [{
29
+ requestID,
30
+ requestType: 'PauseRecord',
31
+ }];
32
+ case "stop_recording":
33
+ return [{
34
+ requestID,
35
+ requestType: 'StopRecord',
36
+ }];
37
+ case "advanced_scene_switcher":
38
+ if (event.switcher_message) {
39
+ return [{
40
+ requestID,
41
+ requestType: 'CallVendorRequest',
42
+ requestData: {
43
+ requestData: {
44
+ message: event.switcher_message,
45
+ },
46
+ requestType: "AdvancedSceneSwitcherMessage",
47
+ vendorName: "AdvancedSceneSwitcher",
48
+ },
49
+ }];
50
+ } else {
51
+ return [];
52
+ }
53
+ case "obs_ws":
54
+ if (event.ws_request) {
55
+ return [{
56
+ requestID,
57
+ requestType: event.ws_request.type,
58
+ requestData: event.ws_request.data,
59
+ }];
60
+ } else {
61
+ return [];
62
+ }
63
+ }
64
+ }
@@ -0,0 +1,17 @@
1
+ {
2
+ "$schema": "../config-schema.json",
3
+ "events": [
4
+ {
5
+ "name": "Example Event 1",
6
+ "schedule_type": "date",
7
+ "date": "2026-01-06T10:59",
8
+ "action": "start_recording"
9
+ },
10
+ {
11
+ "name": "Example Event 2",
12
+ "schedule_type": "recurring",
13
+ "schedule": "",
14
+ "action": "start_recording"
15
+ }
16
+ ]
17
+ }
package/package.json ADDED
@@ -0,0 +1,28 @@
1
+ {
2
+ "name": "obs-scheduler",
3
+ "version": "0.0.1",
4
+ "description": "A CLI tool for scheduling OBS functionality.",
5
+ "author": "edonv",
6
+ "type": "module",
7
+ "main": "./dist/index.js",
8
+ "scripts": {
9
+ "test": "echo \"Error: no test specified\" && exit 1"
10
+ },
11
+ "license": "MIT",
12
+ "repository": {
13
+ "type": "git",
14
+ "url": "git+https://github.com/edonv/obs-scheduler.git"
15
+ },
16
+ "bugs": {
17
+ "url": "https://github.com/edonv/obs-scheduler/issues"
18
+ },
19
+ "homepage": "https://github.com/edonv/obs-scheduler#readme",
20
+ "dependencies": {
21
+ "commander": "^14.0.2",
22
+ "luxon": "^3.7.2",
23
+ "obs-websocket-js": "^5.0.7"
24
+ },
25
+ "bin": {
26
+ "obs-scheduler": "cli.js"
27
+ }
28
+ }