API add_schedule command

TVMosaic live and recorded TV products for Desktop/NAS/Raspbery Pi
Post Reply
Jantje
Posts: 22
Joined: Thu Feb 07, 2019 9:31 pm

API add_schedule command

Post by Jantje » Tue Apr 09, 2019 7:37 pm

Hi,

I try to use the API, during testing/development with Postman later on in C#. Simple commands like get_channels, get_recordings and get_xmltv_epg work nice.
Even I got get_epg_channel_config working where I needed to send an extra xml_param query param.

But I also want to add_schedule. I am using the EPG data and took a movie:

Code: Select all

    <programme channel="2:360000:1791:8:9" start="20190412202000" stop="20190412225500">
        <title>Sherlock Holmes: A Game of Shadows</title>
        <desc>Film
Als de prins van Oostenrijk dood wordt aangetroffen, wordt er gedacht aan zelfmoord. Sherlock Holmes denkt echter dat de prins is vermoord, en die moord is slechts één deel van een onheilspellende puzzel. Een spoor van aanwijzingen brengt Holmes in een ondergrondse herensociëteit. Daar heffen hij en zijn broer Mycroft het glas op Dr. Watson, om zijn laatste avond als vrijgezel te vieren. In die club maakt Holmes kennis met Sim, een waarzegster die veel meer kan zien dan ze vertelt. Omdat ze ook meer weet van de moord op de prins, dreigt zij het volgende slachtoffer van de moordenaar te worden.</desc>
        <language>NLD</language>
    </programme>
I converted the start datetime 20190412202000 to EPOC using https://www.epochconverter.com/
I calculated the duration by subtracting stop from start which in this case is 22:55 - 20:20 = 2:35 = 2*60*60+35*60=9300 seconds

This is my POST request:

Code: Select all

POST /mobile/?command=add_schedule&amp; xml_param=<schedule>
  <priority/>0
  <active/>true
  <manual>
    <channel_id/>2:360000:1791:8:9
    <start_time/>1555100400
    <duration/>9300
    <day_mask/>0
  </manual>
</schedule> HTTP/1.1
Host: 192.168.11.100:9270
Content-Type: application/x-www-form-urlencoded
cache-control: no-cache
Postman-Token: 01e3e53f-d920-49ef-a336-92863c23d1e5
I got this response:

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<response>
    <status_code>0</status_code>
</response>
But no schedule is added. I checked it using the iOS TV Mosaic app and by doing:

Code: Select all

GET /mobile/?command=get_recordings HTTP/1.1
Host: 192.168.11.100:9270
cache-control: no-cache
Postman-Token: 28258958-fc89-466e-a46a-0f8d18b0720e
which responsed with current recording but the above movie.

What am I doing wrong? Thanks for any help.

the_man
Site Admin
Posts: 126
Joined: Fri Jan 06, 2017 1:13 pm

Re: API add_schedule command

Post by the_man » Wed Apr 17, 2019 10:01 am

Try with open and close tags:

xml_param=<schedule>
<priority>0</priority>
<active>true</active>
<manual>
<channel_id>2:360000:1791:8:9</channel_id>
<title>TEST</title>
<start_time>1555100400</start_time>
<duration>9300</duration>
<day_mask>0</day_mask>
</manual>
</schedule>

Maverickz
Posts: 35
Joined: Thu Oct 25, 2018 11:37 pm

Re: API add_schedule command

Post by Maverickz » Thu Apr 18, 2019 9:12 am

I don't use C# but I have done this with both Classic ASP and JavaScript and have it working in both code bases. I am not 100% sure what your issue is but I have some possible tips.

First, with your POST line:
POST /mobile/?command=add_schedule&amp; xml_param=<schedule>
It appears that this would cause a space between the ampersand and the xml_param, since this is a URL that could cause issues. In both of my implementations this whole command is encased in quotes and so the ampersand can be written normally. Also since this is a URL and not html, if C# requires you to not use quotes, then you should have used %26 and no space instead of amp;.

Here is my command URL line from the ASP code base, notice the quotes and &:

Code: Select all

httpRequest.Open "POST", "http://myserver:9270/mobile/?command=add_schedule&xml_param=" & strXML, True
Second, when using manual format (or any of them) "recordings_to_keep" is a mandatory field, but I see it's missing in your xml.

Finally, in my xml I used the xml tag and full open and close tag syntax. Also I included the "margin_before" and "margin_after" tags. You will notice I used the "by_epg" format instead of the "manual" format but "manual" should work fine.

This is how I built the xml in the Javascript codebase.

Code: Select all

		strXML = '<?xml version="1.0" encoding="utf-8" ?>';
		strXML += '<schedule>';
		strXML += '<margine_before>' + start + '</margine_before>';
		strXML += '<margine_after>' + stop + '</margine_after>';
		strXML += '<priority>' + priority + '</priority>';
		strXML += '<active>' + active + '</active>';
		strXML += '<by_epg>';
		strXML += '<channel_id>' + chanID + '</channel_id>';
		strXML += '<program_id>' + pID + '</program_id>';
		if (type == "series"){strXML += '<repeat>true</repeat>'};
		if (type == "series"){strXML += '<new_only>' + newOnly + '</new_only>'};
		strXML += '<recordings_to_keep>' + keep + '</recordings_to_keep>';
		strXML += '</by_epg>';
		strXML += '</schedule>';
I hope this helps you resolve the issue.

Jantje
Posts: 22
Joined: Thu Feb 07, 2019 9:31 pm

Re: API add_schedule command

Post by Jantje » Thu Apr 18, 2019 9:48 am

With help from support I got it to work...

-I used begin <...> and end </...> tags instead of short form <.../>. The documentation is incorrect which shows/uses the short form!
-I double checked the channel_id for correctness -> you can find them by GET http://192.168.11.100:9270/mobile/?command=get_channels
-Added a <title> tag (which is optional by the way but recommended for easier finding, or else your recording shows up with NO NAME title)

So why didn't it work for me before? Here my findings:
-Be sure to have your begin and end tags syntax correctly. Or else you will get an return status code 1000.
-Not all params support the short form <.../> for example <start_time>! To be sure always use for all params the long form <...> </...>
-Also I found out that using the wrong channel_id still gets you return status code of 0. This let the developer thinks the call succeeeded but actually it failed. It would be nice if this was checked for correctness and used a result code !=0 for example 1001 or 1002

Correct xml_param example:
<schedule>
<priority>0</priority>
<active>true</active>
<manual>
<channel_id>2:384000:1791:11:43</channel_id>
<title>TEST</title>
<start_time>1555740000</start_time>
<duration>9300</duration>
<day_mask>0</day_mask>
</manual>
</schedule>
Attachments
screenshot2.png
screenshot2.png (55.51 KiB) Viewed 19 times

Post Reply