Webserver

Questions and comments specific to a particular plugin should go here.
leejk
Posts: 16
Joined: Sun Dec 04, 2016 4:32 pm

Re: Webserver

Post by leejk » Wed Aug 14, 2019 11:22 pm

That would be cool! For ports, only in the url the webhook posts to, like http://192.168.0.100:80

There are a few examples of using node.js to parse the payload and control hue lights, so in theory I could adapt these to send events to EG, but better if there’s not a middle layer.

User avatar
kgschlosser
Site Admin
Posts: 4931
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: Webserver

Post by kgschlosser » Thu Aug 15, 2019 6:09 am

do you have an example of the data you are being sent?
If you like the work I have been doing then feel free to Image

leejk
Posts: 16
Joined: Sun Dec 04, 2016 4:32 pm

Re: Webserver

Post by leejk » Sat Aug 17, 2019 12:12 am

kgschlosser wrote:
Thu Aug 15, 2019 6:09 am
do you have an example of the data you are being sent?
Sort of. I am running Homebridge on my Mac, and so I put it into debug mode to print out everything being sent to it.

Code: Select all

[8/16/2019, 7:59:56 PM] [homebridge-plex-sensors.Plex] Homebridge Plex Sensors listening for webhooks on: http://<homebridge ip>:22987
[8/16/2019, 7:59:56 PM] Homebridge is running on port 60084.
[8/16/2019, 8:02:07 PM] [homebridge-plex-sensors.Plex] Plex incoming webhook
[8/16/2019, 8:02:07 PM] [homebridge-plex-sensors.Plex] Seen player: "Safari" (with UUID: "skciahdqsfr0b1n4hyig9del")
[8/16/2019, 8:02:07 PM] [homebridge-plex-sensors.Plex] Seen user: "xxxxxx"
[8/16/2019, 8:02:07 PM] [homebridge-plex-sensors.Plex] Processing event: {"event":"media.play","user":true,"owner":true,"Account":{"id":1,"thumb":"https://plex.tv/users/9d468cacd1184e2a/avatar?c=1556848787","title":"xxxxxx"},"Server":{"title":"macmini","uuid":"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"},"Player":{"local":true,"publicAddress":"","title":"Safari","uuid":"skciahdqsfr0b1n4hyig9del"},"Metadata":{"librarySectionType":"show","ratingKey":"156298","key":"/library/metadata/156298","parentRatingKey":"156036","grandparentRatingKey":"155958","guid":"com.plexapp.agents.thetvdb://70600/26/39?lang=en","parentGuid":"com.plexapp.agents.thetvdb://70600/26?lang=en","grandparentGuid":"com.plexapp.agents.thetvdb://70600?lang=en","librarySectionTitle":"TV Shows","librarySectionID":2,"librarySectionKey":"/library/sections/2","type":"episode","title":"The College Fraternity Crisis","titleSort":"College Fraternity Crisis","grandparentKey":"/library/metadata/155958","parentKey":"/library/metadata/156036","grandparentTitle":"Dateline NBC","parentTitle":"Season 26","contentRating":"TV-PG","summary":"Andrea Canning reports on cases of alleged hazing at schools and fraternities across the country, including LSU, Texas Tech, Florida A&M, Rider University and more.","index":39,"parentIndex":26,"viewOffset":2297000,"lastViewedAt":1566000127,"year":2018,"thumb":"/library/metadata/156298/thumb/1565665538","art":"/library/metadata/155958/art/1565665539","grandparentThumb":"/library/metadata/155958/thumb/1565665539","grandparentArt":"/library/metadata/155958/art/1565665539","grandparentTheme":"/library/metadata/155958/theme/1565665539","duration":7200000,"originallyAvailableAt":"2018-06-03","addedAt":1564887601,"updatedAt":1565665538,"Genre":[{"id":61057,"filter":"genre=61057","tag":"News"}]}}
And at line 149 in homebridge-plex-sensors is where it spits all that out. Not that homebridge-plex-sensors listens for the webhooks on a certain configurable port. Maybe this approach would work also for EG?

thanks

User avatar
kgschlosser
Site Admin
Posts: 4931
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: Webserver

Post by kgschlosser » Sat Aug 17, 2019 2:46 am

OK I think what you are needing is an interface to Plex. instead of busting out with the rubber bands toothpicks and duck tape to make it work.
If you like the work I have been doing then feel free to Image

