# Reset default prefs

**URL:** <https://forums.plex.tv/t/reset-default-prefs/54963>\
**Category:** Dev/API Corner\
**Tags:** plugin-dev\
**Created:** [January 21, 2014, 7:32pm UTC](https://forums.plex.tv/t/reset-default-prefs/54963 "2014-01-21T19:32:22Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![s\_razer](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/s_razer/32/8537_2.png) [@s\_razer](https://forums.plex.tv/u/s_razer)\
**Post date:** [January 21, 2014, 7:32pm UTC](https://forums.plex.tv/t/reset-default-prefs/54963/1 "2014-01-21T19:32:22Z")

</div>

Is there a way to reset a single or even all preferences to their default values from within a plugin?

&nbsp;

I ask this because with the FindUnmatched plugin I have a field of valid media extensions to scan for and the user could change it to 'all' to check for all extensions. I have since added a checkbox to scan for all extensions. I would like to reset the valid extensions pref if the user had it set to 'all'.

&nbsp;

&nbsp;

Thanks,

Chris

---

<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:** [January 21, 2014, 8:04pm UTC](https://forums.plex.tv/t/reset-default-prefs/54963/2 "2014-01-21T20:04:39Z")

</div>

Maybe nuke Library/P M S/Plug-in Support/Preferences/com.plexapp.plugins.findUnmatch.xml

Not sure though, but try it

/T

---

<div class="post-metadata">

**Author:** ![s\_razer](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/s_razer/32/8537_2.png) [@s\_razer](https://forums.plex.tv/u/s_razer)\
**Post date:** [January 21, 2014, 8:20pm UTC](https://forums.plex.tv/t/reset-default-prefs/54963/3 "2014-01-21T20:20:15Z")

</div>

I was hoping for a built in method. I really don’t want to delete the file because of the other settings. I can always edit the file directly if I have to.

---

<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:** [January 21, 2014, 11:17pm UTC](https://forums.plex.tv/t/reset-default-prefs/54963/4 "2014-01-21T23:17:10Z")

</div>

> I was hoping for a built in method. I really don't want to delete the file because of the other settings. I can always edit the file directly if I have to.

Standby...Reversed it, and will check in code soon....

And This is IMHO kinda nice, and AFAIK, undocumented ;)

/Tommy

---

<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:** [January 21, 2014, 11:50pm UTC](https://forums.plex.tv/t/reset-default-prefs/54963/5 "2014-01-21T23:50:04Z")

</div>

> Standby...Reversed it, and will check in code soon....
> 
> And This is IMHO kinda nice, and AFAIK, undocumented ;)
> 
> /Tommy

Checked into branch Tommy-work....

Take a peek and merge if agree

/T

---

<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:** [January 22, 2014, 12:53am UTC](https://forums.plex.tv/t/reset-default-prefs/54963/6 "2014-01-22T00:53:09Z")

</div>

> Checked into branch Tommy-work....
> 
> Take a peek and merge if agree
> 
> /T

And updated this one to reflect it:

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

/Tommy

---

<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:** [January 22, 2014, 1:44am UTC](https://forums.plex.tv/t/reset-default-prefs/54963/7 "2014-01-22T01:44:34Z")

</div>

And for people watching this:

Chris even managed to find a tweak to my method, making it even more cool

As soon as he check in his code, I'll update this:

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

with his additions.

But Basic, no need to have defaults stored in more place than one

/T

---

<div class="post-metadata">

**Author:** ![s\_razer](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/s_razer/32/8537_2.png) [@s\_razer](https://forums.plex.tv/u/s_razer)\
**Post date:** [January 22, 2014, 2:01am UTC](https://forums.plex.tv/t/reset-default-prefs/54963/8 "2014-01-22T02:01:23Z")

</div>

Basically it boils down to doing a URL request. Like this:

```
u = urllib.urlopen('http://{PMS_IP}:32400/:/plugins/{PLUGIN STRING}/prefs/set?{VARIABLE}={VALUE}')
```

Replace what's in the {}

An example from FindUnmatched:

```
u = urllib.urlopen('http://localhost:32400/:/plugins/com.plexapp.plugins.findUnmatch/prefs/set?ALL_EXTENSIONS=True')
```

You can reset it to default by setting an empty value like:

```
u = urllib.urlopen('http://localhost:32400/:/plugins/com.plexapp.plugins.findUnmatch/prefs/set?VALID_EXTENSIONS=')
```

Chris

Edit:

A better method is to use the HTTP.Request that is in the framework.

```
HTTP.Request('http://localhost:32400/:/plugins/com.plexapp.plugins.findUnmatch/prefs/set?VARIABLE=VALUE', immediate=True)
```

To set multiple Prefs with one request:

```
HTTP.Request('http://localhost:32400/:/plugins/com.plexapp.plugins.findUnmatch/prefs/set?VARIABLE1=VALUE1&VARIABLE2=VALUE2', immediate=True)
```

Note the "&" between the two.

---

<div class="post-metadata">

**Author:** ![walktheway](https://avatars.discourse-cdn.com/v4/letter/w/ccd318/32.png) [@walktheway](https://forums.plex.tv/u/walktheway)\
**Post date:** [March 2, 2014, 11:33pm UTC](https://forums.plex.tv/t/reset-default-prefs/54963/9 "2014-03-02T23:33:35Z")

</div>

Has anyone tried this using HTTP.Request and actually setting a value, like a string?

I had to do this:

PLEX\_PREFS &nbsp; = '[http://localhost:32400/:/plugins/com.plexapp.plugins.vlcplayer/prefs/set?'](http://localhost:32400/:/plugins/com.plexapp.plugins.vlcplayer/prefs/set?%27)

&nbsp;

try:

&nbsp; &nbsp; u = HTTP.Request(PLEX\_PREFS+'fq\_file='+fq\_file.replace(' ', '%20'), immediate=True, timeout=0.2).load()

except:

&nbsp; &nbsp; u = None

&nbsp;

Without a .load() or .content nothing happens. &nbsp;When it is done, PMS does not answer, so there is a timeout problem.

This should not be this difficult.

---

<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 2, 2014, 11:44pm UTC](https://forums.plex.tv/t/reset-default-prefs/54963/10 "2014-03-02T23:44:41Z")

</div>

To be frank here....

I found this, but used the urllib when doing so

Later, both me and Chris was informed about the HTTP api, which was unknown to us, so, an dmy bad here...added without testing to [this](https://docs.google.com/document/d/1hhLjV1pI-TA5y91TiJq64BdgKwdLnFt4hWgeOqpz1NA/edit#heading=h.l855tyscwl1i)

So in order to correct the doc....please tell me what .content and .load() does?

All I can say so far, is that with urllib and urllib2, it rocks, as seen in the "[Find UnMatched](https://forums.plex.tv/topic/87745-find-unmatched-items/)" plug-in

/Tommy

---

<div class="post-metadata">

**Author:** ![s\_razer](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/s_razer/32/8537_2.png) [@s\_razer](https://forums.plex.tv/u/s_razer)\
**Post date:** [March 2, 2014, 11:44pm UTC](https://forums.plex.tv/t/reset-default-prefs/54963/11 "2014-03-02T23:44:46Z")

</div>

Also, it is documented in dane22's doc:&nbsp;[https://forums.plex.tv/topic/87348-undocumented-functionality-and-tips-tricks/](https://forums.plex.tv/topic/87348-undocumented-functionality-and-tips-tricks/)

Edit: I haven't changed it in FundUnmatched yet.

---

<div class="post-metadata">

**Author:** ![s\_razer](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/s_razer/32/8537_2.png) [@s\_razer](https://forums.plex.tv/u/s_razer)\
**Post date:** [March 2, 2014, 11:47pm UTC](https://forums.plex.tv/t/reset-default-prefs/54963/12 "2014-03-02T23:47:59Z")

</div>

The UnsupportedAppStore does use it:

```
81: HTTP.Request('http://localhost:32400/:/plugins/com.plexapp.plugins.unsupportedappstore/prefs/set?clear_dict=False', immediate=True)
```

Chris

---

<div class="post-metadata">

**Author:** ![s\_razer](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/s_razer/32/8537_2.png) [@s\_razer](https://forums.plex.tv/u/s_razer)\
**Post date:** [March 2, 2014, 11:55pm UTC](https://forums.plex.tv/t/reset-default-prefs/54963/13 "2014-03-02T23:55:45Z")

</div>

I edited the answer above to use the HTTP.Request framework.

Chris

---

<div class="post-metadata">

**Author:** ![walktheway](https://avatars.discourse-cdn.com/v4/letter/w/ccd318/32.png) [@walktheway](https://forums.plex.tv/u/walktheway)\
**Post date:** [March 3, 2014, 3:27am UTC](https://forums.plex.tv/t/reset-default-prefs/54963/14 "2014-03-03T03:27:22Z")

</div>

Did you do any testing and investigate the results?

I did some more testing.

BTW, the .load() causes the request to be executed. &nbsp;The immediate=True also does this. &nbsp;The .content not only causes the request to occur, it provides the returned page content as the return value.

I have to use the timeout, or I have to wait for the default timeout (several seconds) &nbsp;A timeout of 0.1 seconds works also (not a surprise for the loopback interface).

Even if I use the timeout, which returns execution to the channel, the spinning wheel remains for a lot longer and the log shows a timeout dump for the request. &nbsp;I am using the local PMS web server interface. &nbsp;Not the most reliable, I know. &nbsp;But I don't believe that should change the log file results this much.

The only way I found to avoid all of this is to wrap it in a try block. &nbsp;Then the timeout does its thing and the try block prevents the timeout dump in the log file. &nbsp;And everything seems to work as expected. &nbsp;If you set the timeout to zero and check the Prefs on the next line, it will be too soon to see the change.

This is the only method I have found that at least gives the appearance of working cleanly.

I'm not sure if this is how it is supposed to work (by design). &nbsp;It would be much better if the web interface provided a response (even an empty one). &nbsp;Then the process would complete like other requests.

One other thing I should mention; I am doing this inside the ValidatePrefs() method. &nbsp;I don't know if that is causing this issue. &nbsp;That is a "special" method.

---

<div class="post-metadata">

**Author:** ![s\_razer](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/s_razer/32/8537_2.png) [@s\_razer](https://forums.plex.tv/u/s_razer)\
**Post date:** [March 3, 2014, 3:30am UTC](https://forums.plex.tv/t/reset-default-prefs/54963/15 "2014-03-03T03:30:24Z")

</div>

Drop the “u=” The request runs and doesn’t care about the return or lack thereof. This is used successfully in the unsupportedAppStore.

---

<div class="post-metadata">

**Author:** ![walktheway](https://avatars.discourse-cdn.com/v4/letter/w/ccd318/32.png) [@walktheway](https://forums.plex.tv/u/walktheway)\
**Post date:** [March 3, 2014, 3:58am UTC](https://forums.plex.tv/t/reset-default-prefs/54963/16 "2014-03-03T03:58:49Z")

</div>

No change. &nbsp;I just tested it. &nbsp;I didn't see why it should matter. &nbsp;A function that returns a value doesn't care if you actually use it. &nbsp;It is returned anyway. &nbsp;It just gets popped off the stack and discarded.

I'll check the unsupportedAppStore.

I used:

HTTP.Request(PLEX\_PREFS+'fq\_file='+fq\_file.replace(' ', '%20'), immediate=True, timeout=0.1)

Also, when the wheel stops spinning, I get the sad face, like for a page not found.

MORE INFO:

I checked out the unsupportedAppStore. &nbsp;Add this to the end of ValidatePrefs OUTSIDE the if block, so it always happens:

&nbsp;

HTTP.Request('[http://localhost:32400/:/plugins/com.plexapp.plugins.unsupportedappstore/prefs/set?adult=False](http://localhost:32400/:/plugins/com.plexapp.plugins.unsupportedappstore/prefs/set?adult=False)' immediate=True)

&nbsp;

Then set the preference for Adult plugins to true and see what happens.

---

<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 3, 2014, 8:21am UTC](https://forums.plex.tv/t/reset-default-prefs/54963/17 "2014-03-03T08:21:33Z")

</div>

This is from RemIdx, and does work:

```
opener = urllib2.build_opener(urllib2.HTTPHandler)
	#Enable Index Generation
	request = urllib2.Request('http://127.0.0.1:32400/:/prefs?GenerateIndexFilesDuringAnalysis=1')
	request.get_method = lambda: 'PUT'
	url = opener.open(request)
```

/T

---

<div class="post-metadata">

**Author:** ![s\_razer](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/s_razer/32/8537_2.png) [@s\_razer](https://forums.plex.tv/u/s_razer)\
**Post date:** [March 3, 2014, 7:48pm UTC](https://forums.plex.tv/t/reset-default-prefs/54963/18 "2014-03-03T19:48:56Z")

</div>

> No change. &nbsp;I just tested it. &nbsp;I didn't see why it should matter. &nbsp;A function that returns a value doesn't care if you actually use it. &nbsp;It is returned anyway. &nbsp;It just gets popped off the stack and discarded.
> 
> I'll check the unsupportedAppStore.
> 
> I used:
> 
> HTTP.Request(PLEX\_PREFS+'fq\_file='+fq\_file.replace(' ', '%20'), immediate=True, timeout=0.1)
> 
> Also, when the wheel stops spinning, I get the sad face, like for a page not found.
> 
> MORE INFO:
> 
> I checked out the unsupportedAppStore. &nbsp;Add this to the end of ValidatePrefs OUTSIDE the if block, so it always happens:
> 
> &nbsp;
> 
> HTTP.Request('[http://localhost:32400/:/plugins/com.plexapp.plugins.unsupportedappstore/prefs/set?adult=False](http://localhost:32400/:/plugins/com.plexapp.plugins.unsupportedappstore/prefs/set?adult=False)' immediate=True)
> 
> &nbsp;
> 
> Then set the preference for Adult plugins to true and see what happens.

The problem with putting that outside an if block is that you setup a never ending loop. The change calls ValidatePrefs() which makes a change which calls&nbsp;ValidatePrefs() until you timeout or the plugin crashes.

If you use this at line 82:

```
if Prefs['adult']:
        HTTP.Request('http://localhost:32400/:/plugins/com.plexapp.plugins.unsupportedappstore/prefs/set?adult=False', immediate=True)
```

Checking the "allow adult" it does successfully allow the change to revert to false. So, it is working as expected for me.

Chris

---

<div class="post-metadata">

**Author:** ![walktheway](https://avatars.discourse-cdn.com/v4/letter/w/ccd318/32.png) [@walktheway](https://forums.plex.tv/u/walktheway)\
**Post date:** [March 4, 2014, 1:56am UTC](https://forums.plex.tv/t/reset-default-prefs/54963/19 "2014-03-04T01:56:56Z")

</div>

Oops. &nbsp;Sorry Chris. &nbsp;What an embarrassing fail on my part. &nbsp;It is an infinite loop.

Your code is working fine.

I figured out what I am doing wrong. &nbsp;I am using:

Thread.AcquireLock('main')

and&nbsp;

Thread.ReleaseLock('main')

inside

ValidatePrefs()

I did this to prevent MainMenu() (which also uses this thread control) from running when the Prefs were being validated (and possibly changed). &nbsp;This was to try to prevent a race issue when referencing those values in MainMenu().

However, the Prefs update inside ValidatePrefs()&nbsp;also makes a postback to PMS and invokes&nbsp;ValidatePrefs() again. &nbsp;Which is blocked by the first call, because it has not finished yet.

It appears that PMS cannot complete the response to the first call while the second call is being blocked.

I verified this in your code.

Add these two threading lines to your code (the first at the beginning and the second at the end, of course) and you will see my problem.

The try block allows the failure to occur gracefully and the process completes as expected. &nbsp;This is not acceptable.

&nbsp;

This brings up a concern about updating Prefs inside of&nbsp;ValidatePrefs() due to the callback issue. &nbsp;If several Prefs are updated sequentially (not all in one call) during the first pass, this could get ugly.

I will be changing my code to avoid this altogether. &nbsp;I already use a duplicate set for the Prefs to maintain the last set values to detect changes (which I need to know in my case). &nbsp;Therefore, I should NEVER use the Prefs, only their "last" values. &nbsp;That will be clean and I won't need the thread control at all; I'll let MainMenu control the updates.

&nbsp;

I also realized that my thread control effort is not effective, as the changes to the Prefs occur before it enters&nbsp;ValidatePrefs().

I am not consistently thinking of this channel as a website, and not an application. &nbsp;Big difference there.

&nbsp;

Thanks for the help!

---

<div class="post-metadata">

**Author:** ![s\_razer](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/s_razer/32/8537_2.png) [@s\_razer](https://forums.plex.tv/u/s_razer)\
**Post date:** [March 4, 2014, 2:01am UTC](https://forums.plex.tv/t/reset-default-prefs/54963/20 "2014-03-04T02:01:12Z")

</div>

Yeah, ValidatePrefs() only runs after the Prefs are changed.

Glad I was able to help.

Chris

[Next page](https://forums.plex.tv/t/reset-default-prefs/54963.md?page=2)
