--[[ DISCLAIMER: SCRIPT IS PROVIDED AS IS USE AT YOUR OWN RISK! Save this script as "hockey.lua" Place this script in: - Windows (all users): %ProgramFiles%\VideoLAN\VLC\lua\sd\ - Windows (current user): %APPDATA%\VLC\lua\sd\ - Linux (all users): /usr/share/vlc/lua/sd/ - Linux (current user): ~/.local/share/vlc/lua/sd/ - Mac OS X (all users): VLC.app/Contents/MacOS/share/lua/sd/ If you have issues using this, try changing all `add_subnode` to `add_node`. Older versions of VLC use `add_node`, but recent updates have switched to `add_subnode`. --]] require "simplexml" function descriptor() return { title="/r/hockey" } end function main() local quality = {400, 800, 1200, 1600, 2400, 3000, 4500} local games = simplexml.parse_url("http://208.92.36.37/nlds/as3/get_games.php?client=nhl&playerclient=hop") for _, game in ipairs( games.children ) do if(game.name == "game") then simplexml.add_name_maps( game ) local game_date = game.attributes["game_date"] local game_time = date_to_time(game_date) local home_abr = game.children_map['home_team'][1].children[1] local away_abr = game.children_map['away_team'][1].children[1] local home_team = full_name(home_abr) local away_team = full_name(away_abr) local game_title = game_time .. " " .. away_team .. " @ " .. home_team local node = vlc.sd.add_node( { title = game_title } ) for _, ass in ipairs(game.children_map['assignments'][1].children) do local feed = ass.attributes["feed_display_name"] local feed_title = home_team local feed_abr = home_abr if(feed == "away") then feed_title = away_team feed_abr = away_abr end local d = node:add_subnode({ title = feed_title, arturl = get_logo(feed_abr, "small") }) local ipad = ass.children_map['ipad_url'][1].children[1] for _, q in ipairs(quality) do local url = string.gsub(ipad, "ipad", q) d:add_subitem({ path = url, arturl = get_logo(feed_abr, "small"), title = away_team .. " @ " .. home_team .. ' (' .. q .. ' kbps)' }) end end end end end function date_to_time(game_date) local game_time = string.gsub(game_date, "^.-%s(%d?%d):(%d%d):%d%d", "%1:%2 PM ET") local _, _, hour = string.find(game_time, "^(%d?%d)") hour24 = tonumber(hour) if hour24 < 12 then game_time = string.gsub(game_time, "PM", "AM") elseif hour24 > 12 then local hour12 = tostring(hour24 - 12) game_time = string.gsub(game_time, "^%d?%d", hour12) end return (game_time) end function full_name(abr) local all_names = { BOS = "Boston Bruins", BUF = "Buffalo Sabres", CGY = "Calgary Flames", CHI = "Chicago Blackhawks", DET = "Detroit Redwings", EDM = "Edmonton Oilers", CAR = "Carolina Hurricanes", LOS = "Los Angeles Kings", MON = "Montreal Canadiens", DAL = "Dallas Stars", NJD = "New Jersey Devils", NYI = "NY Islanders Islanders", NYR = "NY Rangers Rangers", PHI = "Philadelphia Flyers", PIT = "Pittsburgh Penguins", COL = "Colorado Avalanche", STL = "St. Louis Blues", TOR = "Toronto Maple Leafs", VAN = "Vancouver Canucks", WSH = "Washington Capitals", PHX = "Phoenix Coyotes", SAN = "San Jose Sharks", OTT = "Ottawa Senators", TAM = "Tampa Bay Lightning", ANA = "Anaheim Ducks", FLA = "Florida Panthers", CBS = "Columbus BlueJackets", MIN = "Minnesota Wild", NSH = "Nashville Predators", WPG = "Winnipeg Jets" } local name = all_names[abr] return(name) end function get_logo(abr, size) -- size should be 'small', 'medium', or 'large' local team_names = { BOS = "bruins", BUF = "sabres", CGY = "flames", CHI = "blackhawks", DET = "redwings", EDM = "oilers", CAR = "hurricanes", LOS = "kings", MON = "canadiens", DAL = "stars", NJD = "devils", NYI = "islanders", NYR = "rangers", PHI = "flyers", PIT = "penguins", COL = "avalanche", STL = "blues", TOR = "mapleleafs", VAN = "canucks", WSH = "capitals", PHX = "coyotes", SAN = "sharks", OTT = "senators", TAM = "lightning", ANA = "ducks", FLA = "panthers", CBS = "bluejackets", MIN = "wild", NSH = "predators", WPG = "jets" } return('http://1.cdn.nhle.com/' .. team_names[abr] .. '/images/logos/' .. size .. '.png') end