Python & Windows scripts for HDHR DVR recordings

Want to write your own code to work with a HDHomeRun or work with the HDHomeRun DVR? We are happy to help with concepts, APIs, best practices.
Post Reply
bdbauer
Posts: 88
Joined: Mon Jul 09, 2018 10:07 am

Python & Windows scripts for HDHR DVR recordings

Post by bdbauer » Mon Sep 03, 2018 5:46 pm

I've put together a few small Python scripts to play with the HDHR DVR API. These allow you to do most things via command line.

*WARNING* - some of these scripts can add or delete recordings. While I've never had any accidental deletions, I do not guarantee you won't (though if you start with the "tasks" scripts you will at least have the Series IDs to add back in should you need them). I also can't guarantee these won't break if the API changes in the future.

Github repository: https://github.com/blainebauer/hdhr_dvr_scripts

Included scripts:
  • tasks - A list of your DVR tasks, including the Task (Rule) ID and Series ID
  • search - Search for a series; will return the Series ID
  • addseries - Add a task for the series ID. Defauts to zero seconds start padding, but you can change that
  • deletetask - Delete a task (get the Task ID using tasks)
  • upcoming - List upcoming episodes for a Series ID
  • allupcoming - List upcoming episodes for all series
I have compiled the Python scripts into Windows executables, so you can run these programs in the Windows command line without installing Python. These are in the file hdhr-dvr-scripts-windows.zip.

Ken.F
Posts: 2148
Joined: Fri Apr 05, 2013 9:20 am
Device ID: 1041A706, 1043EB32, 104BAD9E, 13168DC5, 1322A7AC
Location: West Rockhill, PA

Re: Python & Windows scripts for HDHR DVR recordings

Post by Ken.F » Thu Sep 06, 2018 11:18 am

I can't get any of these scripts to work on Linux. I keep getting errors like this:

Code: Select all

File "allupcoming", line 111
    print qstring
                ^
SyntaxError: Missing parentheses in call to 'print'

signcarver
Expert
Posts: 8402
Joined: Wed Jan 24, 2007 1:04 am
Device ID: 131B34B7 13231F92 1070A18E 1073ED6F

Re: Python & Windows scripts for HDHR DVR recordings

Post by signcarver » Thu Sep 06, 2018 3:09 pm

I believe in python 3 print became a function rather than a statement and as a result one would put () around what would be printed

Ken.F
Posts: 2148
Joined: Fri Apr 05, 2013 9:20 am
Device ID: 1041A706, 1043EB32, 104BAD9E, 13168DC5, 1322A7AC
Location: West Rockhill, PA

Re: Python & Windows scripts for HDHR DVR recordings

Post by Ken.F » Thu Sep 06, 2018 4:28 pm

signcarver wrote:
Thu Sep 06, 2018 3:09 pm
I believe in python 3 print became a function rather than a statement and as a result one would put () around what would be printed
Thanks, but I'm not sure what to do with that information.

signcarver
Expert
Posts: 8402
Joined: Wed Jan 24, 2007 1:04 am
Device ID: 131B34B7 13231F92 1070A18E 1073ED6F

Re: Python & Windows scripts for HDHR DVR recordings

Post by signcarver » Thu Sep 06, 2018 5:19 pm

Ken.F wrote:
Thu Sep 06, 2018 4:28 pm
signcarver wrote:
Thu Sep 06, 2018 3:09 pm
I believe in python 3 print became a function rather than a statement and as a result one would put () around what would be printed
Thanks, but I'm not sure what to do with that information.
I am not at a location I can look at the scripts but from what was reported, I believe line 111 in the file allupcoming (probably allupcoming.py) states " print qstring " if that is the case make it say print(qstring)

In other words use the parentheses like the error message stated. A function requires the items passed to be enclosed inside parentheses, while a statement has no such requirement and python "used" to be a very heavy statement/interpretive language but since version 3 some traditional statements were turned into functions.

Ken.F
Posts: 2148
Joined: Fri Apr 05, 2013 9:20 am
Device ID: 1041A706, 1043EB32, 104BAD9E, 13168DC5, 1322A7AC
Location: West Rockhill, PA

Re: Python & Windows scripts for HDHR DVR recordings

Post by Ken.F » Thu Sep 06, 2018 5:36 pm

Thanks. I fixed the one on line 111 but then I got another one on line 117, and then one on line 124. I'm out of time tonight so I'll have to continue some other time.

gtb
Expert
Posts: 3985
Joined: Thu Oct 06, 2011 1:00 pm
Location: Sunnyvale, CA USA

Re: Python & Windows scripts for HDHR DVR recordings

Post by gtb » Thu Sep 06, 2018 7:18 pm