leejk
Posts: 16
Joined: Sun Dec 04, 2016 4:32 pm

Re: Webserver

Post by leejk » Sat Aug 17, 2019 11:35 pm

I thought about trying to write a EG plugin. Pretty much just need a web server that listens for the Webhooks and then fires an event when it gets a payload. Then use a python script in EG to dissect the payload and perform an action. I’ll have to study up on python first tho.

User avatar
kgschlosser
Site Admin
Posts: 4931
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: Webserver

Post by kgschlosser » Sun Aug 18, 2019 2:28 am

The plug-in would be easy to make as there is already a python binding for the Plex API. Just have to connect the GUI related components to the various parts of the API.
If you like the work I have been doing then feel free to Image

leejk
Posts: 16
Joined: Sun Dec 04, 2016 4:32 pm

Re: Webserver

Post by leejk » Tue Aug 20, 2019 3:56 am

Probably, but that adds an unnecessary layer I think. Webhooks seem more reliable in this case I think. Hopefully I get some time soon to dive into this.

User avatar
kgschlosser
Site Admin
Posts: 4931
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: Webserver

Post by kgschlosser » Tue Aug 20, 2019 4:50 am

The PlexAPI is not an additional layer per say. because in order for me to get something for ya going I would need to create a socket or some form of a webserver in order to have plex connect.. this is just the other way around. Since Plex already has a webserver that runs on it all that is being done is we are creating a connection to it and asking for the data instead. and the code for that whole end of it is already done. Making the GUI related bits is a whole lot easier to do.
If you like the work I have been doing then feel free to Image

jachin99
Experienced User
Posts: 603
Joined: Sat Feb 13, 2016 8:39 pm

Re: Webserver

Post by jachin99 » Thu Aug 22, 2019 2:39 pm

Someone has created a Kodi Plugin that may be easily transformed into a kind of universal plugin for any other media center via the EG Web Server. My idea came from this thread https://www.thegreenbutton.tv/forums/vi ... =9&t=11767 where the developer noted that if I were able to transform his JSON into XML and host it on a local webserver, then programs such as Macrotube for Windows Media Center might be able to easily consume that feed, and display a list of videos.

I don't use WMC anymore as I have switched to JRiver, and Emby BUT I know JRiver, Plex, Emby, and Probably Media Portal at the very least support RSS XML formats. This gave me the idea that possibly using this plugin, coverting the JSON to XML, and hosting the resulting XML page in the EG Web server. From here, a user could point their media center to the XML page on the server, and hopefully the media center would grab a list of videos, and thumbnails, and everything would work. Would it be possible to give the eventghost web server a friendly name that I could point various media centers to such as WebHost, and host RSS XML page on it?

The plugin itself looks to be written in python, and I'm not sure that it can actually be used outside of Kodi but I know EG can run python scripts without Kodi. I'm just curious to see if something like this would be feasible. I don't even watch channel 9 but I'm wondering if this is a solid concept.

leejk
Posts: 16
Joined: Sun Dec 04, 2016 4:32 pm

Re: Webserver

Post by leejk » Sat Aug 24, 2019 4:00 pm

Still not had any time to experiment but been doing a little research. Based on what I saw, the Plex API (which is unofficial) doesn't send events based on playback automatically, but you can query it for all sorts of information. Since it's not official I'd rather not use it for fear of it breaking on the next Plex server release. I still think the Plex webhooks is the best approach. I can see EG getting the payload from Plex webhooks but no repeatable event name is logged for programming an action. The EG web server plugin seems to support variables, but I can't see any examples or documentation on how they work. I wonder if they could be used to store the payload in a variable, then use a Python script action to dissect the payload?

User avatar
kgschlosser
Site Admin
Posts: 4931
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: Webserver

Post by kgschlosser » Sat Aug 24, 2019 5:11 pm

it does send events. the Plex API as a websocket that events are generated on. I do not know to what extent the events are or what they are for.

if you do a search on google for "Plex Python" you will find a library for python already written and it should contain some helpful information
If you like the work I have been doing then feel free to Image

csdollhopf
Posts: 1
Joined: Sat Sep 28, 2019 2:47 am

Re: Webserver

Post by csdollhopf » Sat Sep 28, 2019 3:06 pm

Hi there,

After reading through this thread I understand how to get variables from eventghost in HTML ie {{variable}}. Unfortunately, I still can't figure out how to get javascript to be able to access these variables. Would anybody be able to show me really quickly how to do that. Pardon any ignorance on my part.

