Mailing List Archive

Services API: Does Dvr/AddRecordSchedule work?
I see AddRecordSchedule here
https://www.mythtv.org/wiki/API_parameters_29#Dvr_service but when I try to
use it, I am getting a 500 response. Is this not working, or am I not
calling it correctly?

I am calling it from python:

endpoint = 'Dvr/AddRecordSchedule'
post = recrule.asDict()
opt = {'wrmi':True}

try:
resp_dict = backend.send(endpoint=endpoint, postdata=post, opts=opt)
except RuntimeError as error:
sys.exit('\nFatal error: "{}"'.format(error))
except RuntimeWarning as warning:
print('Warning: {}'.format(warning))

recrule is a classed derived from a named tuple with the various arguments
in it, for example: ChanId, Title, Subtitle, etc.

I admit to not having a lot of python experience, but this seems pretty
straight forward. I just want to verify that the Dvr/AddRecordSchedule is
supposed to be working, before I waste a lot of time debugging this code.
Various other Services API calls are working perfectly.

Thanks,

John
Re: Services API: Does Dvr/AddRecordSchedule work? [ In reply to ]
On 10/12/2018 07:49 PM, John P Poet wrote:
> I see AddRecordSchedule here
> https://www.mythtv.org/wiki/API_parameters_29#Dvr_service but when I try to
> use it, I am getting a 500 response. Is this not working, or am I not
> calling it correctly?
>
> I am calling it from python:
>
> endpoint = 'Dvr/AddRecordSchedule'
> post = recrule.asDict()
> opt = {'wrmi':True}
>
> try:
> resp_dict = backend.send(endpoint=endpoint, postdata=post, opts=opt)
> except RuntimeError as error:
> sys.exit('\nFatal error: "{}"'.format(error))
> except RuntimeWarning as warning:
> print('Warning: {}'.format(warning))
>
> recrule is a classed derived from a named tuple with the various arguments
> in it, for example: ChanId, Title, Subtitle, etc.
>
> I admit to not having a lot of python experience, but this seems pretty
> straight forward. I just want to verify that the Dvr/AddRecordSchedule is
> supposed to be working, before I waste a lot of time debugging this code.
> Various other Services API calls are working perfectly.

It does work. My usual 1st choice is: mythbackend --setverbose http:debug,upnp:debug
(probably overkill.) And check the backend log...

Here's a snippet from one of my tests:

endpoint = 'Dvr/AddRecordSchedule'

params_not_sent = ('AverageDelay', 'CallSign', 'Id', 'LastDeleted',
'LastRecorded', 'NextRecording', 'ParentId')

for param in params_not_sent:
try:
del template[param]
except KeyError:
pass
...


I also use:

logging.basicConfig(level=logging.DEBUG if args['debug'] else logging.INFO)
logging.getLogger('requests.packages.urllib3').setLevel(logging.WARNING)
logging.getLogger('urllib3.connectionpool').setLevel(logging.WARNING)

and a --debug switch to the Python program to activate the log messages. The
send.py you're using has a bit more on the above.

I attached my add_recording_rule.py FYI. The command line (just to test, without --wrmi):
add_recording_rule.py --ho ofc0 --title Elementary --debug --digest admin:mythtv

--
Bill
Re: Services API: Does Dvr/AddRecordSchedule work? [ In reply to ]
On Fri, Oct 12, 2018 at 7:28 PM Bill Meek <keemllib@gmail.com> wrote:

