Skip to content

Instantly share code, notes, and snippets.

@pc-coholic
Forked from anonymous/fneulion.go
Created October 31, 2015 19:29
Show Gist options
  • Save pc-coholic/02ec03496c3653a4e85b to your computer and use it in GitHub Desktop.
Save pc-coholic/02ec03496c3653a4e85b to your computer and use it in GitHub Desktop.
FNeulion
package main
import "os"
import "fmt"
import "strconv"
import "net/http"
import "strings"
import "log"
import "time"
import "crypto/md5"
import "encoding/hex"
import "math/rand"
import "io/ioutil"
const nhlagent = "Mozilla/5.0 (Linux; Android 4.4.4;) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/33.0.0.0 Mobile Safari/537.36 android mobile NLServices 4.1106"
const neulionagent = "Mozilla/5.0 (Linux; Android 4.4.4; Galaxy Build/KTU84P) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/33.0.0.0 Mobile Safari/537.36 android mobile NLServices 4.1106";
const neulionip = "209.87.141.51"
var gameid = 0
var streamname = ""
var streamid = 0
var port = 80
func get_uri() string {
format := "/nhlgc/servlets/publishpoint?type=game&id=%d&gs=live&ft=%d&token=%d.%s";
ident := "R5iwKPLk2Tvod10158";
millis := int(time.Now().UnixNano() / 1000000)
filename := fmt.Sprintf("%s.%d.game.%d", ident, millis, gameid)
hasher := md5.New()
hasher.Write([]byte(filename))
hash := hex.EncodeToString(hasher.Sum(nil))
return fmt.Sprintf(format, gameid, streamid, millis, hash)
}
func get_cookie() string {
lat := []float32 {48.1333, 51.5072, 48.8567}
long := []float32 {11.5667, 0.1275, 2.3508}
url := fmt.Sprintf("http://gamecenter.nhl.com%s", get_uri())
client := &http.Client{}
req, _ := http.NewRequest("GET", url, nil)
req.Header.Add("User-Agent", nhlagent)
req.Header.Add("Geo-Coord", fmt.Sprintf("%f,%f", lat[rand.Intn(len(lat))], long[rand.Intn(len(long))]))
resp, _ := client.Do(req)
cont, _ := ioutil.ReadAll(resp.Body)
contents := string(cont)
pos1 := strings.Index(contents, "hdnea")
pos2 := strings.Index(contents, "]]")
return "nlqptid=nltid=nhlgc&nltdt=8&nltnt=1&" + contents[pos1:pos2]
}
func handler(w http.ResponseWriter, req *http.Request) {
cookie := get_cookie()
fmt.Printf("Proxy Cookie: %s\n", cookie)
fmt.Printf("Proxy Path: %s\n", req.URL)
hostname := req.Host
if strings.Contains(req.Host, "nlsk") {
hostname = neulionip
}
url := fmt.Sprintf("http://%s%s", hostname, req.URL)
client := &http.Client{}
outreq, _ := http.NewRequest("GET", url, nil)
for name, val := range req.Header {
if name == "User-Agent" {
outreq.Header.Add(name, neulionagent)
} else if !strings.HasPrefix(name, "Icy") || !strings.HasPrefix(name, "Range") {
outreq.Header.Add(name, val[0])
}
}
outreq.Header.Add("Cookie", cookie)
resp, _ := client.Do(outreq)
cont, _ := ioutil.ReadAll(resp.Body)
w.Write(cont)
}
func main() {
if len(os.Args) == 3 {
gid, _ := strconv.Atoi(os.Args[1])
gameid = gid
streamname = os.Args[2]
}
switch strings.ToLower(streamname) {
case "home":
streamid = 2
case "away":
streamid = 4
case "french":
streamid = 8
case "gcam1":
streamid = 64
case "gcam2":
streamid = 128
}
if (gameid == 0) || (streamname == "") || (streamid == 0) {
fmt.Println("Usage: " + os.Args[0] + " gameid <home or away or french or gcam1 or gcam2>")
os.Exit(1)
}
http.HandleFunc("/", handler)
log.Fatal(http.ListenAndServe(fmt.Sprintf(":%d", port), nil))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment