Commit 5661954c authored by Ilkka Ollakka's avatar Ilkka Ollakka

lua: fix fuzzy musicbrainz search and use " " around title/artists

parent 03b67fa4
...@@ -38,20 +38,15 @@ function try_query(query) ...@@ -38,20 +38,15 @@ function try_query(query)
local page = s:read( 65653 ) local page = s:read( 65653 )
-- FIXME: multiple results may be available -- FIXME: multiple results may be available
_,_,asin = string.find( page, "<asin>(.-)</asin>" ) asin = string.find( page, "<asin>(%w+)</asin>" )
if asin then if asin then
vlc.msg.dbg( asin )
return "http://images.amazon.com/images/P/"..asin..".01._SCLZZZZZZZ_.jpg" return "http://images.amazon.com/images/P/"..asin..".01._SCLZZZZZZZ_.jpg"
else else
return nil return nil
end end
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 -- Return the artwork
function fetch_art() function fetch_art()
local meta = vlc.item:metas() local meta = vlc.item:metas()
...@@ -59,8 +54,8 @@ function fetch_art() ...@@ -59,8 +54,8 @@ function fetch_art()
return nil return nil
end 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 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="..vlc.strings.encode_uri_component(meta["album"].." AND ".."artist:"..meta["artist"]) 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"])) local query3 = "http://musicbrainz.org/ws/1/release/?type=xml&query=\""..vlc.strings.encode_uri_component(meta["album"].."\"~ AND ".."artist:"..meta["artist"].."~")
return try_query(query1) or try_query(query2) or try_query(query3) return try_query(query1) or try_query(query2) or try_query(query3)
end 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