Commit dee36954 authored by Rémi Duraffort's avatar Rémi Duraffort

librivox: some cleanup and add the book author as artist of the item.

parent d51c1abd
...@@ -26,6 +26,7 @@ function descriptor() ...@@ -26,6 +26,7 @@ function descriptor()
return { title = 'librivox' } return { title = 'librivox' }
end end
-- Transform a duration 'mm:ss' or 'hh::mm::ss' into an integer
function string_2_duration(str) function string_2_duration(str)
local index = string.find( str, ':' ) local index = string.find( str, ':' )
if( index == nil ) then return str if( index == nil ) then return str
...@@ -41,27 +42,32 @@ end ...@@ -41,27 +42,32 @@ end
function main() function main()
local podcast = simplexml.parse_url( 'http://librivox.org/podcast.xml' ) local podcast = simplexml.parse_url( 'http://librivox.org/podcast.xml' )
simplexml.add_name_maps( podcast ) simplexml.add_name_maps( podcast )
local channel = podcast.children_map['channel'][1] local channel = podcast.children_map['channel'][1]
local arturl = '' local arturl = ''
local books = {} local books = {}
for _, item in ipairs( channel.children ) do for _, item in ipairs( channel.children ) do
if( item.name == 'item' ) if( item.name == 'item' ) then
then
simplexml.add_name_maps( item ) simplexml.add_name_maps( item )
-- If the book title is unknown, create a node for it in the sd
local book_title = item.children_map['itunes:subtitle'][1].children[1] local book_title = item.children_map['itunes:subtitle'][1].children[1]
if(books[book_title] == nil) then if( books[book_title] == nil ) then
books[book_title] = vlc.sd.add_node( { title = book_title } ) books[book_title] = vlc.sd.add_node( { title = book_title,
arturl = arturl } )
end end
-- Add the new chapter to the book
books[book_title]:add_subitem( { path = item.children_map['link'][1].children[1], books[book_title]:add_subitem( { path = item.children_map['link'][1].children[1],
title = item.children_map['title'][1].children[1], title = item.children_map['title'][1].children[1],
album = item.children_map['itunes:subtitle'][1].children[1], album = item.children_map['itunes:subtitle'][1].children[1],
artist = item.children_map['itunes:author'][1].children[1],
duration = string_2_duration( item.children_map['itunes:duration'][1].children[1] ), duration = string_2_duration( item.children_map['itunes:duration'][1].children[1] ),
arturl = arturl } ) arturl = arturl } )
elseif( item.name == 'itunes:image' )
then elseif( item.name == 'itunes:image' ) then
arturl = item.attributes['href'] arturl = item.attributes['href']
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment