[vlc-commits] commit: lua: add art fetcher for last.fm (Ilkka Ollakka )
git at videolan.org
git at videolan.org
Tue Apr 13 22:17:13 CEST 2010
vlc | branch: master | Ilkka Ollakka <ileoo at videolan.org> | Tue Apr 13 23:15:23 2010 +0300| [7dbf7908bff43ce5e52b7710f924be9d527daf1a] | committer: Ilkka Ollakka
lua: add art fetcher for last.fm
This can commit bad code and bugs under your name into tree, so beware.
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=7dbf7908bff43ce5e52b7710f924be9d527daf1a
---
share/Makefile.am | 2 +
share/lua/meta/art/03_lastfm.lua | 50 ++++++++++++++++++++++++++++++++++++++
2 files changed, 52 insertions(+), 0 deletions(-)
diff --git a/share/Makefile.am b/share/Makefile.am
index 59d424f..41c46e3 100644
--- a/share/Makefile.am
+++ b/share/Makefile.am
@@ -216,6 +216,7 @@ nobase_vlclib_DATA = \
lua/intf/dumpmeta.luac \
lua/meta/art/01_musicbrainz.luac \
lua/meta/art/02_frenchtv.luac \
+ lua/meta/art/03_lastfm.luac \
lua/meta/art/10_googleimage.luac \
lua/meta/fetcher/tvrage.luac \
lua/meta/reader/filename.luac \
@@ -258,6 +259,7 @@ EXTRA_DIST += \
lua/meta/art/README.txt \
lua/meta/art/01_musicbrainz.lua \
lua/meta/art/02_frenchtv.lua \
+ lua/meta/art/03_lastfm.lua \
lua/meta/art/10_googleimage.lua \
lua/meta/fetcher/README.txt \
lua/meta/fetcher/tvrage.lua \
diff --git a/share/lua/meta/art/03_lastfm.lua b/share/lua/meta/art/03_lastfm.lua
new file mode 100644
index 0000000..ed55866
--- /dev/null
+++ b/share/lua/meta/art/03_lastfm.lua
@@ -0,0 +1,50 @@
+--[[
+ 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
More information about the vlc-commits
mailing list