Exemplo n.º 1
0
def test_get_clips_all_lang_valid_token_ret_clips():
    responses.add(responses.GET,
                  f'{BASE_TWITCHMETRICS_URL}/c/{example_users_list[0]["_id"]}-'
                  f'{example_users_list[0]["name"]}/recent_viewership_values',
                  body=json.dumps(example_twitchmetrics_viewership_resp),
                  status=200,
                  content_type='application/json')
    responses.add(responses.GET, f'{BASE_HELIX_URL}/clips?'
                  f'broadcaster_id={example_users_list[0]["_id"]}',
                  body=json.dumps(example_clips_resp),
                  status=200,
                  content_type='application/json')
    responses.add(responses.GET,
                  f'{BASE_TWITCHMETRICS_URL}/c/{example_users_list[1]["_id"]}-'
                  f'{example_users_list[1]["name"]}/recent_viewership_values',
                  body=json.dumps(example_twitchmetrics_viewership_resp),
                  status=200,
                  content_type='application/json')
    responses.add(responses.GET, f'{BASE_HELIX_URL}/clips?'
                  f'broadcaster_id={example_users_list[1]["_id"]}',
                  body=json.dumps(example_clips_resp2),
                  status=200,
                  content_type='application/json')

    getter = ClipGetter(example_users_list)
    clips = getter.get_clips(oauth_token=example_app_access_token)
    assert len(clips) == 2
    assert clips[0]['id'] == 'RandomClip1'
    assert clips[1]['id'] == 'RandomClip3'
Exemplo n.º 2
0
def test_get_clips_invalid_client_id_and_token_throws_exception():
    responses.add(responses.GET,
                  f'{BASE_TWITCHMETRICS_URL}/c/{example_users_list[0]["_id"]}-'
                  f'{example_users_list[0]["name"]}/recent_viewership_values',
                  body=json.dumps(example_twitchmetrics_viewership_resp),
                  status=200,
                  content_type='application/json')
    responses.add(
        responses.GET, f'{BASE_HELIX_URL}/clips?'
        f'broadcaster_id={example_users_list[0]["_id"]}',
        body=json.dumps(example_clips_resp_invalid_client_id_and_token),
        status=401,
        content_type='application/json')

    getter = ClipGetter(example_users_list)
    with pytest.raises(requests.HTTPError):
        getter.get_clips()
Exemplo n.º 3
0
def main():
    """Executes the Clip9 main script."""
    start_time = time.time()
    args = _parse_args()
    logging.basicConfig(level=logging.INFO, filename=args.log_file,
                        format='[%(asctime)s]%(levelname)s: %(message)s')
    sys.excepthook = handle_exception

    logging.info("-------STARTING CLIP9-------")

    cfg_file_name = f'{os.path.dirname(sys.argv[0])}/../credentials.cfg'
    credentials = _parse_credentials_cfg(cfg_file_name)
    client_id = credentials['TWITCH_CLIENT_ID']
    client_secret = credentials['TWITCH_CLIENT_SECRET']

    token = OauthToken(client_id, client_secret)
    if not token.validate():
        logging.error("Token isn't valid")
        sys.exit(1)
    try:
        team_users = TeamUsers()
        team_users.get(args.team, client_id=client_id, oauth_token=token.token)
        users_list = team_users.users_list
        getter = ClipGetter(users_list, started_at=args.started_at,
                            ended_at=args.ended_at, lang=args.lang)
        clips_list = getter.get_clips(client_id, token.token)
        splicer = ClipSplicer(clips_list)
        splicer.splice(args.output_file, args.clips_dir)
        logging.info("Successfully generated a video of good clips")
    except Exception as e:
        logging.error("There was an exception during execution")
        raise e
    finally:
        token.revoke()
        elapsed_time = time.time() - start_time
        logging.info("Execution time: %s seconds", elapsed_time)