]> git.sesse.net Git - vlc/blob - share/lua/sd/magnatune.lua
lua_sd: add an sd for magnatune (proof of concept for the moment).
[vlc] / share / lua / sd / magnatune.lua
1 --[[
2  $Id$
3
4  Copyright © 2010 VideoLAN and AUTHORS
5
6  Authors: Rémi Duraffort  <ivoire at videolan dot org>
7
8  This program is free software; you can redistribute it and/or modify
9  it under the terms of the GNU General Public License as published by
10  the Free Software Foundation; either version 2 of the License, or
11  (at your option) any later version.
12
13  This program is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  GNU General Public License for more details.
17
18  You should have received a copy of the GNU General Public License
19  along with this program; if not, write to the Free Software
20  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
21 --]]
22
23 require "simplexml"
24
25 function descriptor()
26     return { title="Magnatune" }
27 end
28
29 function main()
30     add_top_albums()
31 end
32
33 function add_top_albums()
34     local fd = vlc.stream( "http://magnatune.com/genres/m3u/ranked_all.xspf" )
35     if not fd then return end
36     local file = ''
37     local line = ''
38     while line ~= nil do
39         line = fd:readline()
40         if line ~= nil then
41             -- repair the XML stream if needed
42             file = file .. string.gsub(line, ' & ', ' &amp; ')
43         end
44     end
45
46     local node = vlc.sd.add_node( {title = "Most popular albums"} )
47
48     local tree = simplexml.parse_string( file )
49     simplexml.add_name_maps( tree )
50     local track_list = tree.children_map['trackList'][1]
51     for _, track in ipairs( track_list.children ) do
52         simplexml.add_name_maps( track )
53         local track_item = node:add_subitem(
54                 { path     = string.gsub(track.children_map['location'][1].children[1], ' ', '%%20'),
55                   title    = track.children_map['annotation'][1].children[1],
56                   arturl   = track.children_map['image'][1].children[1] })
57     end
58 end
59