def updateFriend(self, user, server, sections=None, allowSync=False, allowCameraUpload=False, allowChannels=False, filterMovies=None, filterTelevision=None, filterMusic=None): """ Update the specified user's share settings. Parameters: user (str): MyPlexUser, username, email of the user to be added. server (PlexServer): PlexServer object or machineIdentifier containing the library sections to share. sections: ([Section]): Library sections, names or ids to be shared (default None shares all sections). allowSync (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']} """ # Update friend servers user = self.user(user) machineId = server.machineIdentifier if isinstance( server, PlexServer) else server serverId = [ s for s in user.servers if s.machineIdentifier == machineId ][0].id sectionIds = self._getSectionIds(machineId, sections) params = { 'server_id': machineId, 'shared_server': { 'library_section_ids': sectionIds } } headers = {'Content-Type': 'application/json'} url = self.FRIENDSERVERS.format(machineId=machineId, serverId=serverId) response_servers = self.query(url, self._session.put, json=params, headers=headers) # Update friend filters url = self.FRIENDUPDATE.format(userId=user.id) url += '?allowSync=%s' % ('1' if allowSync else '0') url += '&allowCameraUpload=%s' % ('1' if allowCameraUpload else '0') url += '&allowChannels=%s' % ('1' if allowChannels else '0') url += '&filterMovies=%s' % quote( self._filterDictToStr(filterMovies or {})) url += '&filterTelevision=%s' % quote( self._filterDictToStr(filterTelevision or {})) url += '&filterMusic=%s' % quote( self._filterDictToStr(filterMusic or {})) response_filters = self.query(url, self._session.put) return response_servers, response_filters
def joinArgs(args): if not args: return '' arglist = [] for key in sorted(args, key=lambda x:x.lower()): value = str(args[key]) arglist.append('%s=%s' % (key, quote(value))) return '?%s' % '&'.join(arglist)
def joinArgs(args): if not args: return '' arglist = [] for key in sorted(args, key=lambda x: x.lower()): value = str(args[key]) arglist.append('%s=%s' % (key, quote(value))) return '?%s' % '&'.join(arglist)
def joinArgs(args): """ Returns a query string (uses for HTTP URLs) where only the value is URL encoded. Example return value: '?genre=action&type=1337'. Parameters: args (dict): Arguments to include in query string. """ if not args: return '' arglist = [] for key in sorted(args, key=lambda x: x.lower()): value = str(args[key]) arglist.append('%s=%s' % (key, compat.quote(value))) return '?%s' % '&'.join(arglist)
def joinArgs(args): """ Returns a query string (uses for HTTP URLs) where only the value is URL encoded. Example return value: '?genre=action&type=1337'. Parameters: args (dict): Arguments to include in query string. """ if not args: return '' arglist = [] for key in sorted(args, key=lambda x: x.lower()): value = compat.ustr(args[key]) arglist.append('%s=%s' % (key, compat.quote(value))) return '?%s' % '&'.join(arglist)
def search(self, query, mediatype=None): """Searching within a library section is much more powerful. Args: query (str): Search str mediatype (str, optional): Limit your search to a media type. Returns: List """ items = utils.listItems(self, '/search?query=%s' % quote(query)) if mediatype: return [item for item in items if item.type == mediatype] return items
def save(self): """ Save any outstanding settnig changes to the :class:`~plexapi.server.PlexServer`. This performs a full reload() of Settings after complete. """ params = {} for setting in self.all(): if setting._setValue: log.info('Saving PlexServer setting %s = %s' % (setting.id, setting._setValue)) params[setting.id] = quote(setting._setValue) if not params: raise BadRequest('No setting have been modified.') querystr = '&'.join(['%s=%s' % (k, v) for k, v in params.items()]) url = '%s?%s' % (self.key, querystr) self._server.query(url, self._server._session.put) self.reload()
def joinArgs(args): """Builds a query string where only the value is quoted. Args: args (dict): ex {'genre': 'action', 'type': 1337} Returns: string: ?genre=action&type=1337 """ if not args: return '' arglist = [] for key in sorted(args, key=lambda x: x.lower()): value = str(args[key]) arglist.append('%s=%s' % (key, quote(value))) return '?%s' % '&'.join(arglist)
def search(self, query, mediatype=None): """ Searching within a library section is much more powerful. """ items = utils.listItems(self, '/search?query=%s' % quote(query)) if mediatype: return [item for item in items if item.type == mediatype] return items