Commit 65b62c7b authored by Rémi Duraffort's avatar Rémi Duraffort Committed by Jean-Baptiste Kempf

lua_sd: improve the jamendo script to load the content of an album only if asked for.

The script is faster and decrease the load on the server.
(cherry picked from commit 8532c923b1467a66b95d377a2d93986251c1c53f)
Signed-off-by: default avatarJean-Baptiste Kempf <jb@videolan.org>
parent b4a40fb8
......@@ -4,6 +4,7 @@
Copyright © 2010 VideoLAN and AUTHORS
Authors: Fabio Ritrovato <sephiroth87 at videolan dot org>
Rémi Duraffort <ivoire at videolan dot org>
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
......@@ -38,7 +39,7 @@ function main()
end
function add_top_albums( album_order, tag, max_results )
local url = "http://api.jamendo.com/get2/id+name+artist_name+image/album/xml/?imagesize=500&order=" .. album_order .. "&n=" .. max_results
local url = "http://api.jamendo.com/get2/id+name+artist_name+album_image/album/xml/?imagesize=500&order=" .. album_order .. "&n=" .. max_results
if tag ~= nil then
url = url .. "&tag_idstr=" .. tag
end
......@@ -60,24 +61,15 @@ function add_top_albums( album_order, tag, max_results )
local node = vlc.sd.add_node( {title=node_name} )
for _, album in ipairs( tree.children ) do
simplexml.add_name_maps( album )
local album_node = node:add_node( {title=album.children_map["artist_name"][1].children[1] .. " - " .. album.children_map["name"][1].children[1],
arturl=album.children_map["image"][1].children[1]} )
local tracks = get_tracks_from_album( album.children_map["id"][1].children[1] )
for _, track in ipairs( tracks ) do
album_node:add_subitem( {path="http://api.jamendo.com/get2/stream/track/redirect/?id=" .. track.id,
arturl=album.children_map["image"][1].children[1],
title=track.title,
artist=album.children_map["artist_name"][1].children[1],
album=album.children_map["name"][1].children[1],
genre=track.genre,
duration=track.duration,
date=track.date,} )
end
local album_node = node:add_subitem(
{ path = 'http://api.jamendo.com/get2/id+name+duration+album_name+album_genre+album_dates+album_image/track/xml/?album_id=' .. album.children_map["id"][1].children[1],
title = album.children_map["artist_name"][1].children[1] .. ' - ' .. album.children_map["name"][1].children[1],
arturl = album.children_map["album_image"][1].children[1] })
end
end
function add_top_tracks( track_order, tag, max_results )
local url = "http://api.jamendo.com/get2/id+name+artist_name+album_name+album_id+duration+album_genre+album_image+album_dates/track/xml/track_album+album_artist/?imagesize=500&order=" .. track_order .. "&n=" .. max_results
local url = "http://api.jamendo.com/get2/id+name+duration+artist_name+album_name+album_genre+album_image+album_dates/track/xml/track_album+album_artist/?imagesize=500&order=" .. track_order .. "&n=" .. max_results
if tag ~= nil then
url = url .. "&tag_idstr=" .. tag
end
......@@ -110,20 +102,6 @@ function add_top_tracks( track_order, tag, max_results )
end
end
function get_tracks_from_album( album )
local tree = simplexml.parse_url( "http://api.jamendo.com/get2/id+name+duration+album_genre+album_dates/track/xml/?album_id=" .. album )
local tracks = {}
for _, track in ipairs( tree.children ) do
simplexml.add_name_maps( track )
table.insert( tracks, {title=track.children_map["name"][1].children[1],
genre=track.children_map["album_genre"][1].children[1],
duration=track.children_map["duration"][1].children[1],
id=track.children_map["id"][1].children[1],
date=track.children_map["album_dates"][1].children_map["year"][1].children[1]} )
end
return tracks
end
function add_radio_from_id( id, max_results )
local radio_name
if id == "9" then radio_name="Rock"
......
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