From 8a620bc6cc45b61c4637129fc393121ce340046a Mon Sep 17 00:00:00 2001 From: sceriz Date: Sat, 25 Apr 2026 04:46:46 +0300 Subject: [PATCH 1/2] Check file existence before searching for lyrics --- src/lyric_search.cpp | 8 +++++--- src/tag_util.cpp | 26 ++++++++++++++++++++++---- src/tag_util.h | 3 ++- 3 files changed, 29 insertions(+), 8 deletions(-) diff --git a/src/lyric_search.cpp b/src/lyric_search.cpp index dbe6942f..34858f96 100644 --- a/src/lyric_search.cpp +++ b/src/lyric_search.cpp @@ -190,13 +190,15 @@ void LyricAutosearchManager::on_playback_new_track(metadb_handle_ptr track) const bool search_postponed_for_dynamic_info = track_is_remote( track); // If this is an internet radio then don't search until we get dynamic track info - const bool should_search = track_changed && !search_postponed_for_dynamic_info; + const bool file_exists = track_file_exists(track); + const bool should_search = track_changed && !search_postponed_for_dynamic_info && file_exists; if(!should_search) { - LOG_INFO("Skipping new-playback search. %s, %s", + LOG_INFO("Skipping new-playback search. %s, %s, %s", track_changed ? "The track has changed" : "The track didn't change", search_postponed_for_dynamic_info ? "the search is being postponed waiting for dynamic info" - : "we're not waiting for dynamic track info"); + : "we're not waiting for dynamic track info", + file_exists ? "the track file exists" : "the track file does not exist"); return; } diff --git a/src/tag_util.cpp b/src/tag_util.cpp index 34d0af39..10d5ba4d 100644 --- a/src/tag_util.cpp +++ b/src/tag_util.cpp @@ -251,10 +251,28 @@ bool track_is_remote(metadb_handle_ptr track) const bool is_remote = std::string_view(playloc_str).find("http") == 0; return is_remote; -#endif -} - -bool starts_with_ignore_case(std::string_view input, std::string_view prefix) +#endif +} + +bool track_file_exists(metadb_handle_ptr track) +{ + if(track_is_remote(track)) + { + return true; // Remote tracks don't have local files to check + } + + try + { + const char* path = track->get_path(); + return filesystem::g_exists(path, fb2k::noAbort); + } + catch(const std::exception&) + { + return false; + } +} + +bool starts_with_ignore_case(std::string_view input, std::string_view prefix) { if(input.length() < prefix.length()) { diff --git a/src/tag_util.h b/src/tag_util.h index fdb79f73..5f9115f1 100644 --- a/src/tag_util.h +++ b/src/tag_util.h @@ -19,4 +19,5 @@ bool tag_values_match(std::string_view tagA, std::string_view tagB); std::optional track_duration_in_seconds(const metadb_v2_rec_t& track); -bool track_is_remote(metadb_handle_ptr track); +bool track_is_remote(metadb_handle_ptr track); +bool track_file_exists(metadb_handle_ptr track); From 9323745dd6b51e3072f8dc09fab89391329ced2d Mon Sep 17 00:00:00 2001 From: sceriz Date: Fri, 1 May 2026 04:11:03 +0300 Subject: [PATCH 2/2] Add changelog entry and refactor local file checks --- src/lyric_search.cpp | 8 +++++--- src/main.cpp | 3 +++ src/tag_util.cpp | 39 +++++++++++++++++---------------------- src/tag_util.h | 4 ++-- 4 files changed, 27 insertions(+), 27 deletions(-) diff --git a/src/lyric_search.cpp b/src/lyric_search.cpp index 34858f96..88620d64 100644 --- a/src/lyric_search.cpp +++ b/src/lyric_search.cpp @@ -190,15 +190,17 @@ void LyricAutosearchManager::on_playback_new_track(metadb_handle_ptr track) const bool search_postponed_for_dynamic_info = track_is_remote( track); // If this is an internet radio then don't search until we get dynamic track info - const bool file_exists = track_file_exists(track); - const bool should_search = track_changed && !search_postponed_for_dynamic_info && file_exists; + const bool search_skipped_for_missing_local_file = !search_postponed_for_dynamic_info && !track_exists_on_filesystem( + track); // Skip search for missing local files as it can create lyric files and directories for missing paths + const bool should_search = track_changed && !search_postponed_for_dynamic_info && !search_skipped_for_missing_local_file; if(!should_search) { LOG_INFO("Skipping new-playback search. %s, %s, %s", track_changed ? "The track has changed" : "The track didn't change", search_postponed_for_dynamic_info ? "the search is being postponed waiting for dynamic info" : "we're not waiting for dynamic track info", - file_exists ? "the track file exists" : "the track file does not exist"); + search_skipped_for_missing_local_file ? "the search is being skipped due to a missing local file" + : "the search is not being skipped due to a missing local file"); return; } diff --git a/src/main.cpp b/src/main.cpp index af8b0173..5bf9f7c4 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -26,6 +26,9 @@ namespace out += "\nChangelog:\n"; // out += "Version " OPENLYRICS_VERSION " (" __DATE__ "):\n" // "\n"; + out += "Version " OPENLYRICS_VERSION " (" __DATE__ "):\n" + "- Fix auto-search triggering for missing local files\n" + "\n"; out += "Version 1.13 (2026-01-17):\n" "- Enable searching local sources with no visible panels by default\n" "- Add some clarifying help to the 'Exclude trailing brackets' search option\n" diff --git a/src/tag_util.cpp b/src/tag_util.cpp index 10d5ba4d..6bac04d4 100644 --- a/src/tag_util.cpp +++ b/src/tag_util.cpp @@ -251,28 +251,23 @@ bool track_is_remote(metadb_handle_ptr track) const bool is_remote = std::string_view(playloc_str).find("http") == 0; return is_remote; -#endif -} - -bool track_file_exists(metadb_handle_ptr track) -{ - if(track_is_remote(track)) - { - return true; // Remote tracks don't have local files to check - } - - try - { - const char* path = track->get_path(); - return filesystem::g_exists(path, fb2k::noAbort); - } - catch(const std::exception&) - { - return false; - } -} - -bool starts_with_ignore_case(std::string_view input, std::string_view prefix) +#endif +} + +bool track_exists_on_filesystem(metadb_handle_ptr track) +{ + try + { + const char* path = track->get_path(); + return filesystem::g_exists(path, fb2k::noAbort); + } + catch(const std::exception&) + { + return false; + } +} + +bool starts_with_ignore_case(std::string_view input, std::string_view prefix) { if(input.length() < prefix.length()) { diff --git a/src/tag_util.h b/src/tag_util.h index 5f9115f1..9637fe32 100644 --- a/src/tag_util.h +++ b/src/tag_util.h @@ -19,5 +19,5 @@ bool tag_values_match(std::string_view tagA, std::string_view tagB); std::optional track_duration_in_seconds(const metadb_v2_rec_t& track); -bool track_is_remote(metadb_handle_ptr track); -bool track_file_exists(metadb_handle_ptr track); +bool track_is_remote(metadb_handle_ptr track); +bool track_exists_on_filesystem(metadb_handle_ptr track);