> On 10/12/2018 07:49 PM, John P Poet wrote:
> > I see AddRecordSchedule here
> > https://www.mythtv.org/wiki/API_parameters_29#Dvr_service but when I
> try to
> > use it, I am getting a 500 response. Is this not working, or am I not
> > calling it correctly?
> >
> > I am calling it from python:
> >
> > endpoint = 'Dvr/AddRecordSchedule'
> > post = recrule.asDict()
> > opt = {'wrmi':True}
> >
> > try:
> > resp_dict = backend.send(endpoint=endpoint, postdata=post,
> opts=opt)
> > except RuntimeError as error:
> > sys.exit('\nFatal error: "{}"'.format(error))
> > except RuntimeWarning as warning:
> > print('Warning: {}'.format(warning))
> >
> > recrule is a classed derived from a named tuple with the various
> arguments
> > in it, for example: ChanId, Title, Subtitle, etc.
> >
> > I admit to not having a lot of python experience, but this seems pretty
> > straight forward. I just want to verify that the Dvr/AddRecordSchedule
> is
> > supposed to be working, before I waste a lot of time debugging this code.
> > Various other Services API calls are working perfectly.
>
> It does work. My usual 1st choice is: mythbackend --setverbose
> http:debug,upnp:debug
> (probably overkill.) And check the backend log...
>
> Here's a snippet from one of my tests:
>
> endpoint = 'Dvr/AddRecordSchedule'
>
> params_not_sent = ('AverageDelay', 'CallSign', 'Id', 'LastDeleted',
> 'LastRecorded', 'NextRecording', 'ParentId')
>
> for param in params_not_sent:
> try:
> del template[param]
> except KeyError:
> pass
> ...
>
>
> I also use:
>
> logging.basicConfig(level=logging.DEBUG if args['debug'] else
> logging.INFO)
>
> logging.getLogger('requests.packages.urllib3').setLevel(logging.WARNING)
> logging.getLogger('urllib3.connectionpool').setLevel(logging.WARNING)
>
> and a --debug switch to the Python program to activate the log messages.
> The
> send.py you're using has a bit more on the above.
>
> I attached my add_recording_rule.py FYI. The command line (just to test,
> without --wrmi):
> add_recording_rule.py --ho ofc0 --title Elementary --debug --digest
> admin:mythtv
>
> --
> Bill
> _______________________________________________
> mythtv-dev mailing list
> mythtv-dev@mythtv.org
> http://lists.mythtv.org/mailman/listinfo/mythtv-dev
> http://wiki.mythtv.org/Mailing_List_etiquette
> MythTV Forums: https://forum.mythtv.org


Thanks Bill, that should help.

John
Re: Services API: Does Dvr/AddRecordSchedule work? [ In reply to ]
On Fri, Oct 12, 2018 at 06:49:44PM -0600, John P Poet wrote:
> I see AddRecordSchedule here
> https://www.mythtv.org/wiki/API_parameters_29#Dvr_service but when I try to
> use it, I am getting a 500 response. Is this not working, or am I not
> calling it correctly?

It worked at some time. It's possible it got broken somewhere along
the line.

> I am calling it from python:
>
> endpoint = 'Dvr/AddRecordSchedule'
> post = recrule.asDict()
> opt = {'wrmi':True}
>
> try:
> resp_dict = backend.send(endpoint=endpoint, postdata=post, opts=opt)
> except RuntimeError as error:
> sys.exit('\nFatal error: "{}"'.format(error))
> except RuntimeWarning as warning:
> print('Warning: {}'.format(warning))
>
> recrule is a classed derived from a named tuple with the various arguments
> in it, for example: ChanId, Title, Subtitle, etc.

How are you creating recrule? The strongly preferred way to do so is
to call Dvr/GetRecordSchedule first. That will give you a known, good
rule from which you can modify as needed.

There are 4 ways to call Dvr/GetRecordSchedule:

nRecordId > 0 : Return the existing recording rule itself. Not
necessarily tied to a specific program.

!sTemplate.isEmpty() : Return the existing, template rule itself.

nRecordedId > 0 : Return the rule for the given recording.

nChanId > 0 && dStartTime.isValid() : Return the matching rule for the
given program. Optionally, return an override rule when bMakeOverride
is set.

David

> I admit to not having a lot of python experience, but this seems pretty
> straight forward. I just want to verify that the Dvr/AddRecordSchedule is
> supposed to be working, before I waste a lot of time debugging this code.
> Various other Services API calls are working perfectly.


--
David Engel
david@istwok.net
_______________________________________________
mythtv-dev mailing list
mythtv-dev@mythtv.org
http://lists.mythtv.org/mailman/listinfo/mythtv-dev
http://wiki.mythtv.org/Mailing_List_etiquette
MythTV Forums: https://forum.mythtv.org
Re: Services API: Does Dvr/AddRecordSchedule work? [ In reply to ]
On Fri, Oct 12, 2018 at 7:56 PM David Engel <david@istwok.net> wrote:

