diff --git a/watch/README.md b/watch/README.md new file mode 100644 index 0000000..e55ae49 --- /dev/null +++ b/watch/README.md @@ -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. diff --git a/watch/input.conf b/watch/input.conf new file mode 100644 index 0000000..00e18a9 --- /dev/null +++ b/watch/input.conf @@ -0,0 +1 @@ +q quit 5 diff --git a/watch/watch.sh b/watch/watch.sh new file mode 100755 index 0000000..9b7b645 --- /dev/null +++ b/watch/watch.sh @@ -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