test-ly-files: Display symlink creation, add `-v` to `ln`
[sunny256-utils.git] / p
blobb305686e5c98fb5b5842022acae4af27b67ca75f
1 #!/usr/bin/env bash
3 #=======================================================================
4 # p
5 # File ID: 3623557a-fa66-11dd-83e3-000475e441b9
7 # Play a media file in mpv
9 # Author: Øyvind A. Holm <sunny@sunbase.org>
10 # License: GNU General Public License version 2 or later.
11 #=======================================================================
13 progname=p
14 VERSION=0.4.2
16 ARGS="$(getopt -o "\
17 a:\
21 t:\
23 " -l "\
24 amplify:,\
25 help,\
26 quiet,\
27 slow,\
28 tempo:,\
29 verbose,\
30 version,\
31 " -n "$progname" -- "$@")"
32 test "$?" = "0" || exit 1
33 eval set -- "$ARGS"
35 opt_amplify=''
36 opt_help=0
37 opt_quiet=0
38 opt_slow=0
39 opt_tempo=''
40 opt_verbose=0
41 while :; do
42 case "$1" in
43 -a|--amplify) opt_amplify=$2; shift 2 ;;
44 -h|--help) opt_help=1; shift ;;
45 -q|--quiet) opt_quiet=$(($opt_quiet + 1)); shift ;;
46 -s|--slow) opt_slow=1; shift ;;
47 -t|--tempo) opt_tempo=$2; shift 2 ;;
48 -v|--verbose) opt_verbose=$(($opt_verbose + 1)); shift ;;
49 --version) echo $progname $VERSION; exit 0 ;;
50 --) shift; break ;;
51 *) echo $progname: Internal error >&2; exit 1 ;;
52 esac
53 done
54 opt_verbose=$(($opt_verbose - $opt_quiet))
56 if test "$opt_help" = "1"; then
57 test $opt_verbose -gt 0 && { echo; echo $progname $VERSION; }
58 cat <<END
60 Play a media file in mpv.
62 Usage: $progname [options] file [files [...]]
64 Options:
66 -a X, --amplify X
67 Amplify sound with X dB. 10 is a nice value to start with.
68 -h, --help
69 Show this help.
70 -q, --quiet
71 Be more quiet. Can be repeated to increase silence.
72 -s, --slow
73 Use less resources when playing movie files.
74 -t TEMPO, --tempo TEMPO
75 Play audio with tempo TEMPO without changing the pitch.
76 FIXME: Make it work with video too.
77 -v, --verbose
78 Increase level of verbosity. Can be repeated.
79 --version
80 Print version information.
82 END
83 exit 0
86 sess_str="sess -d p -t c_p --"
87 test "$HISTFILE" = "/dev/null" && unset sess_str
88 ao_str=
89 amplify_str=
90 pgrep jackd && ao_str=" -ao jack"
91 if test -n "$opt_amplify"; then
92 echo "$opt_amplify" | grep -q -E '^[0-9]+$' || {
93 # Well, mplayer also understands floats, but it's easier to
94 # just check for [0-9].
95 echo $progname: -a needs an integer argument >&2
96 exit 1
98 amplify_str=" --af=volume=$opt_amplify"
100 test "$opt_slow" = "1" && slow=" -lavdopts fast:skiploopfilter=all"
101 if test -n "$opt_tempo"; then
102 tempo_str=" --af=scaletempo=scale=$opt_tempo"
103 else
104 tempo_str=
106 test -e /dg-vbox.mrk && vo_str=" -vo x11 -zoom"
107 $sess_str mpv -fs --no-audio-display \
108 $tempo_str$slow$vo_str$ao_str$amplify_str "$@"