> On Fri, Oct 12, 2018 at 06:49:44PM -0600, John P Poet wrote:
> > I see AddRecordSchedule here
> > https://www.mythtv.org/wiki/API_parameters_29#Dvr_service but when I
> try to
> > use it, I am getting a 500 response. Is this not working, or am I not
> > calling it correctly?
>
> It worked at some time. It's possible it got broken somewhere along
> the line.
>
> > I am calling it from python:
> >
> > endpoint = 'Dvr/AddRecordSchedule'
> > post = recrule.asDict()
> > opt = {'wrmi':True}
> >
> > try:
> > resp_dict = backend.send(endpoint=endpoint, postdata=post,
> opts=opt)
> > except RuntimeError as error:
> > sys.exit('\nFatal error: "{}"'.format(error))
> > except RuntimeWarning as warning:
> > print('Warning: {}'.format(warning))
> >
> > recrule is a classed derived from a named tuple with the various
> arguments
> > in it, for example: ChanId, Title, Subtitle, etc.
>
> How are you creating recrule? The strongly preferred way to do so is
> to call Dvr/GetRecordSchedule first. That will give you a known, good
> rule from which you can modify as needed.
>

recrule is basically a named tuple, with default values for the arguments:

from typing import Any, NamedTuple

class RecRule(NamedTuple):
ChanId: int
Title: str
Subtitle: str
AutoCommflag: 'RecRule' = 0
AutoExpire: 'RecRule' = 0
AutoMetaLookup: 'RecRule' = 0
AutoTranscode: 'RecRule' = 0
AutoUserJob1: 'RecRule' = 0
AutoUserJob2: 'RecRule' = 0
AutoUserJob3: 'RecRule' = 0
AutoUserJob4: 'RecRule' = 0
Category: 'RecRule' = ''
Description: 'RecRule' = ''
DupIn: 'RecRule' = 15
DupMethod: 'RecRule' = 6
EndOffset: 'RecRule' = 0
EndTime: 'RecRule' = 0
Episode: 'RecRule' = 0
Filter: 'RecRule' = 0
FindDay: 'RecRule' = 0
FindTime: 'RecRule' = '00:00:00'
Inactive: 'RecRule' = 0
Inetref: 'RecRule' = ''
MaxEpisodes: 'RecRule' = 0
MaxNewest: 'RecRule' = 0
ParentId: 'RecRule' = 0
PlayGroup: 'RecRule' = 'Default'
PreferredInput: 'RecRule' = 0
ProgramId: 'RecRule' = ''
RecGroup: 'RecRule' = 'Default'
RecPriority: 'RecRule' = 0
RecProfile: 'RecRule' = 'Default'
SearchType: 'RecRule' = ''
Season: 'RecRule' = 0
SeriesId: 'RecRule' = ''
StartOffset: 'RecRule' = 0
StartTime: 'RecRule' = 0
Station: 'RecRule' = ''
StorageGroup: 'RecRule' = 'Default'
Transcoder: 'RecRule' = 0
Type: 'RecRule' = 0

def asString(self):
result = ''
for attr in dir(self):
if (not callable(getattr(self,attr)) and not
attr.startswith("_")):
if result:
result += '&'
result += attr + '=' + str(getattr(self, attr))
return result

def asDict(self):
result = {}
for attr in dir(self):
if (not callable(getattr(self,attr)) and not
attr.startswith("_")):
result[attr] = str(getattr(self, attr))
return result


> There are 4 ways to call Dvr/GetRecordSchedule:
>
> nRecordId > 0 : Return the existing recording rule itself. Not
> necessarily tied to a specific program.
>
> !sTemplate.isEmpty() : Return the existing, template rule itself.
>
> nRecordedId > 0 : Return the rule for the given recording.
>
> nChanId > 0 && dStartTime.isValid() : Return the matching rule for the
> given program. Optionally, return an override rule when bMakeOverride
> is set.
>

Good to know. I had not thought of retrieving a template first. That
seems like a good approach.

Has anyone written a set of python tools for controlling Myth with the
services API, that has been published somewhere? The documentation is
currently somewhat sparse, and examples might be helpful.

Thanks,

John
Re: Services API: Does Dvr/AddRecordSchedule work? [ In reply to ]
On Sat, Oct 13, 2018 at 11:17:04AM -0600, John P Poet wrote:
> On Fri, Oct 12, 2018 at 7:56 PM David Engel <david@istwok.net> wrote:
> > There are 4 ways to call Dvr/GetRecordSchedule:
> >
> > nRecordId > 0 : Return the existing recording rule itself. Not
> > necessarily tied to a specific program.
> >
> > !sTemplate.isEmpty() : Return the existing, template rule itself.
> >
> > nRecordedId > 0 : Return the rule for the given recording.
> >
> > nChanId > 0 && dStartTime.isValid() : Return the matching rule for the
> > given program. Optionally, return an override rule when bMakeOverride
> > is set.
> >
>
> Good to know. I had not thought of retrieving a template first. That
> seems like a good approach.

Editing recording rules is an area where MythTV's flexibility bites us
hard. It's not reasonable for external users of the API to know all
of the business rules that must be followed. I tried to make it easy
to get the existing rule for a given program or a suitable starting
rule when one doesn't exist. Please let me know if have suggestions
on how to improve things.

> Has anyone written a set of python tools for controlling Myth with the
> services API, that has been published somewhere? The documentation is
> currently somewhat sparse, and examples might be helpful.

None that I know [much] of. Kodi has something but since it probably
conforms to their own, generic, PVR interface, it might not be the
best example. The only other thing I know of is Stuart Morgan's work
on the built-in, web interface but I'm pretty sure that's all in
javascript/jquery.

David
--
David Engel
david@istwok.net
_______________________________________________
mythtv-dev mailing list
mythtv-dev@mythtv.org
http://lists.mythtv.org/mailman/listinfo/mythtv-dev
http://wiki.mythtv.org/Mailing_List_etiquette
MythTV Forums: https://forum.mythtv.org
Re: Services API: Does Dvr/AddRecordSchedule work? [ In reply to ]
On 10/13/2018 12:17 PM, John P Poet wrote:
> Good to know. I had not thought of retrieving a template first. That
> seems like a good approach.
>
> Has anyone written a set of python tools for controlling Myth with the
> services API, that has been published somewhere? The documentation is
> currently somewhat sparse, and examples might be helpful.

Hey John,

This was my attempt at a cookbook. It builds up from simple examples to a
full program with arguments. Since I don't speak fluent Python, I wanted
to show how to use the returned values from the API (and I'd guess that
you were using some of it.)

https://www.mythtv.org/wiki/Python_API_Examples

I've been looking at putting the Python Services API *next to* the existing
Python bindings. That's where mine is installed. I'm not clear on how to
incorporate it into the build process.

Unless we're living in parallel universes, you're using

https://github.com/billmeek/MythTVServicesAPI

and that was my idea of a tool. My original plan was to create a library of
things that could be imported. Like: Capture.py/Content.py/Guide.py...Video.py.
Plus one Connection.py that the others used.

But they were essentially the same, all returning a dictionary with the returned
parameters. And so the more generic backend.send(...) is what I decided on.

I do have a tool just for testing (cleverly named 'api') and it's --help looks
like this:

$ api --help
usage: api [-h] [--debug] [--digest <user:pass>] [--host <host> [<host> ...]]
--endpoint <ep> [--noetag] [--nogzip] [--oneline] [--port <port>]
[--postdata <pd> [<pd> ...] | --rest <rest> [<rest> ...]] [--quiet]
[--timeout <seconds>] [--usexml] [--version] [--wrmi]

Services API Tester

optional arguments:
-h, --help show this help message and exit
--debug output additional information (False)
--digest <user:pass> digest username:password
--noetag tell the backend not to return a ETag (False)
--nogzip tell the backend not to return gzipped data (False)
--oneline print the response on one line, no formatting (False)
--port <port> back/frontend port (6544)
--postdata <pd> [<pd> ...]
Tag=Value *
--rest <rest> [<rest> ...]
Tag=Value *
--quiet don't print any responses (False)
--timeout <seconds> seconds to wait for a response (10)
--usexml ask for an XML response (False)
--version show program's version number and exit
--wrmi allows postdata to be sent to the server (False)

required arguments:
--host <host> [<host> ...]
server hostname(s) or IP address(s)
--endpoint <ep> endpoint to test

* E.g. Id=1 TitleRegEx=\*News\*. Default values are in ()s.

