Having trouble with a power management script
Added by Computer Worm almost 3 years ago
Hello everyone,
I just started using TVheadend a few days ago, and I like it a lot. I'm using version 4.3-1995~g1d0b5e89d~bullseye installed from binary on Debian 11.2 Bullseye. There is just one issue that I can't solve. I'm trying to use this poweroff script: https://tvheadend.org/boards/4/topics/27066?r=45174#message-45174 and the script mostly works - the checks for active connections, subscriptions, users, and comskip work, but it can't detect upcoming recordings. Even when recordings are scheduled, it always falls back to the wake at 2 am for no planned recording clause. I've managed to isolate the problem to the following function:
#get start time for next recording
NEXTREC=$(curl --silent --show-error --digest --user "${USER}:${PASS}" --data-urlencode "limit=999" \
"http://${HOST}:9981/api/dvr/entry/grid_upcoming" | \
jq "[ .entries[] | {start_real,status} | \
select(.status!=\"Invalid\") ] | min_by(.start_real) | .start_real")
if [ "$NEXTREC" == "null" ]; then
logit "no planned recording found"
And I believe that these two lines in particular are probably the source of the bug:
jq "[ .entries[] | {start_real,status} | \
select(.status!=\"Invalid\") ] | min_by(.start_real) | .start_real")
There is something in those two lines that's causing the function to always return "null" even when scheduled recordings do exist, and I've tried reading the man pages for jq, but I can't figure it out. Any help you all can give me will be greatly appreciated.
---UPDATE:--- I got a friend on an IRC channel to help me, and he figured out that the problem is not in the jq code at all. Because the jq function worked fine on the file I posted below, but it didn't work when used with curl. Because curl is not downloading any useful data. Maybe there's a bug in the Tvheadend web APIs. I'll try to investigate some more.
Kind regards,
computerworm110
Replies (3)
RE: Having trouble with a power management script - Added by Mark Clarkstone almost 3 years ago
Check the curl output from tvh matches what jq is looking for.
RE: Having trouble with a power management script - Added by Computer Worm almost 3 years ago
Mark Clarkstone wrote:
Check the curl output from tvh matches what jq is looking for.
I've already checked that and it looks okay to me, nevertheless I've attached a file with the output so you can look at it if you like. And thank you for taking the time to help me, I truly appreciate it.
grid_upcoming (3.23 KB) grid_upcoming |
RE: Having trouble with a power management script - Added by Computer Worm almost 3 years ago
Okay, so the file I posted earlier was the file I got when I pasted the localhost url into Firefox. I just got done trying the original curl command again in the terminal, but adding the --output option to make curl output to a file. This is what curl outputs into the file:
{"entries":[],"total":4}
That's all. So curl isn't getting the proper output. Why isn't curl fetching the entire file? Firefox can get the whole thing . . .
EDIT: Now Firefox is no longer getting the proper output, just this:
{"entries":[],"total":4}
And I got a friend on an IRC channel to help me, and he figured out that the problem was not in the jq code at all. Because the jq function worked fine on that file I posted earlier, but it didn't work when used with curl. Because curl is not downloading any useful data. Maybe there's a bug in the Tvheadend web APIs. I'll try to investigate some more.