Advertisement
Guest User

NHL Streams

a guest
Mar 12th, 2014
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.49 KB | None | 0 0
  1. # This file must be in the same place as the JAR file:
  2. # http://www.reddit.com/r/hockey/comments/1q58xv/how_to_get_vlc_links/cf8zxx8?sort=confidence
  3. #
  4. # Edit this next line to match your VLC binary: ( \ = escape char, so double it for literal \ )
  5. vlcbin = "C:\\Program Files\\VideoLAN\\VLC\\vlc.exe"
  6. # Add this line to your hosts file (minus the comment #)
  7. # 127.0.0.1 nlsk.neulion.com
  8.  
  9. import json, urllib2, os, time
  10.  
  11. r = urllib2.urlopen("http://live.nhl.com/GameData/SeasonSchedule-20132014.json")
  12. h = r.read()
  13. d = json.loads(h)
  14.  
  15. #date = raw_input("Enter date of game [YYYYMMDD]: ")
  16. date = time.strftime("%Y%m%d")
  17.  
  18. games = []
  19. for entry in d:
  20. if entry['est'][:8] == date:
  21. games.append({"id":str(entry['id'])[-4:],"home":entry['h'],"away":entry['a']})
  22.  
  23. if not games:
  24. print "I couldn't find any games for that date. Sorry."
  25. os._exit(0)
  26.  
  27. for (i,game) in enumerate(games):
  28. print "{}: {} at {}".format(i+1,game['away'],game['home'])
  29.  
  30. c = raw_input("Which game would you like to start (#)? ")
  31.  
  32. gameid = games[int(c)-1]['id']
  33.  
  34. url = "http://smb.cdnak.neulion.com/fs/nhl/mobile/feed_new/data/streams/2013/ipad/02_{}.json".format(gameid)
  35. try:
  36. r = urllib2.urlopen(url)
  37. except:
  38. print "It appears that game hasn't started yet. Sorry."
  39. os._exit(0)
  40.  
  41. h = r.read()
  42. d = json.loads(h)
  43.  
  44. home = d['gameStreams']['ipad']['home']['live']['bitrate0']
  45. away = d['gameStreams']['ipad']['away']['live']['bitrate0']
  46.  
  47. if not home or not away:
  48. print "I couldn't find any streams for this game. Sorry."
  49. os._exit(0)
  50.  
  51. if "mp4" in home or "mp4" in away:
  52. print "It appears that game has ended already. Sorry."
  53. os._exit(0)
  54.  
  55. print "Here are the URLs I found for this game:"
  56. bitrates = [1600,3000,4500]
  57. urls = [home,away]
  58. urllist = []
  59. i = 0
  60. for url in urls:
  61. url = url[:-9]
  62. for bitrate in bitrates:
  63. i += 1
  64. string = "{}{}.m3u8".format(url,bitrate)
  65. urllist.append(string)
  66. print "{}: {}".format(i,string)
  67.  
  68. #~ print urllist
  69.  
  70. urlnum = raw_input("Choose a game (#): ")
  71. url = str(urllist[int(urlnum)-1])
  72.  
  73. import subprocess, threading
  74.  
  75. def run_java(url):
  76. process = "java -jar FuckNeulionV1.jar " + url
  77. subprocess.call(process,shell=True)
  78. return
  79.  
  80. def run_vlc(url):
  81. process = '"' + vlcbin + '" ' + url + ' :http-user-agent=iTunesAppleTV/4.1'
  82. subprocess.call(process,shell=True)
  83. return
  84.  
  85. t1 = threading.Thread(target=run_java,args=(url,))
  86. t1.start()
  87. t2 = threading.Thread(target=run_vlc,args=(url,))
  88. t2.start()
  89.  
  90. t2.join()
  91. print "Hit CTRL-C to stop the java process."
  92. t1.join()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement