]> git.sesse.net Git - vlc/commitdiff
lua: add art fetcher for last.fm
authorIlkka Ollakka <ileoo@videolan.org>
Tue, 13 Apr 2010 20:15:23 +0000 (23:15 +0300)
committerIlkka Ollakka <ileoo@videolan.org>
Tue, 13 Apr 2010 20:15:23 +0000 (23:15 +0300)
This can commit bad code and bugs under your name into tree, so beware.

share/Makefile.am
share/lua/meta/art/03_lastfm.lua [new file with mode: 0644]

index 59d424f1992c315ef95965a238eabda7d64bccf8..41c46e34218dcbd29257518cf143bc4e70147377 100644 (file)
@@ -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 (file)
index 0000000..ed55866
--- /dev/null
@@ -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