SHARE
TWEET

nhl

a guest Nov 8th, 2013 1,922 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import subprocess
  2. import simplejson
  3. import requests
  4. import datetime
  5. from datetime import timedelta
  6. import re
  7.  
  8. ua = '#EXTVLCOPT:http-user-agent=AppleCoreMedia/1.0.0.8C148 (iPad; U; CPU OS 4_2_1 like Mac OS X; en_us)\n'
  9. vlcdir = 'C:\\Program Files\\VideoLAN\\VLC\\'
  10. today = datetime.datetime.now() - datetime.timedelta(hours=7)
  11. a = []
  12. h = []
  13. urls = []
  14. ag = []
  15. hg = []
  16.  
  17. def getJSON():
  18.     r = requests.get('http://live.nhl.com/GameData/SeasonSchedule-20132014.json')
  19.     c = r.content
  20.     j = simplejson.loads(c)
  21.     for item in j:
  22.         if item['est'][:8] == today.strftime("%Y%m%d"):
  23.             h.append(item['h'])
  24.             a.append(item['a'])
  25.             id = str(item['id'])
  26.             urls.append('http://smb.cdnak.neulion.com/fs/nhl/mobile/feed_new/data/streams/2013/ipad/02_'+id[6:10]+'.json')
  27.  
  28. def replace(string):
  29.     out = re.sub(r'(.*)_hd_.*',r'\1_hd_4500.m3u8',string)
  30.     return out
  31.    
  32. def getURLS():
  33.     for i in range(len(urls)):
  34.         r = requests.get(urls[i])
  35.         c = r.content
  36.         j = simplejson.loads(c)
  37.         def getnested(*keys):
  38.             ob = j
  39.             for key in keys:
  40.                 try:
  41.                     ob = ob[key]
  42.                 except KeyError:
  43.                     pass
  44.             return ob
  45.         if str(getnested('gameStreams','ipad','home','live','bitrate0')).startswith('http:'):
  46.             hg.append(str(getnested('gameStreams','ipad','home','live','bitrate0')))
  47.         if str(getnested('gameStreams','ipad','home','live','bitrate0')).startswith('http:'):
  48.             ag.append(str(getnested('gameStreams','ipad','away','live','bitrate0')))
  49.  
  50. getJSON()
  51. getURLS()
  52. save_path = 'D:\\uus\\'+str(today.strftime("%Y%m%d"))+'NHLjson.m3u'
  53. playlist = open(save_path,'w+')
  54. playlist.write('#EXTM3U\n')
  55. for i in range(len(hg)):
  56.     playlist.write('\n#EXTINF:0,HOME:   '+h[i].upper()+' @ '+a[i].upper()+'\n')
  57.     playlist.write(str(ua))
  58.     playlist.write(replace(str(hg[i])))
  59.     playlist.write('\n#EXTINF:0,AWAY:   '+a[i].upper()+' @ '+h[i].upper()+'\n')
  60.     playlist.write(str(ua))
  61.     playlist.write(replace(str(ag[i])))
  62. playlist.close()
  63. subprocess.call([vlcdir+"vlc", save_path, '  --m3u-extvlcopt'], shell=True)
RAW Paste Data
Top