pkkid / python-plexapi

Python bindings for the Plex API.
BSD 3-Clause "New" or "Revised" License
1.14k stars 197 forks source link

Add "skipFriendship" option to inviteFriend calls #1189

Open edrock200 opened 1 year ago

edrock200 commented 1 year ago

What is your feature request?

Plex has added a new "Friends" feature in which you can be friends with people who are not on your server and vice versa, not be friends with someone who has guest access to your server. The GUI now prompts when adding someone to ask if you want to add them as a friend as well. The existing API call now defaults to adding them as a friend. However, via curl you can add the option of "skipFriendship": true

Unless I'm missing something, I don't believe the python library can do this right now. I tried adding it as an option to the invite but get the error - TypeError: inviteFriend() got an unexpected keyword argument 'skipFriendship'

Are there any workarounds?

Use the gui or remove the invited guest as a friend after the invite is sent via the gui

Code Snippets

edit I know nothing about python or coding. but I did modify this section of myplex.py to add the skipFriendship to the def invitefriend section as well as a skipFriendship under params, and inital testing, it seems to work: (edit2 proving how bad I am at this, I cannot for the life of me get this code to paste in properly. My apologies lol)

` def inviteFriend(self, user, server, sections=None, allowSync=False, allowCameraUpload=False, allowChannels=False, filterMovies=None, filterTelevision=None, filterMusic=None, skipFriendship=True): """ Share library content with the specified user.

        Parameters:
            user (:class:`~plexapi.myplex.MyPlexUser`): `MyPlexUser` object, username, or email
                of the user to be added.
            server (:class:`~plexapi.server.PlexServer`): `PlexServer` object, or machineIdentifier
                containing the library sections to share.
            sections (List<:class:`~plexapi.library.LibrarySection`>): List of `LibrarySection` objects, or names
                to be shared (default None). `sections` must be defined in order to update shared libraries.
            allowSync (Bool): Set True to allow user to sync content.
            skipFriendship (Bool): Set True to allow user to sync content.
            allowCameraUpload (Bool): Set True to allow user to upload photos.
            allowChannels (Bool): Set True to allow user to utilize installed channels.
            filterMovies (Dict): Dict containing key 'contentRating' and/or 'label' each set to a list of
                values to be filtered. ex: `{'contentRating':['G'], 'label':['foo']}`
            filterTelevision (Dict): Dict containing key 'contentRating' and/or 'label' each set to a list of
                values to be filtered. ex: `{'contentRating':['G'], 'label':['foo']}`
            filterMusic (Dict): Dict containing key 'label' set to a list of values to be filtered.
                ex: `{'label':['foo']}`
    """
    username = user.username if isinstance(user, MyPlexUser) else user
    machineId = server.machineIdentifier if isinstance(server, PlexServer) else server
    sectionIds = self._getSectionIds(machineId, sections)
    params = {
        'server_id': machineId,
        'shared_server': {'library_section_ids': sectionIds, 'invited_email': username},
        'sharing_settings': {
            'allowSync': ('1' if allowSync else '0'),
            'skipFriendship': ('1' if allowSync else '0'),
            'allowCameraUpload': ('1' if allowCameraUpload else '0'),
            'allowChannels': ('1' if allowChannels else '0'),
            'filterMovies': self._filterDictToStr(filterMovies or {}),
            'filterTelevision': self._filterDictToStr(filterTelevision or {}),
            'filterMusic': self._filterDictToStr(filterMusic or {}),
        },
    }`

Additional Context

Would be nice to have this implemented for other functions too such as modify an existing user, add a friend, remove a friend, etc.

edrock200 commented 1 year ago

Not the above actually doesn't work. It still adds as a friend