Cleanup, seperate black/white lists setup
This commit is contained in:
@@ -81,7 +81,6 @@ JELLYFIN_BASEURL = "http://localhost:8096, http://nas:8096"
|
|||||||
JELLYFIN_TOKEN = "SuperSecretToken, SuperSecretToken2"
|
JELLYFIN_TOKEN = "SuperSecretToken, SuperSecretToken2"
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
### Baremetal
|
### Baremetal
|
||||||
|
|||||||
140
src/black_white.py
Normal file
140
src/black_white.py
Normal file
@@ -0,0 +1,140 @@
|
|||||||
|
from src.functions import logger, search_mapping
|
||||||
|
|
||||||
|
|
||||||
|
def setup_black_white_lists(
|
||||||
|
blacklist_library: str,
|
||||||
|
whitelist_library: str,
|
||||||
|
blacklist_library_type: str,
|
||||||
|
whitelist_library_type: str,
|
||||||
|
blacklist_users: str,
|
||||||
|
whitelist_users: str,
|
||||||
|
library_mapping=None,
|
||||||
|
user_mapping=None,
|
||||||
|
):
|
||||||
|
|
||||||
|
blacklist_library, blacklist_library_type, blacklist_users = setup_black_lists(
|
||||||
|
blacklist_library,
|
||||||
|
blacklist_library_type,
|
||||||
|
blacklist_users,
|
||||||
|
library_mapping,
|
||||||
|
user_mapping,
|
||||||
|
)
|
||||||
|
|
||||||
|
whitelist_library, whitelist_library_type, whitelist_users = setup_white_lists(
|
||||||
|
whitelist_library,
|
||||||
|
whitelist_library_type,
|
||||||
|
whitelist_users,
|
||||||
|
library_mapping,
|
||||||
|
user_mapping,
|
||||||
|
)
|
||||||
|
|
||||||
|
return (
|
||||||
|
blacklist_library,
|
||||||
|
whitelist_library,
|
||||||
|
blacklist_library_type,
|
||||||
|
whitelist_library_type,
|
||||||
|
blacklist_users,
|
||||||
|
whitelist_users,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def setup_black_lists(
|
||||||
|
blacklist_library,
|
||||||
|
blacklist_library_type,
|
||||||
|
blacklist_users,
|
||||||
|
library_mapping=None,
|
||||||
|
user_mapping=None,
|
||||||
|
):
|
||||||
|
if blacklist_library:
|
||||||
|
if len(blacklist_library) > 0:
|
||||||
|
blacklist_library = blacklist_library.split(",")
|
||||||
|
blacklist_library = [x.strip() for x in blacklist_library]
|
||||||
|
if library_mapping:
|
||||||
|
temp_library = []
|
||||||
|
for library in blacklist_library:
|
||||||
|
library_other = search_mapping(library_mapping, library)
|
||||||
|
if library_other:
|
||||||
|
temp_library.append(library_other)
|
||||||
|
|
||||||
|
blacklist_library = blacklist_library + temp_library
|
||||||
|
else:
|
||||||
|
blacklist_library = []
|
||||||
|
logger(f"Blacklist Library: {blacklist_library}", 1)
|
||||||
|
|
||||||
|
if blacklist_library_type:
|
||||||
|
if len(blacklist_library_type) > 0:
|
||||||
|
blacklist_library_type = blacklist_library_type.split(",")
|
||||||
|
blacklist_library_type = [x.lower().strip() for x in blacklist_library_type]
|
||||||
|
else:
|
||||||
|
blacklist_library_type = []
|
||||||
|
logger(f"Blacklist Library Type: {blacklist_library_type}", 1)
|
||||||
|
|
||||||
|
if blacklist_users:
|
||||||
|
if len(blacklist_users) > 0:
|
||||||
|
blacklist_users = blacklist_users.split(",")
|
||||||
|
blacklist_users = [x.lower().strip() for x in blacklist_users]
|
||||||
|
if user_mapping:
|
||||||
|
temp_users = []
|
||||||
|
for user in blacklist_users:
|
||||||
|
user_other = search_mapping(user_mapping, user)
|
||||||
|
if user_other:
|
||||||
|
temp_users.append(user_other)
|
||||||
|
|
||||||
|
blacklist_users = blacklist_users + temp_users
|
||||||
|
else:
|
||||||
|
blacklist_users = []
|
||||||
|
logger(f"Blacklist Users: {blacklist_users}", 1)
|
||||||
|
|
||||||
|
return blacklist_library, blacklist_library_type, blacklist_users
|
||||||
|
|
||||||
|
|
||||||
|
def setup_white_lists(
|
||||||
|
whitelist_library,
|
||||||
|
whitelist_library_type,
|
||||||
|
whitelist_users,
|
||||||
|
library_mapping=None,
|
||||||
|
user_mapping=None,
|
||||||
|
):
|
||||||
|
if whitelist_library:
|
||||||
|
if len(whitelist_library) > 0:
|
||||||
|
whitelist_library = whitelist_library.split(",")
|
||||||
|
whitelist_library = [x.strip() for x in whitelist_library]
|
||||||
|
if library_mapping:
|
||||||
|
temp_library = []
|
||||||
|
for library in whitelist_library:
|
||||||
|
library_other = search_mapping(library_mapping, library)
|
||||||
|
if library_other:
|
||||||
|
temp_library.append(library_other)
|
||||||
|
|
||||||
|
whitelist_library = whitelist_library + temp_library
|
||||||
|
else:
|
||||||
|
whitelist_library = []
|
||||||
|
logger(f"Whitelist Library: {whitelist_library}", 1)
|
||||||
|
|
||||||
|
if whitelist_library_type:
|
||||||
|
if len(whitelist_library_type) > 0:
|
||||||
|
whitelist_library_type = whitelist_library_type.split(",")
|
||||||
|
whitelist_library_type = [x.lower().strip() for x in whitelist_library_type]
|
||||||
|
else:
|
||||||
|
whitelist_library_type = []
|
||||||
|
logger(f"Whitelist Library Type: {whitelist_library_type}", 1)
|
||||||
|
|
||||||
|
if whitelist_users:
|
||||||
|
if len(whitelist_users) > 0:
|
||||||
|
whitelist_users = whitelist_users.split(",")
|
||||||
|
whitelist_users = [x.lower().strip() for x in whitelist_users]
|
||||||
|
if user_mapping:
|
||||||
|
temp_users = []
|
||||||
|
for user in whitelist_users:
|
||||||
|
user_other = search_mapping(user_mapping, user)
|
||||||
|
if user_other:
|
||||||
|
temp_users.append(user_other)
|
||||||
|
|
||||||
|
whitelist_users = whitelist_users + temp_users
|
||||||
|
else:
|
||||||
|
whitelist_users = []
|
||||||
|
else:
|
||||||
|
whitelist_users = []
|
||||||
|
logger(f"Whitelist Users: {whitelist_users}", 1)
|
||||||
|
|
||||||
|
return whitelist_library, whitelist_library_type, whitelist_users
|
||||||
101
src/functions.py
101
src/functions.py
@@ -55,107 +55,6 @@ def search_mapping(dictionary: dict, key_value: str):
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
def setup_black_white_lists(
|
|
||||||
blacklist_library: str,
|
|
||||||
whitelist_library: str,
|
|
||||||
blacklist_library_type: str,
|
|
||||||
whitelist_library_type: str,
|
|
||||||
blacklist_users: str,
|
|
||||||
whitelist_users: str,
|
|
||||||
library_mapping=None,
|
|
||||||
user_mapping=None,
|
|
||||||
):
|
|
||||||
if blacklist_library:
|
|
||||||
if len(blacklist_library) > 0:
|
|
||||||
blacklist_library = blacklist_library.split(",")
|
|
||||||
blacklist_library = [x.strip() for x in blacklist_library]
|
|
||||||
if library_mapping:
|
|
||||||
temp_library = []
|
|
||||||
for library in blacklist_library:
|
|
||||||
library_other = search_mapping(library_mapping, library)
|
|
||||||
if library_other:
|
|
||||||
temp_library.append(library_other)
|
|
||||||
|
|
||||||
blacklist_library = blacklist_library + temp_library
|
|
||||||
else:
|
|
||||||
blacklist_library = []
|
|
||||||
logger(f"Blacklist Library: {blacklist_library}", 1)
|
|
||||||
|
|
||||||
if whitelist_library:
|
|
||||||
if len(whitelist_library) > 0:
|
|
||||||
whitelist_library = whitelist_library.split(",")
|
|
||||||
whitelist_library = [x.strip() for x in whitelist_library]
|
|
||||||
if library_mapping:
|
|
||||||
temp_library = []
|
|
||||||
for library in whitelist_library:
|
|
||||||
library_other = search_mapping(library_mapping, library)
|
|
||||||
if library_other:
|
|
||||||
temp_library.append(library_other)
|
|
||||||
|
|
||||||
whitelist_library = whitelist_library + temp_library
|
|
||||||
else:
|
|
||||||
whitelist_library = []
|
|
||||||
logger(f"Whitelist Library: {whitelist_library}", 1)
|
|
||||||
|
|
||||||
if blacklist_library_type:
|
|
||||||
if len(blacklist_library_type) > 0:
|
|
||||||
blacklist_library_type = blacklist_library_type.split(",")
|
|
||||||
blacklist_library_type = [x.lower().strip() for x in blacklist_library_type]
|
|
||||||
else:
|
|
||||||
blacklist_library_type = []
|
|
||||||
logger(f"Blacklist Library Type: {blacklist_library_type}", 1)
|
|
||||||
|
|
||||||
if whitelist_library_type:
|
|
||||||
if len(whitelist_library_type) > 0:
|
|
||||||
whitelist_library_type = whitelist_library_type.split(",")
|
|
||||||
whitelist_library_type = [x.lower().strip() for x in whitelist_library_type]
|
|
||||||
else:
|
|
||||||
whitelist_library_type = []
|
|
||||||
logger(f"Whitelist Library Type: {whitelist_library_type}", 1)
|
|
||||||
|
|
||||||
if blacklist_users:
|
|
||||||
if len(blacklist_users) > 0:
|
|
||||||
blacklist_users = blacklist_users.split(",")
|
|
||||||
blacklist_users = [x.lower().strip() for x in blacklist_users]
|
|
||||||
if user_mapping:
|
|
||||||
temp_users = []
|
|
||||||
for user in blacklist_users:
|
|
||||||
user_other = search_mapping(user_mapping, user)
|
|
||||||
if user_other:
|
|
||||||
temp_users.append(user_other)
|
|
||||||
|
|
||||||
blacklist_users = blacklist_users + temp_users
|
|
||||||
else:
|
|
||||||
blacklist_users = []
|
|
||||||
logger(f"Blacklist Users: {blacklist_users}", 1)
|
|
||||||
|
|
||||||
if whitelist_users:
|
|
||||||
if len(whitelist_users) > 0:
|
|
||||||
whitelist_users = whitelist_users.split(",")
|
|
||||||
whitelist_users = [x.lower().strip() for x in whitelist_users]
|
|
||||||
if user_mapping:
|
|
||||||
temp_users = []
|
|
||||||
for user in whitelist_users:
|
|
||||||
user_other = search_mapping(user_mapping, user)
|
|
||||||
if user_other:
|
|
||||||
temp_users.append(user_other)
|
|
||||||
|
|
||||||
whitelist_users = whitelist_users + temp_users
|
|
||||||
else:
|
|
||||||
whitelist_users = []
|
|
||||||
else:
|
|
||||||
whitelist_users = []
|
|
||||||
logger(f"Whitelist Users: {whitelist_users}", 1)
|
|
||||||
|
|
||||||
return (
|
|
||||||
blacklist_library,
|
|
||||||
whitelist_library,
|
|
||||||
blacklist_library_type,
|
|
||||||
whitelist_library_type,
|
|
||||||
blacklist_users,
|
|
||||||
whitelist_users,
|
|
||||||
)
|
|
||||||
|
|
||||||
def future_thread_executor(args: list, workers: int = -1):
|
def future_thread_executor(args: list, workers: int = -1):
|
||||||
futures_list = []
|
futures_list = []
|
||||||
results = []
|
results = []
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ from src.watched import (
|
|||||||
combine_watched_dicts,
|
combine_watched_dicts,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class Jellyfin:
|
class Jellyfin:
|
||||||
def __init__(self, baseurl, token):
|
def __init__(self, baseurl, token):
|
||||||
self.baseurl = baseurl
|
self.baseurl = baseurl
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ from src.functions import (
|
|||||||
search_mapping,
|
search_mapping,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def check_skip_logic(
|
def check_skip_logic(
|
||||||
library_title,
|
library_title,
|
||||||
library_type,
|
library_type,
|
||||||
@@ -115,4 +116,3 @@ def generate_library_guids_dict(user_list: dict):
|
|||||||
logger("Generating movies_output_dict failed, skipping", 1)
|
logger("Generating movies_output_dict failed, skipping", 1)
|
||||||
|
|
||||||
return show_output_dict, episode_output_dict, movies_output_dict
|
return show_output_dict, episode_output_dict, movies_output_dict
|
||||||
|
|
||||||
@@ -5,8 +5,6 @@ from time import sleep, perf_counter
|
|||||||
from src.functions import (
|
from src.functions import (
|
||||||
logger,
|
logger,
|
||||||
str_to_bool,
|
str_to_bool,
|
||||||
setup_black_white_lists,
|
|
||||||
|
|
||||||
)
|
)
|
||||||
from src.users import (
|
from src.users import (
|
||||||
generate_user_list,
|
generate_user_list,
|
||||||
@@ -17,6 +15,7 @@ from src.users import (
|
|||||||
from src.watched import (
|
from src.watched import (
|
||||||
cleanup_watched,
|
cleanup_watched,
|
||||||
)
|
)
|
||||||
|
from src.black_white import setup_black_white_lists
|
||||||
|
|
||||||
from src.plex import Plex
|
from src.plex import Plex
|
||||||
from src.jellyfin import Jellyfin
|
from src.jellyfin import Jellyfin
|
||||||
@@ -24,8 +23,6 @@ from src.jellyfin import Jellyfin
|
|||||||
load_dotenv(override=True)
|
load_dotenv(override=True)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def setup_users(
|
def setup_users(
|
||||||
server_1, server_2, blacklist_users, whitelist_users, user_mapping=None
|
server_1, server_2, blacklist_users, whitelist_users, user_mapping=None
|
||||||
):
|
):
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ from src.functions import (
|
|||||||
search_mapping,
|
search_mapping,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def generate_user_list(server):
|
def generate_user_list(server):
|
||||||
# generate list of users from server 1 and server 2
|
# generate list of users from server 1 and server 2
|
||||||
server_type = server[0]
|
server_type = server[0]
|
||||||
@@ -16,6 +17,7 @@ def generate_user_list(server):
|
|||||||
|
|
||||||
return server_users
|
return server_users
|
||||||
|
|
||||||
|
|
||||||
def combine_user_lists(server_1_users, server_2_users, user_mapping):
|
def combine_user_lists(server_1_users, server_2_users, user_mapping):
|
||||||
# combined list of overlapping users from plex and jellyfin
|
# combined list of overlapping users from plex and jellyfin
|
||||||
users = {}
|
users = {}
|
||||||
@@ -42,6 +44,7 @@ def combine_user_lists(server_1_users, server_2_users, user_mapping):
|
|||||||
|
|
||||||
return users
|
return users
|
||||||
|
|
||||||
|
|
||||||
def filter_user_lists(users, blacklist_users, whitelist_users):
|
def filter_user_lists(users, blacklist_users, whitelist_users):
|
||||||
users_filtered = {}
|
users_filtered = {}
|
||||||
for user in users:
|
for user in users:
|
||||||
@@ -56,6 +59,7 @@ def filter_user_lists(users, blacklist_users, whitelist_users):
|
|||||||
|
|
||||||
return users_filtered
|
return users_filtered
|
||||||
|
|
||||||
|
|
||||||
def generate_server_users(server, users):
|
def generate_server_users(server, users):
|
||||||
server_users = None
|
server_users = None
|
||||||
|
|
||||||
|
|||||||
@@ -5,9 +5,8 @@ from src.functions import (
|
|||||||
search_mapping,
|
search_mapping,
|
||||||
)
|
)
|
||||||
|
|
||||||
from src.library import (
|
from src.library import generate_library_guids_dict
|
||||||
generate_library_guids_dict
|
|
||||||
)
|
|
||||||
|
|
||||||
def combine_watched_dicts(dicts: list):
|
def combine_watched_dicts(dicts: list):
|
||||||
combined_dict = {}
|
combined_dict = {}
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ parent = os.path.dirname(current)
|
|||||||
# the sys.path.
|
# the sys.path.
|
||||||
sys.path.append(parent)
|
sys.path.append(parent)
|
||||||
|
|
||||||
from src.main import setup_black_white_lists
|
from src.black_white import setup_black_white_lists
|
||||||
|
|
||||||
|
|
||||||
def test_setup_black_white_lists():
|
def test_setup_black_white_lists():
|
||||||
|
|||||||
Reference in New Issue
Block a user