improve content rating choice
content ratings are now pulled from plex instead of assuming the available content ratings.
This commit is contained in:
parent
73a1d701a8
commit
7e560ffd9f
@ -43,7 +43,7 @@ Usage:
|
||||
- USER is still exists as a Friend or Home User
|
||||
|
||||
Excluding;
|
||||
|
||||
|
||||
--user becomes excluded if --allUsers is set
|
||||
plex_api_share.py --share --allUsers -u USER --libraries Movies
|
||||
- Shared libraries: ['Movies' ]with USER1.
|
||||
@ -60,9 +60,8 @@ import argparse
|
||||
import requests
|
||||
|
||||
PLEX_URL = 'http://localhost:32400'
|
||||
PLEX_TOKEN = 'xxxxxxx'
|
||||
PLEX_TOKEN = 'xxxxxx'
|
||||
|
||||
ratings_lst = ['G', 'PG', 'PG-13', 'R', 'NC-17', 'TV-G', 'TV-Y', 'TV-Y7', 'TV-14', 'TV-PG', 'TV-MA']
|
||||
|
||||
sess = requests.Session()
|
||||
sess.verify = False
|
||||
@ -71,8 +70,22 @@ plex = PlexServer(PLEX_URL, PLEX_TOKEN, session=sess)
|
||||
|
||||
user_lst = [x.title for x in plex.myPlexAccount().users()]
|
||||
sections_lst = [x.title for x in plex.library.sections()]
|
||||
movies_keys = [x.key for x in plex.library.sections() if x.type == 'movie']
|
||||
show_keys = [x.key for x in plex.library.sections() if x.type == 'show']
|
||||
movie_ratings = []
|
||||
show_ratings = []
|
||||
|
||||
|
||||
def get_ratings_lst(section_id):
|
||||
headers = {'Accept': 'application/json'}
|
||||
params = {'X-Plex-Token': PLEX_TOKEN}
|
||||
content = requests.get("{}/library/sections/{}/contentRating".format(PLEX_URL, section_id),
|
||||
headers=headers, params=params)
|
||||
|
||||
ratings_keys = content.json()['MediaContainer']['Directory']
|
||||
ratings_lst = [x['title'] for x in ratings_keys]
|
||||
return ratings_lst
|
||||
|
||||
def share(user, sections, allowSync, camera, channels, filterMovies, filterTelevision, filterMusic):
|
||||
plex.myPlexAccount().updateFriend(user=user, server=plex, sections=sections, allowSync=allowSync,
|
||||
allowCameraUpload=camera, allowChannels=channels, filterMovies=filterMovies,
|
||||
@ -87,6 +100,12 @@ def unshare(user, libraries):
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
|
||||
for movie in movies_keys:
|
||||
movie_ratings += get_ratings_lst(movie)
|
||||
for show in show_keys:
|
||||
show_ratings += get_ratings_lst(show)
|
||||
|
||||
parser = argparse.ArgumentParser(description="Share or unshare libraries.",
|
||||
formatter_class=argparse.RawTextHelpFormatter)
|
||||
parser.add_argument('--share', default=False, action='store_true',
|
||||
@ -109,15 +128,19 @@ if __name__ == "__main__":
|
||||
help='Use to allow user to upload photos.')
|
||||
parser.add_argument('--channels', default=False, action='store_true',
|
||||
help='Use to allow user to utilize installed channels.')
|
||||
parser.add_argument('--movieRatings', nargs='+', choices=ratings_lst, metavar='',
|
||||
help='Use to add rating restrictions to movie library types.')
|
||||
parser.add_argument('--movieLabels', nargs='+',
|
||||
parser.add_argument('--movieRatings', nargs='+', choices=list(set(movie_ratings)), metavar='',
|
||||
help='Use to add rating restrictions to movie library types.\n'
|
||||
'Space separated list of case sensitive names to process. Allowed names are: \n'
|
||||
'(choices: %(choices)s')
|
||||
parser.add_argument('--movieLabels', nargs='+', metavar='',
|
||||
help='Use to add label restrictions for movie library types.')
|
||||
parser.add_argument('--tvRatings', nargs='+', choices=ratings_lst, metavar='',
|
||||
help='Use to add rating restrictions for show library types.')
|
||||
parser.add_argument('--tvLabels', nargs='+',
|
||||
parser.add_argument('--tvRatings', nargs='+', choices=list(set(show_ratings)), metavar='',
|
||||
help='Use to add rating restrictions for show library types.\n'
|
||||
'Space separated list of case sensitive names to process. Allowed names are: \n'
|
||||
'(choices: %(choices)s')
|
||||
parser.add_argument('--tvLabels', nargs='+', metavar='',
|
||||
help='Use to add label restrictions for show library types.')
|
||||
parser.add_argument('--musicLabels', nargs='+',
|
||||
parser.add_argument('--musicLabels', nargs='+', metavar='',
|
||||
help='Use to add label restrictions for music library types.')
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user