From 970dcaa04f3c4bda473674f7e7bb2d2d87ab13e8 Mon Sep 17 00:00:00 2001 From: Profpatsch Date: Sat, 14 Sep 2024 15:56:54 +0200 Subject: fix(users/Profpatsch/lyrics): remove special chars from search Leaving out any symbol characters improves the search accuracy. Change-Id: I00c993d4099bb8e9701783b53afc9423f1b2f674 Reviewed-on: https://cl.tvl.fyi/c/depot/+/12480 Reviewed-by: Profpatsch Tested-by: BuildkiteCI --- users/Profpatsch/lyric/lyric-mpv-script.lua | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'users/Profpatsch/lyric/lyric-mpv-script.lua') diff --git a/users/Profpatsch/lyric/lyric-mpv-script.lua b/users/Profpatsch/lyric/lyric-mpv-script.lua index e492bf687140..ba05c7c449f6 100644 --- a/users/Profpatsch/lyric/lyric-mpv-script.lua +++ b/users/Profpatsch/lyric/lyric-mpv-script.lua @@ -1,5 +1,11 @@ -- get_lrc_subtitles.lua +-- Function to remove Unicode symbol characters +function remove_symbols(str) + -- This pattern matches anything that is not a letter, digit, or whitespace + return str:gsub("[%p%c%z]", "") -- remove punctuation, control, and zero-width characters +end + -- Asynchronous callback function to handle the result of the 'get_subtitles' command function handle_subtitle_result(success, result) if not success or result.status ~= 0 then @@ -41,6 +47,9 @@ function load_lrc_subtitles() -- Concatenate the metadata local query = string.format("%s %s %s", artist, album, title) + -- Remove Unicode symbols from the query string + query = remove_symbols(query) + -- Create the command array local cmd = {"@get_subtitles_command@", query} -- cgit 1.4.1