Advertisement
Guest User

Untitled

a guest
Oct 4th, 2013
197
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.   If you have issues using this, try changing all occurances of `add_subnode` to `add_node`.
  13.   Older versions of VLC use `add_node`, but recent updates have switched to `add_subnode`.
  14. --]]
  15. require "simplexml"
  16.  
  17. function descriptor()
  18.     return { title="/r/hockey" }
  19. end
  20.  
  21. function main()
  22.     local quality = {400, 800, 1200, 1600, 2400, 3000, 4500}
  23.     local games = simplexml.parse_url("http://208.92.36.37/nlds/as3/get_games.php?client=nhl&playerclient=hop")
  24.     for _, game in ipairs( games.children ) do
  25.         if(game.name == "game") then
  26.             simplexml.add_name_maps( game )
  27.             local game_date = game.attributes["game_date"]
  28.             local game_time = date_to_time(game_date)
  29.             local home_team = full_name(game.children_map['home_team'][1].children[1])
  30.             local away_team = full_name(game.children_map['away_team'][1].children[1])
  31.             local game_title = game_time .. " " .. away_team .. " @ " .. home_team
  32.             if not string.find(home_team,"^T%d%d$") and not string.find (away_team,"^T%d%d$") then
  33.                 local node = vlc.sd.add_node( { title = game_title } )
  34.                 for _, ass in ipairs(game.children_map['assignments'][1].children) do
  35.                     local feed = ass.attributes["feed_display_name"]
  36.                     local feed_title = home_team
  37.                     if(feed == "away") then
  38.                         feed_title = away_team
  39.                     end
  40.                     local d = node:add_subnode({ title = feed_title })
  41.                     local ipad = ass.children_map['ipad_url'][1].children[1]
  42.                     for _, q in ipairs(quality) do
  43.                         local url = string.gsub(ipad, "ipad", q)
  44.                         d:add_subitem({ path = url, title = q .. ' kbps' })
  45.                     end
  46.                 end
  47.             end
  48.         end
  49.     end
  50. end
  51.  
  52. function date_to_time(game_date)
  53.     -- TIME_OFFSET hours from Eastern time zone (moving westward). ie: Pacific should be 3
  54.     local TIME_OFFSET = 3
  55.     -- Change this so that the proper time is displayed for you.
  56.     -- If you do not live in North America, you can add your timezone abreviation to the if statement below.
  57.     local tz = "ET"
  58.     if TIME_OFFSET == 1 then
  59.         tz = "CT"
  60.     elseif TIME_OFFSET == 2 then
  61.         tz = "MT"
  62.     elseif TIME_OFFSET == 3 then
  63.         tz = "PT"
  64.     end
  65.     local game_time = string.gsub(game_date, "^.-%s(%d?%d):(%d%d):%d%d", "%1:%2 PM " .. tz)
  66.     local _, _, hour = string.find(game_time, "^(%d?%d)")
  67.     hour24 = tonumber(hour)
  68.     local local_noon = (12 + TIME_OFFSET)
  69.     local hour12 = tostring(hour24 - TIME_OFFSET)
  70.     if hour24 < (local_noon) then
  71.         game_time = string.gsub(game_time, "PM", "AM")
  72.     elseif hour24 > (local_noon) then
  73.         hour12 = tostring(hour24 - (local_noon))
  74.     end
  75.     game_time = string.gsub(game_time, "^%d?%d", hour12)
  76.     return (game_time)
  77. end
  78.  
  79. function full_name(abr)
  80.     local all_names = {
  81.         BOS = "Boston Bruins",
  82.         BUF = "Buffalo Sabres",
  83.         CGY = "Calgary Flames",
  84.         CHI = "Chicago Blackhawks",
  85.         DET = "Detroit Red Wings",
  86.         EDM = "Edmonton Oilers",
  87.         CAR = "Carolina Hurricanes",
  88.         LOS = "Los Angeles Kings",
  89.         MON = "Montreal Canadiens",
  90.         DAL = "Dallas Stars",
  91.         NJD = "New Jersey Devils",
  92.         NYI = "New York Islanders",
  93.         NYR = "New York Rangers",
  94.         PHI = "Philadelphia Flyers",
  95.         PIT = "Pittsburgh Penguins",
  96.         COL = "Colorado Avalanche",
  97.         STL = "St. Louis Blues",
  98.         TOR = "Toronto Maple Leafs",
  99.         VAN = "Vancouver Canucks",
  100.         WSH = "Washington Capitals",
  101.         PHX = "Phoenix Coyotes",
  102.         SAN = "San Jose Sharks",
  103.         OTT = "Ottawa Senators",
  104.         TAM = "Tampa Bay Lightning",
  105.         ANA = "Anaheim Ducks",
  106.         FLA = "Florida Panthers",
  107.         CMB = "Columbus Blue Jackets",
  108.         MIN = "Minnesota Wild",
  109.         NSH = "Nashville Predators",
  110.         WPG = "Winnipeg Jets"
  111.     }
  112.     local name = all_names[abr]
  113.     if name == nil then
  114.         name = abr
  115.     end
  116.     return(name)
  117. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement