summaryrefslogtreecommitdiffstats
path: root/.local/bin/mpview
blob: 804a32d46af50e41b5449cff031d2f98ba8b0dcc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/usr/bin/env perl

use strict;
use warnings;
use Scalar::Util qw(looks_like_number);
use Term::ReadKey;
use Term::ANSIColor;

sub get_size
{
	my $size;
	my $answer;

	$size = 0;
	$answer = 0;
	print
	"1) 0\n" .
	"2) 240\n" .
	"3) 360\n" .
	"4) 480\n" .
	"5) 720\n" .
	"6) 1080\n" .
	"\n" .
	"> ";
	open(TTY, "</dev/tty");
	ReadMode "raw";
	$answer = ReadKey 0, *TTY;
	ReadMode "normal";
	close(TTY);
	print "\n";
	if (
		!looks_like_number($answer) ||
		$answer == 0 ||
		$answer == 1 ||
		$answer > 6
	) {
		$size = 0;
	}
	elsif ($answer == 2) {
		$size = 240;
	}
	elsif ($answer == 3) {
		$size = 360;
	}
	elsif ($answer == 4) {
		$size = 480;
	}
	elsif ($answer == 5) {
		$size = 720;
	}
	elsif ($answer == 6) {
		$size = 1080;
	}
	return $size;
}

sub main
{
	my $size;

	if ($#ARGV + 1 == 0) {
		print STDERR "URL needed\n";
		exit 1;
	}
	$size = get_size();
	if ($size != 0) {
		print 'mpv --ytdl-format=[height<=' . $size . '] ' . $ARGV[0] . "\n";
		exec(
			'mpv',
			'--really-quiet',
			'--ytdl-format=[height<=' . $size . ']',
			$ARGV[0]
		);
	}
	else {
		print 'mpv ' . $ARGV[0] . "\n";
		exec(
			'mpv',
			'--really-quiet',
			$ARGV[0]
		);
	}
	print "$size\n";
	exit 0;
}

main();

__END__