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!

What is the right way to use HTTPLiveStreamURL without URL services?

CigarasCigaras Members Posts: 117 ✭✭
edited February 24 in Channel Development

Lets say I have a simple channel plug-in:

NAME = 'HLSTest'
PREFIX = '/video/hlstest'
URL = 'http://abclive.abcnews.com/i/abc_live4@136330/index_1200_av-b.m3u8'

def Start():
    pass

<a href="/profile/handler%28PREFIX">@handler(PREFIX</a>, NAME)
def MainMenu():
    oc = ObjectContainer(title1 = NAME)
    oc.add(CreateVideoClipObject(url = URL, title = NAME, include_container = False))
    return oc

<a href="/profile/route%28PREFIX">@route(PREFIX</a> + '/createvideoclipobject')
def CreateVideoClipObject(url, title, include_container):
    vco = VideoClipObject(
        key = Callback(CreateVideoClipObject, url = url, title = title, include_container = True),
        rating_key = url,
        title = title,
        items = [
            MediaObject(
                parts = [
                    PartObject(
                        key = Callback(PlayVideo, url = url)
                    )
                ],
            )
        ]
    )
    return ObjectContainer(objects = [vco]) if include_container else vco

<a href="/profile/indirect">@indirect</a>
<a href="/profile/route%28PREFIX">@route(PREFIX</a> + '/playvideo')
def PlayVideo(url):
    return IndirectResponse(VideoClipObject, key = url)

What is the right way to incorporate HTTPLiveStreamURL() in here?

Best Answers

  • CigarasCigaras Members Posts: 117 ✭✭
    Accepted Answer

    But what about HTTPLiveStreamURL() then, if I do

    PartObject(key=HTTPLiveStreamURL(Callback(PlayVideo, url = url)))
    

    I get FrameworkException: No route found matching '/video/hlstest/playvideo.m3u8'

Answers

  • sander1sander1 Channel Developer/Admin Members, Plex Pass, Plex Ninja Posts: 3,540 Plex Ninja

    Something not working in a specific client and asking how to create the VideoClipObject are 2 different things.

    @Cigaras: a couple of things:
    If you're sending variables other then text to a function with a route, you have to specify the type of variable. In this case the variable include_container is a boolean:

    <a href="/profile/route%28PREFIX">@route(PREFIX</a> + '/createvideoclipobject', include_container=bool)
    

    Some Plex clients send more variables if they request a function. To catch this problem add **kwargs at the end here to catch (and ignore) those:

    def CreateVideoClipObject(url, title, include_container, **kwargs):
    

    Add the "shortcut" function HTTPLiveStreamURL to your key. This will set most of the MediaObject details (like codecs) automatically. Drop the PlayVideo callback function, it is not needed in your code:

    PartObject(key=HTTPLiveStreamURL(url))
    
  • CigarasCigaras Members Posts: 117 ✭✭

    Thank You @sander1, but my final PlayVideo function does some stuff before playing the video, to be precise it sets http header, like HTTP.SetHeader('User-Agent', Prefs['user_agent']). Alternatively I guess I could set the header in CreateVideoClipObject but as preferences can be changed after creating the VideoClipObject it wont have effect until I "restart" the main menu if I understand how this works correctly...

  • sander1sander1 Channel Developer/Admin Members, Plex Pass, Plex Ninja Posts: 3,540 Plex Ninja

    In that case you can leave the PlayVideo callback in there, that's exactly what it's used for :)

    By the way, from the comments in the Plex framework: The HTTP.SetHeader() function is deprecated. Use HTTP.Headers[] to get and set headers instead.

  • CigarasCigaras Members Posts: 117 ✭✭
    Accepted Answer

    But what about HTTPLiveStreamURL() then, if I do

    PartObject(key=HTTPLiveStreamURL(Callback(PlayVideo, url = url)))
    

    I get FrameworkException: No route found matching '/video/hlstest/playvideo.m3u8'

  • rols1rols1 Members Posts: 215 ✭✭

    @Cigaras said:
    But what about HTTPLiveStreamURL() then, if I do

    PartObject(key=HTTPLiveStreamURL(Callback(PlayVideo, url = url)))
    

    I get FrameworkException: No route found matching '/video/hlstest/playvideo.m3u8'

    my tests shows that pms in this cases needs .m3u8 as appendix to the route, if the url ends with m3u8. The function itself doesn't need it:
    @route(PREFIX + '/playvideo.m3u8')
    def playvideo(url):
    /R

  • CigarasCigaras Members Posts: 117 ✭✭

    needs .m3u8 as appendix to the route

    Or I can drop the route decoration and it will work, but what is the right way intended to be used by Plex?

  • rols1rols1 Members Posts: 215 ✭✭

    @Cigaras said:
    Or I can drop the route decoration and it will work, but what is the right way intended to be used by Plex?

    I don't know, but I assume sander1 has the right answer (I'm also waiting for it)
    /R

Sign In or Register to comment.