Commit e9cfdeed authored by Fabio Ritrovato's avatar Fabio Ritrovato

Lua: Jamendo SD + Demuxer

Jamendo radios are accessed trough the demuxer, otherwise the SD script will be too slow.
The demuxer should also resolve all the Jamendo api calls to the track unit, xml only.
parent 8e9cdc15
......@@ -223,6 +223,7 @@ nobase_vlclib_DATA = \
lua/playlist/dailymotion.luac \
lua/playlist/france2.luac \
lua/playlist/googlevideo.luac \
lua/playlist/jamendo.luac \
lua/playlist/joox.luac \
lua/playlist/katsomo.luac \
lua/playlist/lelombrik.luac \
......@@ -236,6 +237,7 @@ nobase_vlclib_DATA = \
lua/sd/freebox.luac \
lua/sd/frenchtv.luac \
lua/sd/icecast.luac \
lua/sd/jamendo.luac \
$(NULL)
if BUILD_HTTPD
nobase_vlclib_DATA += \
......@@ -263,6 +265,7 @@ EXTRA_DIST += \
lua/playlist/cue.lua \
lua/playlist/dailymotion.lua \
lua/playlist/france2.lua \
lua/playlist/jamendo.lua \
lua/playlist/joox.lua \
lua/playlist/katsomo.lua \
lua/playlist/lelombrik.lua \
......@@ -288,7 +291,8 @@ EXTRA_DIST += \
lua/sd/fmc.lua \
lua/sd/freebox.lua \
lua/sd/frenchtv.lua \
lua/sd/icecast.lua
lua/sd/icecast.lua \
lua/sd/jamendo.lua
DIST_http_lua = \
lua/http/.hosts \
......
--[[
$Id$
Copyright © 2010 VideoLAN and AUTHORS
Authors: Fabio Ritrovato <sephiroth87 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
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
--]]
require "simplexml"
-- Probe function.
function probe()
return vlc.access == "http"
and string.match( vlc.path, "jamendo.com" )
end
-- Parse function.
function parse()
if not ( string.match( vlc.path, "jamendo.com/get2/" ) and string.match( vlc.path, "/track/xml/" ) ) then
vlc.msg.err( "Jamendo URL not supported yet..." )
return {}
end
local page = ""
while true do
local line = vlc.readline()
if line == nil then break end
page = page .. line
end
local tracks = {}
local tree = simplexml.parse_string( page )
for _, track in ipairs( tree.children ) do
simplexml.add_name_maps( track )
if track.children_map["id"] == nil and
track.children_map["stream"] == nil then
vlc.msg.err( "No track id or stream URL, not enough info to add tracks..." )
return {}
end
local stream_url
if track.children_map["id"][1].children[1] then
stream_url = "http://api.jamendo.com/get2/stream/track/redirect/?id=" .. track.children_map["id"][1].children[1]
else
stream_url = track.children_map["stream"][1].children[1]
end
table.insert( tracks, {path=stream_url,
arturl=track.children_map["album_id"] and "http://imgjam.com/albums/".. track.children_map["album_id"][1].children[1] .. "/covers/1.500.jpg" or ( track.children_map["album_image"] and track.children_map["album_image"][1].children[1] or nil ),
title=track.children_map["name"] and track.children_map["name"][1].children[1] or nil,
artist=track.children_map["artist_name"] and track.children_map["artist_name"][1].children[1] or nil,
album=track.children_map["album_name"] and track.children_map["album_name"][1].children[1] or nil,
genre=track.children_map["album_genre"] and track.children_map["album_genre"][1].children[1] or nil,
duration=track.children_map["duration"] and track.children_map["duration"][1].children[1] or nil,
date=track.children_map["album_dates"] and track.children_map["album_dates"][1].children_map["year"][1].children[1] or nil} )
end
return tracks
end
--[[
$Id$
Copyright © 2010 VideoLAN and AUTHORS
Authors: Fabio Ritrovato <sephiroth87 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
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
--]]
require "simplexml"
function descriptor()
return { title="Jamendo Selections" }
end
function main()
add_top_tracks( "ratingweek_desc", nil, 100 )
add_top_albums( "ratingweek_desc", nil, 20 )
add_radio_from_id( "9", 20 )
add_radio_from_id( "8", 20 )
add_radio_from_id( "6", 20 )
add_radio_from_id( "5", 20 )
add_radio_from_id( "7", 20 )
add_radio_from_id( "4", 20 )
end
function add_top_albums( album_order, tag, max_results )
local url = "http://api.jamendo.com/get2/id+name+artist_name/album/xml/?order=" .. album_order .. "&n=" .. max_results
if tag ~= nil then
url = url .. "&tag_idstr=" .. tag
end
local tree = simplexml.parse_url( url )
local node_name = "Top " .. max_results
if album_order == "rating_desc" then node_name = node_name .. " most popular albums"
elseif album_order == "ratingmonth_desc" then node_name = node_name .. " most popular albums this month"
elseif album_order == "ratingweek_desc" then node_name = node_name .. " most popular albums this week"
elseif album_order == "releasedate_desc" then node_name = node_name .. " latest released albums"
elseif album_order == "downloaded_desc" then node_name = node_name .. " most downloaded albums"
elseif album_order == "listened_desc" then node_name = node_name .. " most listened to albums"
elseif album_order == "starred_desc" then node_name = node_name .. " most starred albums"
elseif album_order == "playlisted_desc" then node_name = node_name .. " most playlisted albums"
elseif album_order == "needreviews_desc" then node_name = node_name .. " albums requiring review"
end
if tag ~= nil then
node_name = tag .. " - " .. node_name
end
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="http://imgjam.com/albums/".. album.children_map["id"][1].children[1] .. "/covers/1.500.jpg"} )
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="http://imgjam.com/albums/".. album.children_map["id"][1].children[1] .. "/covers/1.500.jpg",
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
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_dates/track/xml/track_album+album_artist/?order=" .. track_order .. "&n=" .. max_results
if tag ~= nil then
url = url .. "&tag_idstr=" .. tag
end
local tree = simplexml.parse_url( url )
local node_name = "Top " .. max_results
if track_order == "rating_desc" then node_name = node_name .. " most popular tracks"
elseif track_order == "ratingmonth_desc" then node_name = node_name .. " most popular tracks this month"
elseif track_order == "ratingweek_desc" then node_name = node_name .. " most popular tracks this week"
elseif track_order == "releasedate_desc" then node_name = node_name .. " latest released tracks"
elseif track_order == "downloaded_desc" then node_name = node_name .. " most downloaded tracks"
elseif track_order == "listened_desc" then node_name = node_name .. " most listened to tracks"
elseif track_order == "starred_desc" then node_name = node_name .. " most starred tracks"
elseif track_order == "playlisted_desc" then node_name = node_name .. " most playlisted tracks"
elseif track_order == "needreviews_desc" then node_name = node_name .. " tracks requiring review"
end
if tag ~= nil then
node_name = tag .. " - " .. node_name
end
local node = vlc.sd.add_node( {title=node_name} )
for _, track in ipairs( tree.children ) do
simplexml.add_name_maps( track )
node:add_subitem( {path="http://api.jamendo.com/get2/stream/track/redirect/?id=" .. track.children_map["id"][1].children[1],
title=track.children_map["name"][1].children[1],
artist=track.children_map["artist_name"][1].children[1],
album=track.children_map["album_name"][1].children[1],
genre=track.children_map["album_genre"][1].children[1],
date=track.children_map["album_dates"][1].children_map["year"][1].children[1],
arturl="http://imgjam.com/albums/".. track.children_map["album_id"][1].children[1] .. "/covers/1.500.jpg",
duration=track.children_map["duration"][1].children[1]} )
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"
elseif id == "8" then radio_name="Pop / Songwriting"
elseif id == "6" then radio_name="Jazz"
elseif id == "5" then radio_name="Hip-Hop"
elseif id == "7" then radio_name="Lounge"
elseif id == "4" then radio_name="Dance / Electro"
end
vlc.sd.add_item( {path="http://api.jamendo.com/get2/id+name+artist_name+album_name+duration+album_genre+album_dates/track/xml/radio_track_inradioplaylist+track_album+album_artist/?order=random_desc&radio_id=" .. id .. "&n=" .. max_results,
title=radio_name} )
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