Commit 62ce5206 authored by Antoine Cellerier's avatar Antoine Cellerier

Add a third query with fuzzy search enabled for every word. (We could also add...

Add a third query with fuzzy search enabled for every word. (We could also add other searches with lower fuzzyness if the first try fails)
parent ffd70ceb
......@@ -45,6 +45,12 @@ function try_query(query)
end
end
function fuzzy(query)
-- http://musicbrainz.org/doc/TextSearchSyntax#Fuzzy_searches
-- we could even tweak the fuzziness
return string.gsub(query, "([^%s]+)", "%1~")
end
-- Return the artwork
function fetch_art()
local meta = vlc.item:metas()
......@@ -53,6 +59,7 @@ function fetch_art()
end
local query1 = "http://musicbrainz.org/ws/1/release/?type=xml&artist="..vlc.strings.encode_uri_component(meta["artist"]).."&title="..vlc.strings.encode_uri_component(meta["album"])
local query2 = "http://musicbrainz.org/ws/1/release/?type=xml&query=artist:"..vlc.strings.encode_uri_component(meta["artist"]).." AND "..vlc.strings.encode_uri_component(meta["album"])
return try_query(query1) or try_query(query2)
local query2 = "http://musicbrainz.org/ws/1/release/?type=xml&query="..vlc.strings.encode_uri_component(meta["album"].." AND ".."artist:"..meta["artist"])
local query3 = "http://musicbrainz.org/ws/1/release/?type=xml&query="..vlc.strings.encode_uri_component(fuzzy(meta["album"]).." AND ".."artist:"..fuzzy(meta["artist"]))
return try_query(query1) or try_query(query2) or try_query(query3)
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment