Recorder Programming from outside web user interface
Added by Bernd Maier over 8 years ago
I'm using TVheadend running on a Raspi2 with PCTV TripleStick 292e only as a video recorder. Everything really works fine - it's the best video recorder I ever had.
But once a software is really good - users want more:
I would like to find a way to program the video recorder from outside the web user interface,
i.e. either via command line interface, something like
tvheadend -record -channel RTL -begin 2016-03-05-20-15 -end 2016-03-05-21-45
or via a web URL, something like
http:/myTVheadend:9981/record?c=RTL&b=2016-03-05-20-15&e=2016-03-05-21-45
Is there any interface in the package (which I didn't see) to achieve this?
Or is there any idea of a way to implement such a "Video Recorder Web Service"?
Any help appreciated
Snoopy17
Replies (8)
RE: Recorder Programming from outside web user interface - Added by Mark Clarkstone over 8 years ago
Everything the webui does is via a HTTP JSON API - There is no documentation for it but if you use the developer tools of your browser that should tell you everything you need to know.
RE: Recorder Programming from outside web user interface - Added by Bernd Maier over 8 years ago
Hi Mark,
thanks for your good advice. I checked this and found that the dvr programming is a POST:
http://myTVheadend:9981/api/dvr/entry/create
with post data containing
@"params": [{
"name": "conf",
"value": "{
"disp_title":"Title of the recording",
"start":1457370000,
"start_extra":0,
"stop":1457375400,
"stop_extra":0,
"channel":"80780efbe356bd3088f063f1d8b1a4c1",
"config_name":"",
"comment":""}"
}]@
So I have to do some further testing and programming (i.e. how to find out channel-id when I only know channel name) but I think that's the right way to go for.
Thanks again
Snoopy17
RE: Recorder Programming from outside web user interface - Added by Ulrich Buck over 8 years ago
As an alternative to the mentioned (undocumented) HTTP JSON API you can use the HTSP protocol, which is well documented at https://tvheadend.org/projects/tvheadend/wiki/Htsp
A python script using https://github.com/tvheadend/tvheadend/tree/master/lib/py/tvh gives me the command line interface you describe. The script is a modified version of https://github.com/tvheadend/tvheadend/blob/master/support/htspmon. It works very well for me. I have done hundreds of recordings with it.
If you would like to have the script, I can post it on pastebin.com
RE: Recorder Programming from outside web user interface - Added by Bernd Maier over 8 years ago
Hi Ulrich,
great post.
After a first look into the docs this seems to be a promising route.
Thank you for offering your script, I would be glad to get it. Perhaps I can modify it to fit my requirements. btw: is it py2 or py3?
As the video recorder programming request in my case initiates from a http GET of another computer (which I can shape a little bit) I will probably need an Apache and PHP on the TVheadend machine. But TVheadend is already handling http (hopefully only with the port 9981). Is there any collision between TVheadend and Apache+PHP on the same system foreseeable?
Thanks again
Snoopy17
RE: Recorder Programming from outside web user interface - Added by Ulrich Buck over 8 years ago
Hi Bernd
Find the script at http://pastebin.com/7JUFDTwu
It is in py 2.7 and requires https://github.com/tvheadend/tvheadend/tree/master/lib/py/tvh
This is the CLI
python htsp-dvr.py -h usage: htsp-dvr.py [-h] [-a HOST] [-o PORT] [-u USER] [-p PASSWD] [-s] [-add] [-c CHANNEL] [-w WEIGHT] [-t TIMEOUT] [-can] [-del] [-id DVRID] [-sta START] [-sto STOP] [-cre CREATOR] [-pri PRIORITY] [-tit TITLE] optional arguments: -h, --help show this help message and exit -a HOST, --host HOST HTSP server hostname [localhost] -o PORT, --port PORT HTSP server port [9982] -u USER, --user USER HTSP authentication username [None] -p PASSWD, --passwd PASSWD HTSP authentication password [None] -s, --subscribe Subscribe to channel [Do not subscribe] -add, --add Create a new DVR entry [Do not create] -c CHANNEL, --channel CHANNEL Name or ID of channel to subscribe or add DVR [SRF1] -w WEIGHT, --weight WEIGHT Weighting of subscription [99999] -t TIMEOUT, --timeout TIMEOUT Timeout of subscription in seconds [99999] -can, --cancel Cancel an existing recording [Do not cancel] -del, --delete Delete an existing DVR entry [Do not delete] -id DVRID, --dvrid DVRID dvrEntryId to cancel or delete [None] -sta START, --start START Unix Time to start recording [None] -sto STOP, --stop STOP Unix Time to stop recording [None] -cre CREATOR, --creator CREATOR Name of DvrEntry creator [HTSP PyClient] -pri PRIORITY, --priority PRIORITY Recording priority of DvrEntry [0 = Important] -tit TITLE, --title TITLE Recording title of DvrEntry [HTSP-PyClient-DVR]
Not sure if I can fully answer your other questions. Anyway, the script can run from any computer which has network access to Tvheadend, or from the local Tvheadend machine. It uses HTSP port 9982.
To trigger the script on your Tvheadend machine you can use Apache+PHP. I am using Apache+Perl on the Tvheadend machine. There is no collision between Appache+PHP+Perl and Tvheadend on the same machine.
RE: Recorder Programming from outside web user interface - Added by Thorben Thorben over 8 years ago
Hi Ulrich,
i'm interested in your script, but the link you've posted is invalid (expired).
Can you please upload your script again?
Thanks
Thorben
RE: Recorder Programming from outside web user interface - Added by Ulrich Buck over 8 years ago
Hi Thorben
Uploaded the script again, see
The script received a few minor internal improvements.
RE: Recorder Programming from outside web user interface - Added by Thorben Thorben about 8 years ago
Hi Ulrich,
thanks very mutch.
Greets
Thorben