finga
52de56b79d
To resolve the naming conflict with `watch` which executes a program periodically and shows its output.
56 lines
1.5 KiB
Bash
Executable file
56 lines
1.5 KiB
Bash
Executable file
#!/bin/sh
|
|
set -e
|
|
|
|
src_path="${SERIES_SRC_PATH:-/media/hdd1/media/series}"
|
|
link_path="${SERIES_LINK_PATH:-}"
|
|
|
|
find_series() {
|
|
find "$src_path" -maxdepth 1 -printf "%f\\n" | sort | grep -v "$(basename "$src_path")"
|
|
}
|
|
|
|
next() {
|
|
find . -maxdepth 1 -printf "%f\\n" | sort | grep -A1 "$(readlink "$current")" | tail -n 1
|
|
}
|
|
|
|
if [ "$#" -ne 1 ]; then
|
|
echo "Usage: $0 SERIES | list"
|
|
exit 1
|
|
fi
|
|
|
|
# get config_path for mpv's input.conf
|
|
if [ -L "$(command -v "$0")" ]; then
|
|
conf_path="$(cd "$(dirname "$(command -v "$0")")" && cd "$(dirname "$(readlink "$0")")" && pwd)"
|
|
else
|
|
conf_path="$(cd "$(dirname "$0")" && pwd)"
|
|
fi
|
|
|
|
# check for "list" argument
|
|
if [ "$1" = "list" ]; then
|
|
find_series
|
|
exit 0
|
|
fi
|
|
|
|
# if no "list" argument find series and play, if viewed to the end, set
|
|
# "${series}_current" symlink to next
|
|
find_series | while read -r series; do
|
|
if [ "$1" = "$series" ]; then
|
|
cd "$src_path/$series"
|
|
# use absolute or relative linking
|
|
if [ -z "$link_path" ]; then
|
|
src_path=""
|
|
current="${series}_current"
|
|
else
|
|
src_path="$src_path/$series/"
|
|
current="${link_path}/${series}_current"
|
|
fi
|
|
|
|
# create first symlink if series was never watched before
|
|
if [ ! -f "$current" ]; then
|
|
ln -s "$src_path$(find . -maxdepth 1 -printf "%f\\n" | tail -n+2 | sort | head -n1)" "$current"
|
|
fi
|
|
|
|
echo "Playing: $(readlink "$current")"
|
|
mpv --input-conf "${conf_path}/input.conf" "$current" && ln -sf "$src_path$(next)" "$current"
|
|
fi
|
|
done
|