]> git.sesse.net Git - vlc/blob - share/lua/sd/librivox.lua
Add a lua sd for librivox.
[vlc] / share / lua / sd / librivox.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 = 'librivox' }
27 end
28
29 function string_2_duration(str)
30     local index = string.find( str, ':' )
31     if( index == nil ) then return str
32     else
33         local index2 = string.find( str, ':', index + 1 )
34         if( index2 == nil ) then
35             return string.sub( str, 0, index - 1 ) * 60 + string.sub( str, index + 1 )
36         else
37             return string.sub( str, 0, index - 1 ) * 3600 + string.sub( str, index + 1, index2 - 1 ) * 60 + string.sub( str, index2 + 1 )
38         end
39     end
40 end
41
42 function main()
43     local podcast = simplexml.parse_url( 'http://librivox.org/podcast.xml' )
44
45     simplexml.add_name_maps( podcast )
46     local channel = podcast.children_map['channel'][1]
47     local arturl = ''
48
49     for _, item in ipairs( channel.children ) do
50         if( item.name == 'item' )
51         then
52             simplexml.add_name_maps( item )
53             local new_item = vlc.sd.add_item( { path = item.children_map['link'][1].children[1],
54                                                 title = item.children_map['title'][1].children[1],
55                                                 album = item.children_map['itunes:subtitle'][1].children[1],
56                                                 duration = string_2_duration( item.children_map['itunes:duration'][1].children[1] ),
57                                                 arturl = arturl } )
58         elseif( item.name == 'itunes:image' )
59         then
60             arturl = item.attributes['href']
61         end
62     end
63 end
64