Advertisement
Guest User

hockey.luac

a guest
Dec 22nd, 2013
14,121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.02 KB | None | 0 0
  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. require "simplexml"
  13.  
  14. function descriptor()
  15.     return { title="/r/hockey" }
  16. end
  17.  
  18. function main()
  19.     local games = simplexml.parse_url("http://breadwinka.com/get_games.php?client=nhl&playerclient=hop")
  20.     local test_games = {}
  21.     for _, game in ipairs( games.children ) do              
  22.         if(game.name == "game") then          
  23.             simplexml.add_name_maps( game )
  24.             local game_date, home_team, away_team, title = getInfoForGame(game)
  25.             if string.find(home_team,"^T%d+$") or string.find (away_team,"^T%d+$") then
  26.                 table.insert(test_games, game)
  27.             else
  28.                 local node = vlc.sd.add_node( { path = "", title = title } )
  29.                 addNodeForGame(node, game, home_team, away_team)
  30.             end
  31.         end
  32.     end
  33.  
  34.     if table.getn(test_games) > 0 then
  35.         local test_node = vlc.sd.add_node( { path = "", title = "Test Streams" } )
  36.         for _, game in ipairs(test_games) do
  37.             local game_date, home_team, away_team, title = getInfoForGame(game)
  38.             node = test_node:add_subnode({ title = title })
  39.             addNodeForGame(node, game, home_team, away_team)
  40.         end
  41.     end
  42. end
  43.  
  44. function getInfoForGame(game)
  45.     local game_date = game.attributes["game_date"]
  46.     local home_team = full_name(game.children_map['home_team'][1].children[1])
  47.     local away_team = full_name(game.children_map['away_team'][1].children[1])
  48.     local title = game_date .. " " .. away_team .. " @ " .. home_team
  49.     return game_date, home_team, away_team, title
  50. end
  51.  
  52. function addNodeForGame(parentNode, game, home_team, away_team)
  53.     local quality = {400, 800, 1200, 1600, 2400, 3000, 4500}
  54.     for _, ass in ipairs(game.children_map['assignments'][1].children) do
  55.         local feed = ass.attributes["feed_display_name"]
  56.         local feed_title = home_team
  57.         if(feed == "away") then
  58.             feed_title = away_team
  59.         end
  60.         local feed_node = parentNode:add_subnode({ title = feed_title })
  61.         local ipad = ass.children_map['ipad_url'][1].children[1]
  62.         for _, q in ipairs(quality) do
  63.             local url = string.gsub(ipad, "ipad", q)
  64.             feed_node:add_subitem({
  65.                 path = url,
  66.                 title = q .. ' kbps',
  67.                 options = {
  68.                 "http-user-agent=iTunes-AppleTV/4.1"
  69.             }
  70.             })
  71.         end
  72.     end
  73. end
  74.  
  75. function full_name(abr)
  76.     local all_names = {
  77.         BOS = "Boston Bruins",
  78.         BUF = "Buffalo Sabres",
  79.         CGY = "Calgary Flames",
  80.         CHI = "Chicago Blackhawks",
  81.         DET = "Detroit Red Wings",
  82.         EDM = "Edmonton Oilers",
  83.         CAR = "Carolina Hurricanes",
  84.         LAK = "Los Angeles Kings",
  85.         MTL = "Montreal Canadiens",
  86.         DAL = "Dallas Stars",
  87.         NJD = "New Jersey Devils",
  88.         NYI = "New York Islanders",
  89.         NYR = "New York Rangers",
  90.         PHI = "Philadelphia Flyers",
  91.         PIT = "Pittsburgh Penguins",
  92.         COL = "Colorado Avalanche",
  93.         STL = "St. Louis Blues",
  94.         TOR = "Toronto Maple Leafs",
  95.         VAN = "Vancouver Canucks",
  96.         WSH = "Washington Capitals",
  97.         PHX = "Phoenix Coyotes",
  98.         SJS = "San Jose Sharks",
  99.         OTT = "Ottawa Senators",
  100.         TBL = "Tampa Bay Lightning",
  101.         ANA = "Anaheim Ducks",
  102.         FLA = "Florida Panthers",
  103.         CBJ = "Columbus Blue Jackets",
  104.         MIN = "Minnesota Wild",
  105.         NSH = "Nashville Predators",
  106.         WPG = "Winnipeg Jets"
  107.     }
  108.     local name = all_names[abr]
  109.     if name == nil then
  110.         name = abr
  111.     end
  112.     return(name)
  113. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement