Retrieving reference data using API?

Post Reply
fransgl
Junior
Posts: 26
Joined: Tue Nov 10, 2015 9:36 am
Location: Amsterdam-area, NL
Netherlands

Retrieving reference data using API?

Post by fransgl »

Hi MythTV-devs,

I am developing an iOS-client to manage a MythTV-server: seeing recordings, EPG and also setting recording schedules. For this, I am using different kinds of reference data: type (Once, every instance, etc.); duplicates (subtitle, description, both), preferred input (depends on the user's capture cards). See screenshot.
My question is: are there services available to retrieve the options for each of these?

And a related question: for program categories there is a service that retrieves a list of the category names.That's a good start, but I would want more: an id perhaps (which I suppose is used in programs), a color (so that I can keep the colours I use for categories in sync with MythWeb). Is that available?

I hope to hear from you! Thanks in advance!

Frans
Attachments
Simulator Screen Shot - iPhone Xʀ - 2019-05-09 at 14.27.54.png
Simulator Screen Shot - iPhone Xʀ - 2019-05-09 at 14.27.54.png (109.24 KiB) Viewed 3932 times
User avatar
bill6502
Developer
Posts: 2307
Joined: Fri Feb 07, 2014 5:28 pm
United States of America

Re: Retrieving reference data using API?

Post by bill6502 »

Hi,

Maybe you're looking for things like:

Code: Select all

Dvr/RecStatusToString and:
RecStatusToDescription
RecTypeToString
RecTypeToDescription
DupMethodToString
DupMethodToDescription
DupInToString
DupInToDescription
Turns out they're not in the Wiki. You can use: curl localhost:6544/Dvr/wsdl|less
in the mean time (to get the Parameters for each endpoint.)

For the related question: https://www.mythtv.org/wiki/Guide_Servi ... tegoryList
The Category is stored in the DB in plain text.

Colors, no.
fransgl
Junior
Posts: 26
Joined: Tue Nov 10, 2015 9:36 am
Location: Amsterdam-area, NL
Netherlands

Re: Retrieving reference data using API?

Post by fransgl »

Ha, that's brilliant Bill, thanks! :)

That's what I need! My approach so far has been to look in the cpp sources, like https://github.com/MythTV/mythtv/blob/6 ... gtypes.cpp

But these services make it way more convenient. I will continue along these lines.

The service I tried first was DupMethodToString. I was struggling getting it to respond to a specific parameter, for instance http://192.168.1.3:6544/Dvr/DupMethodTo ... upMethod=3 This always seems to return "Match duplicates using subtitle & description", regardless of the DupMethod I pass. But it seems that is an issue with this particular service; the same approach *does* work with for instance "http://192.168.1.3:6544/Dvr/RecTypeToDe ... ?RecType=2".

I will study this further and see if I can puzzle it all together.

To be continued!

Best regards, Frans
User avatar
paulh
Developer
Posts: 909
Joined: Thu Feb 06, 2014 6:09 pm
Great Britain

Re: Retrieving reference data using API?

Post by paulh »

User avatar
bill6502
Developer
Posts: 2307
Joined: Fri Feb 07, 2014 5:28 pm
United States of America

Re: Retrieving reference data using API?

Post by bill6502 »

Right, and here: https://github.com/MythTV/mythtv/tree/m ... acts/enums
only one 'family' of enums have been defined. ISTR reading on IRC years ago about developing a way to
convert to/from numeric values to their text equivalents. I'll see if I can figure out the plan.
fransgl
Junior
Posts: 26
Joined: Tue Nov 10, 2015 9:36 am
Location: Amsterdam-area, NL
Netherlands

Re: Retrieving reference data using API?

Post by fransgl »

@paulh @bill6502: I am interested in your findings!

I put a 'Manage recordings' page together in the iOS-app that I'm developing and I am now able to set recordings. That's a start. Approach is: call /Dvr/GetRecordSchedule to create a record schedule. Then put in values as specified by the user, most notably the Type (Single, Record All, etc.) and then a POST-call to /Dvr/AddRecordSchedule. This is as per the wiki. It needs further work, but is ok for now.
The logical next step is to be able to *cancel* a planned recording. I have not managed to do this so far. What I tried was again calling a GetRecordSchedule, this time returning the rule that will record a particular program. This includes a non-zero id now. I set recordId equal to id, (just to be sure) set station equal to callsign. Then, I change the Type to "None", "Not recording", "Override Recording". I tried many options, inspired by the backend source (https://github.com/MythTV/mythtv/blob/6 ... gtypes.cpp in this case). I consistently get an http 501error with description "Invalid parentID/override." I looked this up in the sources and found this:

Code: Select all

    if ((m_parentRecID && !isOverride) ||
        (!m_parentRecID && isOverride))
    {
        msg = QString("Invalid parentID/override.");
        return false;
    }
See https://github.com/MythTV/mythtv/blob/6 ... e.cpp#L907

I then tried some more: passing *either* a ParentID *or* ensuring that isOverride == true. So far I have not found a combination that successfully lets me cancel a scheduled recording.

Is there anyone who can give me some pointers on this?

Any help is appreciated!

Thanks, Frans
User avatar
bill6502
Developer
Posts: 2307
Joined: Fri Feb 07, 2014 5:28 pm
United States of America

Re: Retrieving reference data using API?

Post by bill6502 »

I've now done override tests myself, it sounds like you're calling GetRecordSchedule with MakeOverride=True along with StartTime (in UTC) and ChanId to get a specific recording in the future. That should get a template you can use to update the rule. Then use Type=DontRecord.

The link in Add/UpdateRecordSchedule has the developers notes which should help. The link is just above the Example Query:.

I will this will avoid the 501 error you're getting.

Edit: Note that the RecordId isn't in the above. The returned template should have the ParentId set to the RecordId of the matching ChanId/StartTime.
Also, the returned Id will be 0. I wouldn't change that because you want the backend to choose a new Id for the override.

Edit: In the initial response from GetRecordSchedule, verify that the Id=0. If it isn't, then an override rule already exists. At that point, you can either remove that rule, or choose not to add the override.
Last edited by bill6502 on Sun May 12, 2019 2:07 pm, edited 1 time in total.
fransgl
Junior
Posts: 26
Joined: Tue Nov 10, 2015 9:36 am
Location: Amsterdam-area, NL
Netherlands

Re: Retrieving reference data using API?

Post by fransgl »

Thanks Bill, you put me on the right track! I did some experiments with this (in the app as well as Postman) and I managed to set and cancel recordings. It all comes down to combinations of (recording schedule) Id, ParentId and (recording) Type. I will need to get to the bottom of this in order to let a user fully control recording schedules. Once I have this sorted, I will release an update in TestFlight.
User avatar
bill6502
Developer
Posts: 2307
Joined: Fri Feb 07, 2014 5:28 pm
United States of America

Re: Retrieving reference data using API?

Post by bill6502 »

Cool. If doing an override, the values for Id (0) and ParentId (the id of the rule getting the override)
will be correct in the returned template. Also for override, type should be set to DontRecord or Override
depending on if you're not going to record a single episode or just changing something (like EndOffset) for
one episode.
fransgl
Junior
Posts: 26
Joined: Tue Nov 10, 2015 9:36 am
Location: Amsterdam-area, NL
Netherlands

Re: Retrieving reference data using API?

Post by fransgl »

Well.. I have progressed a bit. The result is in review by Apple, so that I can release it on TestFlight.

If you feel courageous and you want to test it, just send me a PM with your AppleId and I will add you to TestFlight. Apart from courage, you will need an iDevice: iPhone or iPad, running iOS 10.3 or higher. And obviously, you will need a MythTV-backend server.

Short summary of my findings on the topic of recording rules/schedules and overrides (still discovering new things):
Manage recording schedule/rules:
• Retrieve the recording rule by calling

Code: Select all

/Dvr/GetRecordSchedule
, passing in the start time and the channel id. Make any changes and call

Code: Select all

/Dvr/UpdateRecordSchedule
. Mm.. actually, currently I use delete and re-create, because I have not quite figured out why Update is giving errors back in many cases. The exact Type (i.e. recording types) to pass are a bit fiddly and not very consistent. My current implementation definitely requires further testing.

Overrides:
An override is an exception to a recording rule.
• If there is no recording rule for a startTime/ChanId, first get an Override rule template. That is done by calling

Code: Select all

/Dvr/GetRecordSchedule
with parameter

Code: Select all

MakeOverride=true
. Type will be "Single". The recording rule must be added using AddRecordSchedule.
• If there is a 'standard' recording rule for a startTime/ChanId, then also get an Override recording rule. The Type will be set to "Not Recording", which does not work if you try to add the recording rule. Change the Type to "None" and it will successfully insert a new recording rule, causign this specific showing NOT to be recorded.
• If there already is a recording rule for a startTime/ChanId and both id and ParentId are non-zero, that indicates that there is already an override in place. Overriding this override is effectively removing the override rule. So that's the approach: delete the override-schedule by calling

Code: Select all

/Dvr/RemoveRecordSchedule
. Pass the 'id' of the rule as a parameter (not the Parent ID).

I have a question about filters (this channel, this time, this day, etc.) for which I will create a new thread.

Best regards, Frans
fransgl
Junior
Posts: 26
Joined: Tue Nov 10, 2015 9:36 am
Location: Amsterdam-area, NL
Netherlands

Re: Retrieving reference data using API?

Post by fransgl »

OK, I have implemented the PreferredInput as a PoC. The app retrieves the options for your specific mythbackend and presents these in the Manage Recordings page. I will further extend this in the next couple of days. And now first focus on other things. Like getting and update to TestFlight and the AppStore.
Post Reply