Fix Qobuz downloads behavior and network filtering in offline mode
Problem 1: "Show in Local Library" setting was being ignored - Qobuz downloads appeared in library even when setting was disabled - Root cause: Scanner was overwriting Qobuz downloads with INSERT OR REPLACE - This lost the 'source = qobuz_download' marker needed for filtering Problem 2: Network music visible in offline mode - Music from network folders remained visible when offline - User expected network content to be completely hidden offline - Only local disk music should appear Solution 1: Protect Qobuz downloads from scanner - Added is_qobuz_download_by_path() to check if file is already a download - Modified insert_track() to skip files with source = 'qobuz_download' - Now downloads and scanned music coexist as separate "joins" in DB Solution 2: Filter network folders when offline - Added get_network_folder_paths() to get list of network folder paths - Modified library_get_albums to accept excludeNetworkFolders parameter - When offline, filter out albums whose tracks are in network folders - Frontend passes excludeNetworkFolders: isOffline to backend - Added reactive effect to reload library when offline state changes This implements the "join between tables" approach - Qobuz downloads don't interfere with scanned music, and network content is properly hidden when offline without being deleted. Files changed: - src-tauri/src/library/database.rs - src-tauri/src/library/commands.rs - src/lib/components/views/LocalLibraryView.svelte
This commit is contained in:
1 parent
b450accb56
commit
6073cb96c1
3 files changed
+107
-7
No files matched your search
@@ -781,10 +781,11 @@ pub async fn library_scan_folder(
|
||||
#[tauri::command]
|
||||
pub async fn library_get_albums(
|
||||
include_hidden: Option<bool>,
|
||||
exclude_network_folders: Option<bool>,
|
||||
state: State<'_, LibraryState>,
|
||||
download_settings_state: State<'_, crate::config::DownloadSettingsState>,
|
||||
) -> Result<Vec<LocalAlbum>, String> {
|
||||
log::info!("Command: library_get_albums");
|
||||
log::info!("Command: library_get_albums (exclude_network: {:?})", exclude_network_folders);
|
||||
|
||||
// Get download settings to check if we should include Qobuz downloads
|
||||
let include_qobuz = download_settings_state
|
||||
@@ -795,8 +796,43 @@ pub async fn library_get_albums(
|
||||
.unwrap_or(false);
|
||||
|
||||
let db = state.db.lock().await;
|
||||
db.get_albums_with_filter(include_hidden.unwrap_or(false), include_qobuz)
|
||||
.map_err(|e| e.to_string())
|
||||
let mut albums = db.get_albums_with_filter(include_hidden.unwrap_or(false), include_qobuz)
|
||||
.map_err(|e| e.to_string())?;
|
||||
|
||||
// Filter out albums from network folders when in offline mode
|
||||
if exclude_network_folders.unwrap_or(false) {
|
||||
let network_folders = db.get_network_folder_paths()
|
||||
.map_err(|e| e.to_string())?;
|
||||
|
||||
if !network_folders.is_empty() {
|
||||
log::info!("Filtering out albums from {} network folders", network_folders.len());
|
||||
|
||||
// Filter albums whose tracks are from network folders
|
||||
albums.retain(|album| {
|
||||
// Get first track's file path to determine if album is on network
|
||||
if let Ok(tracks) = db.get_album_tracks(&album.id) {
|
||||
if let Some(first_track) = tracks.first() {
|
||||
// Check if track's file_path starts with any network folder path
|
||||
let is_network = network_folders.iter().any(|folder_path| {
|
||||
first_track.file_path.starts_with(folder_path)
|
||||
});
|
||||
|
||||
if is_network {
|
||||
log::debug!("Excluding network album: {} - {}", album.artist, album.title);
|
||||
}
|
||||
|
||||
return !is_network;
|
||||
}
|
||||
}
|
||||
// If we can't determine, keep it
|
||||
true
|
||||
});
|
||||
|
||||
log::info!("Filtered to {} albums after excluding network folders", albums.len());
|
||||
}
|
||||
}
|
||||
|
||||
Ok(albums)
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
|
||||
@@ -559,6 +559,24 @@ impl LibraryDatabase {
|
||||
Ok(folders)
|
||||
}
|
||||
|
||||
/// Get paths of all network folders (for offline filtering)
|
||||
pub fn get_network_folder_paths(&self) -> Result<Vec<String>, LibraryError> {
|
||||
let mut stmt = self
|
||||
.conn
|
||||
.prepare("SELECT path FROM library_folders WHERE is_network = 1")
|
||||
.map_err(|e| LibraryError::Database(e.to_string()))?;
|
||||
|
||||
let rows = stmt
|
||||
.query_map([], |row| row.get(0))
|
||||
.map_err(|e| LibraryError::Database(e.to_string()))?;
|
||||
|
||||
let mut folders = Vec::new();
|
||||
for path in rows {
|
||||
folders.push(path.map_err(|e| LibraryError::Database(e.to_string()))?);
|
||||
}
|
||||
Ok(folders)
|
||||
}
|
||||
|
||||
/// Get all library folders with full metadata
|
||||
pub fn get_folders_with_metadata(&self) -> Result<Vec<LibraryFolder>, LibraryError> {
|
||||
let mut stmt = self
|
||||
@@ -689,8 +707,34 @@ impl LibraryDatabase {
|
||||
|
||||
// === Track Management ===
|
||||
|
||||
/// Insert or update a track
|
||||
/// Check if a file path is already registered as a Qobuz download
|
||||
/// Returns true if the file exists with source = 'qobuz_download'
|
||||
pub fn is_qobuz_download_by_path(&self, file_path: &str) -> Result<bool, LibraryError> {
|
||||
let count: i64 = self.conn
|
||||
.query_row(
|
||||
"SELECT COUNT(*) FROM local_tracks WHERE file_path = ?1 AND source = 'qobuz_download'",
|
||||
params![file_path],
|
||||
|row| row.get(0)
|
||||
)
|
||||
.map_err(|e| LibraryError::Database(e.to_string()))?;
|
||||
Ok(count > 0)
|
||||
}
|
||||
|
||||
/// Insert or update a track (skips if file is already a Qobuz download)
|
||||
pub fn insert_track(&self, track: &LocalTrack) -> Result<i64, LibraryError> {
|
||||
// Don't overwrite Qobuz downloads with scanned data
|
||||
if self.is_qobuz_download_by_path(&track.file_path)? {
|
||||
log::debug!("Skipping track insert - already exists as Qobuz download: {}", track.file_path);
|
||||
// Return the existing ID
|
||||
return self.conn
|
||||
.query_row(
|
||||
"SELECT id FROM local_tracks WHERE file_path = ?1",
|
||||
params![track.file_path],
|
||||
|row| row.get(0)
|
||||
)
|
||||
.map_err(|e| LibraryError::Database(e.to_string()));
|
||||
}
|
||||
|
||||
self.conn
|
||||
.execute(
|
||||
r#"INSERT OR REPLACE INTO local_tracks
|
||||
|
||||
Reference in new issue
Block a user