# Correctly handle feeds quality

**URL:** <https://forums.plex.tv/t/correctly-handle-feeds-quality/168819>\
**Category:** Dev/API Corner\
**Tags:** plugin-dev\
**Created:** [November 29, 2016, 12:20am UTC](https://forums.plex.tv/t/correctly-handle-feeds-quality/168819 "2016-11-29T00:20:46Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![tuxity](https://avatars.discourse-cdn.com/v4/letter/t/65b543/32.png) [@tuxity](https://forums.plex.tv/u/tuxity)\
**Post date:** [November 29, 2016, 12:20am UTC](https://forums.plex.tv/t/correctly-handle-feeds-quality/168819/1 "2016-11-29T00:20:46Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Twoure](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/twoure/32/91016_2.png) [@Twoure](https://forums.plex.tv/u/Twoure)\
**Post date:** [November 29, 2016, 2:12am UTC](https://forums.plex.tv/t/correctly-handle-feeds-quality/168819/2 "2016-11-29T02:12:03Z")

</div>

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](https://github.com/plexinc-plugins/Services.bundle/blob/ad3560ca3e7d1d1cae952634a03f3f91741c09ce/Contents/Service%20Sets/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](https://github.com/Twoure/UnSupportedServices.bundle/blob/8e87dea02d1499c5cedeca2c0f0df38da1d5d6fb/Contents/Service%20Sets/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](https://github.com/plexinc-plugins/Services.bundle) is a good resource for finding service code examples. You may also find some useful examples within my [UnSupportedServices.bundle](https://github.com/Twoure/UnSupportedServices.bundle).

* * *

**Edit**

Looking at your post history, is this [MYTF1.bundle/Contents/Code/\_\_init\_\_.py#L132…L172](https://github.com/tuxity/MYTF1.bundle/blob/55a7ff0372a6c8fc00a94cfaccf84f57d8c83d09/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](https://github.com/Twoure/GreekTV.bundle/blob/c9f0f76ac9430ba34368501e7ffe0bb1ab1066c3/Contents/Code/ __init__.py#L133...L152)

---

<div class="post-metadata">

**Author:** ![tuxity](https://avatars.discourse-cdn.com/v4/letter/t/65b543/32.png) [@tuxity](https://forums.plex.tv/u/tuxity)\
**Post date:** [November 29, 2016, 5:56am UTC](https://forums.plex.tv/t/correctly-handle-feeds-quality/168819/3 "2016-11-29T05:56:35Z")

</div>

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 🙂

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

---

<div class="post-metadata">

**Author:** ![tuxity](https://avatars.discourse-cdn.com/v4/letter/t/65b543/32.png) [@tuxity](https://forums.plex.tv/u/tuxity)\
**Post date:** [December 11, 2016, 11:41pm UTC](https://forums.plex.tv/t/correctly-handle-feeds-quality/168819/4 "2016-12-11T23:41:26Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![tuxity](https://avatars.discourse-cdn.com/v4/letter/t/65b543/32.png) [@tuxity](https://forums.plex.tv/u/tuxity)\
**Post date:** [January 8, 2017, 7:51pm UTC](https://forums.plex.tv/t/correctly-handle-feeds-quality/168819/5 "2017-01-08T19:51:05Z")

</div>

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](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

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/plex/original/3X/2/a/2acb9765406f63293d357b4ec509ec39aa28f2ad.png) [@system](https://forums.plex.tv/u/system)\
**Post date:** [January 8, 2020, 8:00pm UTC](https://forums.plex.tv/t/correctly-handle-feeds-quality/168819/6 "2020-01-08T20:00:34Z")

</div>


