From 79d58d13bba060af64c63a4960f2019e5e3a4c7c Mon Sep 17 00:00:00 2001 From: Admin9705 <9705@duck.com> Date: Tue, 8 Apr 2025 13:54:06 -0400 Subject: [PATCH 1/5] update --- main.py | 3 +++ web_server.py | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/main.py b/main.py index 739898e5..37818043 100644 --- a/main.py +++ b/main.py @@ -83,6 +83,9 @@ def main_loop() -> None: # Calculate time until the next reset calculate_reset_time() + # Refresh settings before sleep to get the latest sleep_duration + refresh_settings() + # Sleep at the end of the cycle only logger.info(f"Cycle complete. Sleeping {SLEEP_DURATION}s before next cycle...") logger.info("⭐ Tool Great? Donate @ https://donate.plex.one for Daughter's College Fund!") diff --git a/web_server.py b/web_server.py index 53663268..5a8e6908 100644 --- a/web_server.py +++ b/web_server.py @@ -89,7 +89,7 @@ def update_settings(): if "huntarr" in data: old_settings = settings_manager.get_setting("huntarr", None, {}) for key, value in data["huntarr"].items(): - old_value = old_settings.get(key, None) + old_value = old_settings.get(key, "Default") # Use "Default" instead of None for display if old_value != value: changes_log.append(f"Changed {key} from {old_value} to {value}") settings_manager.update_setting("huntarr", key, value) @@ -98,7 +98,7 @@ def update_settings(): if "ui" in data: old_settings = settings_manager.get_setting("ui", None, {}) for key, value in data["ui"].items(): - old_value = old_settings.get(key, None) + old_value = old_settings.get(key, "Default") # Use "Default" instead of None for display if old_value != value: changes_log.append(f"Changed UI.{key} from {old_value} to {value}") settings_manager.update_setting("ui", key, value) From 0b4a16f6001a0ce9ef51acf98fe4a0a1eb93af86 Mon Sep 17 00:00:00 2001 From: Admin9705 <9705@duck.com> Date: Tue, 8 Apr 2025 13:57:14 -0400 Subject: [PATCH 2/5] update --- LICENSE | 2 +- README.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/LICENSE b/LICENSE index f288702d..b01123cb 100644 --- a/LICENSE +++ b/LICENSE @@ -1,5 +1,5 @@ GNU GENERAL PUBLIC LICENSE - Version 3, 29 June 2007 + Version 3, 29 June 2007 Copyright (C) 2007 Free Software Foundation, Inc. Everyone is permitted to copy and distribute verbatim copies diff --git a/README.md b/README.md index 6a66abf9..0c8f7ced 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Huntarr [Sonarr Edition] - Force Sonarr to Hunt Missing Shows & Upgrade Episode Qualities -

Want to Help? Click the Star in the Upper-Right Corner! ⭐

+

Want to Help? Click the Star in the Upper-Right Corner! ⭐

