Dynamic Building of DefaultPrefs

Is there still no way to build the DefaultPrefs using the Plex Framework?

 

Couldn't find anything in the Docs other than Reading Prefs.

 

I did find this post, but it's from 2010 - http://forums.plexapp.com/index.php/topic/19917-dynamic-preferences/

In it, Jam states "DefaultPrefs.json [file] is the only way of creating preferences..."

 

Is that still the case or has something been added and the docs not updated yet?

 

If, in fact, there is no way to do it using the Plex Framework - would it be possible using Pythons File.Read and Write?

 

Thanks for any help!

M

There is no framework support for dynamic creation of prefs. If you want to get creative, theoretically you could modify the DefaultPrefs.json file using python io methods. There are a couple hurdles to that plan. A major one is that several of the python methods you might want to use (including file I think) are black-listed by the restricted python used by the plugin framework. Using the “elevated” code policy will allow access to some of them, although some can still be problematic. Another hurdle is that being a completely unsupported hack, if it works, there’s no guarantee that it will continue to do so.

What sort of prefs do you need dynamic control over? Perhaps there’s a more stable way to achieve the same/similar result.

Hey Mike - thanks for the reply.

The prefs are a list of video servers that the user has access to depending on their location and ISP.

Hey Mike - thanks for the reply.

The prefs are a list of video servers that the user has access to depending on their location and ISP.

Ok. So, then the user has the option to select which server(s) to use from the localized list?

Yeah - depending on where you are, you'll get a different result; https://api.hockeystreams.com/GetLocations

I tried a PopupDirectoryObject, which worked OK, but I wasn't able to specify the selected sever name in the menu so the user could see which one they were using. It always defaults back to the top one.

I also entertained the thought of having all servers listed in the Prefs. Then, when the user chooses one, see if it's in their GetLocations result, and if not, tell them they have to choose a different one... but that's wrong on so many levels.

That sounds somewhat similar to a challenge I had to deal with for the SickBeard plugin. What I ended up doing was creating my own “selected”/“un-selected” flag as part of the titles for the items in the PopupDirectoryObject and storing the values as well as their states in the plugin Dict. Here’s an example: https://github.com/mikedm139/SickBeard.bundle/blob/master/Contents/Code/init.py#L315

It’s not perfect, but it’s a viable work-around.

Hey Mike - so I set it up similar to what you did in SickBeard (thanks for the example). And it works OK.

But, I did notice that it only works in PMC/PHT. iOS/Web give me errors... I'm assuming since it's a DirectoryObject with nothing to display it just fails?

Also - what's the deal with the PreferenceObject not working in PHT?

Thanks again,

M

Hey Mike - so I set it up similar to what you did in SickBeard (thanks for the example). And it works OK.

But, I did notice that it only works in PMC/PHT. iOS/Web give me errors... I'm assuming since it's a DirectoryObject with nothing to display it just fails?

Also - what's the deal with the PreferenceObject not working in PHT?

Thanks again,

M

I'm curious as to why it would fail for iOS and Plex/Web. The code I linked for the SickBeard plugin works on both iOS and Plex/Web as well as PMC/PHT. Can you post the code that's causing problems?

The PrefsObject issue with PHT is a known issue which, I _believe_, is fixed in the next release.

I decided to put the whole (static) list of servers in the Prefs... and like a dummy didn't save the code that I was using for the PopupDirectory. Which is unfortunate, 'cause I would like to know why it didn't work for me in iOS & Web.

If I find it in an archive or something I'll post it.

Thanks so much for your help, I really appreciate it.

M

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.