Commit 7144c1d3 authored by Francois Cartegnie's avatar Francois Cartegnie

lua: sd: strengthen icecast. (fix #8425)

XML is correct, but data is still random and full of junk...
parent ff7aeef9
...@@ -25,12 +25,16 @@ function descriptor() ...@@ -25,12 +25,16 @@ function descriptor()
return { title="Icecast Radio Directory" } return { title="Icecast Radio Directory" }
end end
function dropnil(s)
if s == nil then return "" else return s end
end
function main() function main()
local tree = simplexml.parse_url("http://dir.xiph.org/yp.xml") local tree = simplexml.parse_url("http://dir.xiph.org/yp.xml")
for _, station in ipairs( tree.children ) do for _, station in ipairs( tree.children ) do
simplexml.add_name_maps( station ) simplexml.add_name_maps( station )
local station_name = station.children_map["server_name"][1].children[1] local station_name = station.children_map["server_name"][1].children[1]
if station_name == "Unspecified name" or station_name == "" if station_name == "Unspecified name" or station_name == "" or station_name == nil
then then
station_name = station.children_map["listen_url"][1].children[1] station_name = station.children_map["listen_url"][1].children[1]
if string.find( station_name, "radionomy.com" ) if string.find( station_name, "radionomy.com" )
...@@ -41,15 +45,15 @@ function main() ...@@ -41,15 +45,15 @@ function main()
end end
vlc.sd.add_item( {path=station.children_map["listen_url"][1].children[1], vlc.sd.add_item( {path=station.children_map["listen_url"][1].children[1],
title=station_name, title=station_name,
genre=station.children_map["genre"][1].children[1], genre=dropnil(station.children_map["genre"][1].children[1]),
nowplaying=station.children_map["current_song"][1].children[1], nowplaying=dropnil(station.children_map["current_song"][1].children[1]),
uiddata=station.children_map["listen_url"][1].children[1] uiddata=station.children_map["listen_url"][1].children[1]
.. station.children_map["server_name"][1].children[1], .. dropnil(station.children_map["server_name"][1].children[1]),
meta={ meta={
["Listing Source"]="dir.xiph.org", ["Listing Source"]="dir.xiph.org",
["Listing Type"]="radio", ["Listing Type"]="radio",
["Icecast Bitrate"]=station.children_map["bitrate"][1].children[1], ["Icecast Bitrate"]=dropnil(station.children_map["bitrate"][1].children[1]),
["Icecast Server Type"]=station.children_map["server_type"][1].children[1] ["Icecast Server Type"]=dropnil(station.children_map["server_type"][1].children[1])
}} ) }} )
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