Jump to content

Autotimer and Web API


DetlefM

Recommended Posts

I am sorry, but I didn't find an api call to create an autotimer. Do I miss something or is it not possible?

My second question is the channel numbers in the channels path of the an autotimer.

The don't match with my channel list. How are they calculated?

Most of the other values are self explained - but a little bit more information will be fine.

 

autotimers.xml.txt

Channels.xml.txt

Link to comment
12 hours ago, DetlefM said:

I didn't find an api call to create an autotimer.

 

Can't find it in the DMS code either. However, you can trigger the Auto Timer task:

 

/api/tasks.html?task=AutoTimer

 

12 hours ago, DetlefM said:

My second question is the channel numbers in the channels path of the an autotimer.

The don't match with my channel list.

 

These are no channel numbers, but EPG Channel IDs:

type
  TEPGChannelID = record
    case Integer of
      0: (ID: Int64);
      1: (Lo, Hi: DWord);
      2: (SID: Word; TID: Word; NID: Word; TunerType: Byte; Source: Byte);
  end;

...what you would call a union. What you see in the channels.xml is the decimal 64 bit ID. Let's have a look at "Das Erste HD":

 

EPGID="562954315180093" = 0x02 0001 03FB 283D

(from right to left Service ID, Transportstream ID, Network ID as 16 bit values, Tuner Type as byte = DVB-S).

 

Now the same from the Sherlock auto timer in your autotimers.xml:

 

<channel>4361758781</channel> = 0x00 0001 03FB 283D

 

Can you see the match? Every part of the EPG Channel ID can be 0, which means "undefined". It must be handled as wildcard that always matches. Dunno why the tuner type is missing in the searches.xml (why did you rename it to autotimers.xml? These are no auto timers, but search definitions). I will have a closer look at it later.

 

BTW: You can copy the EPG Channel ID of a channel (including the tuner type) to the Windows clipboard by selecting it in the DVBViewer Channel Editor and pressing Ctrl+G (secret feature for developers :))

 

Link to comment
18 hours ago, DetlefM said:

I am sorry, but I didn't find an api call to create an autotimer. Do I miss something or is it not possible?

 

You can create a http post request to the webinterface. This of course will only work as long as there are no bigger changes.to the webinterface.

Something like this:
 

Spoiler



public void CreateSeriesSchedule(SeriesTimerInfo timer)
{
	var configuration = Plugin.Instance.Configuration;
	var channels = GetChannelList();

	Dictionary<string, string> header = new Dictionary<string, string>()
	{
		{ "search_id", "-1" },
		{ "cbtitle", "on" },
		{ "ignorecase", "on" },
		
		{ "searchphrase", GeneralExtensions.SetSearchPhrase(timer.Name) },
		{ "Savename", GeneralExtensions.ToUrlString(timer.Name) }, 
		{ "Series", GeneralExtensions.ToUrlString(timer.Name) },

		{ "chan_id", timer.RecordAnyChannel ? "" : channels.Where(c => c.Nr == timer.ChannelId).Select(c => c.EPGID).FirstOrDefault() },
		{ "startH", timer.RecordAnyTime ? "00:00" : GeneralExtensions.ToTimeString(timer.StartDate.AddSeconds(-timer.PrePaddingSeconds)) },
		{ "endH", timer.RecordAnyTime ? "23:59" : GeneralExtensions.ToTimeString(timer.EndDate.AddSeconds(timer.PostPaddingSeconds)) },
		{ "epgbefore", (timer.PrePaddingSeconds / 60).ToString() },
		{ "epgafter", (timer.PostPaddingSeconds / 60).ToString() },

		{ "MonitorForStart", "1" },
		{ "AutoRec", "on" },
		{ "Save", ""},
	};

	if (timer.Days.Contains(DayOfWeek.Monday))
		header.Add("D0", "1");
	if (timer.Days.Contains(DayOfWeek.Tuesday))
		header.Add("D1", "1");
	if (timer.Days.Contains(DayOfWeek.Wednesday))
		header.Add("D2", "1");
	if (timer.Days.Contains(DayOfWeek.Thursday))
		header.Add("D3", "1");
	if (timer.Days.Contains(DayOfWeek.Friday))
		header.Add("D4", "1");
	if (timer.Days.Contains(DayOfWeek.Saturday))
		header.Add("D5", "1");
	if (timer.Days.Contains(DayOfWeek.Sunday))
		header.Add("D6", "1");

	if (timer.RecordNewOnly)
	{
		if (configuration.CheckRecordingTitel)
			header.Add("chkrectitel", "on");
		if (configuration.CheckRecordingInfo)
			header.Add("chkrecsubtitel", "on");
		if (configuration.CheckTimerName)
			header.Add("chktimer", "on");
	}
	
	PostToService(header);
}


