Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Edit Library and Show's Advanced Settings #507

Merged
merged 20 commits into from
Oct 2, 2020
Merged

Conversation

blacktwin
Copy link
Collaborator

@blacktwin blacktwin commented Jun 5, 2020

Allow for editing a show's advanced settings

show.editAdvanced(showOrdering='aired', autoDeletionItemPolicyWatchedLibrary=0)

Allow for editing a library's advanced settings

library.editAdvanced(enableBIFGeneration=0, collectionMode=2)

allow for editing a show's advanced settings using kwargs
allows for defaulting all advanced settings
@blacktwin
Copy link
Collaborator Author

blacktwin commented Jun 5, 2020

I can move/add these methods to settings.Preferences if I carry over the show's key into settings.Preferences's _initpath.

    def preferences(self):
        """ Returns a list of :class:`~plexapi.settings.Preferences` objects. """
        items = []
        data = self._server.query(self._details_key)
        for item in data.iter('Preferences'):
            for elem in item:
                setting = settings.Preferences(data=elem, server=self._server)
                setting._initpath = self.key
                items.append(setting)

        return items

This way the settings could be updated from the show object in mass or from the preference object.

@blacktwin
Copy link
Collaborator Author

I should add some tests to this. Switch settings, reload, assert.

@blacktwin blacktwin marked this pull request as draft June 6, 2020 18:03
@blacktwin blacktwin changed the title Edit Show's Advanced Settings Edit Library and Show's Advanced Settings Jun 10, 2020
@blacktwin blacktwin marked this pull request as ready for review June 18, 2020 14:02
@blacktwin
Copy link
Collaborator Author

@Hellowlol this should be ready for review.

if self.type == 'int':
url = key + '%s=%s' % (self.id, self.default)
else:
url = key + '%s=%s' % (self.id, self.default.decode())
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it still needed to decode this? py2 has been dropped.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.default is a value so it also is a byte that is either an int or str.

plexapi/video.py Outdated
try:
enumValues = [int(x) for x in preferences.get(settingID)]
except ValueError:
enumValues = [x.decode() for x in preferences.get(settingID)]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same again, why do we need to decode?

Copy link
Collaborator Author

@blacktwin blacktwin Jul 28, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The .value can be classed as a byte that is either an int or str. Majority of the time they're int -1, 1, 2 something like that.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

    _bool_cast = lambda x: True if x == 'true' or x == '1' else False
    _bool_str = lambda x: str(x).lower()
    _str = lambda x: str(x).encode('utf-8') # py2 dependant?
    TYPES = {
        'bool': {'type': bool, 'cast': _bool_cast, 'tostr': _bool_str},
        'double': {'type': float, 'cast': float, 'tostr': _str},
        'int': {'type': int, 'cast': int, 'tostr': _str},
        'text': {'type': str, 'cast': _str , 'tostr': _str},
    }

Updating the the tostr: _str references to tostr: str should resolve the issue.

@jjlawren
Copy link
Collaborator

Calling PlexServer.settings.get("FriendlyName") is returning an empty value for some reason in this test, and only for this PR. Could one of the changes/tests be inadvertently clearing it somehow? Or maybe it just needs a reload() at the start of the failing test?

@coveralls
Copy link

Coverage Status

Coverage increased (+0.4%) to 72.024% when pulling 0123904 on show_advanced_setting into 737401b on master.

py2 support has been dropped. returning str instead of bytes now due to 5045ddc
@blacktwin
Copy link
Collaborator Author

This PR should be gtg.

@Hellowlol Hellowlol merged commit 163d94d into master Oct 2, 2020
@jjlawren jjlawren mentioned this pull request Nov 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants