]> git.sesse.net Git - vlc/commitdiff
lua: sd: strengthen icecast. (fix #8425)
authorFrancois Cartegnie <fcvlcdev@free.fr>
Wed, 24 Apr 2013 14:30:31 +0000 (16:30 +0200)
committerFrancois Cartegnie <fcvlcdev@free.fr>
Wed, 24 Apr 2013 14:33:20 +0000 (16:33 +0200)
XML is correct, but data is still random and full of junk...

share/lua/sd/icecast.lua

index 7242ec4817f6ed4f3d7e2d113e772efa9e1bf2a0..d6ecefe29ffb35a6ca5fc8f1aea6734f94cbea32 100644 (file)
@@ -25,12 +25,16 @@ function descriptor()
     return { title="Icecast Radio Directory" }
 end
 
+function dropnil(s)
+    if s == nil then return "" else return s end
+end
+
 function main()
     local tree = simplexml.parse_url("http://dir.xiph.org/yp.xml")
     for _, station in ipairs( tree.children ) do
         simplexml.add_name_maps( station )
         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
                 station_name = station.children_map["listen_url"][1].children[1]
                 if string.find( station_name, "radionomy.com" )
@@ -41,15 +45,15 @@ function main()
         end
         vlc.sd.add_item( {path=station.children_map["listen_url"][1].children[1],
                           title=station_name,
-                          genre=station.children_map["genre"][1].children[1],
-                          nowplaying=station.children_map["current_song"][1].children[1],
+                          genre=dropnil(station.children_map["genre"][1].children[1]),
+                          nowplaying=dropnil(station.children_map["current_song"][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={
                                   ["Listing Source"]="dir.xiph.org",
                                   ["Listing Type"]="radio",
-                                  ["Icecast Bitrate"]=station.children_map["bitrate"][1].children[1],
-                                  ["Icecast Server Type"]=station.children_map["server_type"][1].children[1]
+                                  ["Icecast Bitrate"]=dropnil(station.children_map["bitrate"][1].children[1]),
+                                  ["Icecast Server Type"]=dropnil(station.children_map["server_type"][1].children[1])
                           }} )
     end
 end