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)
评论列表
文章目录