Ken.F wrote:
Thu Sep 06, 2018 5:36 pm
Thanks. I fixed the one on line 111 but then I got another one on line 117, and then one on line 124. I'm out of time tonight so I'll have to continue some other time.
There are a number of (semi-)automated tools to assist in conversion of legacy (obsolete) python2 scripts to python3. Only those stuck in the past, and accept obsolescence in less than 18 months still write anything in python2. There still exist many such people.

airdrummer
Posts: 74
Joined: Tue Jan 08, 2013 8:39 am

Re: Python & Windows scripts for HDHR DVR recordings

Post by airdrummer » Fri Jan 04, 2019 7:55 pm

thanx for posting these...i just did a quick scan of the files, and noticed a few problems:
python files are usually suffixed with .py, shell scripts with .sh, jussayin...
every python script contains the same HDHRdiscover function...dry, dude
in addseries.py,

Code: Select all

	print ("\naddseries <seriesID> [HDHR-IP]\n")
seems to imply argv[1] is seriesID, argv[2] is HDHomeRun IP, yet

Code: Select all

110	 device = sys.argv[1]
111 url = 'http://' + device + '/discover.json'
and

Code: Select all

127 vars['SeriesID'] = sys.argv[1]
so how did this ever work? i'll try to sort thru this & make sense of it...is the api available somewhere?

gtb
Expert
Posts: 3985
Joined: Thu Oct 06, 2011 1:00 pm
Location: Sunnyvale, CA USA

Re: Python & Windows scripts for HDHR DVR recordings

Post by gtb » Sat Jan 05, 2019 4:26 am

airdrummer wrote:
Fri Jan 04, 2019 7:55 pm
is the api available somewhere?
None of the discovery/device interfaces are formal APIs (the only formally documented and supported APIs are on the SiliconDust github pages, and those are for the DVR engine). People have just reverse engineered the requests and responses. That also means that those functions may change (or break) at any time (or the reverse engineering is wrong or incomplete), so the usual rule (caveat emptor) applies if you decide to use some of those examples. While I believe it is unlikely to see a wholesale elimination of what the community has deduced, no one should have expectations about the future unless they do become formal APIs.

themusj
Posts: 198
Joined: Wed Aug 30, 2017 5:44 pm

Re: Python & Windows scripts for HDHR DVR recordings

Post by themusj » Sun Feb 03, 2019 7:15 pm

I tried running the Tasks.exe and pipe the content to >Tasks.txt and I get the following error:

Traceback (most recent call last):
File "tasks", line 107, in <module>

NameError: name 'exit' is not defined
[3604] Failed to execute script tasks

bdbauer
Posts: 88
Joined: Mon Jul 09, 2018 10:07 am

Re: Python & Windows scripts for HDHR DVR recordings

Post by bdbauer » Tue Feb 12, 2019 4:13 pm

themusj wrote:
Sun Feb 03, 2019 7:15 pm
I tried running the Tasks.exe and pipe the content to >Tasks.txt and I get the following error:

Traceback (most recent call last):
File "tasks", line 107, in <module>

NameError: name 'exit' is not defined
[3604] Failed to execute script tasks
I'll try to replicate that - it is the part where it tells you that HDHR tuner discovery failed. So even if it didn't error out, it probably would fail because the discovery fails. I borrowed the discovery code from someone else and from what I've seen it isn't as reliable as specifying the address of your HDHR tuner.

If you know the address of your HDHR, you can use "tasks x.x.x.x" (x.x.x.x being the IP address of the HDHR tuner). This will be more reliable.

themusj
Posts: 198
Joined: Wed Aug 30, 2017 5:44 pm

Re: Python & Windows scripts for HDHR DVR recordings

Post by themusj » Sun Feb 17, 2019 8:54 am

That worked, thank you!

I sure hope the day comes when the new UI will alert when there is a scheduling conflict with all tuners in use and trying to add something where there are no available tuners.

themusj
Posts: 198
Joined: Wed Aug 30, 2017 5:44 pm

Re: Python & Windows scripts for HDHR DVR recordings

Post by themusj » Sun Jul 21, 2019 1:25 pm

Do these scripts still work with the HDHomeRun Quatro? For example on the script allupcoming, I get the following error at a command prompt.

Traceback (most recent call last):
File "allupcoming", line 119, in <module>
NameError: name 'exit' is not defined
[5296] Failed to execute script allupcoming

I am trying to get my tasks output to a text file of movies and the single TV episodes I selected. Not all the entire TV series I have queued up in tasks. Until the new UI warns of duplicates, this is the best method I know of to avoid over scheduling.

themusj
Posts: 198
Joined: Wed Aug 30, 2017 5:44 pm

Re: Python & Windows scripts for HDHR DVR recordings

Post by themusj » Tue Jul 23, 2019 5:27 pm

Anyone able to share if this script still works?

Post Reply