Last time, I told you how to take a video from some website and see it in VLC media player. Pretty cool, huh?

Yesterday, I was trying to think of funny and useless thing to do with VLC, and it occured to me that Lua gives a lot of opportunities to do that.

So, it is my pleasure to present you with the "Flickr diaporama Lua script for VLC"!

--[[

 Copyright © 2009 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.
--]]

-- Probe function.
function probe()
    if vlc.access ~= "http" then
        return false
    end
    vlc.msg.info( vlc.path )
	koreus_site = string.match( vlc.path, "www.flickr.com" )
    if not koreus_site then
        return false
    end
    return (  string.match( vlc.path, "sets" )  )
end

-- Parse function.
function parse()
    _,_,artist = string.find( vlc.path, "photos/(.-)/sets/" )
    vlc.msg.info( artist )
    while true do
        line = vlc.readline()
        if not line then break end
        if string.match( line,"<div id=\"setThumbs\"") then
            start = 0
            pl = {}
            line = vlc.readline()
            while true do
                _,start,url = string.find(line, "<img src=\"(.-)_s.jpg\"", start)
                if start == nil then
                    return pl
                end
                _,_,description = string.find(line, "alt=\"(.-)\"", start)
                opt = { ":fake-duration=5000"; ":fullscreen" }
                pth = "fake://" .. url .. ".jpg"
                table.insert(pl, {path = pth; name = start; title=description; 
                description = description; artist = artist;options=opt})
            end
        end
    end
end

So, how does it work? Give some Flickr album url to VLC, like this one with the funny cats. VLC will parse the page, find all the thumbnails urls (the ones finishing with _s.jpg), deduce the urls of the the full pictures (replacing "_s.jpg" by ".jpg"), and show them. As simple as that.

The fake access module is used to tell VLC that "hey, this is not one picture, it's a video with a lot of frames like this picture". I added the "fake-duration" option, to choose how much time (in ms) the picture will be displayed, and the "fullscreen" option. You can of course tweak it, and, let's say, use the directx wallpaper mode to have a flickr diaporama as your wallpaper!

To use this script, you can either place it in C:\Program Files\VideoLAN\VLC\lua\playlist, or in C:\Users\YOURUSERNAME\AppData\Roaming\vlc\lua\playlist.

I strongly encourage you to try and write your own Lua scripts, it's really easy! Come to the Videolan forum to share your scripts or ask for help.

See also