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 = \
lua/intf/modules/host.luac \
lua/intf/rc.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/03_lastfm.luac \
lua/meta/art/10_googleimage.luac \
lua/meta/art/01_googleimage.luac \
lua/meta/fetcher/tvrage.luac \
lua/meta/reader/filename.luac \
lua/modules/sandbox.luac \
......@@ -280,10 +280,10 @@ EXTRA_DIST += \
lua/intf/rc.lua \
lua/intf/telnet.lua \
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/03_lastfm.lua \
lua/meta/art/10_googleimage.lua \
lua/meta/art/01_googleimage.lua \
lua/meta/fetcher/README.txt \
lua/meta/fetcher/tvrage.lua \
lua/meta/reader/README.txt \
......
......@@ -19,40 +19,23 @@
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
function fetch_art()
-- This is disabled because we have too much false positive by the inherent nature of this script.
if true then vlc.msg.dbg("10_googleimage.lua is disabled") return nil end
if vlc.input == nil then return nil end
if vlc.item == nil then return nil end
local item = vlc.input.item()
local meta = item:metas()
local meta = vlc.item:metas()
if meta["artist"] and meta["album"] then
title = meta["artist"].." "..meta["album"]
elseif meta["artist"] and meta["title"] then
title = meta["artist"].." "..meta["title"]
elseif meta["title"] then
title = meta["title"]
elseif meta["filename"] then
title = meta["filename"]
else
vlc.msg.err("No filename")
return nil
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
page = fd:read( 65653 )
fd = nil
_, _, arturl = string.find( page, "imgurl=([^&]+)" )
_, _, arturl = string.find( page, "imgurl=([^&]*)" )
return arturl
end
......@@ -23,9 +23,9 @@ function try_query(query)
local l = vlc.object.libvlc()
local t = vlc.var.get( l, "musicbrainz-previousdate" )
if t ~= nil then
if t + 1000000. > 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.misc.mwait( t + 1000000. )
if t + 2000000. > vlc.misc.mdate() then
vlc.msg.warn( "We must wait 2 second between requests unless we want to be blacklisted from the musicbrainz server." )
vlc.misc.mwait( t + 2000000. )
end
vlc.var.set( l, "musicbrainz-previousdate", vlc.misc.mdate() )
else
......@@ -55,7 +55,5 @@ 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=\""..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(meta["album"].."\"~ AND ".."artist:"..meta["artist"].."~")
return try_query(query1) or try_query(query2) or try_query(query3)
return try_query(query1)
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