mirror of https://github.com/rwxrob/dot
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
39 lines
730 B
Perl
39 lines
730 B
Perl
#!/usr/bin/perl
|
|
use v5.14;
|
|
|
|
my ($name, $format);
|
|
|
|
sub pick_one {
|
|
my $x=1;
|
|
chomp @_;
|
|
map {say "$x. $_[$x-1]"; $x++} @_;
|
|
my $answer;
|
|
while ($answer !~ /^\d+$/) {
|
|
print "? ";
|
|
$answer = <STDIN>;
|
|
}
|
|
return $answer;
|
|
}
|
|
|
|
sub usage {
|
|
my @path = split '/', $0;
|
|
say "$path[-1] <twitch-username>";
|
|
exit(1);
|
|
}
|
|
|
|
sub get_format {
|
|
my @formats = `twitch-formats $name`;
|
|
say "Pick a format: ";
|
|
return @formats[pick_one(@formats)-1];
|
|
}
|
|
$name = $ARGV[0];
|
|
not $name and $name = $ENV{"TWITCH_LOGIN"};
|
|
not $name and usage();
|
|
|
|
my $format = $ARGV[1];
|
|
not $format and $format = get_format();
|
|
say $format;
|
|
|
|
my $url = "https://twitch.tv/$name";
|
|
exec "mpv --ytdl-format=\"$format\" \"$url\""
|