Ejemplo n.º 1
0
def play_stream(game_rec,
                team_to_play,
                feedtype,
                date_str,
                fetch,
                from_start,
                inning_ident,
                is_multi_highlight=False):
    if game_rec['doubleHeader'] != 'N':
        LOG.info('Selected game number %s of doubleheader',
                 game_rec['gameNumber'])
    if feedtype is not None and feedtype in config.HIGHLIGHT_FEEDTYPES:
        # handle condensed/recap
        playback_url = find_highlight_url_for_team(game_rec, feedtype)
        if playback_url is None:
            util.die("No playback url for feed '{}'".format(feedtype))
        stream.play_highlight(
            playback_url,
            stream.get_fetch_filename(date_str, game_rec['home']['abbrev'],
                                      game_rec['away']['abbrev'], feedtype,
                                      fetch), is_multi_highlight)
    else:
        # handle full game (live or archive)
        # this is the only feature requiring an authenticated session
        import mlbv.mlbam.mlbsession as mlbsession
        mlb_session = mlbsession.MLBSession()

        media_playback_id, media_state = select_feed_for_team(
            game_rec, team_to_play, feedtype)
        if media_playback_id is not None:
            stream_url = mlb_session.lookup_stream_url(game_rec['game_pk'],
                                                       media_playback_id)
            if stream_url is not None:
                offset = None
                if config.SAVE_PLAYLIST_FILE:
                    mlb_session.save_playlist_to_file(stream_url)
                if inning_ident:
                    offset = _calculate_inning_offset(inning_ident,
                                                      media_state,
                                                      media_playback_id,
                                                      game_rec)
                    if offset is None:
                        return 0  # already logged
                stream.streamlink(
                    stream_url, mlb_session,
                    stream.get_fetch_filename(date_str,
                                              game_rec['home']['abbrev'],
                                              game_rec['away']['abbrev'],
                                              feedtype, fetch), from_start,
                    offset)
            else:
                LOG.error("No stream URL found")
        else:
            LOG.info("No game stream found for %s", team_to_play)
    return 0
Ejemplo n.º 2
0
def get_game_rec(game_data, team_to_play, game_number_str):
    """ game_number_str: is an string 1 or 2 indicating game number for doubleheader
    """
    game_rec = None
    for game_pk in game_data:
        if team_to_play in (game_data[game_pk]['away']['abbrev'], game_data[game_pk]['home']['abbrev']):
            if game_data[game_pk]['doubleHeader'] != 'N' and game_number_str != game_data[game_pk]['gameNumber']:
                # game is doubleheader but not our game_number
                continue
            game_rec = game_data[game_pk]
            break
    if game_rec is None:
        if int(game_number_str) > 1:
            util.die("No second game available for team {}".format(team_to_play))
        util.die("No game found for team {}".format(team_to_play))
    return game_rec