--
Bill
_______________________________________________
mythtv-dev mailing list
mythtv-dev@mythtv.org
http://lists.mythtv.org/mailman/listinfo/mythtv-dev
http://wiki.mythtv.org/Mailing_List_etiquette
MythTV Forums: https://forum.mythtv.org
Re: Services API: Does Dvr/AddRecordSchedule work? [ In reply to ]
On Sun, Oct 14, 2018 at 11:17 AM David Engel <david@istwok.net> wrote:

> On Sat, Oct 13, 2018 at 11:17:04AM -0600, John P Poet wrote:
> > On Fri, Oct 12, 2018 at 7:56 PM David Engel <david@istwok.net> wrote:
> > > There are 4 ways to call Dvr/GetRecordSchedule:
> > >
> > > nRecordId > 0 : Return the existing recording rule itself. Not
> > > necessarily tied to a specific program.
> > >
> > > !sTemplate.isEmpty() : Return the existing, template rule itself.
> > >
> > > nRecordedId > 0 : Return the rule for the given recording.
> > >
> > > nChanId > 0 && dStartTime.isValid() : Return the matching rule for the
> > > given program. Optionally, return an override rule when bMakeOverride
> > > is set.
> > >
> >
> > Good to know. I had not thought of retrieving a template first. That
> > seems like a good approach.
>
> Editing recording rules is an area where MythTV's flexibility bites us
> hard. It's not reasonable for external users of the API to know all
> of the business rules that must be followed. I tried to make it easy
> to get the existing rule for a given program or a suitable starting
> rule when one doesn't exist. Please let me know if have suggestions
> on how to improve things.
>
> > Has anyone written a set of python tools for controlling Myth with the
> > services API, that has been published somewhere? The documentation is
> > currently somewhat sparse, and examples might be helpful.
>
> None that I know [much] of. Kodi has something but since it probably
> conforms to their own, generic, PVR interface, it might not be the
> best example. The only other thing I know of is Stuart Morgan's work
> on the built-in, web interface but I'm pretty sure that's all in
> javascript/jquery.
>
>
Thanks, David.

John
Re: Services API: Does Dvr/AddRecordSchedule work? [ In reply to ]
On 10/15/2018 03:51 PM, John P Poet wrote:
> > Has anyone written a set of python tools for controlling Myth with the
> > services API, that has been published somewhere?  The documentation is
> > currently somewhat sparse, and examples might be helpful.

I recommend SOAPUI for testing web services and finding examples of the
parameters and results. It has been very useful to me in the past.

Peter
_______________________________________________
mythtv-dev mailing list
mythtv-dev@mythtv.org
http://lists.mythtv.org/mailman/listinfo/mythtv-dev
http://wiki.mythtv.org/Mailing_List_etiquette
MythTV Forums: https://forum.mythtv.org
Re: Services API: Does Dvr/AddRecordSchedule work? [ In reply to ]
On Sun, Oct 14, 2018 at 11:34 AM Bill Meek <keemllib@gmail.com> wrote:

> On 10/13/2018 12:17 PM, John P Poet wrote:
> > Good to know. I had not thought of retrieving a template first. That
> > seems like a good approach.
> >
> > Has anyone written a set of python tools for controlling Myth with the
> > services API, that has been published somewhere? The documentation is
> > currently somewhat sparse, and examples might be helpful.
>
> Hey John,
>
> This was my attempt at a cookbook. It builds up from simple examples to a
> full program with arguments. Since I don't speak fluent Python, I wanted
> to show how to use the returned values from the API (and I'd guess that
> you were using some of it.)
>
> https://www.mythtv.org/wiki/Python_API_Examples
>
> I've been looking at putting the Python Services API *next to* the existing
> Python bindings. That's where mine is installed. I'm not clear on how to
> incorporate it into the build process.
>
> Unless we're living in parallel universes, you're using
>
> https://github.com/billmeek/MythTVServicesAPI
>
> and that was my idea of a tool. My original plan was to create a library of
> things that could be imported. Like:
> Capture.py/Content.py/Guide.py...Video.py.
> Plus one Connection.py that the others used.
>
> But they were essentially the same, all returning a dictionary with the
> returned
> parameters. And so the more generic backend.send(...) is what I decided on.
>
> I do have a tool just for testing (cleverly named 'api') and it's --help
> looks
> like this:
>
> $ api --help
> usage: api [-h] [--debug] [--digest <user:pass>] [--host <host> [<host>
> ...]]
> --endpoint <ep> [--noetag] [--nogzip] [--oneline] [--port
> <port>]
> [--postdata <pd> [<pd> ...] | --rest <rest> [<rest> ...]]
> [--quiet]
> [--timeout <seconds>] [--usexml] [--version] [--wrmi]
>
> Services API Tester
>
> optional arguments:
> -h, --help show this help message and exit
> --debug output additional information (False)
> --digest <user:pass> digest username:password
> --noetag tell the backend not to return a ETag (False)
> --nogzip tell the backend not to return gzipped data
> (False)
> --oneline print the response on one line, no formatting
> (False)
> --port <port> back/frontend port (6544)
> --postdata <pd> [<pd> ...]
> Tag=Value *
> --rest <rest> [<rest> ...]
> Tag=Value *
> --quiet don't print any responses (False)
> --timeout <seconds> seconds to wait for a response (10)
> --usexml ask for an XML response (False)
> --version show program's version number and exit
> --wrmi allows postdata to be sent to the server (False)
>
> required arguments:
> --host <host> [<host> ...]
> server hostname(s) or IP address(s)
> --endpoint <ep> endpoint to test
>
> * E.g. Id=1 TitleRegEx=\*News\*. Default values are in ()s.
>

