Add watch script

This commit is contained in:
finga 2020-04-18 01:50:37 +02:00
parent f3a5808afc
commit 448736f5e4
3 changed files with 64 additions and 0 deletions

11
watch/README.md Normal file
View file

@ -0,0 +1,11 @@
# watch
A small script to help me remember were I left off playing
alphabetically ordered media files.
## Configuration
The path containing the media can be set via the `WATCH_SRC_PATH`
environment variable. The path for keeping the symlinks (the current
file to be watched) can be set via the `WATCH_LINK_PATH` environment
variable. If `WATCH_LINK_PATH` is not set the symlinks are kept in the
folder of the series and will point to a relative path. If
`WATCH_LINK_PATH` is set the symlink points to an absolute path.

1
watch/input.conf Normal file
View file

@ -0,0 +1 @@
q quit 5

52
watch/watch.sh Executable file
View file

@ -0,0 +1,52 @@
#!/bin/sh
set -e
src_path="${WATCH_SRC_PATH:-/media/hdd1/media/series}"
link_path="${WATCH_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"
if [ -z "$link_path" ]; then
src_path=""
current="${series}_current"
else
src_path="$src_path/$series/"
current="${link_path}/${series}_current"
fi
if [ ! -f "$current" ]; then
ln -s "$src_path$(find . -maxdepth 1 -printf "%f\\n" | tail -n+2 | sort | head -n1)" "$current"
fi
mpv --input-conf "${conf_path}/input.conf" "$current" && ln -sf "$src_path$(next)" "$current"
fi
done