cli.py 文件源码

python
阅读 25 收藏 0 点赞 0 评论 0

项目:ggmt 作者: Granitosaurus 项目源码 文件源码
def watch(game, show, template, in_window, use_streamlink, quality, just_print):
    matches = list(download_matches(game))
    if not show:
        matches = [m for m in matches if m.get('stream')]
    if not matches:
        click.echo('No streams found :(')
        return

    template = template if template else DEFAULT_TEMPLATE_ALL if game == 'all' else DEFAULT_TEMPLATE
    template = Template(template)
    items = ['{}: {}'.format(i, template.render(m)) for i, m in enumerate(matches)]
    for item in items:
        click.echo(item)
    click.echo('-' * len(sorted(items)[0]))
    while True:
        click.echo('select stream to show: ', nl=False)
        choice = input('')
        if not choice.isdigit():
            click.echo('  "{}" is not a number'.format(choice))
            continue
        choice = int(choice)
        if choice not in range(0, len(matches)):
            click.echo('  {} is out of range'.format(choice))
            continue
        break

    selected = matches[choice].get('stream')
    if not selected:
        click.secho('cannot stream for match #{}: no stream'.format(choice), err=True, fg='red')
        return

    if just_print:
        click.echo(selected)
        return
    click.echo('Opening {}...'.format(selected))
    if use_streamlink:
        subprocess.Popen(['nohup streamlink "{}" {} &'.format(selected, quality)], shell=True, start_new_session=True)
    elif not in_window:
        webbrowser.open_new_tab(selected)
    else:
        webbrowser.open(selected, new=1)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号