@@ -62,6 +62,7 @@ class MyPlexAccount(PlexObject):
6262 _session (obj): Requests session object used to access this client.
6363 """
6464 FRIENDINVITE = 'https://plex.tv/api/servers/{machineId}/shared_servers' # post with data
65+ HOMEUSERCREATE = 'https://plex.tv/api/home/users?title={title}' # post with data
6566 FRIENDSERVERS = 'https://plex.tv/api/servers/{machineId}/shared_servers/{serverId}' # put with data
6667 PLEXSERVERS = 'https://plex.tv/api/servers/{machineId}' # get
6768 FRIENDUPDATE = 'https://plex.tv/api/friends/{userId}' # put with args, delete
@@ -230,6 +231,52 @@ def inviteFriend(self, user, server, sections=None, allowSync=False, allowCamera
230231 url = self .FRIENDINVITE .format (machineId = machineId )
231232 return self .query (url , self ._session .post , json = params , headers = headers )
232233
234+ def createHomeUser (self , user , server , sections = None , allowSync = False , allowCameraUpload = False ,
235+ allowChannels = False , filterMovies = None , filterTelevision = None , filterMusic = None ):
236+ """ Share library content with the specified user.
237+
238+ Parameters:
239+ user (str): MyPlexUser, username, email of the user to be added.
240+ server (PlexServer): PlexServer object or machineIdentifier containing the library sections to share.
241+ sections ([Section]): Library sections, names or ids to be shared (default None shares all sections).
242+ allowSync (Bool): Set True to allow user to sync content.
243+ allowCameraUpload (Bool): Set True to allow user to upload photos.
244+ allowChannels (Bool): Set True to allow user to utilize installed channels.
245+ filterMovies (Dict): Dict containing key 'contentRating' and/or 'label' each set to a list of
246+ values to be filtered. ex: {'contentRating':['G'], 'label':['foo']}
247+ filterTelevision (Dict): Dict containing key 'contentRating' and/or 'label' each set to a list of
248+ values to be filtered. ex: {'contentRating':['G'], 'label':['foo']}
249+ filterMusic (Dict): Dict containing key 'label' set to a list of values to be filtered.
250+ ex: {'label':['foo']}
251+ """
252+ machineId = server .machineIdentifier if isinstance (server , PlexServer ) else server
253+ sectionIds = self ._getSectionIds (server , sections )
254+
255+ headers = {'Content-Type' : 'application/json' }
256+ url = self .HOMEUSERCREATE .format (title = user )
257+ # UserID needs to be created and referenced when adding sections
258+ user_creation = self .query (url , self ._session .post , headers = headers )
259+ userIds = {}
260+ for elem in user_creation .findall ("." ):
261+ # Find userID
262+ userIds ['id' ] = elem .attrib .get ('id' )
263+ log .debug (userIds )
264+ params = {
265+ 'server_id' : machineId ,
266+ 'shared_server' : {'library_section_ids' : sectionIds , 'invited_id' : userIds ['id' ]},
267+ 'sharing_settings' : {
268+ 'allowSync' : ('1' if allowSync else '0' ),
269+ 'allowCameraUpload' : ('1' if allowCameraUpload else '0' ),
270+ 'allowChannels' : ('1' if allowChannels else '0' ),
271+ 'filterMovies' : self ._filterDictToStr (filterMovies or {}),
272+ 'filterTelevision' : self ._filterDictToStr (filterTelevision or {}),
273+ 'filterMusic' : self ._filterDictToStr (filterMusic or {}),
274+ },
275+ }
276+ url = self .FRIENDINVITE .format (machineId = machineId )
277+ library_assignment = self .query (url , self ._session .post , json = params , headers = headers )
278+ return user_creation , library_assignment
279+
233280 def removeFriend (self , user ):
234281 """ Remove the specified user from all sharing.
235282
0 commit comments