mirror of
https://github.com/rwxrob/dot
synced 2024-11-16 21:25:29 +00:00
39 lines
730 B
Plaintext
39 lines
730 B
Plaintext
|
#!/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\""
|