Welcome to our forums! Please take a few moments to read through our Community Guidelines (also conveniently linked in the header at the top of each page). There, you'll find guidelines on conduct, tips on getting the help you may be searching for, and more!

On Media Play/Stop

jnymrisjnymris Posts: 5 Plex Pass
edited April 26 in Channel Development

Hi,

I've created a channel which allows users to play .m3u8 files.
I'd like to be able to monitor what is being played from the WebServer.

I'm using the following for when a menu is loaded

values =  {'message': 'Loaded Menu {Menu name here}',
                  'username': get_username(),
                  'device': Request.Headers['X-Plex-Device-Name'],
                  'product': Request.Headers['X-Plex-Product']}
x = HTTP.Request('url to my web server', values, cacheTime=0)

I'm now trying to add the above couple of lines when a stream is 'previewed', played or stop. But i'm not sure were I would insert this?

I've tried inserting it into the following sections but this does not appear to be valid.
def GetMediaObject(url):
def CreateVideoClipObject(title, thumb, url, include_container=False, *args, **kwargs):

Just as a side note does anyone know how to get the client (plex client)'s IP Address?

Can anyone shed any more light on this?

Thanks.

Johnny

Answers

  • czukowskiczukowski Posts: 119 ✭✭

    @jnymris

    For play, you'll need to put a callback to Part objects and execute a request from that callback before redirecting to the actual media URL. For example:

    def MediaObjectsForURL(url):
        return [
            MediaObject(
                ...
                parts=[
                    PartObject(
                        key=Callback(PlayVideo, url=url)
                    )
                ]
            )
        ]
    
    @indirect
    def PlayVideo(url):
        m3u8_url = retrieve_the_actual_m3u8_url_from_the_webpage_at(url)
        try:
            HTTP.Request(...)
        except:
            pass
        return IndirectResponse(VideoClipObject, key=m3u8_url)
    

    I'm not sure what a stream preview is (in terms of Plex channels) and I don't think it's possible to hook up to playback stop events.

  • czukowskiczukowski Posts: 119 ✭✭

    You may yet be in luck, take a look at this: https://support.plex.tv/hc/en-us/articles/115002267687-Webhooks

Sign In or Register to comment.