From c1865f77def51bb39a942ae1730fef6cb0e91572 Mon Sep 17 00:00:00 2001 From: Blacktwin Date: Fri, 4 Jan 2019 13:09:43 -0500 Subject: [PATCH] create exclusions function --- fun/playlist_manager.py | 57 ++++++++++++++++++++++++++--------------- 1 file changed, 36 insertions(+), 21 deletions(-) diff --git a/fun/playlist_manager.py b/fun/playlist_manager.py index dab85fc..6f8b853 100644 --- a/fun/playlist_manager.py +++ b/fun/playlist_manager.py @@ -161,6 +161,39 @@ def selectors(): return selections +def exclusions(all_true, select, all_items): + + output = '' + if isinstance(all_items, list): + output = [] + # Defining users + if all_true and not select: + output = all_items + elif not all_true and select: + output = select + elif all_true and select: + # If allUsers is used then any users listed will be excluded + for x in select: + all_items.remove(x) + output = all_items + elif isinstance(all_items, dict): + output = {} + # Defining libraries + if all_true and not select: + output = all_items + elif not all_true and select: + for key, value in all_items.items(): + if value in select: + output[key] = value + elif all_true and select: + # If allLibraries is used then any libraries listed will be excluded + for key, value in all_items.items(): + if value not in select: + output[key] = value + + return output + + def get_home_stats(time_range, stats_count): # Get the homepage watch statistics. payload = {'apikey': TAUTULLI_APIKEY, @@ -587,28 +620,10 @@ if __name__ == "__main__": exit() # Defining users - if opts.allUsers and not opts.user: - users = user_lst - elif not opts.allUsers and opts.user: - users = opts.user - elif opts.allUsers and opts.user: - # If allUsers is used then any users listed will be excluded - for user in opts.user: - user_lst.remove(user) - users = user_lst - + users = exclusions(opts.allUsers, opts.user, user_lst) + # Defining libraries - if opts.allLibraries and not opts.libraries: - libraries = sections_dict - elif not opts.allLibraries and opts.libraries: - for key, name in sections_dict.items(): - if name in opts.libraries: - libraries[key] = name - elif opts.allLibraries and opts.libraries: - # If allLibraries is used then any libraries listed will be excluded - for key, name in sections_dict.items(): - if name not in opts.libraries: - libraries[key] = name + libraries = exclusions(opts.allLibraries, opts.libraries, sections_dict) # Defining playlist if opts.allPlaylists and not opts.playlists: