Advertisement
Guest User

Untitled

a guest
Mar 2nd, 2016
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.58 KB | None | 0 0
  1. import sys
  2. import os
  3. import urllib
  4. import xbmc
  5. import xbmcgui
  6. import xbmcplugin
  7. import xbmcaddon
  8. import logging
  9. from operator import itemgetter
  10. import urllib2
  11. import json
  12.  
  13. def show_tags():
  14. tag_handle = int(sys.argv[1])
  15. xbmcplugin.setContent(tag_handle, 'tags')
  16.  
  17. for tag in tags:
  18. iconPath = os.path.join(home, 'resources', 'media', tag['icon'])
  19. li = xbmcgui.ListItem(tag['title'], iconImage=iconPath)
  20. url = sys.argv[0] + '?tag=' + str(tag['id'])
  21. xbmcplugin.addDirectoryItem(handle=tag_handle, url=url, listitem=li, isFolder=True)
  22.  
  23. xbmcplugin.endOfDirectory(tag_handle)
  24.  
  25. def show_streams(tag):
  26. stream_handle = int(sys.argv[1])
  27. xbmcplugin.setContent(stream_handle, 'streams')
  28. logging.warning('TAG show_streams!!!! %s', tag)
  29. for stream in streams[str(tag)]:
  30. logging.debug('STREAM HERE!!! %s', stream['title'])
  31. iconPath = os.path.join(home, 'resources', 'media', stream['icon'])
  32. li = xbmcgui.ListItem(stream['title'], iconImage=iconPath)
  33. xbmcplugin.addDirectoryItem(handle=stream_handle, url=stream['url'], listitem=li)
  34.  
  35. xbmcplugin.endOfDirectory(stream_handle)
  36.  
  37. def show_day(day):
  38. logging.warning('LEAGUE show_games!!!! %s', day)
  39.  
  40. stream_handle = int(sys.argv[1])
  41. xbmcplugin.setContent(stream_handle, 'streams')
  42. for game in day['games']:
  43. xbmc.log(str(game), xbmc.LOGERROR)
  44. iconPath = os.path.join(home, 'resources', 'media', 'default-live.png')
  45. title = game['title'] if not 'time' in game else game['title'] + ' ' + game['time']
  46. title = title if not game['isLive'] else title + ' (Live)'
  47. li = xbmcgui.ListItem(title, iconImage=iconPath)
  48. xbmcplugin.addDirectoryItem(handle=stream_handle, url=game['url'], listitem=li)
  49.  
  50. xbmcplugin.endOfDirectory(stream_handle)
  51.  
  52.  
  53. def show_feeds():
  54. feed_handle = int(sys.argv[1])
  55. xbmcplugin.setContent(feed_handle, 'feeds')
  56.  
  57. for feed in feeds:
  58. iconPath = os.path.join(home, 'resources', 'media', 'default-live.png')
  59. li = xbmcgui.ListItem(feed, iconImage=iconPath)
  60. url = sys.argv[0] + '?feed=' + feed
  61. xbmcplugin.addDirectoryItem(handle=feed_handle, url=url, listitem=li, isFolder=True)
  62.  
  63. xbmcplugin.endOfDirectory(feed_handle)
  64.  
  65. def show_feed(id):
  66. logging.warning('FEED show_feed!!!! %s', id)
  67. # feedsFlat = dict((x['id'], x) for x in feeds[id])
  68. # feed = feedsFlat[id]
  69.  
  70. # leagues
  71. leagues = feeds[id]
  72. feed_handle = int(sys.argv[1])
  73. xbmcplugin.setContent(feed_handle, 'feeds')
  74.  
  75. for league in leagues:
  76. iconPath = os.path.join(home, 'resources', 'media', 'default-live.png')
  77. li = xbmcgui.ListItem(league, iconImage=iconPath)
  78. url = sys.argv[0] + '?feed=' + id + '&league='+str(league)
  79. xbmcplugin.addDirectoryItem(handle=feed_handle, url=url, listitem=li, isFolder=True)
  80.  
  81. xbmcplugin.endOfDirectory(feed_handle)
  82.  
  83. def show_channels(id):
  84. logging.warning('CHANNELS show_channels!!!! %s', id)
  85. # leagues
  86. channels = sorted(feeds[id], key=lambda x: x['title'].lower())
  87. # channels = feeds[id]
  88. channel_handle = int(sys.argv[1])
  89. xbmcplugin.setContent(channel_handle, 'channels')
  90.  
  91. for channel in channels:
  92. # if channel['disabled'] is True:
  93. # continue
  94. #hide disabled
  95. xbmc.log(str(channel), xbmc.LOGERROR)
  96. iconPath = os.path.join(home, 'resources', 'media', channel['icon'])
  97. title = channel['title']
  98. li = xbmcgui.ListItem(title, iconImage=iconPath)
  99. url = channel['url']
  100.  
  101. #headers
  102. if 'user-agent' in channel:
  103. url += '|User-Agent='+channel['user-agent']
  104.  
  105. xbmcplugin.addDirectoryItem(handle=channel_handle, url=url, listitem=li)
  106.  
  107. xbmcplugin.endOfDirectory(channel_handle)
  108.  
  109.  
  110. def show_games(id, league):
  111. logging.warning('LEAGUE data %s', league)
  112. league = feeds[id][league]
  113. day = league[0]
  114. show_day(day)
  115.  
  116. def get_params():
  117. """
  118. Retrieves the current existing parameters from XBMC.
  119. """
  120. param = []
  121. paramstring = sys.argv[2]
  122. if len(paramstring) >= 2:
  123. params = sys.argv[2]
  124. cleanedparams = params.replace('?', '')
  125. if params[len(params) - 1] == '/':
  126. params = params[0:len(params) - 2]
  127. pairsofparams = cleanedparams.split('&')
  128. param = {}
  129. for i in range(len(pairsofparams)):
  130. splitparams = {}
  131. splitparams = pairsofparams[i].split('=')
  132. if (len(splitparams)) == 2:
  133. param[splitparams[0]] = splitparams[1]
  134. return param
  135.  
  136.  
  137. def lower_getter(field):
  138. def _getter(obj):
  139. return obj[field].lower()
  140.  
  141. return _getter
  142.  
  143.  
  144. addon = xbmcaddon.Addon()
  145. username = addon.getSetting('username')
  146. password = addon.getSetting('password')
  147. port = addon.getSetting('port')
  148. home = xbmc.translatePath(addon.getAddonInfo('path'))
  149.  
  150. tags = [
  151. {
  152. 'title': 'Sports',
  153. 'id': 'sports',
  154. 'icon': 'tag-sports.png',
  155. }, {
  156. 'title': 'News',
  157. 'id': 'news',
  158. 'icon': 'tag-news.png'
  159. }, {
  160. 'title': 'Music',
  161. 'id': 'music',
  162. 'icon': 'tag-music.png'
  163. }, {
  164. 'title': 'Kids',
  165. 'id': 'kids',
  166. 'icon': 'tag-kids.png'
  167. },{
  168. 'title': 'Live Sports',
  169. 'id': 'live-sports',
  170. 'icon': 'tag-sports.png',
  171. },{
  172. 'title': 'Live News',
  173. 'id': 'live-news',
  174. 'icon': 'tag-news.png',
  175. }
  176. ]
  177.  
  178. feeds = {}
  179.  
  180. feeds['games'] = json.load(urllib2.urlopen('http://schedule.torula.com/games.json'))
  181. # feeds['channels-sports'] = json.load(urllib2.urlopen('http://schedule.torula.com/channels-sports.json'))
  182. # feeds['channels-news'] = json.load(urllib2.urlopen('http://schedule.torula.com/channels-news.json'))
  183. # feeds['channels-music'] = json.load(urllib2.urlopen('http://schedule.torula.com/channels-music.json'))
  184. # feeds['channels-kids'] = json.load(urllib2.urlopen('http://schedule.torula.com/channels-kids.json'))
  185.  
  186. live_sports_url = "http://torula.us.to:%s/live-sports.json" % (port)
  187. live_news_url = "http://torula.us.to:%s/live-news.json" % (port)
  188. logging.warning("live_sports_url", live_sports_url)
  189. logging.warning("live_news_url", live_news_url)
  190. feeds['channels-live-sports'] = json.load(urllib2.urlopen(live_sports_url))
  191. feeds['channels-live-news'] = json.load(urllib2.urlopen(live_news_url))
  192.  
  193. PARAMS = get_params()
  194. TAG = None
  195. FEED = None
  196. LEAGUE = None
  197. logging.warning('PARAMS!!!! %s', PARAMS)
  198.  
  199. try:
  200. # TAG = PARAMS['tag']
  201. FEED = PARAMS['feed']
  202. LEAGUE = PARAMS['league']
  203. except:
  204. pass
  205.  
  206. logging.warning('ARGS!!!! sys.argv %s', sys.argv)
  207.  
  208. # if TAG == None and FEED == None:
  209. if FEED == None:
  210. # show_tags()
  211. show_feeds()
  212. # elif TAG:
  213. # show_streams(TAG)
  214. elif FEED and FEED == 'games' and not LEAGUE:
  215. show_feed(FEED)
  216. elif FEED and FEED != 'games' and not LEAGUE:
  217. show_channels(FEED)
  218. elif FEED and LEAGUE:
  219. show_games(FEED, LEAGUE)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement