Commit 7dbf7908 authored by Ilkka Ollakka's avatar Ilkka Ollakka

lua: add art fetcher for last.fm

This can commit bad code and bugs under your name into tree, so beware.
parent ea900bc7
...@@ -216,6 +216,7 @@ nobase_vlclib_DATA = \ ...@@ -216,6 +216,7 @@ nobase_vlclib_DATA = \
lua/intf/dumpmeta.luac \ lua/intf/dumpmeta.luac \
lua/meta/art/01_musicbrainz.luac \ lua/meta/art/01_musicbrainz.luac \
lua/meta/art/02_frenchtv.luac \ lua/meta/art/02_frenchtv.luac \
lua/meta/art/03_lastfm.luac \
lua/meta/art/10_googleimage.luac \ lua/meta/art/10_googleimage.luac \
lua/meta/fetcher/tvrage.luac \ lua/meta/fetcher/tvrage.luac \
lua/meta/reader/filename.luac \ lua/meta/reader/filename.luac \
...@@ -258,6 +259,7 @@ EXTRA_DIST += \ ...@@ -258,6 +259,7 @@ EXTRA_DIST += \
lua/meta/art/README.txt \ lua/meta/art/README.txt \
lua/meta/art/01_musicbrainz.lua \ lua/meta/art/01_musicbrainz.lua \
lua/meta/art/02_frenchtv.lua \ lua/meta/art/02_frenchtv.lua \
lua/meta/art/03_lastfm.lua \
lua/meta/art/10_googleimage.lua \ lua/meta/art/10_googleimage.lua \
lua/meta/fetcher/README.txt \ lua/meta/fetcher/README.txt \
lua/meta/fetcher/tvrage.lua \ lua/meta/fetcher/tvrage.lua \
......
--[[
Gets an artwork from last.fm
$Id$
Copyright © 2010 the VideoLAN team
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
--]]
-- Return the artwork
function fetch_art()
if vlc.input == nil then return nil end
local item = vlc.input.item()
local meta = item:metas()
if meta["artist"] and meta["album"] then
title = meta["artist"].."/"..meta["album"]
else
return nil
end
-- remove -.* from string
title = string.gsub( title, " ?%-.*", "" )
-- remove (info..) from string
title = string.gsub( title, "%(.*%)", "" )
-- remove CD2 etc from string
title = string.gsub( title, "CD%d+", "" )
-- remove Disc \w+ from string
title = string.gsub( title, "Disc %w+", "" )
fd = vlc.stream( "http://www.last.fm/music/" .. title )
if not fd then return nil end
page = fd:read( 65653 )
fd = nil
_, _, arturl = string.find( page, "<img width=\"174\" src=\"([^\"]+)\" class=\"art\" />\n" )
-- Don't use default album-art (not found one)
if not arturl or string.find( arturl, "default_album_mega.png") then
return nil
end
return arturl
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