# DefaultPrefs.json loading and preferences modification

**URL:** <https://forums.plex.tv/t/defaultprefs-json-loading-and-preferences-modification/61681>\
**Category:** Dev/API Corner\
**Tags:** plugin-dev\
**Created:** [March 26, 2014, 7:25pm UTC](https://forums.plex.tv/t/defaultprefs-json-loading-and-preferences-modification/61681 "2014-03-26T19:25:33Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sengian](https://avatars.discourse-cdn.com/v4/letter/s/13edae/32.png) [@Sengian](https://forums.plex.tv/u/Sengian)\
**Post date:** [March 26, 2014, 7:25pm UTC](https://forums.plex.tv/t/defaultprefs-json-loading-and-preferences-modification/61681/1 "2014-03-26T19:25:33Z")

</div>

Hello all,

I have a question as now when I try to add preferences to a plugin I develop, I have a window with all the preferences of the server but not the plugin preferences.

Hower, I do not get any error in the log, see below:

```
2014-03-26 07:59:07,180 (f64) : DEBUG (preferences:256) - Loaded preferences from DefaultPrefs.json
2014-03-26 07:59:07,181 (f64) : DEBUG (preferences:178) - Loaded the user preferences for com.plexapp.plugins.xkcd
```

and on the server log:

```
Mar 26, 2014 07:59:07:174 [6732] DEBUG - Read configuration for [com.plexapp.plugins.xkcd], had 1 prefixes
Mar 26, 2014 07:59:07:175 [6732] DEBUG - [com.plexapp.plugins.xkcd] Sending command over HTTP (GET): /photos/xkcd
Mar 26, 2014 07:59:07:175 [6732] DEBUG - HTTP requesting to: http://127.0.0.1:49992/photos/xkcd
```

Any idea? Stupid mistake I would have made? Bad Spirit hauting my server?

---

<div class="post-metadata">

**Author:** ![mikedm139](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/mikedm139/32/96909_2.png) [@mikedm139](https://forums.plex.tv/u/mikedm139)\
**Post date:** [March 26, 2014, 7:50pm UTC](https://forums.plex.tv/t/defaultprefs-json-loading-and-preferences-modification/61681/2 "2014-03-26T19:50:36Z")

</div>

What app are you using for testing your plugin?

To confirm whether the preferences are being read/loaded properly, you can check the XML directly by hitting:

```
http://localhost:32400/plugins/com.plexapp.plugins.xkcd/prefs
```

---

<div class="post-metadata">

**Author:** ![Sengian](https://avatars.discourse-cdn.com/v4/letter/s/13edae/32.png) [@Sengian](https://forums.plex.tv/u/Sengian)\
**Post date:** [March 26, 2014, 8:20pm UTC](https://forums.plex.tv/t/defaultprefs-json-loading-and-preferences-modification/61681/3 "2014-03-26T20:20:50Z")

</div>

> What app are you using for testing your plugin?
> 
> To confirm whether the preferences are being read/loaded properly, you can check the XML directly by hitting:
> 
> ```
> http://localhost:32400/plugins/com.plexapp.plugins.xkcd/prefs
> ```

I naively didn't use any app, expecting the server to put a warning if the code was calling a non existing prefs file. Seems I was wrong.

I get a 404 error attempting to get it using your method so for the server it is not accessible...

Now a good question is why?

---

<div class="post-metadata">

**Author:** ![Sengian](https://avatars.discourse-cdn.com/v4/letter/s/13edae/32.png) [@Sengian](https://forums.plex.tv/u/Sengian)\
**Post date:** [March 26, 2014, 8:39pm UTC](https://forums.plex.tv/t/defaultprefs-json-loading-and-preferences-modification/61681/4 "2014-03-26T20:39:55Z")

</div>

Ok, a first answer is that it was encoded using UTF-8 without BOM. I changed it to ASCII and added a comma at the end, then it worked using [http://127.0.0.1:32400/:/plugins/com.plexapp.plugins.xkcd/prefs](http://127.0.0.1:32400/:/plugins/com.plexapp.plugins.xkcd/prefs)!

I reverted back to UTF-8 and removed the comma, it still works... Oooooook! No problem!

However, I still have an issue with preferences which can't be modified using plexweb.

Bonus question: can you use localised text in preferences? (I would think it is possible but)

---

<div class="post-metadata">

**Author:** ![dane22](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/dane22/32/4389_2.png) [@dane22](https://forums.plex.tv/u/dane22)\
**Post date:** [March 26, 2014, 9:06pm UTC](https://forums.plex.tv/t/defaultprefs-json-loading-and-preferences-modification/61681/5 "2014-03-26T21:06:24Z")

</div>

> However, I still have an issue with preferences which can't be modified using plexweb.

Rephrase Q please.

Do you mean from the Prefs object, or if from code, look here:

[https://forums.plex.tv/topic/87348-undocumented-functionality-and-tips-tricks/](https://forums.plex.tv/topic/87348-undocumented-functionality-and-tips-tricks/)

/T

---

<div class="post-metadata">

**Author:** ![Sengian](https://avatars.discourse-cdn.com/v4/letter/s/13edae/32.png) [@Sengian](https://forums.plex.tv/u/Sengian)\
**Post date:** [March 26, 2014, 9:55pm UTC](https://forums.plex.tv/t/defaultprefs-json-loading-and-preferences-modification/61681/6 "2014-03-26T21:55:23Z")

</div>

> Rephrase Q please.
> 
> Do you mean from the Prefs object, or if from code, look here:
> 
> [https://forums.plex.tv/topic/87348-undocumented-functionality-and-tips-tricks/](https://forums.plex.tv/topic/87348-undocumented-functionality-and-tips-tricks/)
> 
> /T

Thanks, for the link, I really like the Reset option as I thought about how to implement this at some point ^\_^.

Reformulation: I click on the button to modify prefs (see image 1) and I get this (see image 2)

They are in French, but this is totally not the prefs I was looking for.

---

<div class="post-metadata">

**Author:** ![dane22](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/dane22/32/4389_2.png) [@dane22](https://forums.plex.tv/u/dane22)\
**Post date:** [March 26, 2014, 10:09pm UTC](https://forums.plex.tv/t/defaultprefs-json-loading-and-preferences-modification/61681/7 "2014-03-26T22:09:00Z")

</div>

Locate the following

/Cache, and delete the directory with the plug-in name in Q

Same for :

/Data

and then delete the .xml file in /Preferences

Then restart your PMS

With above deletions, it'll be like a new born baby, and completely reset

If above doesn't help, then post the DefaultPrefs.json from the plug-in

/T

---

<div class="post-metadata">

**Author:** ![Sengian](https://avatars.discourse-cdn.com/v4/letter/s/13edae/32.png) [@Sengian](https://forums.plex.tv/u/Sengian)\
**Post date:** [March 26, 2014, 10:32pm UTC](https://forums.plex.tv/t/defaultprefs-json-loading-and-preferences-modification/61681/8 "2014-03-26T22:32:10Z")

</div>

No change, attached the DefaultPrefs.json

---

<div class="post-metadata">

**Author:** ![dane22](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/dane22/32/4389_2.png) [@dane22](https://forums.plex.tv/u/dane22)\
**Post date:** [March 26, 2014, 10:43pm UTC](https://forums.plex.tv/t/defaultprefs-json-loading-and-preferences-modification/61681/9 "2014-03-26T22:43:25Z")

</div>

Hmm....Looks okay. Is this the only channel that is buggy?

/T

---

<div class="post-metadata">

**Author:** ![Sengian](https://avatars.discourse-cdn.com/v4/letter/s/13edae/32.png) [@Sengian](https://forums.plex.tv/u/Sengian)\
**Post date:** [March 26, 2014, 10:56pm UTC](https://forums.plex.tv/t/defaultprefs-json-loading-and-preferences-modification/61681/10 "2014-03-26T22:56:36Z")

</div>

Not sure as I use this server only for development. I will have a look tomorrow. Thanks for the help and the tips  
  
  
Envoyé de mon GT-N8010 en utilisant Tapatalk

---

<div class="post-metadata">

**Author:** ![Sengian](https://avatars.discourse-cdn.com/v4/letter/s/13edae/32.png) [@Sengian](https://forums.plex.tv/u/Sengian)\
**Post date:** [March 27, 2014, 7:03pm UTC](https://forums.plex.tv/t/defaultprefs-json-loading-and-preferences-modification/61681/11 "2014-03-27T19:03:31Z")

</div>

Ok, I checked with You Tube plugin, no problem.

I really have a problem with Plex and its error management.

I will try to dig a little bit more into this. Any idea welcome!

---

<div class="post-metadata">

**Author:** ![mikedm139](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/mikedm139/32/96909_2.png) [@mikedm139](https://forums.plex.tv/u/mikedm139)\
**Post date:** [March 28, 2014, 12:00am UTC](https://forums.plex.tv/t/defaultprefs-json-loading-and-preferences-modification/61681/12 "2014-03-28T00:00:24Z")

</div>

Does your plugin code include a PrefsObject() in the MainMenu?

---

<div class="post-metadata">

**Author:** ![Sengian](https://avatars.discourse-cdn.com/v4/letter/s/13edae/32.png) [@Sengian](https://forums.plex.tv/u/Sengian)\
**Post date:** [March 28, 2014, 12:21am UTC](https://forums.plex.tv/t/defaultprefs-json-loading-and-preferences-modification/61681/13 "2014-03-28T00:21:17Z")

</div>

There was one, this may be the problem.

However, I removed every use of prefs in the plugin and I still have a problem.

What is puzzling me is that the plugin is in fact launching the main menu even when I just call preferences.

By this, I mean that I see in the log the function calls indicating the main menu is proceeding even if I see nothing.

The only think I can suspect is that I get a timeout somewhere as the main menu is long to lad the first time due to necessary caching.

I don't know if you can specify a timeout for a function call or something like this to tell plex to wait...

However, i still don't understand why the main menu would be called when you want to change the preferences.

---

<div class="post-metadata">

**Author:** ![dane22](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/dane22/32/4389_2.png) [@dane22](https://forums.plex.tv/u/dane22)\
**Post date:** [March 28, 2014, 12:23am UTC](https://forums.plex.tv/t/defaultprefs-json-loading-and-preferences-modification/61681/14 "2014-03-28T00:23:44Z")

</div>

> There was one, this may be the problem.
> 
> However, I removed every use of prefs in the plugin and I still have a problem.
> 
> What is puzzling me is that the plugin is in fact launching the main menu even when I just call preferences.
> 
> By this, I mean that I see in the log the function calls indicating the main menu is proceeding even if I see nothing.
> 
> The only think I can suspect is that I get a timeout somewhere as the main menu is long to lad the first time due to necessary caching.
> 
> I don't know if you can specify a timeout for a function call or something like this to tell plex to wait...
> 
> However, i still don't understand why the main menu would be called when you want to change the preferences.

Think it's time to post a link to github for the **complete** code :rolleyes:

/T

---

<div class="post-metadata">

**Author:** ![Sengian](https://avatars.discourse-cdn.com/v4/letter/s/13edae/32.png) [@Sengian](https://forums.plex.tv/u/Sengian)\
**Post date:** [March 28, 2014, 6:18am UTC](https://forums.plex.tv/t/defaultprefs-json-loading-and-preferences-modification/61681/15 "2014-03-28T06:18:02Z")

</div>

Ah sorry, here you can find the link to the branch with the modifications: [https://github.com/sengian/xkcd.bundle/tree/Prefs](https://github.com/sengian/xkcd.bundle/tree/Prefs)

Master is working but I don't have prefs..

---

<div class="post-metadata">

**Author:** ![mikedm139](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/mikedm139/32/96909_2.png) [@mikedm139](https://forums.plex.tv/u/mikedm139)\
**Post date:** [March 29, 2014, 12:08am UTC](https://forums.plex.tv/t/defaultprefs-json-loading-and-preferences-modification/61681/16 "2014-03-29T00:08:20Z")

</div>

> Ah sorry, here you can find the link to the branch with the modifications: [https://github.com/sengian/xkcd.bundle/tree/Prefs](https://github.com/sengian/xkcd.bundle/tree/Prefs)  
> Master is working but I don't have prefs..

On a quick review I see two issues. First and likely not the cause if your issues, your trying to assign your own viewtypes. That behaviour is no longer supported and most client apps will just ignore what you set anyway.  
Second and possibly (although still unlikely to be) the cause of the problem, you're making a call to the Prefs in the ObjectContainer definition for the MainMenu. I don't \_think\_ that is supported although I'm not 100% sure. Since it's for the purpose of setting the view-type, I would ditch that (as mentioned above) and see if it solves your problem.

---

<div class="post-metadata">

**Author:** ![Sengian](https://avatars.discourse-cdn.com/v4/letter/s/13edae/32.png) [@Sengian](https://forums.plex.tv/u/Sengian)\
**Post date:** [March 30, 2014, 3:19pm UTC](https://forums.plex.tv/t/defaultprefs-json-loading-and-preferences-modification/61681/17 "2014-03-30T15:19:06Z")

</div>

> On a quick review I see two issues. First and likely not the cause if your issues, your trying to assign your own viewtypes. That behaviour is no longer supported and most client apps will just ignore what you set anyway.

Ok for trial purposes I ditched everything linked to plugin view ie:

```
Plugin.AddViewGroup("InfoList", viewMode="InfoList", mediaType="items")
    Plugin.AddViewGroup("List", viewMode="List", mediaType="items")
    Plugin.AddViewGroup("Pictures", viewMode="Pictures", mediaType="photos")

```
ObjectContainer.view_group = "List"

```
```

> Second and possibly (although still unlikely to be) the cause of the problem, you're making a call to the Prefs in the ObjectContainer definition for the MainMenu. I don't \_think\_ that is supported although I'm not 100% sure. Since it's for the purpose of setting the view-type, I would ditch that (as mentioned above) and see if it solves your problem.

I also removed in ObjectContainer the call to Prefs and the view. I just then call Prefs to assign it to a variable, then I clear cache.

And still the same issue... :angry:

If someone knows it, I would like to know what should be the Prefs file encoding, as it seems I had problems with that (converting to ASCII solved it but still).

---

<div class="post-metadata">

**Author:** ![mikedm139](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/mikedm139/32/96909_2.png) [@mikedm139](https://forums.plex.tv/u/mikedm139)\
**Post date:** [March 30, 2014, 5:41pm UTC](https://forums.plex.tv/t/defaultprefs-json-loading-and-preferences-modification/61681/18 "2014-03-30T17:41:40Z")

</div>

> Ok for trial purposes I ditched everything linked to plugin view ie:
> 
> ```
> Plugin.AddViewGroup("InfoList", viewMode="InfoList", mediaType="items")
> Plugin.AddViewGroup("List", viewMode="List", mediaType="items")
> Plugin.AddViewGroup("Pictures", viewMode="Pictures", mediaType="photos")
> 
> ```
> ObjectContainer.view_group = "List"
> 
> ```
> ```
> 
> I also removed in ObjectContainer the call to Prefs and the view. I just then call Prefs to assign it to a variable, then I clear cache.
> 
> And still the same issue... :angry:
> 
> If someone knows it, I would like to know what should be the Prefs file encoding, as it seems I had problems with that (converting to ASCII solved it but still).

I believe UTF-8 is the most common. I'm pretty stumped here...

you might try removing the extra lines between the pref definitions.

```
[
    {
        "id": "vmodemenu",
        "type": "enum",
        "label": "Main menu view mode",
        "values": ["InfoList", "List"],
        "default": "List"
    },
    {
        "id": "vmodeyear",
        "type": "enum",
        "label": "Year submenu view mode",
        "values": ["InfoList", "List"],
        "default": "List"
    },
    {
        "id": "vmodemonth",
        "type": "enum",
        "label": "Month submenu view mode",
        "values": ["InfoList", "List", "Pictures"],
        "default": "Pictures"
    }
]
```

rather than

```
[
    {
        "id": "vmodemenu",
        "type": "enum",
        "label": "Main menu view mode",
        "values": ["InfoList", "List"],
        "default": "List"
    },

```
{
    "id": "vmodeyear",
    "type": "enum",
    "label": "Year submenu view mode",
    "values": ["InfoList", "List"],
    "default": "List"
},

{
    "id": "vmodemonth",
    "type": "enum",
    "label": "Month submenu view mode",
    "values": ["InfoList", "List", "Pictures"],
    "default": "Pictures"
}

```

]
```

---

<div class="post-metadata">

**Author:** ![Sengian](https://avatars.discourse-cdn.com/v4/letter/s/13edae/32.png) [@Sengian](https://forums.plex.tv/u/Sengian)\
**Post date:** [March 30, 2014, 6:14pm UTC](https://forums.plex.tv/t/defaultprefs-json-loading-and-preferences-modification/61681/19 "2014-03-30T18:14:13Z")

</div>

Ok, I tried, I even reduced the main menu to nothing:

```
@handler(PREFIX, NAME, art = ART, thumb = ICON)
def XKCDMenu():
    # view_prefs = Prefs['vmodemenu']
    oc = ObjectContainer()
    BasicInfos = GetBasicInfos()

```
if not BasicInfos:
    # Not able to get even basic infos, aborting
    Log.Error('Basic infos were not found, xkcd may not be available')
    return ObjectContainer(header=NAME, message=L("ErrorBasics"))

#Create yearly subdirectories
# for i in xrange(BasicInfos['first_year'], BasicInfos['last_year']+1):
    # first_nb, last_nb = GetYearNumbers(i)
    # if not first_nb:
        # continue
    # name = Locale.LocalStringWithFormat('Year_Dirname', i, first_nb, last_nb)
    # oc.add(DirectoryObject(
                        # key = Callback(YearDirectory, year=i),
                        # title= name,
                        # thumb = Callback(GetIcon, year=i)
                        # ))
return oc

```
```

Then I removed the cache, the logs everything before restarting... and it is still not working!

At this point, I will stop anyway as what I wanted to do is not really possible.

But frankly, I remember now why I really don't like to develop for Plex.

Anyway, thank you all guys for the help.

Offtopic, a last question, is there a way to launch some code running in the background when the plugin is installed?

---

<div class="post-metadata">

**Author:** ![mikedm139](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/mikedm139/32/96909_2.png) [@mikedm139](https://forums.plex.tv/u/mikedm139)\
**Post date:** [March 30, 2014, 7:21pm UTC](https://forums.plex.tv/t/defaultprefs-json-loading-and-preferences-modification/61681/20 "2014-03-30T19:21:15Z")

</div>

> Then I removed the cache, the logs everything before restarting... and it is still not working!
> 
> At this point, I will stop anyway as what I wanted to do is not really possible.
> 
> But frankly, I remember now why I really don't like to develop for Plex.
> 
> Anyway, thank you all guys for the help.

Sorry I couldn't be more help.

> Offtopic, a last question, is there a way to launch some code running in the background when the plugin is installed?

I don't believe there's any hook that you could use to launch on install. It might be technically possible to run external code when the plugin is launched but, I don't think there are any examples of that.

[Next page](https://forums.plex.tv/t/defaultprefs-json-loading-and-preferences-modification/61681.md?page=2)