Thanks!

User avatar
TAz00
Posts: 4
Joined: Sun Sep 29, 2019 3:13 pm
Location: Denmark
Contact:

Re: Webserver

Post by TAz00 » Sun Sep 29, 2019 6:05 pm

Thought i'd mention I made an arduino sketch for the Webserver plugin to talk to an Arduino, and vice versa.

I've already made a tutorial and posted it on the forum, but while we wait for approval, I will post it here since it relates to the webserver plugin.

More information http://drebsdorf.net/default.aspx?id=1#29
Eventlog.png
Eventghost-arduino-webserver.zip
(4.44 KiB) Downloaded 14 times

Mikey
Posts: 2
Joined: Fri Nov 01, 2019 9:07 am

Re: Webserver

Post by Mikey » Fri Nov 01, 2019 9:18 am

Hi, not quite sure if this is the correct place, but it seems like it should be.

I am running a webserver from EG under Win10. The served pages are accessed from Chrome running in Kiosk mode, and occasionally one of the pages will "error out", usually 404 but also occasionally server errors like 503. This results in an error page which seems custom to EG's webserver (it's not the default Chrome one).

I would like to make some custom error pages the same way I'd do on an IIS server, ie if the webserver encounters a 404, redirect to (say) <serverroot>/errors/404.html, and so on and so forth.

The config page for the webserver plugin offers nothing (that I can see), and I've dug around the EG folder (like EG\plugins\Webserver\__init__.py) with no success.

How/where/what do I edit to add in some custom redirects (ideal), alternately some custom in-line HTML (if the redirect is not possible). Any pointers would be very welcome! Thanks in advance, M.

User avatar
kgschlosser
Site Admin
Posts: 4931
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: Webserver

Post by kgschlosser » Sat Nov 02, 2019 3:57 am

We can do a wee bit of monkey patching to accomplish this task.


OK I am going to do something really creative here.
This is what you are going to need to do.

go to the folder where the website files are located. You need to be in the same location that you gave to the webserver plugin when setting it up.

make a new folder called "errors" and in that new folder create an html file for each of the errors you want to customize. at the top of the file on the very first line of the error file must be <!-- text/html --> This is important to have so the header can be properly built. You can change the text/html to whatever content type you want to use for that error.

The error file names for the errors are like so "404.html "

error codes 204, 205 and 304 will not be supported.


Next up.. In EG locate the autostart group.. should be at the top of your tree. Locate the webserver plugin. immediately after the webserver plugin create a python script action. paste the code below into the action. This is a set it and forget it mechanism It will only need to run a single time. hence the reason why it is in the autostart group. Even if you enable and then disable the webserver plugin this is going to still work.

any errors that you do not make a custom file for the default message will be displayed

Code: Select all

import os
import BaseHTTPServer

try:
    patch
except NameError:

    def patch():
        def send_error(self, code, message=None):

            path = os.path.join(self.basepath, 'errors', str(code) + '.html')

            if os.path.exists(path):

                try:
                    short, long = self.responses[code]
                except KeyError:
                    short, long = '???', '???'
                if message is None:
                    message = short
                explain = long
                self.log_error("code %d, message %s", code, message)
                self.send_response(code, message)
                self.send_header('Connection', 'close')


                if code >= 200 and code not in (204, 205, 304):
                    with open(path, 'r') as f:
                        content = f.read()

                    content_type = content.split('-->', 1)[0].strip()
                    content_type = content_type.lstrip('<!--').strip()

                    self.send_header("Content-Type", content_type)
                    self.end_headers()

                    if self.command != 'HEAD':
                        self.wfile.write(content)
                else:
                    self.end_headers()
            else:
                BaseHTTPServer.BaseHTTPRequestHandler.send_error(self, code, message)

        server = getattr(eg.plugins.Webserver.plugin, 'server', None)
        
        if server is not None:
            server.RequestHandlerClass.send_error = send_error

    old_start = eg.plugins.Webserver.plugin.__start__

    def start(*args, **kwargs):
        old_start(*args, **kwargs)
        patch()


    eg.plugins.Webserver.plugin.__start__ = start
    patch()
   
I hope this helps.. If there are any issues with it let me know. I have not tested the code.. it looks like it should work.. :shock: 8)
If you like the work I have been doing then feel free to Image

Post Reply