]> git.sesse.net Git - vlc/blob - share/lua/sd/jamendo.lua
jamendo: also get the artist along with the list of songs for one album.
[vlc] / share / lua / sd / jamendo.lua
1 --[[
2  $Id$
3
4  Copyright © 2010 VideoLAN and AUTHORS
5
6  Authors: Fabio Ritrovato <sephiroth87 at videolan dot org>
7           Rémi Duraffort  <ivoire at videolan dot org>
8
9  This program is free software; you can redistribute it and/or modify
10  it under the terms of the GNU General Public License as published by
11  the Free Software Foundation; either version 2 of the License, or
12  (at your option) any later version.
13
14  This program is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  GNU General Public License for more details.
18
19  You should have received a copy of the GNU General Public License
20  along with this program; if not, write to the Free Software
21  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 --]]
23
24 require "simplexml"
25
26 function descriptor()
27     return { title="Jamendo Selections" }
28 end
29
30 function main()
31     add_top_tracks( "ratingweek_desc", nil, 100 )
32     add_top_albums( "ratingweek_desc", nil, 20 )
33     add_radio_from_id( "9", 20 )
34     add_radio_from_id( "8", 20 )
35     add_radio_from_id( "6", 20 )
36     add_radio_from_id( "5", 20 )
37     add_radio_from_id( "7", 20 )
38     add_radio_from_id( "4", 20 )
39 end
40
41 function add_top_albums( album_order, tag, max_results )
42     local url = "http://api.jamendo.com/get2/id+name+artist_name+album_image/album/xml/?imagesize=500&order=" .. album_order .. "&n=" .. max_results
43     if tag ~= nil then
44         url = url .. "&tag_idstr=" .. tag
45     end
46     local tree = simplexml.parse_url( url )
47     local node_name = "Top " .. max_results
48     if album_order == "rating_desc" then node_name = node_name .. " most popular albums"
49     elseif album_order == "ratingmonth_desc" then node_name = node_name .. " most popular albums this month"
50     elseif album_order == "ratingweek_desc" then node_name = node_name .. " most popular albums this week"
51     elseif album_order == "releasedate_desc" then node_name = node_name .. " latest released albums"
52     elseif album_order == "downloaded_desc" then node_name = node_name .. " most downloaded albums"
53     elseif album_order == "listened_desc" then node_name = node_name .. " most listened to albums"
54     elseif album_order == "starred_desc" then node_name = node_name .. " most starred albums"
55     elseif album_order == "playlisted_desc" then node_name = node_name .. " most playlisted albums"
56     elseif album_order == "needreviews_desc" then node_name = node_name .. " albums requiring review"
57     end
58     if tag ~= nil then
59         node_name = tag .. " - " .. node_name
60     end
61     local node = vlc.sd.add_node( {title=node_name} )
62     for _, album in ipairs( tree.children ) do
63         simplexml.add_name_maps( album )
64         local album_node = node:add_subitem(
65                 { path     = 'http://api.jamendo.com/get2/id+name+duration+artist_name+album_name+album_genre+album_dates+album_image/track/xml/track_album+album_artist/?album_id=' .. album.children_map["id"][1].children[1],
66                   title    = album.children_map["artist_name"][1].children[1] .. ' - ' .. album.children_map["name"][1].children[1],
67                   arturl   = album.children_map["album_image"][1].children[1] })
68     end
69 end
70
71 function add_top_tracks( track_order, tag, max_results )
72     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
73     if tag ~= nil then
74         url = url .. "&tag_idstr=" .. tag
75     end
76     local tree = simplexml.parse_url( url )
77     local node_name = "Top " .. max_results
78     if track_order == "rating_desc" then node_name = node_name .. " most popular tracks"
79     elseif track_order == "ratingmonth_desc" then node_name = node_name .. " most popular tracks this month"
80     elseif track_order == "ratingweek_desc" then node_name = node_name .. " most popular tracks this week"
81     elseif track_order == "releasedate_desc" then node_name = node_name .. " latest released tracks"
82     elseif track_order == "downloaded_desc" then node_name = node_name .. " most downloaded tracks"
83     elseif track_order == "listened_desc" then node_name = node_name .. " most listened to tracks"
84     elseif track_order == "starred_desc" then node_name = node_name .. " most starred tracks"
85     elseif track_order == "playlisted_desc" then node_name = node_name .. " most playlisted tracks"
86     elseif track_order == "needreviews_desc" then node_name = node_name .. " tracks requiring review"
87     end
88     if tag ~= nil then
89         node_name = tag .. " - " .. node_name
90     end
91     local node = vlc.sd.add_node( {title=node_name} )
92     for _, track in ipairs( tree.children ) do
93         simplexml.add_name_maps( track )
94         node:add_subitem( {path="http://api.jamendo.com/get2/stream/track/redirect/?id=" .. track.children_map["id"][1].children[1],
95                            title=track.children_map["name"][1].children[1],
96                            artist=track.children_map["artist_name"][1].children[1],
97                            album=track.children_map["album_name"][1].children[1],
98                            genre=track.children_map["album_genre"][1].children[1],
99                            date=track.children_map["album_dates"][1].children_map["year"][1].children[1],
100                            arturl=track.children_map["album_image"][1].children[1],
101                            duration=track.children_map["duration"][1].children[1]} )
102     end
103 end
104
105 function add_radio_from_id( id, max_results )
106     local radio_name
107     if id == "9" then radio_name="Rock"
108     elseif id == "8" then radio_name="Pop / Songwriting"
109     elseif id == "6" then radio_name="Jazz"
110     elseif id == "5" then radio_name="Hip-Hop"
111     elseif id == "7" then radio_name="Lounge"
112     elseif id == "4" then radio_name="Dance / Electro"
113     end
114     vlc.sd.add_item( {path="http://api.jamendo.com/get2/id+name+artist_name+album_name+duration+album_genre+album_image+album_dates/track/xml/radio_track_inradioplaylist+track_album+album_artist/?imagesize=500&order=random_desc&radio_id=" .. id .. "&n=" .. max_results,
115                       title=radio_name} )
116 end
117