View difference between Paste ID: xSaNQYx5 and PyZdAnqU
SHOW: | | - or go back to the newest paste.
1
--[[
2
  DISCLAIMER: SCRIPT IS PROVIDED AS IS USE AT YOUR OWN RISK!
3-
 
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/  
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-
 
13+
  Older versions of VLC use `add_node`, but recent updates have switched to `add_subnode`.
14
--]]
15
require "simplexml"
16
17-
 
17+
18
    return { title="/r/hockey" }
19
end
20
21-
    for _, game in ipairs( games.children ) do              
21+
22-
        if(game.name == "game") then           
22+
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-
            local home_team = game.children_map['home_team'][1].children[1]
25+
        if(game.name == "game") then
26-
            local away_team = game.children_map['away_team'][1].children[1]
26+
27-
            local title = game_date .. " " .. away_team .. " @ " .. home_team
27+
28-
            local node = vlc.sd.add_node( { path = "", title = title } )            
28+
            local game_time = date_to_time(game_date)
29-
            for _, ass in ipairs(game.children_map['assignments'][1].children) do
29+
            local home_team = full_name(game.children_map['home_team'][1].children[1])
30-
                local feed = ass.attributes["feed_display_name"]
30+
            local away_team = full_name(game.children_map['away_team'][1].children[1])
31-
                local feed_title = home_team
31+
            local game_title = game_time .. " " .. away_team .. " @ " .. home_team
32-
                if(feed == "away") then
32+
            if not string.find(home_team,"^T%d%d$") and not string.find (away_team,"^T%d%d$") then
33-
                    feed_title = away_team
33+
                local node = vlc.sd.add_node( { title = game_title } )
34-
					
34+
                for _, ass in ipairs(game.children_map['assignments'][1].children) do
35
                    local feed = ass.attributes["feed_display_name"]
36-
                local d = node:add_subnode({title = feed_title})                
36+
                    local feed_title = home_team
37-
                local ipad = ass.children_map['ipad_url'][1].children[1]
37+
                    if(feed == "away") then
38-
                for _, q in ipairs(quality) do
38+
                        feed_title = away_team
39-
                    local url = string.gsub(ipad, "ipad", q)
39+
                    end
40-
                    d:add_subitem({path = url , options = {":http-user-agent=AppleCoreMedia%2f1.0.0.8F455%20(AppleTV%3b%20U%3b%20CPU%20OS%204_3%20like%??20Mac%20OS%20X%3b%20de_de"} , title = away_team .. " @ " .. home_team .. '(' .. q .. ' kbps)'})
40+
                    local feed_node = node:add_subnode({ title = feed_title })
41
                    local ipad = ass.children_map['ipad_url'][1].children[1]
42-
                
42+
                    for _, q in ipairs(quality) do
43
                        local url = string.gsub(ipad, "ipad", q)
44
                        feed_node:add_subitem({ path = url,
45
                                                title = q .. ' kbps',
46
                                                options = { "http-user-agent=AppleCoreMedia/1.0.0.8C148 (iPad; U; CPU OS 4_2_1 like Mac OS X; en_us)" }
47
                                              })
48
                    end
49
                end
50
            end
51
        end
52
    end
53
end
54
55
function date_to_time(game_date)
56
    -- TIME_OFFSET hours from Eastern time zone (moving westward). ie: Pacific should be 3
57
    local TIME_OFFSET = 3
58
    -- Change this so that the proper time is displayed for you.
59
    -- If you do not live in North America, you can add your timezone abreviation to the if statement below.
60
    local tz = "ET"
61
    if TIME_OFFSET == 1 then
62
        tz = "CT"
63
    elseif TIME_OFFSET == 2 then
64
        tz = "MT"
65
    elseif TIME_OFFSET == 3 then
66
        tz = "PT"
67
    end
68
    local game_time = string.gsub(game_date, "^.-%s(%d?%d):(%d%d):%d%d", "%1:%2 PM " .. tz)
69
    local _, _, hour = string.find(game_time, "^(%d?%d)")
70
    hour24 = tonumber(hour)
71
    local local_noon = (12 + TIME_OFFSET)
72
    local hour12 = tostring(hour24 - TIME_OFFSET)
73
    if hour24 < (local_noon) then
74
        game_time = string.gsub(game_time, "PM", "AM")
75
    elseif hour24 > (local_noon) then
76
        hour12 = tostring(hour24 - (local_noon))
77
    end
78
    game_time = string.gsub(game_time, "^%d?%d", hour12)
79
    return (game_time)
80
end
81
82
function full_name(abr)
83
    local all_names = {
84
        BOS = "Boston Bruins",
85
        BUF = "Buffalo Sabres",
86
        CGY = "Calgary Flames",
87
        CHI = "Chicago Blackhawks",
88
        DET = "Detroit Red Wings",
89
        EDM = "Edmonton Oilers",
90
        CAR = "Carolina Hurricanes",
91
        LOS = "Los Angeles Kings",
92
        MON = "Montreal Canadiens",
93
        DAL = "Dallas Stars",
94
        NJD = "New Jersey Devils",
95
        NYI = "New York Islanders",
96
        NYR = "New York Rangers",
97
        PHI = "Philadelphia Flyers",
98
        PIT = "Pittsburgh Penguins",
99
        COL = "Colorado Avalanche",
100
        STL = "St. Louis Blues",
101
        TOR = "Toronto Maple Leafs",
102
        VAN = "Vancouver Canucks",
103
        WSH = "Washington Capitals",
104
        PHX = "Phoenix Coyotes",
105
        SAN = "San Jose Sharks",
106
        OTT = "Ottawa Senators",
107
        TAM = "Tampa Bay Lightning",
108
        ANA = "Anaheim Ducks",
109
        FLA = "Florida Panthers",
110
        CMB = "Columbus Blue Jackets",
111
        MIN = "Minnesota Wild",
112
        NSH = "Nashville Predators",
113
        WPG = "Winnipeg Jets"
114
    }
115
    local name = all_names[abr]
116
    if name == nil then
117
        name = abr
118
    end
119
    return(name)
120
end