public Task PostToService(Dictionary<string, string> header)
{
	var configuration = Plugin.Instance.Configuration;
	
	var request = new HttpRequestOptions()
	{
		Url = String.Format("http://{0}:{1}/epg_search.html", configuration.ApiHostName, configuration.ApiPortNumber),
		RequestContentType = "application/x-www-form-urlencoded",
		UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.87 Safari/537.36",
		EnableKeepAlive = true,
		LogErrorResponseBody = true,
		LogRequest = true,
	};

	request.SetPostData(header);

	if (configuration.RequiresAuthentication)
	{
		string authInfo = String.Format("{0}:{1}", configuration.UserName, configuration.Password);
		authInfo = Convert.ToBase64String(Encoding.Default.GetBytes(authInfo));
		request.RequestHeaders["Authorization"] = "Basic " + authInfo;
	}

	return Task.FromResult(HttpClient.Post(request));
}


 

 

Edited by Griga
Spoiler tags added
Link to comment
Quote

Can't find it in the DMS code either. However, you can trigger the Auto Timer task:

 

/api/tasks.html?task=AutoTimer

 

But not create a new autotimer - right?

 

Btw. when I do not start the autotimer manually - when do it start (every day?, hour?, one epg udpates?)

 

Quote

These are no channel numbers, but EPG Channel IDs:

 

That was my first guess - but I can't get it.

And when I count rigth then the search channel ids are a bitwise "and" from the epg id with 0x1FFFFFFFF ( epgid & 0x1FFFFFFFF) ( I am not sure about the 1 in front)

I thought about it. The only reason I can see for storing it without tuner id is if the epgids are the same across services  / tuners and you want to do the search not only on DVB-S2 but also on maybe a service on DVB-T oder -C. or maybe other hardware issues. Maybe also for copy search items to another hardware.

 

.

Quote

Dunno why the tuner type is missing in the searches.xml (why did you rename it to autotimers.xml? These are no auto timers, but search definitions).

 

Searches are the more better naming. But all over the documentation and forum entries I found tthe term "autotimer". It makes more sense to use "EPG Seaches" and the timer events in the timer list are autogenerated timers, short autotimers. And I didn't rename it - I get it from a python call and store it to a file. I try to never work directly with the configuration files but to deal with the web api.

Link to comment
Quote

You can create a http post request to the webinterface. This of course will only work as long as there are no bigger changes.to the webinterface.

Something like this:

		
	


 

Thank you. - I will try it. Where is this snippet from? Are you already dealing with the Searches / autotimers?

Link to comment
2 hours ago, DetlefM said:

I get it from a python call and store it to a file.

 

With which API call?

 

2 hours ago, DetlefM said:

Btw. when I do not start the autotimer manually - when do it start (every day?, hour?, one epg udpates?)

 

In the Desktop Web Interface you can add an Internal Task Timer to the list of timers (see Timer Page) that executes the predefined EPG Auto Timer task (see Tasks Page) daily or on certain days. However, you can't create such an Internal Task Timer by API, as far as I can see.

 

You may also tick the DMS Options (svcoptions.exe) -> EPG -> "Execute auto-search after an update" checkbox in order to let the DMS automatically execute the EPG Auto Timer task after each completed EPG Update task.

 

So what do you want to do? Add a search definition to the list of searches, I guess? You may use the method stated by Pünktchen (see above). However, this is not part of the API, but used internally for the Web Interfaces and may be subject to changes in future.

 

2 hours ago, DetlefM said:

And when I count rigth then the search channel ids are a bitwise "and" from the epg id with 0x1FFFFFFFF ( epgid & 0x1FFFFFFFF) ( I am not sure about the 1 in front)

 

Rather 0x0000FFFFFFFFFFFF. But that's no clean solution. Each of the involved fields (SID, TID, NID, tuner type) can be zero (maybe the information is not available for some reason) and must be handled as wildcard in this case. The source field (most significant byte indicating the source of the EPG data) can be ignored becaue it is only used internally and not exposed in API calls due to compatibility reasons.

 

2 hours ago, DetlefM said:

The only reason I can see for storing it without tuner id is if the epgids are the same across services  / tuners

 

They aren't. At least the Network IDs would also be different. NID = 1 is Astra 19° East, by the way.

Link to comment
1 hour ago, Griga said:

With which API call?

 

Ok - its just like copy but yes I use the api "/api/getconfigfile.html?file=config%5Csearches.xml"

 

1 hour ago, Griga said:

So what do you want to do?

 

As a test I try to make it easier for newbies to create a Search - with one click.

Therefore he must click on an epg entry ( open to be implemented),

next step is to take that epg entry and extract the channel, the title (easy - no problem),

next step show the newbie a list of matching epg entries in the future (same channel, same titel) (easy - no problem)

and the possibility to change the titel and define the search of title like "startswith", "is part of" or "equal", on every choice he gets a new list of matching epgs (is work but nothing to really care about).

Now came the tricky part: To integrate the result from the user input into a foreign system without documentation.

I have learned I can't use the EPG Ids directly and the other fields are also not self explained. But I will go with the snippet from @pünktchen .

So the first try will be a command line call with something like "The Mentalist" (sorry is only example) as a try without any EPG.entry.

This call can go to the epgs of the favorites, looks for a match and creates a search entry.

 

1 hour ago, Griga said:

In the Desktop Web Interface you can add an Internal Task Timer to the list of timers (see Timer Page) that executes the predefined EPG Auto Timer task (see Tasks Page) daily or on certain days. However, you can't create such an Internal Task Timer by API, as far as I can see.

 

I am not sure what have to be done when I have created the search entry. I think I have to call /api/tasks.html?task=AutoTimer.

Normally it is too much - it is not necessary to update all searches but ...

 

I think after the search is in the system the system will update the timer list by itself (when ever).

 

1 hour ago, Griga said:

Rather 0x0000FFFFFFFFFFFF. But that's no clean solution.

 

It is my way for the reverse part.   I have a search entry and a  "channel". And want to get the EPG id as easy as possible. When I compare the list of channel epgids with the list of search entry channels a match must show the right epg id ?

Like  for c in favorites; if  c.epgid & 0xFFFFFFFF == search.channel & 0xFFFFFFFF then found. Just comparing the lower bits (This is no computer language)

 

 

Link to comment
8 hours ago, Griga said:

Dunno why the tuner type is missing in the searches.xml

 

Now I know. It's a bug from my side. :oops: I wanted to mask the source byte out and did a bit too much. Will be fixed in the next release.

 

40 minutes ago, DetlefM said:

if  c.epgid & 0xFFFFFFFF == search.channel & 0xFFFFFFFF then found

 

That's a rough solution, but it will do in most cases. A clean solution must regard the ID as union and check the parts:

Match :=

  ((ID1.SID = 0) or (ID2.SID = 0) or (ID1.SID = ID2.SID)) and

  ((ID1.TID = 0) or (ID2.TID = 0) or (ID1.TID = ID2.TID)) and

  ((ID1.NID = 0) or (ID2.NID = 0) or (ID1.NID = ID2.NID)) and

  ((ID1.TunerType = 0) or (ID2.Tunertype = 0) or (ID1.TunerType = ID2.TunerType));

That's how the DMS compares EPG Channel IDs and that's why the bug doesn't have much effect.

 

50 minutes ago, DetlefM said:

As a test I try to make it easier for newbies to create a Search - with one click.

 

Hmm... we are still looking for someone who would enjoy working voluntarily on the web interfaces...

 

BTW: You may want to have a look at SVCweb\epg_search.html. :whistle:That's where the data gets posted:

 

<form action="epg_search.html" method="post"....

Link to comment

P.S.

 

Quote

if  c.epgid & 0xFFFFFFFF == search.channel & 0xFFFFFFFF then found

 

No good. You can easily go wrong with the number of F's. That happened to me (see above). There must be 3 x 4 = 12 F's for three 16 bit values covering SID, NID and TID

 

if  c.epgid & 0xFFFFFFFFFFFF == search.channel & 0xFFFFFFFFFFFF then found

 

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...