Advertisement
Guest User

2.10 Hockey.lua update

a guest
Sep 27th, 2013
5,019
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --[[
  2.   DISCLAIMER: SCRIPT IS PROVIDED AS IS USE AT YOUR OWN RISK!
  3.  
  4.   Save this script as "hockey.lua"
  5.   Place this script in:
  6.     - Windows (all users):   %ProgramFiles%\VideoLAN\VLC\lua\sd\
  7.     - Windows (current user):   %APPDATA%\VLC\lua\sd\
  8.     - Linux (all users):     /usr/share/vlc/lua/sd/
  9.     - Linux (current user):  ~/.local/share/vlc/lua/sd/
  10.     - Mac OS X (all users):  VLC.app/Contents/MacOS/share/lua/sd/
  11.  
  12.  
  13.   If you have issues using this, try changing all `add_subnode` to `add_node`.
  14.   Older versions of VLC use `add_node`, but recent updates have switched to `add_subnode`.
  15.  
  16. --]]
  17. require "simplexml"
  18.  
  19. function descriptor()
  20.     return { title="/r/hockey" }
  21. end
  22.  
  23. function main()
  24.     local quality = {400, 800, 1200, 1600, 2400, 3000, 4500}
  25.     local games = simplexml.parse_url("http://208.92.36.37/nlds/as3/get_games.php?client=nhl&playerclient=hop")
  26.     for _, game in ipairs( games.children ) do
  27.         if(game.name == "game") then
  28.             simplexml.add_name_maps( game )
  29.             local game_date = game.attributes["game_date"]
  30.             local game_time = date_to_time(game_date)
  31.             local home_abr = game.children_map['home_team'][1].children[1]
  32.             local away_abr = game.children_map['away_team'][1].children[1]
  33.             local home_team = full_name(home_abr)
  34.             local away_team = full_name(away_abr)
  35.             local game_title = game_time .. " " .. away_team .. " @ " .. home_team
  36.             local node = vlc.sd.add_node( { title = game_title } )
  37.             for _, ass in ipairs(game.children_map['assignments'][1].children) do
  38.                 local feed = ass.attributes["feed_display_name"]
  39.                 local feed_title = home_team
  40.                 local feed_abr = home_abr
  41.                 if(feed == "away") then
  42.                     feed_title = away_team
  43.                     feed_abr = away_abr
  44.                 end
  45.                 local d = node:add_subnode({ title = feed_title,
  46.                                              arturl = get_logo(feed_abr, "small")
  47.                                            })
  48.                 local ipad = ass.children_map['ipad_url'][1].children[1]
  49.                 for _, q in ipairs(quality) do
  50.                     local url = string.gsub(ipad, "ipad", q)
  51.                     d:add_subitem({ path = url,
  52.                                     arturl = get_logo(feed_abr, "small"),
  53.                                     title = away_team .. " @ " .. home_team .. ' (' .. q .. ' kbps)'
  54.                                   })
  55.                 end
  56.             end
  57.         end
  58.     end
  59. end
  60.  
  61. function date_to_time(game_date)
  62.     local game_time = string.gsub(game_date, "^.-%s(%d?%d):(%d%d):%d%d", "%1:%2 PM ET")
  63.     local _, _, hour = string.find(game_time, "^(%d?%d)")
  64.     hour24 = tonumber(hour)
  65.     if hour24 < 12 then
  66.         game_time = string.gsub(game_time, "PM", "AM")
  67.     elseif hour24 > 12 then
  68.         local hour12 = tostring(hour24 - 12)
  69.         game_time = string.gsub(game_time, "^%d?%d", hour12)
  70.     end
  71.     return (game_time)
  72. end
  73.  
  74. function full_name(abr)
  75.     local all_names = {
  76.         BOS = "Boston Bruins",
  77.         BUF = "Buffalo Sabres",
  78.         CGY = "Calgary Flames",
  79.         CHI = "Chicago Blackhawks",
  80.         DET = "Detroit Redwings",
  81.         EDM = "Edmonton Oilers",
  82.         CAR = "Carolina Hurricanes",
  83.         LOS = "Los Angeles Kings",
  84.         MON = "Montreal Canadiens",
  85.         DAL = "Dallas Stars",
  86.         NJD = "New Jersey Devils",
  87.         NYI = "NY Islanders Islanders",
  88.         NYR = "NY Rangers Rangers",
  89.         PHI = "Philadelphia Flyers",
  90.         PIT = "Pittsburgh Penguins",
  91.         COL = "Colorado Avalanche",
  92.         STL = "St. Louis Blues",
  93.         TOR = "Toronto Maple Leafs",
  94.         VAN = "Vancouver Canucks",
  95.         WSH = "Washington Capitals",
  96.         PHX = "Phoenix Coyotes",
  97.         SAN = "San Jose Sharks",
  98.         OTT = "Ottawa Senators",
  99.         TAM = "Tampa Bay Lightning",
  100.         ANA = "Anaheim Ducks",
  101.         FLA = "Florida Panthers",
  102.         CBS = "Columbus BlueJackets",
  103.         MIN = "Minnesota Wild",
  104.         NSH = "Nashville Predators",
  105.         WPG = "Winnipeg Jets"
  106.     }
  107.     local name = all_names[abr]
  108.     return(name)
  109. end
  110.  
  111. function get_logo(abr, size)
  112.     -- size should be 'small', 'medium', or 'large'
  113.     local team_names = {
  114.         BOS = "bruins",
  115.         BUF = "sabres",
  116.         CGY = "flames",
  117.         CHI = "blackhawks",
  118.         DET = "redwings",
  119.         EDM = "oilers",
  120.         CAR = "hurricanes",
  121.         LOS = "kings",
  122.         MON = "canadiens",
  123.         DAL = "stars",
  124.         NJD = "devils",
  125.         NYI = "islanders",
  126.         NYR = "rangers",
  127.         PHI = "flyers",
  128.         PIT = "penguins",
  129.         COL = "avalanche",
  130.         STL = "blues",
  131.         TOR = "mapleleafs",
  132.         VAN = "canucks",
  133.         WSH = "capitals",
  134.         PHX = "coyotes",
  135.         SAN = "sharks",
  136.         OTT = "senators",
  137.         TAM = "lightning",
  138.         ANA = "ducks",
  139.         FLA = "panthers",
  140.         CBS = "bluejackets",
  141.         MIN = "wild",
  142.         NSH = "predators",
  143.         WPG = "jets"
  144.     }
  145.     return('http://1.cdn.nhle.com/' .. team_names[abr] .. '/images/logos/' .. size .. '.png')
  146. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement