def obtain_radarr_parameters( content_discovery, content_manager, tmdb_id=None, ): """Returns the common parameters needed for adding a series to Radarr.""" conreq_config = ConreqConfig.get_solo() is_anime = content_discovery.is_anime(tmdb_id, "movie") all_root_dirs = content_manager.radarr_root_dirs() if is_anime: radarr_root = is_key_value_in_list( "id", conreq_config.radarr_anime_folder, all_root_dirs, return_item=True )["path"] radarr_profile_id = conreq_config.radarr_anime_quality_profile else: radarr_root = is_key_value_in_list( "id", conreq_config.radarr_movies_folder, all_root_dirs, return_item=True )["path"] radarr_profile_id = conreq_config.radarr_movies_quality_profile return { "radarr_profile_id": radarr_profile_id, "radarr_root": radarr_root, }
def initialization(request): conreq_config = ConreqConfig.get_solo() user_objects = get_user_model().objects # Authenticate using Organizr headers organizr_username = request.headers.get("X-WEBAUTH-USER") if conreq_config.conreq_http_header_auth and organizr_username: organizr_email = request.headers.get("X-WEBAUTH-EMAIL") organizr_group = int(request.headers.get("X-WEBAUTH-GROUP")) user = user_objects.get_or_create(username=organizr_username, )[0] user.email = organizr_email user.is_staff = False if organizr_group == 0: user.is_superuser = True if organizr_group == 0 or organizr_group == 1: user.is_staff = True user.save() login(request, user) # Run the first time initialization if needed if conreq_config.conreq_initialized is False: # User submitted the first time setup form if request.method == "POST": form = InitializationForm(request.POST) # Create the superuser and set up the database if the form is valid if form.is_valid(): form.save() username = form.cleaned_data.get("username") password = form.cleaned_data.get("password1") user = authenticate(username=username, password=password) user.is_staff = True user.is_admin = True user.is_superuser = True user.save() login(request, user) initialize_conreq(conreq_config, form) return redirect("base:index") # Form data wasn't valid, so return the error codes template = loader.get_template("registration/initialization.html") return HttpResponse(template.render({"form": form}, request)) # User needs to fill out the first time setup template = loader.get_template("registration/initialization.html") return HttpResponse(template.render({}, request)) # If a base URL is set, redirect the user to it if request.path[1:] != BASE_URL: return redirect("/" + BASE_URL) # Render the base return login_required(render)(request, "primary/base.html", generate_context({}))
def __init__(self): # Database values self.conreq_config = ConreqConfig.get_solo() # Connections to Sonarr and Radarr self.__sonarr = SonarrAPI( self.conreq_config.sonarr_url, self.conreq_config.sonarr_api_key ) self.__radarr = RadarrAPI( self.conreq_config.radarr_url, self.conreq_config.radarr_api_key )
def __init__(self): # Database values self.conreq_config = ConreqConfig.get_solo() # Connections to Sonarr and Radarr self.__sonarr = SonarrAPI(self.conreq_config.sonarr_url, self.conreq_config.sonarr_api_key) self.__radarr = RadarrAPI(self.conreq_config.radarr_url, self.conreq_config.radarr_api_key) # Creating a logger (for log files) self.__logger = log.get_logger(__name__)
def __init__(self): # Database values self.conreq_config = ConreqConfig.get_solo() # Connections to Sonarr and Radarr self.__sonarr = SonarrAPI(self.conreq_config.sonarr_url, self.conreq_config.sonarr_api_key) self.__radarr = RadarrAPI(self.conreq_config.radarr_url, self.conreq_config.radarr_api_key) # Algorithm for determining string similarity self.__damerau = Damerau()
def __init__(self, periodic_refresh=False): # Database values self.conreq_config = ConreqConfig.get_solo() # Connections to Sonarr and Radarr self.__sonarr = SonarrAPI(self.conreq_config.sonarr_url, self.conreq_config.sonarr_api_key) self.__radarr = RadarrAPI(self.conreq_config.radarr_url, self.conreq_config.radarr_api_key) # Creating a logger (for log files) self.__logger = log.get_logger(__name__) # Periodically run a task to re-populate the cache every minute if periodic_refresh: Thread(target=self.refresh_content, daemon=True).start()
def obtain_sonarr_parameters( content_discovery, content_manager, tmdb_id=None, tvdb_id=None, ): """Returns the common parameters needed for adding a series to Sonarr.""" conreq_config = ConreqConfig.get_solo() # Attempt to convert TVDB to TMDB if possible if tmdb_id is None: conversion = content_discovery.get_by_tvdb_id(tvdb_id) if conversion.__contains__("tv_results") and conversion["tv_results"]: tmdb_id = conversion["tv_results"][0]["id"] # Determine series type, root directory, and profile ID is_anime = False if tmdb_id is not None: is_anime = content_discovery.is_anime(tmdb_id, "tv") season_folders = conreq_config.sonarr_season_folders all_root_dirs = content_manager.sonarr_root_dirs() # Generate parameters if is_anime: series_type = "Anime" sonarr_root = is_key_value_in_list("id", conreq_config.sonarr_anime_folder, all_root_dirs, return_item=True)["path"] sonarr_profile_id = conreq_config.sonarr_anime_quality_profile else: series_type = "Standard" sonarr_root = is_key_value_in_list("id", conreq_config.sonarr_tv_folder, all_root_dirs, return_item=True)["path"] sonarr_profile_id = conreq_config.sonarr_tv_quality_profile return { "sonarr_profile_id": sonarr_profile_id, "sonarr_root": sonarr_root, "series_type": series_type, "season_folders": season_folders, }
def obtain_sonarr_parameters( content_discovery, content_manager, tmdb_id=None, tvdb_id=None, ): """Returns the common parameters needed for adding a series to Sonarr.""" conreq_config = ConreqConfig.get_solo() # Determine series type, root directory, and profile ID if tmdb_id is None: tmdb_id = content_discovery.get_by_tvdb_id(tvdb_id)["tv_results"]["id"] is_anime = content_discovery.is_anime(tmdb_id, "tv") season_folders = conreq_config.sonarr_season_folders all_root_dirs = content_manager.sonarr_root_dirs() if is_anime: series_type = "Anime" sonarr_root = is_key_value_in_list( "id", conreq_config.sonarr_anime_folder, all_root_dirs, return_item=True )["path"] sonarr_profile_id = conreq_config.sonarr_anime_quality_profile else: series_type = "Standard" sonarr_root = is_key_value_in_list( "id", conreq_config.sonarr_tv_folder, all_root_dirs, return_item=True )["path"] sonarr_profile_id = conreq_config.sonarr_tv_quality_profile return { "sonarr_profile_id": sonarr_profile_id, "sonarr_root": sonarr_root, "series_type": series_type, "season_folders": season_folders, }
def initialization(request): conreq_config = ConreqConfig.get_solo() config_has_changed = False # Ensure API key is configured if not conreq_config.conreq_api_key: conreq_config.conreq_api_key = secrets.token_hex(16) config_has_changed = True # Ensure URL or API key is configured if sonarr is enabled if (not conreq_config.sonarr_url or not conreq_config.sonarr_api_key) and conreq_config.sonarr_enabled: conreq_config.sonarr_enabled = False config_has_changed = True # Ensure URL or API key is configured if radarr is enabled if (not conreq_config.radarr_url or not conreq_config.radarr_api_key) and conreq_config.radarr_enabled: conreq_config.radarr_enabled = False config_has_changed = True # Save the new values if things have changed if config_has_changed: conreq_config.save() # Run the first time initialization if needed if conreq_config.conreq_initialized is False: pass # Display the first run template # template = loader.get_template("initialization/first_run.html") # return HttpResponse(template.render({}, request)) # If a base URL is set, redirect the user to it if request.path[1:] != BASE_URL: return redirect("/" + BASE_URL) return homepage(request)
def server_settings(request): template = loader.get_template("viewport/server_settings.html") # Database values conreq_config = ConreqConfig.get_solo() # Obtain sonarr and radarr information content_manger = ContentManager() sonarr_quality_profiles = [] current_sonarr_anime_quality_profile = "" current_sonarr_tv_quality_profile = "" sonarr_folders = [] current_sonarr_anime_folder = "" current_sonarr_tv_folder = "" radarr_quality_profiles = [] current_radarr_anime_quality_profile = "" current_radarr_movies_quality_profile = "" radarr_folders = [] current_radarr_anime_folder = "" current_radarr_movies_folder = "" if conreq_config.sonarr_enabled: # Sonarr Quality Profiles try: for profile in content_manger.sonarr_quality_profiles(): # Current anime profile if conreq_config.sonarr_anime_quality_profile == profile["id"]: current_sonarr_anime_quality_profile = profile["name"] # Current TV profile if conreq_config.sonarr_tv_quality_profile == profile["id"]: current_sonarr_tv_quality_profile = profile["name"] # List of all dropdown entries sonarr_quality_profiles.append( {"id": profile["id"], "label": profile["name"]} ) except: log.handler( "Failed to obtain Sonarr Quality Profiles!", log.ERROR, __logger ) # Sonarr Folder Paths try: for path in content_manger.sonarr_root_dirs(): # Current anime dirs if conreq_config.sonarr_anime_folder == path["id"]: current_sonarr_anime_folder = path["path"] # Current TV dirs if conreq_config.sonarr_anime_folder == path["id"]: current_sonarr_tv_folder = path["path"] # List of all dropdown entries sonarr_folders.append({"id": path["id"], "label": path["path"]}) except: log.handler("Failed to obtain Sonarr Folder Paths!", log.ERROR, __logger) if conreq_config.radarr_enabled: # Radarr Quality Profiles try: for profile in content_manger.radarr_quality_profiles(): # Current anime movies profile if conreq_config.radarr_anime_quality_profile == profile["id"]: current_radarr_anime_quality_profile = profile["name"] # Current TV profile if conreq_config.radarr_movies_quality_profile == profile["id"]: current_radarr_movies_quality_profile = profile["name"] # List of all dropdown entries radarr_quality_profiles.append( {"id": profile["id"], "label": profile["name"]} ) except: log.handler( "Failed to obtain Radarr Quality Profiles!", log.ERROR, __logger ) # Radarr Folder Paths try: for path in content_manger.radarr_root_dirs(): # Current anime movies dirs if conreq_config.radarr_anime_folder == path["id"]: current_radarr_anime_folder = path["path"] # Current TV dirs if conreq_config.radarr_anime_folder == path["id"]: current_radarr_movies_folder = path["path"] # List of all dropdown entries radarr_folders.append({"id": path["id"], "label": path["path"]}) except: log.handler("Failed to obtain Radarr Folder Paths!", log.ERROR, __logger) context = { "os_platform": platform(), "sonarr_quality_profiles": sonarr_quality_profiles, "current_sonarr_anime_quality_profile": current_sonarr_anime_quality_profile, "current_sonarr_tv_quality_profile": current_sonarr_tv_quality_profile, "sonarr_folders": sonarr_folders, "current_sonarr_anime_folder": current_sonarr_anime_folder, "current_sonarr_tv_folder": current_sonarr_tv_folder, "radarr_quality_profiles": radarr_quality_profiles, "current_radarr_anime_quality_profile": current_radarr_anime_quality_profile, "current_radarr_movies_quality_profile": current_radarr_movies_quality_profile, "radarr_folders": radarr_folders, "current_radarr_anime_folder": current_radarr_anime_folder, "current_radarr_movies_folder": current_radarr_movies_folder, } return HttpResponse(template.render(context, request))
def update_settings(request): if request.method == "POST": response = { "success": True, } message = json.loads(request.body.decode("utf-8")) try: # Database values conreq_config = ConreqConfig.get_solo() # Basic Configuration if message["setting_name"] == "Conreq Application Name": conreq_config.conreq_app_name = message["value"] elif message[ "setting_name"] == "Conreq Application URL/Web Domain": conreq_config.conreq_app_url = message["value"] elif message["setting_name"] == "Conreq API Key": conreq_config.conreq_api_key = secrets.token_hex(16) response["command_name"] = "new conreq api key" response["value"] = conreq_config.conreq_api_key elif message["setting_name"] == "Conreq Language": conreq_config.conreq_language = message["value"] elif message["setting_name"] == "Conreq Custom CSS": conreq_config.conreq_custom_css = message["value"] elif message["setting_name"] == "Conreq Custom JS": conreq_config.conreq_custom_js = message["value"] elif message[ "setting_name"] == "Conreq Automatically Resolve Issues": conreq_config.conreq_auto_resolve_issues = message["value"] elif message[ "setting_name"] == "Conreq Allow Guest Login/Requests": conreq_config.conreq_guest_login = message["value"] elif message[ "setting_name"] == "Conreq Simple/Minimal Poster Cards": conreq_config.conreq_simple_posters = message["value"] elif message["setting_name"] == "Conreq Dark Theme": conreq_config.conreq_dark_theme = message["value"] elif message[ "setting_name"] == "Conreq Organizr User Authentication": conreq_config.conreq_http_header_auth = message["value"] # Sonarr Settings elif message["setting_name"] == "Sonarr URL": conreq_config.sonarr_url = message["value"] elif message["setting_name"] == "Sonarr API Key": conreq_config.sonarr_api_key = message["value"] elif message["setting_name"] == "Sonarr Anime Quality Profile": conreq_config.sonarr_anime_quality_profile = message["value"] elif message["setting_name"] == "Sonarr TV Quality Profile": conreq_config.sonarr_tv_quality_profile = message["value"] elif message["setting_name"] == "Sonarr Anime Folder Path": conreq_config.sonarr_anime_folder = message["value"] elif message["setting_name"] == "Sonarr TV Folder Path": conreq_config.sonarr_tv_folder = message["value"] elif message["setting_name"] == "Enable Sonarr": conreq_config.sonarr_enabled = message["value"] elif message["setting_name"] == "Sonarr Season Folders": conreq_config.sonarr_season_folders = message["value"] # Radarr Settings elif message["setting_name"] == "Radarr URL": conreq_config.radarr_url = message["value"] elif message["setting_name"] == "Radarr API Key": conreq_config.radarr_api_key = message["value"] elif message["setting_name"] == "Radarr Anime Quality Profile": conreq_config.radarr_anime_quality_profile = message["value"] elif message["setting_name"] == "Radarr Movies Quality Profile": conreq_config.radarr_movies_quality_profile = message["value"] elif message["setting_name"] == "Radarr Anime Folder Path": conreq_config.radarr_anime_folder = message["value"] elif message["setting_name"] == "Radarr Movies Folder Path": conreq_config.radarr_movies_folder = message["value"] elif message["setting_name"] == "Enable Radarr": conreq_config.radarr_enabled = message["value"] # Unhandled setting failure else: log.handler( 'Server setting "' + message["setting_name"] + '" is currently not handled!', log.WARNING, _logger, ) response["success"] = False response["error_message"] = "Unhandled server setting!" return JsonResponse(response) # Model fails validation schema try: conreq_config.clean_fields() except ValidationError as error: for field, message in dict(error).items(): response["success"] = False response["error_message"] = field + ": " + message[0] # Send a message to the user return JsonResponse(response) # Save the model if it passes all checks if response["success"]: conreq_config.save() log.handler( message, log.INFO, _logger, ) return JsonResponse(response) # Unknown exception occured except: response["success"] = False response["error_message"] = "Unknown error!" log.handler( "Unknown error has occurred within server websocket!", log.ERROR, _logger, ) return JsonResponse(response) return HttpResponseBadRequest()