obs-scheduler 0.0.2 → 0.1.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/README.md CHANGED
@@ -1,5 +1,8 @@
1
1
  # obs-scheduler
2
2
 
3
+ ![NPM Version](https://img.shields.io/npm/v/obs-scheduler?color=%23302E31)
4
+ ![Static Badge](https://img.shields.io/badge/OBS-302E31?logo=obsstudio)
5
+
3
6
  A CLI for scheduling actions in OBS.
4
7
 
5
8
  ## Install
@@ -37,7 +40,8 @@ Options:
37
40
  {
38
41
  "name": "Example Event 2",
39
42
  "schedule_type": "recurring",
40
- "schedule": "* * * * * *",
43
+ // At 14:15 (2:15pm) on each first day of the month.
44
+ "schedule": "15 14 1 * *",
41
45
  "action": "start_recording"
42
46
  }
43
47
  ]
package/cli.js CHANGED
@@ -17,7 +17,7 @@ program
17
17
  undefined,
18
18
  )
19
19
  .option('-c, --config <file-path>', 'config file path')
20
- .version('0.0.2')
20
+ .version('0.1.1')
21
21
  .action(run);
22
22
 
23
23
  await program.parseAsync(process.argv);
@@ -53,9 +53,11 @@
53
53
  },
54
54
  "schedule": {
55
55
  "title": "Schedule",
56
- "description": "[WIP] A schedule for a recurring event.",
56
+ "description": "A schedule for a recurring event in crontab format.",
57
57
  "propertyOrder": 4,
58
58
  "type": "string",
59
+ "format": "crontab",
60
+ "pattern": "^((((\\d+,)+\\d+|(\\d+(\\/|-|#)\\d+)|\\d+L?|\\*(\\/\\d+)?|L(-\\d+)?|\\?|[A-Z]{3}(-[A-Z]{3})?) ?){5,7})|(@(annually|yearly|monthly|weekly|daily|hourly|reboot))|(@every (\\d+(ns|us|µs|ms|s|m|h))+)$",
59
61
  "options": {
60
62
  "dependencies": {
61
63
  "schedule_type": "recurring"
package/dist/config.js CHANGED
@@ -1,3 +1,4 @@
1
+ import CronExpressionParser from "cron-parser";
1
2
  import { DateTime } from "luxon";
2
3
 
3
4
  /** @typedef {'date'|'recurring'} ConfigEventType */
@@ -36,17 +37,27 @@ import { DateTime } from "luxon";
36
37
  * @returns {boolean}
37
38
  */
38
39
  export function checkEventSchedule(date, event) {
40
+ // Ignore a disabled event
39
41
  if (event.enabled == false) {
40
42
  return false;
41
43
  }
42
44
 
43
- if (event.date) {
45
+ if (event.date) { // If event has the `date` field
46
+ // Parse event's date string to `DateTime`
44
47
  const eventDate = DateTime.fromISO(event.date);
45
48
  // console.log(eventDate.getTime(), date.getTime())
49
+ // Compare parsed date (rounded to the previous second) to the current `date`
46
50
  return eventDate.startOf('second').toMillis() == date.toMillis();
47
- } else if (event.schedule) {
48
- // TODO: match `schedule` field
49
- return false;
51
+ } else if (event.schedule) { // If event has the `schedule` field
52
+ try {
53
+ // Parse crontab string
54
+ const schedule = CronExpressionParser.parse(event.schedule);
55
+ // Return if the parsed schedule includes the current `date`
56
+ return schedule.includesDate(date.toJSDate());
57
+ } catch (error) {
58
+ // If parse fails, return `false`
59
+ return false;
60
+ }
50
61
  } else {
51
62
  return false;
52
63
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "obs-scheduler",
3
- "version": "0.0.2",
3
+ "version": "0.1.1",
4
4
  "description": "A CLI tool for scheduling OBS functionality.",
5
5
  "author": "edonv",
6
6
  "type": "module",
@@ -19,6 +19,7 @@
19
19
  "homepage": "https://github.com/edonv/obs-scheduler#readme",
20
20
  "dependencies": {
21
21
  "commander": "^14.0.2",
22
+ "cron-parser": "^5.4.0",
22
23
  "luxon": "^3.7.2",
23
24
  "obs-websocket-js": "^5.0.7"
24
25
  },