Skip to content
Merged

Dev #51

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -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. <https://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Huntarr [Sonarr Edition] - Force Sonarr to Hunt Missing Shows & Upgrade Episode Qualities

<h2 align="center">Want to Help? Click the Star in the Upper-Right Corner! ⭐</h2>
<h2 align="center">Want to Help? Click the Star in the Upper-Right Corner! ⭐</h2>

<table>
<tr>
Expand Down
28 changes: 18 additions & 10 deletions config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""
Expand Down
9 changes: 7 additions & 2 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,13 @@ 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()
# 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
Expand All @@ -94,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
Expand Down
5 changes: 5 additions & 0 deletions static/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
23 changes: 17 additions & 6 deletions static/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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'
Expand All @@ -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;
Expand Down
11 changes: 9 additions & 2 deletions templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@ <h1><a href="https://github.com/plexguide/huntarr-sonarr" target="_blank" class=
<div id="settingsContainer" class="content-section" style="display: none;">
<div class="settings-form">
<h2>Huntarr Settings</h2>

<!-- Add buttons here near the top -->
<div class="settings-buttons top-buttons">
<button id="saveSettings" class="save-button">Save Settings</button>
<button id="resetSettings" class="reset-button">Reset to Defaults</button>
</div>

<div class="settings-group">
<h3>Hunt Settings</h3>
<div class="setting-item">
Expand Down Expand Up @@ -111,8 +118,8 @@ <h3>Processing Options</h3>
</div>

<div class="settings-buttons">
<button id="saveSettings" class="save-button">Save Settings</button>
<button id="resetSettings" class="reset-button">Reset to Defaults</button>
<button id="saveSettingsBottom" class="save-button">Save Settings</button>
<button id="resetSettingsBottom" class="reset-button">Reset to Defaults</button>
</div>
</div>
</div>
Expand Down
4 changes: 2 additions & 2 deletions web_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down