Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sys
- import os
- import urllib
- import xbmc
- import xbmcgui
- import xbmcplugin
- import xbmcaddon
- import logging
- from operator import itemgetter
- import urllib2
- import json
- def show_tags():
- tag_handle = int(sys.argv[1])
- xbmcplugin.setContent(tag_handle, 'tags')
- for tag in tags:
- iconPath = os.path.join(home, 'resources', 'media', tag['icon'])
- li = xbmcgui.ListItem(tag['title'], iconImage=iconPath)
- url = sys.argv[0] + '?tag=' + str(tag['id'])
- xbmcplugin.addDirectoryItem(handle=tag_handle, url=url, listitem=li, isFolder=True)
- xbmcplugin.endOfDirectory(tag_handle)
- def show_streams(tag):
- stream_handle = int(sys.argv[1])
- xbmcplugin.setContent(stream_handle, 'streams')
- logging.warning('TAG show_streams!!!! %s', tag)
- for stream in streams[str(tag)]:
- logging.debug('STREAM HERE!!! %s', stream['title'])
- iconPath = os.path.join(home, 'resources', 'media', stream['icon'])
- li = xbmcgui.ListItem(stream['title'], iconImage=iconPath)
- xbmcplugin.addDirectoryItem(handle=stream_handle, url=stream['url'], listitem=li)
- xbmcplugin.endOfDirectory(stream_handle)
- def show_day(day):
- logging.warning('LEAGUE show_games!!!! %s', day)
- stream_handle = int(sys.argv[1])
- xbmcplugin.setContent(stream_handle, 'streams')
- for game in day['games']:
- xbmc.log(str(game), xbmc.LOGERROR)
- iconPath = os.path.join(home, 'resources', 'media', 'default-live.png')
- title = game['title'] if not 'time' in game else game['title'] + ' ' + game['time']
- title = title if not game['isLive'] else title + ' (Live)'
- li = xbmcgui.ListItem(title, iconImage=iconPath)
- xbmcplugin.addDirectoryItem(handle=stream_handle, url=game['url'], listitem=li)
- xbmcplugin.endOfDirectory(stream_handle)
- def show_feeds():
- feed_handle = int(sys.argv[1])
- xbmcplugin.setContent(feed_handle, 'feeds')
- for feed in feeds:
- iconPath = os.path.join(home, 'resources', 'media', 'default-live.png')
- li = xbmcgui.ListItem(feed, iconImage=iconPath)
- url = sys.argv[0] + '?feed=' + feed
- xbmcplugin.addDirectoryItem(handle=feed_handle, url=url, listitem=li, isFolder=True)
- xbmcplugin.endOfDirectory(feed_handle)
- def show_feed(id):
- logging.warning('FEED show_feed!!!! %s', id)
- # feedsFlat = dict((x['id'], x) for x in feeds[id])
- # feed = feedsFlat[id]
- # leagues
- leagues = feeds[id]
- feed_handle = int(sys.argv[1])
- xbmcplugin.setContent(feed_handle, 'feeds')
- for league in leagues:
- iconPath = os.path.join(home, 'resources', 'media', 'default-live.png')
- li = xbmcgui.ListItem(league, iconImage=iconPath)
- url = sys.argv[0] + '?feed=' + id + '&league='+str(league)
- xbmcplugin.addDirectoryItem(handle=feed_handle, url=url, listitem=li, isFolder=True)
- xbmcplugin.endOfDirectory(feed_handle)
- def show_channels(id):
- logging.warning('CHANNELS show_channels!!!! %s', id)
- # leagues
- channels = sorted(feeds[id], key=lambda x: x['title'].lower())
- # channels = feeds[id]
- channel_handle = int(sys.argv[1])
- xbmcplugin.setContent(channel_handle, 'channels')
- for channel in channels:
- # if channel['disabled'] is True:
- # continue
- #hide disabled
- xbmc.log(str(channel), xbmc.LOGERROR)
- iconPath = os.path.join(home, 'resources', 'media', channel['icon'])
- title = channel['title']
- li = xbmcgui.ListItem(title, iconImage=iconPath)
- url = channel['url']
- #headers
- if 'user-agent' in channel:
- url += '|User-Agent='+channel['user-agent']
- xbmcplugin.addDirectoryItem(handle=channel_handle, url=url, listitem=li)
- xbmcplugin.endOfDirectory(channel_handle)
- def show_games(id, league):
- logging.warning('LEAGUE data %s', league)
- league = feeds[id][league]
- day = league[0]
- show_day(day)
- def get_params():
- """
- Retrieves the current existing parameters from XBMC.
- """
- param = []
- paramstring = sys.argv[2]
- if len(paramstring) >= 2:
- params = sys.argv[2]
- cleanedparams = params.replace('?', '')
- if params[len(params) - 1] == '/':
- params = params[0:len(params) - 2]
- pairsofparams = cleanedparams.split('&')
- param = {}
- for i in range(len(pairsofparams)):
- splitparams = {}
- splitparams = pairsofparams[i].split('=')
- if (len(splitparams)) == 2:
- param[splitparams[0]] = splitparams[1]
- return param
- def lower_getter(field):
- def _getter(obj):
- return obj[field].lower()
- return _getter
- addon = xbmcaddon.Addon()
- username = addon.getSetting('username')
- password = addon.getSetting('password')
- port = addon.getSetting('port')
- home = xbmc.translatePath(addon.getAddonInfo('path'))
- tags = [
- {
- 'title': 'Sports',
- 'id': 'sports',
- 'icon': 'tag-sports.png',
- }, {
- 'title': 'News',
- 'id': 'news',
- 'icon': 'tag-news.png'
- }, {
- 'title': 'Music',
- 'id': 'music',
- 'icon': 'tag-music.png'
- }, {
- 'title': 'Kids',
- 'id': 'kids',
- 'icon': 'tag-kids.png'
- },{
- 'title': 'Live Sports',
- 'id': 'live-sports',
- 'icon': 'tag-sports.png',
- },{
- 'title': 'Live News',
- 'id': 'live-news',
- 'icon': 'tag-news.png',
- }
- ]
- feeds = {}
- feeds['games'] = json.load(urllib2.urlopen('http://schedule.torula.com/games.json'))
- # feeds['channels-sports'] = json.load(urllib2.urlopen('http://schedule.torula.com/channels-sports.json'))
- # feeds['channels-news'] = json.load(urllib2.urlopen('http://schedule.torula.com/channels-news.json'))
- # feeds['channels-music'] = json.load(urllib2.urlopen('http://schedule.torula.com/channels-music.json'))
- # feeds['channels-kids'] = json.load(urllib2.urlopen('http://schedule.torula.com/channels-kids.json'))
- live_sports_url = "http://torula.us.to:%s/live-sports.json" % (port)
- live_news_url = "http://torula.us.to:%s/live-news.json" % (port)
- logging.warning("live_sports_url", live_sports_url)
- logging.warning("live_news_url", live_news_url)
- feeds['channels-live-sports'] = json.load(urllib2.urlopen(live_sports_url))
- feeds['channels-live-news'] = json.load(urllib2.urlopen(live_news_url))
- PARAMS = get_params()
- TAG = None
- FEED = None
- LEAGUE = None
- logging.warning('PARAMS!!!! %s', PARAMS)
- try:
- # TAG = PARAMS['tag']
- FEED = PARAMS['feed']
- LEAGUE = PARAMS['league']
- except:
- pass
- logging.warning('ARGS!!!! sys.argv %s', sys.argv)
- # if TAG == None and FEED == None:
- if FEED == None:
- # show_tags()
- show_feeds()
- # elif TAG:
- # show_streams(TAG)
- elif FEED and FEED == 'games' and not LEAGUE:
- show_feed(FEED)
- elif FEED and FEED != 'games' and not LEAGUE:
- show_channels(FEED)
- elif FEED and LEAGUE:
- show_games(FEED, LEAGUE)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement