Notice: This forum has been recovered from an old backup, so some content, links, and dates may be outdated. The forum is currently read-only while we restore sign-in and registration functionality. Details

If you find this forum valuable and would like to help keep it online, donations to help cover hosting and domain costs are greatly appreciated, but never expected. You can support the forum through Buy Me a Coffee or Ko-fi. Thank you for helping preserve the EventGhost community.

Getting events from a HTTP GET querry

If you have a question or need help, this is the place to be.
Post Reply
DarkCinema
Posts: 25
Joined: Wed Sep 26, 2012 10:46 pm

Getting events from a HTTP GET querry

Post by DarkCinema »

I like to know if it would be possible to use Eventghost to send a HTTP request to my Popcorn Hour A-400 and trigger an event on the received XML output.
Forn instance when I send the command:

http://<A-400>:8008/playback?arg0=get_current_vod_info I receive the playback status in XML syntax:

Code: Select all

<theDavidBox>
<request>
    <arg0>get_current_vod_info</arg0>
    <module>playback</module>
</request>
<response>
    <currentStatus>play</currentStatus>
    <currentTime>15</currentTime>
    <currentchapter>1</currentchapter>
    <downloadSpeed>0</downloadSpeed>
    <fullPath>
         /opt/sybhttpd/localhost.drives/NETWORK_SHARE/share1/Alien (1979)/Alien (1979).mkv
    </fullPath>
    <lastPacketTime>0</lastPacketTime>
    <mediatype>OTHERS</mediatype>
    <seekEnable>true</seekEnable>
    <title>Alien (1979).mkv</title>
    <totalTime>6949</totalTime>
    <totalchapter>40</totalchapter>
</response>
<returnValue>0</returnValue>
</theDavidBox>
I would like to trigger an event for the current status: play/pause/stop.
Does anyone know if this is possible with Eventghost?
bruinlax
Posts: 26
Joined: Thu Sep 29, 2011 4:31 pm

Re: Getting events from a HTTP GET querry

Post by bruinlax »

yes use a script. something _like_ (my code sucks, but should get you in the right direction with some google.)

Code: Select all

import urllib
import xml.dom.minidom

response = urllib.urlopen('http://<A-400>:8008/playback?arg0=get_current_vod_info') #assumes the response is ready to parse into xml
status = dom.getElementsByTagName('theDavidBox')[0].getElementsByTagName('response')[0].getElementsByTagName('currentStatus')[0].firstChild.data  #ugly, but should work - or something like it
eg.TriggerEvent('PopcornPlayStatus.' + status) #trigger an event based on the status
DarkCinema
Posts: 25
Joined: Wed Sep 26, 2012 10:46 pm

Re: Getting events from a HTTP GET querry

Post by DarkCinema »

Cool Thanks a lot.
Gonna try this and see I if can get this to work.
DarkCinema
Posts: 25
Joined: Wed Sep 26, 2012 10:46 pm

Re: Getting events from a HTTP GET querry

Post by DarkCinema »

Got it working :).

Added:

Code: Select all

from xml.dom.minidom import parse
dom = parse (response)
I had to look at the Tag "returnvalue" 0=stop 1=playing

If noting is playing the response is:

Code: Select all

<theDavidBox>
<request>
<arg0>get_current_vod_info</arg0>
<module>playback</module>
</request>
<response/>
<returnValue>1</returnValue>
</theDavidBox>
Python Code I use:

Code: Select all

import urllib
import xml.dom.minidom
from xml.dom.minidom import parse

response = urllib.urlopen('http://172.19.3.210:8008/playback?arg0=get_current_vod_info') #assumes the response is ready to parse into xml
dom = parse (response)
#status = dom.getElementsByTagName('theDavidBox')[0].getElementsByTagName('response')[0].getElementsByTagName('currentStatus')[0].firstChild.data  #ugly, but should work - or something like it
status = dom.getElementsByTagName('theDavidBox')[0].getElementsByTagName('returnValue')[0].firstChild.data
eg.TriggerEvent('PopcornPlayStatus.' + status) #trigger an event based on the status
Result:

Code: Select all

11:28:42   Python Script
11:28:42   Main.PopcornPlayStatus.1
11:29:23   Python Script
11:29:23   Main.PopcornPlayStatus.0
bruinlax
Posts: 26
Joined: Thu Sep 29, 2011 4:31 pm

Re: Getting events from a HTTP GET querry

Post by bruinlax »

awesome.

this might be proving my knowledge limits of python, but in your code

isn't this redundant?:

import xml.dom.minidom
from xml.dom.minidom import parse
DarkCinema
Posts: 25
Joined: Wed Sep 26, 2012 10:46 pm

Re: Getting events from a HTTP GET querry

Post by DarkCinema »

I am merely a copycat when it comes to Python coding.
Since it wasnÔÇÖt working I looked at the wiki page https://wiki.python.org/moin/MiniDom%20 ... 20example.
Sem;colon
Plugin Developer
Posts: 625
Joined: Sat Feb 18, 2012 10:51 am
Location: Germany

Re: Getting events from a HTTP GET querry

Post by Sem;colon »

DarkCinema wrote:I like to know if it would be possible to use Eventghost to send a HTTP request to my Popcorn Hour A-400 and trigger an event on the received XML output.
Forn instance when I send the command:

http://<A-400>:8008/playback?arg0=get_current_vod_info I receive the playback status in XML syntax:

Code: Select all

<theDavidBox>
<request>
    <arg0>get_current_vod_info</arg0>
    <module>playback</module>
</request>
<response>
    <currentStatus>play</currentStatus>
    <currentTime>15</currentTime>
    <currentchapter>1</currentchapter>
    <downloadSpeed>0</downloadSpeed>
    <fullPath>
         /opt/sybhttpd/localhost.drives/NETWORK_SHARE/share1/Alien (1979)/Alien (1979).mkv
    </fullPath>
    <lastPacketTime>0</lastPacketTime>
    <mediatype>OTHERS</mediatype>
    <seekEnable>true</seekEnable>
    <title>Alien (1979).mkv</title>
    <totalTime>6949</totalTime>
    <totalchapter>40</totalchapter>
</response>
<returnValue>0</returnValue>
</theDavidBox>
I would like to trigger an event for the current status: play/pause/stop.
Does anyone know if this is possible with Eventghost?
...the first part is also a default function from the webserver plugin (send Event to external webserver) ;-)
If you like my work, Image me a drink :wink:
Post Reply