Advertisement
Guest User

Untitled

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