fix for plexapi update

removeSection is explicit.
This commit is contained in:
blacktwin 2017-09-29 14:47:45 -04:00 committed by GitHub
parent fa736b49d2
commit 01aa066d2c

View File

@ -4,7 +4,7 @@ Share or unshare libraries.
optional arguments: optional arguments:
-h, --help show this help message and exit -h, --help show this help message and exit
-s [], --share [] To share or to unshare.: -s [], --share [] To share or to unshare.:
(choices: share, unshare) (choices: share, share_all, unshare, unshare_all)
-u [], --user [] Space separated list of case sensitive names to process. Allowed names are: -u [], --user [] Space separated list of case sensitive names to process. Allowed names are:
(choices: All users names) (choices: All users names)
-l [ ...], --libraries [ ...] -l [ ...], --libraries [ ...]
@ -13,15 +13,23 @@ optional arguments:
(default: All Libraries) (default: All Libraries)
Usage: Usage:
plex_api_share.py -s unshare -u USER
- Unshared all libraries with USER.
- USER is still exists as a Friend or Home User
plex_api_share.py -s share -u USER -l Movies plex_api_share.py -s share -u USER -l Movies
- Shared libraries: ['Movies'] with USER - Shared libraries: ['Movies'] with USER
plex_api_share.py -s share -u USER -l Movies "TV Shows" plex_api_share.py -s share -u USER -l Movies "TV Shows"
- Shared libraries: ['Movies', 'TV Shows'] with USER - Shared libraries: ['Movies', 'TV Shows'] with USER
* Double Quote libraries with spaces
plex_api_share.py -s share_all -u USER
- Shared all libraries with USER.
plex_api_share.py -s unshare -u USER -l Movies
- Unshared libraries: ['Movies'] from USER
plex_api_share.py -s unshare_all -u USER
- Unshared all libraries with USER.
- USER is still exists as a Friend or Home User
''' '''
@ -29,12 +37,13 @@ from plexapi.server import PlexServer
import argparse import argparse
PLEX_URL = 'http://localhost:32400' PLEX_URL = 'http://localhost:32400'
PLEX_TOKEN = 'xxxxxxxx' PLEX_TOKEN = 'xxxxx'
plex = PlexServer(PLEX_URL, PLEX_TOKEN) plex = PlexServer(PLEX_URL, PLEX_TOKEN)
user_lst = [x.title for x in plex.myPlexAccount().users()] user_lst = [x.title for x in plex.myPlexAccount().users()]
sections_lst = [x.title for x in plex.library.sections()] sections_lst = [x.title for x in plex.library.sections()]
def share(user, libraries): def share(user, libraries):
plex.myPlexAccount().updateFriend(user=user, server=plex, sections=libraries) plex.myPlexAccount().updateFriend(user=user, server=plex, sections=libraries)
if not libraries: if not libraries:
@ -42,17 +51,19 @@ def share(user, libraries):
else: else:
print('Shared libraries: {libraries} with {user}.'.format(libraries=libraries, user=user)) print('Shared libraries: {libraries} with {user}.'.format(libraries=libraries, user=user))
def unshare(user):
plex.myPlexAccount().updateFriend(user=user, server=plex, removeSections=True) def unshare(user, libraries):
plex.myPlexAccount().updateFriend(user=user, server=plex, removeSections=True, sections=libraries)
print('Unshared all libraries with {user}.'.format(user=user)) print('Unshared all libraries with {user}.'.format(user=user))
if __name__ == "__main__": if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Share or unshare libraries.", parser = argparse.ArgumentParser(description="Share or unshare libraries.",
formatter_class=argparse.RawTextHelpFormatter) formatter_class=argparse.RawTextHelpFormatter)
parser.add_argument('-s', '--share', nargs='?', type=str, required=True, choices=['share', 'unshare'], metavar='', parser.add_argument('-s', '--share', nargs='?', type=str, required=True,
help='To share or to unshare.: \n' choices=['share', 'share_all', 'unshare', 'unshare_all'], metavar='',
'(choices: %(choices)s)') help='To share or to unshare.: \n (choices: %(choices)s)')
parser.add_argument('-u', '--user', nargs='?', type=str, required=True, choices=user_lst, metavar='', parser.add_argument('-u', '--user', nargs='?', type=str, required=True, choices=user_lst, metavar='',
help='Space separated list of case sensitive names to process. Allowed names are: \n' help='Space separated list of case sensitive names to process. Allowed names are: \n'
'(choices: %(choices)s)') '(choices: %(choices)s)')
@ -65,6 +76,10 @@ if __name__ == "__main__":
if opts.share == 'share': if opts.share == 'share':
share(opts.user, opts.libraries) share(opts.user, opts.libraries)
elif opts.share == 'unshare': elif opts.share == 'unshare':
unshare(opts.user) unshare(opts.user, opts.libraries)
elif opts.share == 'share_all':
unshare(opts.user, sections_lst)
elif opts.share == 'unshare_all':
unshare(opts.user, sections_lst)
else: else:
print('I don\'t know what else you want.') print('I don\'t know what else you want.')