def episode_menu(): if vars.params.get("custom_date", False): date = datetime.datetime.combine( common.getDate(), datetime.time(hour=4, minute=0, second=0)) else: date = utils.nowEST().replace(hour=4, minute=0, second=0) utils.log("date for episodes: %s (from %s)" % (date, utils.nowEST()), xbmc.LOGDEBUG) schedule = 'https://nlnbamdnyc-a.akamaihd.net/fs/nba/feeds/epg/2019/%s_%s.js?t=%d' % ( date.month, date.day, time.time()) utils.log('Requesting %s' % schedule, xbmc.LOGDEBUG) now_timestamp = int(calendar.timegm(date.timetuple())) now_timestamp_milliseconds = now_timestamp * 1000 req = urllib2.Request(schedule, None) response = str(urllib2.urlopen(req).read()) json_response = json.loads(response[response.find("["):]) for entry in json_response: entry = entry['entry'] start_hours, start_minutes = entry['start'].split(':') start_timestamp_milliseconds = now_timestamp_milliseconds + ( int(start_hours) * 60 * 60 + int(start_minutes) * 60) * 1000 utils.log( "date for episode %s: %d (from %d)" % (entry['title'], start_timestamp_milliseconds, now_timestamp_milliseconds), xbmc.LOGDEBUG) duration_hours, duration_minutes = entry['duration'].split(":") duration_milliseconds = (int(duration_hours) * 60 * 60 + int(duration_minutes) * 60) * 1000 params = { 'duration': duration_milliseconds, 'start_timestamp': start_timestamp_milliseconds } name = "%s - %s (%s)" % (entry['start'], entry['title'], entry['duration']) common.addListItem(name, '', 'nbatvliveepisode', iconimage=entry['image'], customparams=params)
def chooseGameMenu(mode, video_type, date2Use = None): try: if mode == "selectdate": date = common.getDate() elif mode == "oldseason": date = date2Use else: date = utils.nowEST() utils.log("current date (america timezone) is %s" % str(date), xbmc.LOGDEBUG) # starts on mondays day = date.isoweekday() date = date - timedelta(day-1) if mode == "lastweek": date = date - timedelta(7) addGamesLinks(date, video_type) # Can't sort the games list correctly because XBMC treats file items and directory # items differently and puts directory first, then file items (home/away feeds # require a directory item while only-home-feed games is a file item) #xbmcplugin.addSortMethod( handle=int(sys.argv[1]), sortMethod=xbmcplugin.SORT_METHOD_DATE ) except: xbmcplugin.endOfDirectory(handle = int(sys.argv[1]),succeeded=False) return None
def chooseGameMenu(mode, video_type, date2Use = None): try: if mode == "selectdate": date = common.getDate() elif mode == "oldseason": date = date2Use else: date = utils.nowEST() utils.log("current date (america timezone) is %s" % str(date), xbmc.LOGDEBUG) # starts on mondays day = date.isoweekday() date = date - timedelta(day-1) if mode == "lastweek": date = date - timedelta(7) addGamesLinks(date, video_type) # Can't sort the games list correctly because XBMC treats file items and directory # items differently and puts directory first, then file items (home/away feeds # require a directory item while only-home-feed games is a file item) #xbmcplugin.addSortMethod( handle=int(sys.argv[1]), sortMethod=xbmcplugin.SORT_METHOD_DATE ) except: xbmcplugin.endOfDirectory(handle = int(sys.argv[1]),succeeded=False) return None
def chooseGameMenu(mode, video_type, date2Use=None): try: if mode == "selectdate": date = common.get_date() elif mode == "oldseason": date = date2Use else: date = utils.nowEST() utils.log("current date (america timezone) is %s" % date, xbmc.LOGDEBUG) # Starts on mondays day = date.isoweekday() #2 = tuesday date = date - timedelta(day - 1) if vars.use_alternative_archive_menu: playlist = None if 'playlist' in mode: playlist = xbmc.PlayList(1) playlist.clear() if '4-10' in mode: if day <= 5: date = date - timedelta(7) addGamesLinks(date, video_type, playlist) if day <= 5 and day > 1: #no need to query empty list when day < 2 date = date + timedelta(7) addGamesLinks(date, video_type, playlist) else: #to counter empty list on mondays for 'this week' #playlist.add("", xbmcgui.ListItem(str(date))) if day < 2: date = date - timedelta(7) nr_weeks = 1 if "last2weeks" in mode or 'playlist2w' in mode: nr_weeks = 2 elif "last3weeks" in mode or 'playlist3w' in mode: nr_weeks = 3 for n in range(nr_weeks, 0, -1): date1 = date - timedelta(7 * (n - 1)) addGamesLinks(date1, video_type, playlist) else: if mode == "lastweek": date = date - timedelta(7) addGamesLinks(date, video_type) # Can't sort the games list correctly because XBMC treats file items and directory # items differently and puts directory first, then file items (home/away feeds # require a directory item while only-home-feed games is a file item) #xbmcplugin.addSortMethod(handle=int(sys.argv[1]), sortMethod=xbmcplugin.SORT_METHOD_DATE) except Exception as ee: raise ee xbmcplugin.endOfDirectory(handle=int(sys.argv[1]), succeeded=False) return None
def addGamesLinks(date = '', video_type = "archive"): try: now_datetime_est = utils.nowEST() schedule = 'https://nlnbamdnyc-a.akamaihd.net/fs/nba/feeds_s2019/schedule/%04d/%d_%d.js?t=%d' % \ (date.year, date.month, date.day, time.time()) utils.log('Requesting %s' % schedule, xbmc.LOGDEBUG) schedule_request = urllib2.Request(schedule, None) schedule_response = str(urllib2.urlopen(schedule_request).read()) schedule_json = json.loads(schedule_response[schedule_response.find("{"):]) unknown_teams = {} for index, daily_games in enumerate(schedule_json['games']): utils.log("daily games for day %d are %s" % (index, daily_games), xbmc.LOGDEBUG) for game in daily_games: h = game.get('h', '') v = game.get('v', '') game_id = game.get('id', '') game_start_date_est = game.get('d', '') vs = game.get('vs', '') hs = game.get('hs', '') name = game.get('name', '') image = game.get('image', '') seo_name = game.get("seoName", "") has_condensed_video = game.get("video", {}).get("c", False) has_away_feed = False video_details = game.get('video', {}) has_away_feed = bool(video_details.get("af", {})) # Try to convert start date to datetime try: game_start_datetime_est = datetime.datetime.strptime(game_start_date_est, "%Y-%m-%dT%H:%M:%S.%f" ) except: game_start_datetime_est = datetime.datetime.fromtimestamp(time.mktime(time.strptime(game_start_date_est, "%Y-%m-%dT%H:%M:%S.%f"))) #Set game start date in the past if python can't parse the date #so it doesn't get flagged as live or future game and you can still play it #if a video is available if type(game_start_datetime_est) is not datetime.datetime: game_start_datetime_est = now_datetime_est + timedelta(-30) #guess end date by adding 4 hours to start date game_end_datetime_est = game_start_datetime_est + timedelta(hours=4) # Get playoff game number, if available playoff_game_number = 0 playoff_status = "" if 'playoff' in game: playoff_home_wins = int(game['playoff']['hr'].split("-")[0]) playoff_visitor_wins = int(game['playoff']['vr'].split("-")[0]) playoff_status = "%d-%d" % (playoff_visitor_wins, playoff_home_wins) playoff_game_number = playoff_home_wins + playoff_visitor_wins if game_id != '': # Get pretty names for the team names [visitor_name, host_name] = [vars.config['teams'].get(t.lower(), t) for t in [v, h]] [unknown_teams.setdefault(t, []).append(game_start_datetime_est.strftime("%Y-%m-%d")) for t in [v, h] if t.lower() not in vars.config['teams']] has_video = "video" in game future_video = game_start_datetime_est > now_datetime_est and \ game_start_datetime_est.date() == now_datetime_est.date() live_video = game_start_datetime_est < now_datetime_est < game_end_datetime_est # Create the title if host_name and visitor_name: name = game_start_datetime_est.strftime("%Y-%m-%d") if video_type == "live": name = utils.toLocalTimezone(game_start_datetime_est).strftime("%Y-%m-%d (at %I:%M %p)") # Add the teams' names and the scores if needed name += ' %s vs %s' % (visitor_name, host_name) if playoff_game_number != 0: name += ' (game %d)' % (playoff_game_number) if vars.show_scores and not future_video: name += ' %s:%s' % (str(vs), str(hs)) if playoff_status: name += " (series: %s)" % playoff_status thumbnail_url = utils.generateCombinedThumbnail(v, h) elif image: thumbnail_url = "https://nbadsdmt.akamaized.net/media/nba/nba/thumbs/%s" % image if video_type == "live": if future_video: name = "UPCOMING: " + name elif live_video: name = "LIVE: " + name add_link = True if video_type == "live" and not (live_video or future_video): add_link = False elif video_type != "live" and (live_video or future_video): add_link = False elif not future_video and not has_video: add_link = False if add_link == True: params = { 'video_id': game_id, 'video_type': video_type, 'seo_name': seo_name, 'visitor_team': visitor_name, 'home_team': host_name, 'has_away_feed': 1 if has_away_feed else 0, 'has_condensed_game': 1 if has_condensed_video else 0, } if 'st' in game: start_time = calendar.timegm(time.strptime(game['st'], '%Y-%m-%dT%H:%M:%S.%f')) * 1000 params['start_time'] = start_time if 'et' in game: end_time = calendar.timegm(time.strptime(game['et'], '%Y-%m-%dT%H:%M:%S.%f')) * 1000 params['end_time'] = end_time params['duration'] = end_time - start_time else: # create my own et for game (now) end_time = str(datetime.datetime.now()).replace(' ', 'T') end_time = calendar.timegm(time.strptime(end_time, '%Y-%m-%dT%H:%M:%S.%f')) * 1000 params['end_time'] = end_time params['duration'] = end_time - start_time # Add a directory item that contains home/away/condensed items common.addListItem(name, url="", mode="gamechoosevideo", iconimage=thumbnail_url, isfolder=True, customparams=params) if unknown_teams: utils.log("Unknown teams: %s" % str(unknown_teams), xbmc.LOGWARNING) except Exception, e: utils.littleErrorPopup("Error: %s" % str(e)) utils.log(traceback.format_exc(), xbmc.LOGDEBUG) pass
def addGamesLinks(date = '', video_type = "archive"): try: now_datetime_est = utils.nowEST() #example: http://smb.cdnak.neulion.com/fs/nba/feeds_s2012/schedule/2013/10_7.js?t=1381054350000 schedule = 'http://smb.cdnak.neulion.com/fs/nba/feeds_s2012/schedule/%04d/%d_%d.js?t=%d' % \ (date.year, date.month, date.day, time.time()) utils.log('Requesting %s' % schedule, xbmc.LOGDEBUG) schedule_request = urllib2.Request(schedule, None) schedule_response = str(urllib2.urlopen(schedule_request).read()) schedule_json = json.loads(schedule_response[schedule_response.find("{"):]) unknown_teams = {} for index, daily_games in enumerate(schedule_json['games']): utils.log("daily games for day %d are %s" % (index, daily_games), xbmc.LOGDEBUG) for game in daily_games: h = game.get('h', '') v = game.get('v', '') game_id = game.get('id', '') game_start_date_est = game.get('d', '') vs = game.get('vs', '') hs = game.get('hs', '') name = game.get('name', '') image = game.get('image', '') seo_name = game.get("seoName", "") has_condensed_video = game.get("video", {}).get("c", False) has_away_feed = False video_details = game.get('video', {}) has_away_feed = bool(video_details.get("af", {})) # Try to convert start date to datetime try: game_start_datetime_est = datetime.datetime.strptime(game_start_date_est, "%Y-%m-%dT%H:%M:%S.%f" ) except: game_start_datetime_est = datetime.datetime.fromtimestamp(time.mktime(time.strptime(game_start_date_est, "%Y-%m-%dT%H:%M:%S.%f"))) #Set game start date in the past if python can't parse the date #so it doesn't get flagged as live or future game and you can still play it #if a video is available if type(game_start_datetime_est) is not datetime.datetime: game_start_datetime_est = now_datetime_est + timedelta(-30) #guess end date by adding 4 hours to start date game_end_datetime_est = game_start_datetime_est + timedelta(hours=4) # Get playoff game number, if available playoff_game_number = 0 playoff_status = "" if 'playoff' in game: playoff_home_wins = int(game['playoff']['hr'].split("-")[0]) playoff_visitor_wins = int(game['playoff']['vr'].split("-")[0]) playoff_status = "%d-%d" % (playoff_visitor_wins, playoff_home_wins) playoff_game_number = playoff_home_wins + playoff_visitor_wins if game_id != '': # Get pretty names for the team names [visitor_name, host_name] = [vars.config['teams'].get(t.lower(), t) for t in [v, h]] [unknown_teams.setdefault(t, []).append(game_start_datetime_est.strftime("%Y-%m-%d")) for t in [v, h] if t.lower() not in vars.config['teams']] has_video = "video" in game future_video = game_start_datetime_est > now_datetime_est and \ game_start_datetime_est.date() == now_datetime_est.date() live_video = game_start_datetime_est < now_datetime_est < game_end_datetime_est # Create the title if host_name and visitor_name: name = game_start_datetime_est.strftime("%Y-%m-%d") if video_type == "live": name = utils.toLocalTimezone(game_start_datetime_est).strftime("%Y-%m-%d (at %I:%M %p)") # Add the teams' names and the scores if needed name += ' %s vs %s' % (visitor_name, host_name) if playoff_game_number != 0: name += ' (game %d)' % (playoff_game_number) if vars.show_scores and not future_video: name += ' %s:%s' % (str(vs), str(hs)) if playoff_status: name += " (series: %s)" % playoff_status thumbnail_url = utils.generateCombinedThumbnail(v, h) elif image: thumbnail_url = "https://neulionmdnyc-a.akamaihd.net/u/nba/nba/thumbs/%s" % image if video_type == "live": if future_video: name = "UPCOMING: " + name elif live_video: name = "LIVE: " + name add_link = True if video_type == "live" and not (live_video or future_video): add_link = False elif video_type != "live" and (live_video or future_video): add_link = False elif not future_video and not has_video: add_link = False if add_link == True: params = { 'video_id': game_id, 'video_type': video_type, 'seo_name': seo_name, 'visitor_team': visitor_name, 'home_team': host_name, 'has_away_feed': 1 if has_away_feed else 0, 'has_condensed_game': 1 if has_condensed_video else 0, } if 'st' in game: start_time = calendar.timegm(time.strptime(game['st'], '%Y-%m-%dT%H:%M:%S.%f')) * 1000 params['start_time'] = start_time if 'et' in game: end_time = calendar.timegm(time.strptime(game['et'], '%Y-%m-%dT%H:%M:%S.%f')) * 1000 params['end_time'] = end_time params['duration'] = end_time - start_time else: # create my own et for game (now) end_time = str(datetime.datetime.now()).replace(' ', 'T') end_time = calendar.timegm(time.strptime(end_time, '%Y-%m-%dT%H:%M:%S.%f')) * 1000 params['end_time'] = end_time params['duration'] = end_time - start_time # Add a directory item that contains home/away/condensed items common.addListItem(name, url="", mode="gamechoosevideo", iconimage=thumbnail_url, isfolder=True, customparams=params) if unknown_teams: utils.log("Unknown teams: %s" % str(unknown_teams), xbmc.LOGWARNING) except Exception, e: utils.littleErrorPopup("Error: %s" % str(e)) utils.log(traceback.format_exc(), xbmc.LOGDEBUG) pass
def addGamesLinks(date='', video_type="archive", playlist=None, in_a_hurry=False): try: now_datetime_est = utils.nowEST() schedule = 'https://nlnbamdnyc-a.akamaihd.net/fs/nba/feeds_s2019/schedule/%04d/%d_%d.js?t=%d' % \ (date.year, date.month, date.day, time.time()) utils.log('Requesting %s' % schedule, xbmc.LOGDEBUG) schedule_request = urllib2.Request(schedule, None) schedule_response = str(urllib2.urlopen(schedule_request).read()) schedule_json = json.loads(schedule_response[schedule_response.find("{"):]) unknown_teams = {} for index, daily_games in enumerate(schedule_json['games']): utils.log("daily games for day %d are %s" % (index, daily_games), xbmc.LOGDEBUG) for game in daily_games: processed_keys = set() v = process_key(game, 'v', processed_keys) h = process_key(game, 'h', processed_keys) vr = process_key(game, 'vr', processed_keys) hr = process_key(game, 'hr', processed_keys) vs = process_key(game, 'vs', processed_keys) hs = process_key(game, 'hs', processed_keys) if v is None or h is None: # TODO utils.log(json.dumps(game), xbmc.LOGDEBUG) continue game_id = process_key(game, 'id', processed_keys) game_start_date_est = process_key(game, 'd', processed_keys) name = process_key(game, 'name', processed_keys) image = process_key(game, 'image', processed_keys) seo_name = process_key(game, 'seoName', processed_keys) video = process_key(game, 'video', processed_keys) has_video = video is not None has_condensed_video = has_video and bool(video.get('c')) has_away_feed = has_video and bool(video.get('af')) # Try to convert start date to datetime try: game_start_datetime_est = datetime.datetime.strptime(game_start_date_est, "%Y-%m-%dT%H:%M:%S.%f") except: game_start_datetime_est = datetime.datetime.fromtimestamp(time.mktime(time.strptime(game_start_date_est, "%Y-%m-%dT%H:%M:%S.%f"))) #Set game start date in the past if python can't parse the date #so it doesn't get flagged as live or future game and you can still play it #if a video is available if type(game_start_datetime_est) is not datetime.datetime: game_start_datetime_est = now_datetime_est + timedelta(-30) # Guess end date by adding 4 hours to start date game_end_datetime_est = game_start_datetime_est + timedelta(hours=4) # Get playoff game number, if available playoff_game_number = 0 playoff_status = "" if 'playoff' in game: playoff_home_wins = int(game['playoff']['hr'].split("-")[0]) playoff_visitor_wins = int(game['playoff']['vr'].split("-")[0]) playoff_status = "%d-%d" % (playoff_visitor_wins, playoff_home_wins) playoff_game_number = playoff_home_wins + playoff_visitor_wins if game_id is not None: # Get pretty names for the team names [visitor_name, host_name] = [vars.config['teams'].get(t.lower(), t) for t in [v, h]] [unknown_teams.setdefault(t, []).append(game_start_datetime_est.strftime("%Y-%m-%d")) for t in [v, h] if t.lower() not in vars.config['teams']] future_video = game_start_datetime_est > now_datetime_est and \ game_start_datetime_est.date() == now_datetime_est.date() live_video = game_start_datetime_est < now_datetime_est < game_end_datetime_est name = game_start_datetime_est.strftime("%Y-%m-%d") if video_type == "live": name = utils.toLocalTimezone(game_start_datetime_est).strftime("%Y-%m-%d (at %I:%M %p)") name += " %s%s vs %s%s" % (visitor_name, " (%s)" % vr if vars.show_records_and_scores else '', host_name, " (%s)" % hr if vars.show_records_and_scores else '') if playoff_game_number != 0: name += ' (game %d)' % (playoff_game_number) if vars.show_records_and_scores and not future_video: name += ' %s:%s' % (vs, hs) if playoff_status: name += " (series: %s)" % playoff_status thumbnail_url = utils.generateCombinedThumbnail(v, h) if video_type == "live": if future_video: name = "UPCOMING: " + name elif live_video: name = "LIVE: " + name add_link = True if video_type == "live" and not (live_video or future_video): add_link = False elif video_type != "live" and (live_video or future_video): add_link = False elif not future_video and not has_video: add_link = False if add_link: params = { 'video_id': game_id, 'video_type': video_type, 'seo_name': seo_name, 'visitor_team': visitor_name, 'home_team': host_name, 'has_away_feed': "1" if has_away_feed else "0", 'has_condensed_game': "1" if has_condensed_video else "0", 'foldername': name, 'iconimage': thumbnail_url, } if 'st' in game: start_time = calendar.timegm(time.strptime(game['st'], '%Y-%m-%dT%H:%M:%S.%f')) * 1000 params['start_time'] = start_time if 'et' in game: end_time = calendar.timegm(time.strptime(game['et'], '%Y-%m-%dT%H:%M:%S.%f')) * 1000 params['end_time'] = end_time params['duration'] = end_time - start_time else: # create my own et for game (now) end_time = str(datetime.datetime.now()).replace(' ', 'T') end_time = calendar.timegm(time.strptime(end_time, '%Y-%m-%dT%H:%M:%S.%f')) * 1000 params['end_time'] = end_time params['duration'] = end_time - start_time # Add a directory item that contains home/away/condensed items if playlist is None: common.addListItem(name, url="", mode="gamechoosevideo", iconimage=thumbnail_url, isfolder=True, customparams=params) else: chooseGameVideoMenu(playlist, params, in_a_hurry) remaining_keys = set(game.keys()).difference(processed_keys) utils.log('Remaining keys: {}'.format(remaining_keys), xbmc.LOGDEBUG) if unknown_teams: utils.log("Unknown teams: %s" % str(unknown_teams), xbmc.LOGWARNING) except Exception, e: utils.littleErrorPopup("Error: %s" % str(e)) utils.log(traceback.format_exc(), xbmc.LOGDEBUG) pass