access: bluray: fix debug code
[vlc.git] / share / lua / sd / librivox.lua
blob9aa34a1ce1d19b2227770d3c333f50ec2351e799
1 --[[
2 $Id$
4 Copyright © 2010 VideoLAN and AUTHORS
6 Authors: Rémi Duraffort <ivoire at videolan dot org>
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.
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.
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 --]]
23 require "simplexml"
25 function descriptor()
26 return { title = 'librivox' }
27 end
29 -- Transform a duration 'mm:ss' or 'hh::mm::ss' into an integer
30 function string_2_duration(str)
31 local index = string.find( str, ':' )
32 if( index == nil ) then return str
33 else
34 if( index == 1 ) then
35 return string.sub( str, 2 )
36 end
37 local index2 = string.find( str, ':', index + 1 )
38 if( index2 == nil ) then
39 return string.sub( str, 0, index - 1 ) * 60 + string.sub( str, index + 1 )
40 else
41 return string.sub( str, 0, index - 1 ) * 3600 + string.sub( str, index + 1, index2 - 1 ) * 60 + string.sub( str, index2 + 1 )
42 end
43 end
44 end
46 function main()
47 local podcast = simplexml.parse_url( 'http://librivox.org/podcast.xml' )
48 simplexml.add_name_maps( podcast )
50 local channel = podcast.children_map['channel'][1]
51 local arturl = ''
52 local books = {}
54 for _, item in ipairs( channel.children ) do
55 if( item.name == 'item' ) then
56 simplexml.add_name_maps( item )
58 -- If the book title is unknown, create a node for it in the sd
59 local book_title = item.children_map['itunes:subtitle'][1].children[1]
60 if( books[book_title] == nil ) then
61 books[book_title] = vlc.sd.add_node( { title = book_title,
62 arturl = arturl } )
63 end
65 -- Add the new chapter to the book
66 books[book_title]:add_subitem( { path = item.children_map['link'][1].children[1],
67 title = item.children_map['title'][1].children[1],
68 album = item.children_map['itunes:subtitle'][1].children[1],
69 artist = item.children_map['itunes:author'][1].children[1],
70 duration = string_2_duration( item.children_map['itunes:duration'][1].children[1] ),
71 arturl = arturl } )
73 elseif( item.name == 'itunes:image' ) then
74 arturl = item.attributes['href']
75 end
76 end
77 end