Add FLAC bit depth fallback option to quality profile

This commit is contained in:
Broque Thomas 2026-03-14 19:24:25 -07:00
parent 4a73ef6d24
commit 9a22c49a0e
3 changed files with 51 additions and 6 deletions

View file

@ -15062,6 +15062,7 @@ def _check_flac_bit_depth(file_path, context, context_key):
"""
Check if a FLAC file matches the user's preferred bit depth.
Returns True if the file was rejected (caller should return), False if OK.
With fallback enabled (default), accepts any FLAC bit depth rather than quarantining.
"""
if not context.get('_audio_quality', '').startswith('FLAC'):
return False
@ -15069,7 +15070,8 @@ def _check_flac_bit_depth(file_path, context, context_key):
from database.music_database import MusicDatabase
_qp_db = MusicDatabase()
_quality_profile = _qp_db.get_quality_profile()
_flac_pref = _quality_profile.get('qualities', {}).get('flac', {}).get('bit_depth', 'any')
_flac_config = _quality_profile.get('qualities', {}).get('flac', {})
_flac_pref = _flac_config.get('bit_depth', 'any')
if _flac_pref == 'any':
return False
@ -15079,7 +15081,17 @@ def _check_flac_bit_depth(file_path, context, context_key):
if _actual_bits == _flac_pref:
return False
# Reject — same pattern as AcoustID verification failure
# Bit depth doesn't match preference — check if fallback is enabled
_flac_fallback = _flac_config.get('bit_depth_fallback', True)
if _flac_fallback:
# Accept the file — a FLAC at any bit depth is better than a failed download
track_info = context.get('track_info', {})
track_name = track_info.get('name', os.path.basename(file_path))
print(f"📀 [FLAC Fallback] Accepted {_actual_bits}-bit FLAC (preferred {_flac_pref}-bit): {track_name}")
return False
# Strict mode — reject and quarantine
rejection_msg = f"FLAC bit depth mismatch: file is {_actual_bits}-bit, preference is {_flac_pref}-bit"
try:
quarantine_path = _move_to_quarantine(file_path, context, rejection_msg)

View file

@ -4014,8 +4014,14 @@
<button class="bit-depth-btn" data-value="16" onclick="setFlacBitDepth('16')">16-bit</button>
<button class="bit-depth-btn" data-value="24" onclick="setFlacBitDepth('24')">24-bit</button>
</div>
<div style="color: #888; font-size: 0.75em; margin-top: 4px;">
Rejects FLAC files that don't match the selected bit depth
<div class="flac-fallback-toggle" id="flac-fallback-toggle" style="display: none; margin-top: 6px;">
<label style="display: flex; align-items: center; gap: 6px; cursor: pointer; font-size: 0.8em; color: #ccc;">
<input type="checkbox" id="flac-bit-depth-fallback" checked onchange="setFlacBitDepthFallback(this.checked)">
Accept other bit depths as fallback
</label>
<div style="color: #888; font-size: 0.75em; margin-top: 2px;">
When enabled, accepts any FLAC rather than rejecting on bit depth mismatch
</div>
</div>
</div>
</div>

View file

@ -4943,7 +4943,7 @@ function populateQualityProfileUI(profile) {
}
}
// FLAC-specific: restore bit depth selector
// FLAC-specific: restore bit depth selector and fallback toggle
if (quality === 'flac') {
const bitDepthValue = config.bit_depth || 'any';
document.querySelectorAll('.bit-depth-btn').forEach(btn => {
@ -4957,6 +4957,15 @@ function populateQualityProfileUI(profile) {
bitDepthSelector.classList.add('disabled');
}
}
// Show/hide and restore fallback toggle
const fallbackToggle = document.getElementById('flac-fallback-toggle');
if (fallbackToggle) {
fallbackToggle.style.display = bitDepthValue === 'any' ? 'none' : 'block';
}
const fallbackCb = document.getElementById('flac-bit-depth-fallback');
if (fallbackCb) {
fallbackCb.checked = config.bit_depth_fallback !== false;
}
}
}
});
@ -5033,6 +5042,12 @@ function setFlacBitDepth(value) {
btn.classList.toggle('active', btn.getAttribute('data-value') === value);
});
// Show/hide fallback toggle — only relevant when a specific bit depth is selected
const fallbackToggle = document.getElementById('flac-fallback-toggle');
if (fallbackToggle) {
fallbackToggle.style.display = value === 'any' ? 'none' : 'block';
}
// Mark preset as custom when manually changing
if (currentQualityProfile) {
currentQualityProfile.preset = 'custom';
@ -5044,6 +5059,16 @@ function setFlacBitDepth(value) {
debouncedAutoSaveSettings();
}
function setFlacBitDepthFallback(enabled) {
if (currentQualityProfile) {
currentQualityProfile.preset = 'custom';
document.querySelectorAll('.preset-button').forEach(btn => {
btn.classList.remove('active');
});
}
debouncedAutoSaveSettings();
}
async function applyQualityPreset(presetName) {
try {
showLoadingOverlay(`Applying ${presetName} preset...`);
@ -5094,10 +5119,12 @@ function collectQualityProfileFromUI() {
priority: existingPriority
};
// Add FLAC-specific bit_depth setting
// Add FLAC-specific bit_depth and fallback settings
if (quality === 'flac') {
const activeBtn = document.querySelector('.bit-depth-btn.active');
profile.qualities[quality].bit_depth = activeBtn ? activeBtn.getAttribute('data-value') : 'any';
const fallbackCb = document.getElementById('flac-bit-depth-fallback');
profile.qualities[quality].bit_depth_fallback = fallbackCb ? fallbackCb.checked : true;
}
});