Commit c559cc48 authored by Ilkka Ollakka's avatar Ilkka Ollakka

lua art: don't try too much to find some art

Move googleimage search first, and enable it again but don't use eg filename in search query.
Move musicbrainz after last.fm, and don't try more than one way to find art, also do query once in 2 sec

If you get bad hits from googleimage album-art, please report them to me.
parent 7bf3ee3c
...@@ -217,10 +217,10 @@ nobase_vlclib_DATA = \ ...@@ -217,10 +217,10 @@ nobase_vlclib_DATA = \
lua/intf/modules/host.luac \ lua/intf/modules/host.luac \
lua/intf/rc.luac \ lua/intf/rc.luac \
lua/intf/telnet.luac \ lua/intf/telnet.luac \
lua/meta/art/01_musicbrainz.luac \ lua/meta/art/04_musicbrainz.luac \
lua/meta/art/02_frenchtv.luac \ lua/meta/art/02_frenchtv.luac \
lua/meta/art/03_lastfm.luac \ lua/meta/art/03_lastfm.luac \
lua/meta/art/10_googleimage.luac \ lua/meta/art/01_googleimage.luac \
lua/meta/fetcher/tvrage.luac \ lua/meta/fetcher/tvrage.luac \
lua/meta/reader/filename.luac \ lua/meta/reader/filename.luac \
lua/modules/sandbox.luac \ lua/modules/sandbox.luac \
...@@ -280,10 +280,10 @@ EXTRA_DIST += \ ...@@ -280,10 +280,10 @@ EXTRA_DIST += \
lua/intf/rc.lua \ lua/intf/rc.lua \
lua/intf/telnet.lua \ lua/intf/telnet.lua \
lua/meta/art/README.txt \ lua/meta/art/README.txt \
lua/meta/art/01_musicbrainz.lua \ lua/meta/art/04_musicbrainz.lua \
lua/meta/art/02_frenchtv.lua \ lua/meta/art/02_frenchtv.lua \
lua/meta/art/03_lastfm.lua \ lua/meta/art/03_lastfm.lua \
lua/meta/art/10_googleimage.lua \ lua/meta/art/01_googleimage.lua \
lua/meta/fetcher/README.txt \ lua/meta/fetcher/README.txt \
lua/meta/fetcher/tvrage.lua \ lua/meta/fetcher/tvrage.lua \
lua/meta/reader/README.txt \ lua/meta/reader/README.txt \
......
...@@ -19,40 +19,23 @@ ...@@ -19,40 +19,23 @@
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
--]] --]]
-- Replace non alphanumeric char by +
function get_query( title )
-- If we have a .EXT remove the extension.
str = string.gsub( title, "(.*)%....$", "%1" )
return string.gsub( str, "([^%w ])",
function (c) return string.format ("%%%02X", string.byte(c)) end)
end
-- Return the artwork -- Return the artwork
function fetch_art() function fetch_art()
-- This is disabled because we have too much false positive by the inherent nature of this script. if vlc.item == nil then return nil end
if true then vlc.msg.dbg("10_googleimage.lua is disabled") return nil end
if vlc.input == nil then return nil end
local item = vlc.input.item() local meta = vlc.item:metas()
local meta = item:metas()
if meta["artist"] and meta["album"] then if meta["artist"] and meta["album"] then
title = meta["artist"].." "..meta["album"] title = meta["artist"].." "..meta["album"]
elseif meta["artist"] and meta["title"] then elseif meta["artist"] and meta["title"] then
title = meta["artist"].." "..meta["title"] title = meta["artist"].." "..meta["title"]
elseif meta["title"] then
title = meta["title"]
elseif meta["filename"] then
title = meta["filename"]
else else
vlc.msg.err("No filename")
return nil return nil
end end
fd = vlc.stream( "http://images.google.com/images?q=" .. get_query( title ) ) fd = vlc.stream( "http://images.google.com/images?q="..vlc.strings.encode_uri_component( title.." cover" ) )
if not fd then return nil end if not fd then return nil end
page = fd:read( 65653 ) page = fd:read( 65653 )
fd = nil fd = nil
_, _, arturl = string.find( page, "imgurl=([^&]+)" ) _, _, arturl = string.find( page, "imgurl=([^&]*)" )
return arturl return arturl
end end
...@@ -23,9 +23,9 @@ function try_query(query) ...@@ -23,9 +23,9 @@ function try_query(query)
local l = vlc.object.libvlc() local l = vlc.object.libvlc()
local t = vlc.var.get( l, "musicbrainz-previousdate" ) local t = vlc.var.get( l, "musicbrainz-previousdate" )
if t ~= nil then if t ~= nil then
if t + 1000000. > vlc.misc.mdate() then if t + 2000000. > vlc.misc.mdate() then
vlc.msg.warn( "We must wait 1 second between requests unless we want to be blacklisted from the musicbrainz server." ) vlc.msg.warn( "We must wait 2 second between requests unless we want to be blacklisted from the musicbrainz server." )
vlc.misc.mwait( t + 1000000. ) vlc.misc.mwait( t + 2000000. )
end end
vlc.var.set( l, "musicbrainz-previousdate", vlc.misc.mdate() ) vlc.var.set( l, "musicbrainz-previousdate", vlc.misc.mdate() )
else else
...@@ -55,7 +55,5 @@ function fetch_art() ...@@ -55,7 +55,5 @@ function fetch_art()
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"]) return try_query(query1)
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)
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