-
Notifications
You must be signed in to change notification settings - Fork 6
/
mpv
executable file
·50 lines (40 loc) · 1.54 KB
/
mpv
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
#!/usr/bin/env bash
# launches mpv with a unique mpv socket at /tmp/mpvsockets
# can set the MPV_SOCKET_DIR environment variable to override the location
# https://github.com/purarue/mpv-sockets
declare socket_dir mpv_loc default_tmp_dir default_socket_dir
declare -a mpv_possible_paths mpv_options
default_tmp_dir="${TMPDIR:-/tmp}"
default_socket_dir="${default_tmp_dir}/mpvsockets"
socket_dir="${MPV_SOCKET_DIR:-${default_socket_dir}}"
mpv_possible_paths=()
[[ -n "${MPV_PATH}" ]] && mpv_possible_paths+=("${MPV_PATH}")
# fallbacks if MPV_PATH wasn't set
mpv_possible_paths+=('/usr/bin/mpv' '/bin/mpv' '/usr/local/bin/mpv')
# try common paths to find the mpv binary
for pos in "${mpv_possible_paths[@]}"; do
if [[ -e "${pos}" ]]; then
mpv_loc="${pos}"
break
fi
done
[[ -z "${mpv_loc}" ]] && {
# if mpv_loc isn't set here, none of the fallbacks worked. If the user
# set the MPV_PATH variable, we should warn them that no binary exists there
if [[ -n "${MPV_PATH}" ]]; then
printf 'Error: could not find mpv at "%s"\n' "${MPV_PATH}" >&2
fi
echo 'Could not find the mpv binary at common locations' >&2
echo 'Set the MPV_PATH environment variable to the absolute path of mpv' >&2
exit 1
}
# done with configuration
readonly mpv_loc socket_dir
# make sockets directory
mkdir -p "${socket_dir}" || exit $?
# exec mpv, with the --input-ipc-server flag, using epoch nanoseconds
# to guarantee unique ipc sockets
declare -a mpv_options
mpv_options=(--input-ipc-server="${socket_dir}/$(date +%s%N)")
mpv_options+=("$@")
exec "${mpv_loc}" "${mpv_options[@]}"