HTTP headers when opening a stream

Hey,

Just looking for some help.

When plex opens a HLS stream is there any way to add a x-forwarded-header when a device opens the stream?

I can add the usual headers etc to open webpages etc but not when it comes to the stream i want the device to open the stream with that header set.

i tried adding the header on the object container but it does not appear to be passing it.

oc = ObjectContainer(http_headers={‘X-Forwarded-For’:‘127.0.0.1’})

I’ve been using burp to check

If the clients don’t respect the http_headers parameter you could try having the server act as a proxy for the playlist.

something like this might work in a url service:

def MediaObjectsForURL(url):
    return [
        MediaObject(
            protocol='hls',
            container='mpegts',
            video_codec=VideoCodec.H264,
            audio_codec=AudioCodec.AAC,
            audio_channels=2,
            optimized_for_streaming=True,
            parts=[PartObject(key=Callback(playlist, url=url, ext='m3u8'))]
        )
    ]


def playlist(url):
    return HTTP.Request(url, headers={'X-Headers': '...'}).content

Depending on what you need and how you setup your MediaObjectsForURL function you can include the http_headers field within a VideoClipObject and/or the PartObject.

Examples iTunes Movie Trailers, ForaTV (Note: ForaTV is doing basically the same thing as you already tried),

def MediaObjectsForURL(url):
    return [
        MediaObject(
            parts=[PartObject(
                key=HTTPLiveStreamURL(Callback(PlayVideo, url=url))
                )]
            )
        ]

@indirect
def PlayVideo(url, **kwargs): 
    """
    do the things
    Parse for m3u8_url and set video headers
    """
    headers={'X-Forwarded-For': '127.0.0.1'}
    return IndirectResponse(VideoClipObject, key=m3u8_url, http_headers=headers)

If you do not want to use the Callback method within the PartObject, you should be able to set the PartObject key to the stream URL and set the http_headers to your {'X-Forwarded-For': '127.0.0.1'},

def MediaObjectsForURL(url):
    headers={'X-Forwarded-For': '127.0.0.1'}
    return [
        MediaObject(
            parts=[PartObject(
                key=HTTPLiveStreamURL(url), http_headers=headers
                )]
            )
        ]

If you leave out the HTTPLiveStreamURL function, then you will need to include the information outlined in Comment_1168292, so Plex can handle the HLS stream correctly.

All of the above can be found within the objectkit.py file within the following directory:

Framework.bundle/Contents/Resources/Versions/2/Python/Framework/api