[vlc-commits] commit: lua_sd: improve the jamendo script to load the content of an album only if asked for . ( Rémi Duraffort )

git at videolan.org git at videolan.org
Wed Aug 18 13:52:35 CEST 2010


vlc/vlc-1.1 | branch: master | Rémi Duraffort <ivoire at videolan.org> | Tue Aug 17 20:23:51 2010 +0200| [65b62c7b622b0424d269f92273df91ad5d617ab0] | committer: 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: Jean-Baptiste Kempf <jb at videolan.org>

> http://git.videolan.org/gitweb.cgi/vlc/vlc-1.1.git/?a=commit;h=65b62c7b622b0424d269f92273df91ad5d617ab0
---

 share/lua/sd/jamendo.lua |   36 +++++++-----------------------------
 1 files changed, 7 insertions(+), 29 deletions(-)

diff --git a/share/lua/sd/jamendo.lua b/share/lua/sd/jamendo.lua
index bb6b93a..d76d005 100644
--- a/share/lua/sd/jamendo.lua
+++ b/share/lua/sd/jamendo.lua
@@ -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"



More information about the vlc-commits mailing list