From 95f8902486273419af06af3f336087d50cd1077c Mon Sep 17 00:00:00 2001 From: Denis Lehmann Date: Sun, 13 Jun 2021 10:01:40 +0200 Subject: [PATCH] add rsync dependency --- README.org | 5 ++++- strm | 21 +++++++++++++-------- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/README.org b/README.org index 8a85fc7..4c43725 100644 --- a/README.org +++ b/README.org @@ -67,6 +67,8 @@ - The machine shall serve as controller :: An SSH client must be installed and *strm* must be executable. A machine can be used for multiple purposes, make sure all required dependencies are fulfilled. + + If the =playback_directory= is set, [[https://rsync.samba.org/][rsync]] is used to synchronize it with a local directory. ** Installation @@ -162,10 +164,11 @@ # bob@another-machine/media/movies,bob@10.0.0.1/home/bob/series media_directories="" - # Directory with which the saved playback positions are synchronized on exit of the following form: + # Directory which contains the saved playback positions of the following form: # # # + # It is synchronized with the local ~/.cache/strm directory before and after playing files. # If it is not set, the mpv resume playback functionality is not enabled by default. # If is not set, 'localhost' is used. # diff --git a/strm b/strm index 6c1c463..cc0670d 100755 --- a/strm +++ b/strm @@ -205,8 +205,10 @@ fi # Synchronize playback directory if [ "$list" == false ] && [ "$playback_directory" != "" ]; then - # Make local playback directory if not existent - mkdir -p "$HOME/.cache/strm" + # Check if rsync is installed + if ! command -v rsync &>/dev/null; then + error "rsync was not found, please install it" + fi # Get connection string and remote directory IFS="/" read -r connection_string directory <<< "$playback_directory" @@ -216,16 +218,19 @@ if [ "$list" == false ] && [ "$playback_directory" != "" ]; then connection_string="localhost" fi - echo -ne "Synchronizing playback directory with $text_bold$(basename $connection_string)$text_reset\n" - # Check validity of directory if [ "$directory" == "" ]; then error "Not a valid playback directory ($playback_directory)" fi + # Make local playback directory if not existent + mkdir -p "$HOME/.cache/strm" + # Add leading and trailing slash to directory if missing [[ "$directory" != /*/ ]] && directory="/$directory/" + echo -ne "Synchronizing playback directory with $text_bold$(basename $connection_string)$text_reset\n" + # Make remote directory if not existent ssh -o ConnectTimeout=10 "$connection_string" "mkdir -p $directory" @@ -282,11 +287,11 @@ for media_directory in "${media_directories[@]}"; do error "Not a valid media directory ($media_directory)" fi - echo -ne "Fetching results from $text_bold$(basename $directory)$text_reset on $text_bold$connection_string$text_reset\n" - # Add leading and trailing slash to directory if missing [[ "$directory" != /*/ ]] && directory="/$directory/" + echo -ne "Fetching results from $text_bold$(basename $directory)$text_reset on $text_bold$connection_string$text_reset\n" + # Get search results from remote # Look for paths matching given queries in visible directories, listing only filenames and links mapfile -t tmp_results < <(ssh -o ConnectTimeout=10 "$connection_string" find "'$directory'" "${find_arguments[@]}" | sort) @@ -387,11 +392,11 @@ if [ "$list" == false ]; then connection_string="localhost" fi - echo -ne "\nSynchronizing playback directory with $text_bold$(basename $connection_string)$text_reset" - # Add leading and trailing slash to directory if missing [[ "$directory" != /*/ ]] && directory="/$directory/" + echo -ne "\nSynchronizing playback directory with $text_bold$(basename $connection_string)$text_reset" + # Synchronize local to remote rsync -az --delete "$HOME/.cache/strm/" "$connection_string:$directory" fi