From 9e9b2706d65a4da5e2733590e3c2024f873e461e Mon Sep 17 00:00:00 2001 From: Admin9705 <9705@duck.com> Date: Tue, 8 Apr 2025 14:11:10 -0400 Subject: [PATCH 3/5] updates --- config.py | 28 +++++++++++++-------- main.py | 6 +++-- static/css/style.css | 5 ++++ static/js/main.js | 59 ++++++++++++++------------------------------ templates/index.html | 11 +++++++-- 5 files changed, 54 insertions(+), 55 deletions(-) diff --git a/config.py b/config.py index 3a3067dd..f2748576 100644 --- a/config.py +++ b/config.py @@ -88,22 +88,30 @@ # Debug Settings DEBUG_MODE = os.environ.get("DEBUG_MODE", "false").lower() == "true" -# Override settings from settings manager if they exist def refresh_settings(): """Refresh configuration settings from the settings manager.""" global HUNT_MISSING_SHOWS, HUNT_UPGRADE_EPISODES, SLEEP_DURATION global STATE_RESET_INTERVAL_HOURS, MONITORED_ONLY, RANDOM_SELECTION global SKIP_FUTURE_EPISODES, SKIP_SERIES_REFRESH - # Load settings from settings manager - HUNT_MISSING_SHOWS = settings_manager.get_setting("huntarr", "hunt_missing_shows", HUNT_MISSING_SHOWS) - HUNT_UPGRADE_EPISODES = settings_manager.get_setting("huntarr", "hunt_upgrade_episodes", HUNT_UPGRADE_EPISODES) - SLEEP_DURATION = settings_manager.get_setting("huntarr", "sleep_duration", SLEEP_DURATION) - STATE_RESET_INTERVAL_HOURS = settings_manager.get_setting("huntarr", "state_reset_interval_hours", STATE_RESET_INTERVAL_HOURS) - MONITORED_ONLY = settings_manager.get_setting("huntarr", "monitored_only", MONITORED_ONLY) - RANDOM_SELECTION = settings_manager.get_setting("huntarr", "random_selection", RANDOM_SELECTION) - SKIP_FUTURE_EPISODES = settings_manager.get_setting("huntarr", "skip_future_episodes", SKIP_FUTURE_EPISODES) - SKIP_SERIES_REFRESH = settings_manager.get_setting("huntarr", "skip_series_refresh", SKIP_SERIES_REFRESH) + # Load settings directly from settings manager + settings = settings_manager.get_all_settings() + huntarr_settings = settings.get("huntarr", {}) + + # Update global variables with fresh values + HUNT_MISSING_SHOWS = huntarr_settings.get("hunt_missing_shows", HUNT_MISSING_SHOWS) + HUNT_UPGRADE_EPISODES = huntarr_settings.get("hunt_upgrade_episodes", HUNT_UPGRADE_EPISODES) + SLEEP_DURATION = huntarr_settings.get("sleep_duration", SLEEP_DURATION) + STATE_RESET_INTERVAL_HOURS = huntarr_settings.get("state_reset_interval_hours", STATE_RESET_INTERVAL_HOURS) + MONITORED_ONLY = huntarr_settings.get("monitored_only", MONITORED_ONLY) + RANDOM_SELECTION = huntarr_settings.get("random_selection", RANDOM_SELECTION) + SKIP_FUTURE_EPISODES = huntarr_settings.get("skip_future_episodes", SKIP_FUTURE_EPISODES) + SKIP_SERIES_REFRESH = huntarr_settings.get("skip_series_refresh", SKIP_SERIES_REFRESH) + + # Log the refresh for debugging + import logging + logger = logging.getLogger("huntarr-sonarr") + logger.debug(f"Settings refreshed: SLEEP_DURATION={SLEEP_DURATION}, HUNT_MISSING_SHOWS={HUNT_MISSING_SHOWS}") def log_configuration(logger): """Log the current configuration settings""" diff --git a/main.py b/main.py index 37818043..e7229b5b 100644 --- a/main.py +++ b/main.py @@ -85,9 +85,11 @@ def main_loop() -> None: # Refresh settings before sleep to get the latest sleep_duration refresh_settings() + # Import it directly from the settings manager to ensure latest value + from config import SLEEP_DURATION as CURRENT_SLEEP_DURATION # Sleep at the end of the cycle only - logger.info(f"Cycle complete. Sleeping {SLEEP_DURATION}s before next cycle...") + logger.info(f"Cycle complete. Sleeping {CURRENT_SLEEP_DURATION}s before next cycle...") logger.info("⭐ Tool Great? Donate @ https://donate.plex.one for Daughter's College Fund!") # Log web UI information if enabled @@ -97,7 +99,7 @@ def main_loop() -> None: # Sleep with progress updates for the web interface sleep_start = time.time() - sleep_end = sleep_start + SLEEP_DURATION + sleep_end = sleep_start + CURRENT_SLEEP_DURATION while time.time() < sleep_end: # Sleep in smaller chunks for more responsive shutdown diff --git a/static/css/style.css b/static/css/style.css index 09be8c41..5c76db5c 100644 --- a/static/css/style.css +++ b/static/css/style.css @@ -382,6 +382,11 @@ input:checked + .slider:before { justify-content: flex-end; } +.top-buttons { + margin-bottom: 20px; + margin-top: 10px; +} + .save-button { background-color: var(--save-button-bg); color: white; diff --git a/static/js/main.js b/static/js/main.js index e1b52b7e..0e2aa2d3 100644 --- a/static/js/main.js +++ b/static/js/main.js @@ -21,8 +21,12 @@ document.addEventListener('DOMContentLoaded', function() { const randomSelectionInput = document.getElementById('random_selection'); const skipFutureEpisodesInput = document.getElementById('skip_future_episodes'); const skipSeriesRefreshInput = document.getElementById('skip_series_refresh'); + + // Button elements for saving and resetting settings const saveSettingsButton = document.getElementById('saveSettings'); const resetSettingsButton = document.getElementById('resetSettings'); + const saveSettingsBottomButton = document.getElementById('saveSettingsBottom'); + const resetSettingsBottomButton = document.getElementById('resetSettingsBottom'); // Update sleep duration display function updateSleepDurationDisplay() { @@ -135,8 +139,8 @@ document.addEventListener('DOMContentLoaded', function() { .catch(error => console.error('Error loading settings:', error)); } - // Save settings to API - saveSettingsButton.addEventListener('click', function() { + // Function to save settings + function saveSettings() { const settings = { huntarr: { hunt_missing_shows: parseInt(huntMissingShowsInput.value) || 0, @@ -169,10 +173,10 @@ document.addEventListener('DOMContentLoaded', function() { console.error('Error saving settings:', error); alert('Error saving settings: ' + error.message); }); - }); + } - // Reset settings to defaults - resetSettingsButton.addEventListener('click', function() { + // Function to reset settings + function resetSettings() { if (confirm('Are you sure you want to reset all settings to default values?')) { fetch('/api/settings/reset', { method: 'POST' @@ -191,7 +195,14 @@ document.addEventListener('DOMContentLoaded', function() { alert('Error resetting settings: ' + error.message); }); } - }); + } + + // Add event listeners to both button sets + saveSettingsButton.addEventListener('click', saveSettings); + resetSettingsButton.addEventListener('click', resetSettings); + + saveSettingsBottomButton.addEventListener('click', saveSettings); + resetSettingsBottomButton.addEventListener('click', resetSettings); // Event source for logs let eventSource; @@ -226,38 +237,4 @@ document.addEventListener('DOMContentLoaded', function() { } else if (event.data.includes(' - WARNING - ')) { logEntry.classList.add('log-warning'); } else if (event.data.includes(' - ERROR - ')) { - logEntry.classList.add('log-error'); - } else if (event.data.includes(' - DEBUG - ')) { - logEntry.classList.add('log-debug'); - } - - logEntry.textContent = event.data; - logsElement.appendChild(logEntry); - - // Auto-scroll to bottom if enabled - scrollToBottom(); - }; - } - - // Observe scroll event to detect manual scrolling - logsElement.addEventListener('scroll', function() { - // If we're at the bottom or near it (within 20px), ensure auto-scroll stays on - const atBottom = (logsElement.scrollHeight - logsElement.scrollTop - logsElement.clientHeight) < 20; - if (!atBottom && autoScrollCheckbox.checked) { - // User manually scrolled up, disable auto-scroll - autoScrollCheckbox.checked = false; - } - }); - - // Re-enable auto-scroll when checkbox is checked - autoScrollCheckbox.addEventListener('change', function() { - if (this.checked) { - scrollToBottom(); - } - }); - - // Initialize - loadTheme(); - updateSleepDurationDisplay(); - connectEventSource(); -}); \ No newline at end of file + logEntry.classList.ad \ No newline at end of file diff --git a/templates/index.html b/templates/index.html index e8c790b2..60aaabbf 100644 --- a/templates/index.html +++ b/templates/index.html @@ -43,6 +43,13 @@