OliveTin for Channels: An Interface for Misc Channels DVR Scripts & Tricks

@chDVRuser Playing around with this a bit more, I believe I will move to looking exclusively forward for job matches based on the interval specified. However, it does take a few seconds from when the current api/v1/jobs JSON is grabbed and jq'd for any matches, to when the script loop is complete. To avoid having a missed match between loops, I think it makes sense to look forward an extra 10 seconds.

This will result in the possibility of a second notification for anyone not deleting the dvr job after the notification is sent -- but this should be reasonably rare. I'd rather have the odd double notification, as opposed to having anything fall in an unaccounted-for gap between loops (which measured at 7 seconds in my case, with 2 clients offline).

I just set it up and manually scheduled a recording with 10 second pre-pad that starts in 3 minutes.
Have it set to email notification using olivetin://

Got an email titled Reminder a minute before it started recording
Event: The Big Bang Theory
Start Time: 16:30
Channels: 6033

I'll set another recording further out and see when the notification happens.
Would be nice if it logged it too. The file 192.168.1.4-8190_remind.running only contains this

remind.sh 192.168.1.4:8190 5 10 "olivetin://" false

Quite right, I'll add that.

The .running files btw, are what's used when the OliveTin container is started to restart anything that should be running in the background. The script to run, with its arguments.

Right, so I would want a 192.168.1.4-8190_remind_latest.log

Looks like it's better to set a longer frequency if you want to be notified more than a minute before.
I'll try 10 minutes, since using 5 minutes I didn't see the email until a minute before recording time.

1 Like

Yes. Also, when testing, you can go ahead and trigger the Action without going through the whole kill-and-restart process. When there's an active background process for a given server it'll be killed, and the script run again immediately. Saves some waiting around when testing. :slight_smile:

So just change the frequency? Nice.

Yes. Don't forget to hit refresh after though, or the next time you run the Action it'll appear to hang.

1 Like

Can you send email to more than one recipient?
- ALERT_EMAIL_TO=${ALERT_EMAIL_TO} # Recipient address for alert e-mails.
If so, how do you separate them? space comma semicolon

Yes. @Edwin_Perez was doing that. I believe it's a space, but hopefully he'll confirm.

Comma

Might want to go a minute or two.
The last two tests I tried using 10 minute frequency, I got the notification a minute after the recordings started. Depends on what time you start the action and when the recording starts.

‎Saturday 2025-03-01 
‏‎17:39:54 Started Action (timestamp of 192.168.1.4-8190_remind.running file)
17:49:54 expect notification
17:59:50 recording#1 started w/10 second pre-pad
17:59:54
18:00:xx notified
18:09:54
18:19:54 expected notification, but none
18:29:50 recording#2 started w/10 second pre-pad
18:29:54 no notification
18:39:54 no notification

I think I'll make it configurable.

Regarding a log, here's what I've setup so far:

2025-03-01 17:54:07 - Checking for DVR jobs set to start in the next 10 minutes...
{
  "id": "1740877200-ch6001",
  "name": "NBA Countdown",
  "start_time": 1740877200,
  "end_time": 1740879010,
  "duration": 1810,
  "channels": [
    "6001"
  ],
  "skipped": false,
  "failed": false,
  "updated_at": 1740876819438,
  "item": {
    "show_id": "9668236",
    "program_id": "EP016700270183",
    "episode_number": 22,
    "title": "NBA Countdown",
    "summary": "Bold opinions, discussion and debate centered on the top storylines from around the league.",
    "full_summary": "Bold opinions, discussion and debate centered on the top storylines from around the league. Mike Greenberg hosts this pregame show with analysts Stephen A. Smith and Michael Wilbon.",
    "image_url": "https://tmsimg.fancybits.co/assets/p9668236_b_h9_ag.jpg?w=720&h=540",
    "playback_time": 0,
    "original_air_date": "2025-03-01",
    "genres": [
      "Basketball"
    ],
    "tags": [
      "CC",
      "HD 720p",
      "HDTV",
      "Live",
      "New",
      "Stereo"
    ],
    "categories": [
      "Episode",
      "Sports non-event"
    ],
    "cast": [
      "Malika Andrews",
      "Stephen A. Smith",
      "Kendrick Perkins"
    ],
    "watched": false,
    "favorited": false,
    "delayed": false,
    "cancelled": false,
    "corrupted": false,
    "completed": false,
    "processed": false,
    "locked": false,
    "verified": false
  }
}
2025-03-01 18:04:14 - Checking for DVR jobs set to start in the next 10 minutes...
2025-03-01 18:14:14 - Checking for DVR jobs set to start in the next 10 minutes...
2025-03-01 18:24:14 - Checking for DVR jobs set to start in the next 10 minutes...
2025-03-01 18:34:14 - Checking for DVR jobs set to start in the next 10 minutes...
2025-03-01 18:44:14 - Checking for DVR jobs set to start in the next 10 minutes...
2025-03-01 18:54:14 - Checking for DVR jobs set to start in the next 10 minutes...
2025-03-01 19:04:14 - Checking for DVR jobs set to start in the next 10 minutes...
2025-03-01 19:14:14 - Checking for DVR jobs set to start in the next 10 minutes...

The JSON indicates a match at the time shown just above. As you can see, at least in my case, there's only about a +7 seconds required to allow for script run (including notifications to offline and tailscale clients, which take a few extra seconds).

I'll wait until you implement the logging and the customized "look ahead".
No notification yet for my second test recording that started over 10 minutes ago.

Can you log the time the notification was sent?

No problem. I'll push an update in the AM PST.

Thanks, once again, for your quality feedback!

1 Like

Here's what I'm doing for logging now:

2025-03-01 20:39:11 - Checking for DVR jobs set to start in the next 20 minutes with 10 second padding...
{
  "id": "1740887400-ch6122",
  "name": "Marvel's Spidey and His Amazing Friends",
  "start_time": 1740887400,
  "end_time": 1740888910,
  "duration": 1510,
  "channels": [
    "6122"
  ],
  "skipped": false,
  "failed": false,
  "updated_at": 1740886702239,
  "item": {
    "show_id": "20327168",
    "program_id": "EP039322850251",
    "season_number": 3,
    "title": "Marvel's Spidey and His Amazing Friends",
    "episode_title": "The Campout Mystery; Gobby's Metal Menace",
    "summary": "Team Spidey must rescue the Bigfoot, who gets caught in Trapster's trap.",
    "full_summary": "Team Spidey must rescue the Bigfoot, who gets caught in Trapster's trap; Gobby's dino-mech creates metal Gobbybots that causes chaos in the city.",
    "content_rating": "TV-Y",
    "image_url": "https://tmsimg.fancybits.co/assets/p26284583_b_h9_aa.jpg?w=720&h=540",
    "playback_time": 0,
    "original_air_date": "2025-02-14",
    "genres": [
      "Animated",
      "Children",
      "Adventure"
    ],
    "tags": [
      "CC",
      "HD 720p",
      "HDTV",
      "Stereo"
    ],
    "categories": [
      "Episode",
      "Series"
    ],
    "cast": [
      "Alkaio Thiele",
      "Jakari Fraser",
      "Audrey Bennett"
    ],
    "watched": false,
    "favorited": false,
    "delayed": false,
    "cancelled": false,
    "corrupted": false,
    "completed": false,
    "processed": false,
    "locked": false,
    "verified": false
  }
}
2025-03-01 20:39:18 - Notification(s) sent via Channels API
2025-03-01 20:39:19 - Notification(s) sent via OliveTin alerts
2025-03-01 20:39:20 - Notification(s) sent via Apprise
2025-03-01 20:39:20 - DVR job deleted

I had the same time drift issue with the maddox pluto container, so modified it to run fetching epg exactly every 2 hours.
If you're using a sleep for the frequency * 60, just modify it.

At the top of your loop

WOKE_AT=$(date +%s)
NEXT_RUN=$(($WOKE_AT + $checkInterval))
# echo "Woke at:  $(date --date=@$WOKE_AT)"

At the end of your loop

# echo "Next run: $(date --date=@$NEXT_RUN)"
SLEEP_TIME=$(($NEXT_RUN - $(date +%s)))
# echo "Sleeping: $SLEEP_TIME"
sleep $SLEEP_TIME
1 Like

Perfect.

1 Like

What do you think, would this work?
With a 2 minute lookAhead, shouldn't miss any.

lookAhead=$((2 * 60))
checkInterval=$(($frequency * 60))
...
sendReminder=$(curl -s http://$dvr/api/v1/jobs | jq ".[] | select(.duration % 100 == ${paddingSeconds} and (.start_time >= $(date +%s) and .start_time <= ($(date +%s) + ${checkInterval} + ${lookAhead})))")
1 Like

New bnhf/olivetin:latest (aka bnhf/olivetin:2025.03.02) pushed this morning with fixes/enhancements to the new CDVR Guide Event Reminder Action.

Highlights:

  • The run/check interval now looks exclusively forward, so when you specify an interval of 5 minutes, the check runs every 5 minutes and matches jobs starting in the next 5 minutes.

  • There's now a check_extra value that allows for adding up to 120 seconds to the interval above. So, a 5 minute check interval with a 120 second check_extra value, will match DVR jobs occurring in the next 7 minutes. Larger values can lead to multiple notifications if you have delete_job=false.

  • Multiple space-separated notifications supported for a single event. Also, when using channels:// to notify all Channels clients, a number of seconds can be appended to override the default value of 40. This defines how many seconds an onscreen notification will remain on the screen. For example, channels://60 will send a 60 second long notification.

  • Scenarios where there are multiple DVR job matches at the same time has been improved, with notifications sent in this format to cover more than event (two in this example):

   Event: The Simpsons
   The Simpsons
   Start Time: 11:00
   11:00
   Channels: 6082
   6083
  • Logging has been added, with each loop timestamped and logged, along with any matching JSON records and notifications sent.