Hi Bill,

Yes, I am making use of those tools that you have written. They are a huge
help -- although I had not noticed your `api` application, and will need to
check it out.

It is a challenge to document "best practices" for each possible API call
(e.g. retrieving a template to use for creating a new recording). I was
just wondering if anyone had used the Services API in a fairly complete
application, that acted as a good example.

Thank you,

John
Re: Services API: Does Dvr/AddRecordSchedule work? [ In reply to ]
On 10/15/2018 02:55 PM, John P Poet wrote:
> Yes, I am making use of those tools that you have written. They are a huge
> help -- although I had not noticed your `api` application, and will need to
> check it out.

api only exists on my box, but attached here. I'll look at the
tool Peter just mentioned too.

--
Bill
Re: Services API: Does Dvr/AddRecordSchedule work? [ In reply to ]
On Fri, Oct 12, 2018 at 7:28 PM Bill Meek <keemllib@gmail.com> wrote:

>
> It does work. My usual 1st choice is: mythbackend --setverbose
> http:debug,upnp:debug
> (probably overkill.) And check the backend log...
>
> Here's a snippet from one of my tests:
>
> endpoint = 'Dvr/AddRecordSchedule'
>
> params_not_sent = ('AverageDelay', 'CallSign', 'Id', 'LastDeleted',
> 'LastRecorded', 'NextRecording', 'ParentId')
>
> for param in params_not_sent:
> try:
> del template[param]
> except KeyError:
> pass
> ...
>
>
> I also use:
>
> logging.basicConfig(level=logging.DEBUG if args['debug'] else
> logging.INFO)
>
> logging.getLogger('requests.packages.urllib3').setLevel(logging.WARNING)
> logging.getLogger('urllib3.connectionpool').setLevel(logging.WARNING)
>
> and a --debug switch to the Python program to activate the log messages.
> The
> send.py you're using has a bit more on the above.
>
> I attached my add_recording_rule.py FYI. The command line (just to test,
> without --wrmi):
> add_recording_rule.py --ho ofc0 --title Elementary --debug --digest
> admin:mythtv
>

Bill,

I am attaching my modifications to your work. Basically, I just added
support for manual recording rules. My next TODO is to add "power"
recording rule support. I called it mythtv_record.py so you can easily diff
it, to see what I added.

As a side note, the 500 error I was getting was because I did not have the
SearchType set correctly. It took my a bit to figure that out.

John
Re: Services API: Does Dvr/AddRecordSchedule work? [ In reply to ]
On 10/24/18 4:41 PM, John P Poet wrote:
> I am attaching my modifications to your work. Basically, I just added
> support for manual recording rules. My next TODO is to add "power"
> recording rule support. I called it mythtv_record.py so you can easily diff
> it, to see what I added

Nice, thanks.

--
Bill
_______________________________________________
mythtv-dev mailing list
mythtv-dev@mythtv.org
http://lists.mythtv.org/mailman/listinfo/mythtv-dev
http://wiki.mythtv.org/Mailing_List_etiquette
MythTV Forums: https://forum.mythtv.org