If you have not already, we suggest setting your Plex username to something else rather than email which is displayed on your posts in forum. You can change the username at https://app.plex.tv/desktop#!/account
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!

Resolution Selection In Channel Plugin

celeste.andrewceleste.andrew Posts: 9Members ✭✭
edited September 10 in Channel Plugin Development

Hi there,
I'm attempting to write a channel plugin. It's working except that I have 'hardcoded' my resolution selection.

The site I'm streaming content from has different URLs for each resolution - for instance:
http://whatever/filename_360p.mp4
http://whatever/filename_480p.mp4
http://whatever/filename_1080p.mp4 <-- so I end up always using this one.

But I would like the choice!
I notice on other channels I've downloaded, a box pops up with resolution options before streaming the content.
I'm wondering how this way done!? Trying to peak at the code I see the following, but because my URLs are different I don't see that working for me.

MediaObject(
                parts = [
                    PartObject(key=Callback(PlayVideo, smil_url=smil_url, resolution=resolution))
                ],
                container = Container.MP4,
                video_codec = VideoCodec.H264,
                audio_codec = AudioCodec.AAC,
                audio_channels = 2,
                video_resolution = resolution
            ) for resolution in [720, 540, 480]

I really just want to know how to trigger the resolution selection box.
Look at the food network plugin if you need an example!
Thanks for your help!

Answers

  • czukowskiczukowski Posts: 131Members ✭✭✭
    edited September 10

    @celeste.andrew

    The code above literally says: "for each resolution in a given set, create a MediaObject object with the specified parameters". Plex client can then see that there's a choice between three options and asks the users to select the one they'd like better.

    By the way, you can format source code when posting following this guide.

  • celeste.andrewceleste.andrew Posts: 9Members ✭✭

    @czukowski

    Thanks for the formatting tip!

    So in my case, where I have different URLs for different resolutions, how can I allow the user to select a particular resolution?

    I have this function which creates the VideoClipObject:

    def CreateVideoClipObject(url, title, summary, duration, thumb, include_container=False):
    

    ... and the URL I'm passing is hardcoded to url[2] so I never choose which resolution.

  • czukowskiczukowski Posts: 131Members ✭✭✭

    @celeste.andrew

    I can't see your function so my advice will not be very specific, but since your goal is to create a separate MediaObject for each url you have, make sure the function receives all URLs and builds media objects in a similar fashion as you've posted in OP, could be roughly like this:

        MediaObject(
            parts = [
                PartObject(key=Callback(PlayVideo, url=url))
            ],
            video_resolution = parse_resolution(url),
            ...
        ) for url in url_list
    

    I assume the resolutions can be decoded from the URL and parse_resolution is a function you implement to take the URL and return a number.

  • celeste.andrewceleste.andrew Posts: 9Members ✭✭

    @czukowski

    Awesome... I will try that tonight, thanks!

  • shopgirl284shopgirl284 Posts: 2,699Members, Plex Pass, Plex Ninja, Forum Moderator Plex Ninja

    In the original MediaObject() example you gave, the developer is creating multiple media objects for one piece of media. The developer is sending each resolution value listed in the for resolution in [720, 540, 480] to the PlayVideo function and then in that PlayVideo function he has written code that will get the URL value that corresponds to the resolution value that was sent to the PlayVideo function and then the PlayVideo function returns the URL value for that resolution to the MediaObject() and creates a unique media object for that resolution.

    Just understand that Plex player apps handle multiple versions of a video from a channel plugin differently than they handle multiple versions of a video in your local library. And each Plex player app may handle multiple versions of a video from a channel plugin differently. Some will automatically choose the media object whose quality best matches the users' overall online video quality settings and some do not even recognize multiple media objects for channel plugins and will always just choose the first one listed. And I am not sure which Plex player app you are using, but I have never seen one that pops up with a box listing the multiple media objects for a piece of media in a channel (though it could be Samsung TVs or AppleTV).

    The Roku app, for example, will by default choose the media object whose quality best reflects your overall online video quality setting, but you can also choose between the various media object versions that are offered for that video. (During video playback, hit the star (*) button on your remote to bring up Video Playback Settings and they are listed under Streams > Version and you can choose a different version)

    Plex Web, on the other hand, just chooses the first one listed and doesn't even show the various media object options. When I pointed that out to Plex Web app developers, they didn't even know there could be multiple media objects for a video in a channel plugin.(The three cable icon has nothing to do with multiple media objects for a video in a channel plugin, that just allows you to change your online video quality setting)

    If you want to see how that code in your OP works in a channel plugins on a particular Plex player app, two channel plugins that use code very similar to that and offer multiple media objects for a video (with a unique URL for each resolution) are CBS (720p and 320p) and Food Network channel (720p, 540p, and 480p)

    Many issues and questions can be resolved by reviewing the Plex Support Documentation
    Providing details about your issue, Plex setup, and including log files are important when when asking for help on the forums.
    See Log Files
    Before posting channel plugin questions or issues, please review the pinned threads at the top of the Channel Plugin forum:
    READ FIRST: Guidelines for Posting Channel Plugin Issues/Questions and Things to Check First
    FAQ for Channel Plugin FAQ

Sign In or Register to comment.