about summary refs log tree commit diff
path: root/users/Profpatsch/lyric/lyric-mpv-script.lua
diff options
context:
space:
mode:
authorProfpatsch <mail@profpatsch.de>2024-09-14T13·56+0200
committerProfpatsch <mail@profpatsch.de>2024-10-05T13·49+0000
commit970dcaa04f3c4bda473674f7e7bb2d2d87ab13e8 (patch)
tree43ef26ec7499a67294f92ce9c0d0b1b64239a2c7 /users/Profpatsch/lyric/lyric-mpv-script.lua
parentffdcb3bb5e8d7689254c82260a29f5d6b2a09281 (diff)
fix(users/Profpatsch/lyrics): remove special chars from search r/8758
Leaving out any symbol characters improves the search accuracy.

Change-Id: I00c993d4099bb8e9701783b53afc9423f1b2f674
Reviewed-on: https://cl.tvl.fyi/c/depot/+/12480
Reviewed-by: Profpatsch <mail@profpatsch.de>
Tested-by: BuildkiteCI
Diffstat (limited to 'users/Profpatsch/lyric/lyric-mpv-script.lua')
-rw-r--r--users/Profpatsch/lyric/lyric-mpv-script.lua9
1 files changed, 9 insertions, 0 deletions
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}