[mythtv] Services API: Does Dvr/AddRecordSchedule work?

John P Poet jppoet at gmail.com
Sat Oct 13 17:17:04 UTC 2018


On Fri, Oct 12, 2018 at 7:56 PM David Engel <david at 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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mythtv.org/pipermail/mythtv-dev/attachments/20181013/46540c18/attachment.html>


More information about the mythtv-dev mailing list