Correctly handle feeds quality

Hi guys,

I’m doing my first Plex bundle and I have a question about how to handle feeds correctly.

I’ve a m3u8 file with multiple feeds with different quality versions. Actually I parse it and create multiple MediaObject, depending on the quality feed versions, inside my VideoClipObject object. Each of the MediaObject use the main m3u8 file url with HTTPLiveStreamURL.

It’s working but the quality isn’t handled, Plex alway get the first stream in the m3u8 playlist. Plex should handle the quality and switch if necessary no ? I don’t understand

Thanks

There are multiple ways to do this. The main part you need is the video_resolution, and optionally the bitrate within the MediaObject(). Note: Clients will honor bitrate settings over video_resolution.

Example 1:

Traditionally it is better NOT to call a URL within the MediaObjectsForURL() function, as it will slow down a channels performance, especially when videos are presented in a list. So, if you have relatively consistent content (similar bitrates, resolutions, etc… from one video to another) then its better to hard code the resolution and bitrate within the MediaObjectsForURL() and use an @indirect approach to find which resolution and bitrate are truly available.
Services.bundle/Contents/Service Sets/com.plexapp.plugins.vimeo/URL/Vimeo/ServiceCode.pys#L83…L176

Here, because the PlayVideo() is an @indirect Callback, it makes a HTTP request only when a user presses the play button within a Plex Client. The PlayVideo() code tries to find the closes match for the selected bitrate and resolution.

Example 2:

Sometimes it’s not feasible to hard code the bitrate and resolution, as it fluctuates too much between streams, and/or in reality there is only a couple resolutions available instead of hard coding 5 (that may only have a need once-in-a-blue-moon). Alternatively the @deferred method can be used to parse the URL for stream information within the MediaObjectsForURL() and return the direct stream.
UnSupportedServices.bundle/Contents/Service Sets/com.plexapp.plugins.xvideosharing/URL/WatchVideo/ServiceCode.pys#L53…L77

Here the MediaObjectsForURL() does all the work, and returns the video streams directly. It’s pulling down the master m3u8 file, parsing for bitrate, resolution, and stream. Then using list comprehension to build the final MediaObject(). To save some time, each URL is cached for 10 seconds, as many clients make the same request twice rapidly to fill out metadata and stream information.


The official Services.bundle is a good resource for finding service code examples. You may also find some useful examples within my UnSupportedServices.bundle.


Edit

Looking at your post history, is this MYTF1.bundle/Contents/Code/__init__.py#L132…L172 the code your having issues with?

If so, then try including the @indirect decorator and returning an IndirectResponse() from your PlayVideo() function.

Example: GreekTV.bundle/Contents/Code/__init__.py#L133…L152

Thank you very much for your help @Twoure

Yes it’s for this bundle exactly, I’ve just updated it according to your recommandations. I can play the stream but not the good one I think because I still get a very poor quality. When I play it in VLC the quality is a looot better

I have a side question, that’s the difference between a script in Service.bundle like the links you sent me, and creating a bundle a part from it ? That’s okay, I understand it now. Gonna try this after to clean the bundle code :slight_smile:

EDIT:
It working! The feed doesn’t auto adjust on Google Chrome only

I’m still trying to figure out why I can’t force the PMS to transcode stream for not compatible devices. On some devices the lower quality is always selected and I can’t change it.

I doesn’t work on:

  • Chromecast
  • Google Chrome

It work on:

  • Safari
  • iOS app

I’ve begun to update my plugin code to handle HD streams on other devices/browser than apple thought the plex transcoder https://github.com/tuxity/MYTF1.bundle/tree/transcode
I’m parsing the m3u file to reorder feeds from higher quality to lower and it doesn’t work. I always get a low quality when I’m playing and item on Google Chrome.

Do someone have an idea ? I’m really stuck
ping @sander1 @Twoure