def authenticate(): """ Authenticate with the MLS service. This method pops up an error if authentication fails @return an MLS Live object """ # get the user name username = __settings__.getSetting("username") if len(username) == 0: dialog = xbmcgui.Dialog() dialog.ok(__language__(30000), __language__(30001)) xbmcplugin.endOfDirectory(handle=int(sys.argv[1]), succeeded=False) return None # get the password password = __settings__.getSetting("password") if len(password) == 0: dialog = xbmcgui.Dialog() dialog.ok(__language__(30002), __language__(30003)) xbmcplugin.endOfDirectory(handle=int(sys.argv[1]), succeeded=False) return None # authenticate with MLS live my_mls = mlslive.MLSLive() if not my_mls.login(username, password): dialog = xbmcgui.Dialog() dialog.ok(__language__(30004), __language__(30005)) xbmcplugin.endOfDirectory(handle=int(sys.argv[1]), succeeded=False) return None return my_mls
def playGame(value_string): values = urlparse.parse_qs(value_string) title = values['title'][0] condensed = False if 'condensed' in values.keys(): game = values['condensed'][0] condensed = True else: game = values['game'][0] if 'result' in values.keys(): if values['result'][0] == 'F': createFinalMenu(game, title) return mls = mlslive.MLSLive() stream = mls.getGameLiveStream(game, condensed) if stream == '': dialog = xbmcgui.Dialog() dialog.ok(__language__(30015), __language__(30016)) else: li = xbmcgui.ListItem(title) li.setInfo(type="Video", infoLabels={"Title": title}) p = xbmc.Player() p.play(stream, li)
def favoriteTeam(): mls = mlslive.MLSLive() clubs = mls.getClubs(xff) if clubs == None: xbmcgui.Dialog().ok(__language__(30028),__language__(30028)) return mls_clubs = {} for club in clubs: if club['isMLS']: mls_clubs[club['name']['full']] = club['id'] names = sorted(mls_clubs.keys()) index = xbmcgui.Dialog().select("Select Favorite Team", names) if index < 0: return mls.setFavoriteClub(mls_clubs[names[index]]) return
def createMonthMenu(month, complete=False): mls = mlslive.MLSLive() games = mls.getGames(month) if games == None: dialog = xbmcgui.Dialog() dialog.ok(__language__(30018), __language__(30019)) # signal the end of the directory xbmcplugin.endOfDirectory(int(sys.argv[1])) return None for game in games: final = False if 'result' in game.keys(): if game['result'] == 'F': final = True # skip any finished games if showing live or upcomming if final and not complete: continue # skip if showing completed and live or upcomming if complete and not final: continue title = mls.getGameString(game, __language__(30008)) li = xbmcgui.ListItem(title) values = {'game': game['id'], 'title': title} # if the game has a result pass it along if 'result' in game.keys(): values['result'] = game['result'] xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]), url=sys.argv[0] + '?' + urllib.urlencode(values), listitem=li, isFolder=True) # signal the end of the directory xbmcplugin.endOfDirectory(int(sys.argv[1]))
dest='month', help="List games of the month") parser.add_option('-x', '--x-forward-for', type='string', dest='xff', help="X-Forward-For header value") parser.add_option('-c', '--clubs', action='store_true', dest='clubs', help="List clubs") (options, args) = parser.parse_args() my_mls = mlslive.MLSLive() if options.clubs: clubs = my_mls.getClubs() if clubs == None: print "Unable to get clubs" sys.exit(1) for club in clubs: if club['isMLS']: print "{0}) {1}".format(club['id'], club['name']['full']) sys.exit(0) if options.user != None and options.password != None: if not my_mls.login(options.user, options.password, options.xff): print "*** Unable to authenticte with MLS live. please set username and password."
def createGamesMenu(complete = False, offset = None): """ Create the list of game. @param complete flag to indicate if we're showing completed games @param offset from the current date for which completed games will be shown """ mls = mlslive.MLSLive() fav = mls.getFavoriteClub() dt = datetime.datetime.now(); if not offset == None: dt = datetime.datetime.fromtimestamp(time.mktime(time.strptime(offset, "%c"))) games = mls.getGames(dt, xff) if games == None: dialog = xbmcgui.Dialog() dialog.ok(__language__(30018), __language__(30019)) return None for game in games: # Skip completed games in the live menu if complete == False and game['period'] == 'FullTime': continue elif complete and game['period'] != 'FullTime': continue plot = mls.getDescription(game, __language__(30021), __language__(30023), __language__(30024)) infos = { 'genre' : game['competition']['name'], 'title' : mls.getFullTitle(game, __language__(30008)), 'tvshowtitle' : game['competition']['name'], 'plot' : plot, 'plotoutline' : plot } title = mls.getGameString(game, __language__(30008)) li = xbmcgui.ListItem(title) li.setInfo('video', infos) # if an image is available, use it img = mls.getImage(game, fav) if not img == None: li.setIconImage(img) values = {'game' : game['optaId'], 'title' : title} xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]), url=sys.argv[0] + '?' + urllib.urlencode(values), listitem = li, isFolder = True) if complete: delta = datetime.timedelta(days=7); values = {'id' : 'complete', 'offset' : (dt - delta).strftime('%c')} li = xbmcgui.ListItem(__language__(30020)) xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]), url=sys.argv[0] + '?' + urllib.urlencode(values), listitem = li, isFolder = True) # signal the end of the directory xbmcplugin.endOfDirectory(int(sys.argv[1]))
def logout(): mls = mlslive.MLSLive() mls.deleteAccesstoken() xbmcgui.Dialog().notification(__language__(30029),__language__(30030), xbmcgui.NOTIFICATION_INFO)
def playGame(values, selected_media = None): """ Play a game. @param values the dictionary containing game details @param selected_media used to recursively call playGame on reauthentication. prevents user from having to reselect condensed or full match. """ title = values['title'][0] game = values['game'][0] mls = mlslive.MLSLive() medias = mls.getStreams(game, xff) if medias == None: dialog = xbmcgui.Dialog() dialog.ok(__language__(30015), __language__(30016)) return False names = [] for media in medias: names.append(media['name']) if not selected_media == None: media = selected_media elif len(names) > 1: index = xbmcgui.Dialog().select("Select Stream", names) if index < 0: return False media = medias[index] else: media = medias[0] try: streams = mls.getStreamURIs(media, xff) except RuntimeError as ex: err = str(ex) print "Error getting stream URIs: '{0}'".format(err) if err == 'blackout': xbmcgui.Dialog().ok(__language__(30016), __language__(30025)) return False elif err[:12] == 'access-token': if authenticate(mls): return playGame(values, media) else: return False elif err == 'media.not-playable': xbmcgui.Dialog().ok(__language__(30016), __language__(30031)) return False if streams == None: xbmcgui.Dialog().ok(__language__(30016), __language__(30006)) return False bitrates = [int(x) for x in streams.keys()] bitrates = [str(x) for x in reversed(sorted(bitrates)) ] index = xbmcgui.Dialog().select("Select Bitrate", bitrates) stream = streams[bitrates[index]] li = xbmcgui.ListItem(title) li.setInfo( type="Video", infoLabels={"Title" : title}) p = xbmc.Player() p.play(stream, li)