add resume playback if no queries given
This commit is contained in:
parent
893686790d
commit
2200ce3d43
2 changed files with 61 additions and 47 deletions
|
|
@ -114,8 +114,12 @@
|
|||
- =<= and =>= :: Go backward/forward in the playlist.
|
||||
- =f= :: Toggle fullscreen.
|
||||
- =q= :: Stop playing and quit.
|
||||
If the =playback_directory= is configured or the =--playback-directory= argument ist set, the playback position of the current file is saved on exit and synchronized with the given directory.
|
||||
Otherwise (or if the =--neat= flag is set) the playback position is not saved on exit and nothing is synchronized.
|
||||
If the =playback_directory= is configured (or the =--playback-directory= argument ist set), the playback position of the current file is saved on exit and synchronized with the given directory.
|
||||
Otherwise (or if the =--tidy= flag is set) the playback position is not saved on exit and nothing is synchronized.
|
||||
|
||||
The last query arguments are saved if a =playback_directory= is set and neither the =--list= or =--tidy= flags are set.
|
||||
If you wan't to resume playback at a later time, it is sufficient to call =strm= without arguments.
|
||||
Non-query parameters, such as =--shuffle= or =--or= must still be provided.
|
||||
|
||||
*** The =--remote= flag
|
||||
|
||||
|
|
|
|||
100
strm
100
strm
|
|
@ -47,7 +47,7 @@ fullscreen=false
|
|||
is_remote_call=false
|
||||
list=false
|
||||
media_directories=""
|
||||
neat=false
|
||||
tidy=false
|
||||
or=false
|
||||
queries=()
|
||||
remote=""
|
||||
|
|
@ -101,11 +101,6 @@ while (( "$#" )); do
|
|||
error "Argument for '$1' is missing"
|
||||
fi
|
||||
;;
|
||||
-n|--neat)
|
||||
neat=true
|
||||
remote_arguments+=("$1")
|
||||
shift
|
||||
;;
|
||||
-o|--or)
|
||||
or=true
|
||||
remote_arguments+=("$1")
|
||||
|
|
@ -124,6 +119,11 @@ while (( "$#" )); do
|
|||
remote_arguments+=("$1")
|
||||
shift
|
||||
;;
|
||||
-t|--tidy)
|
||||
tidy=true
|
||||
remote_arguments+=("$1")
|
||||
shift
|
||||
;;
|
||||
-*|--*=)
|
||||
error "Unsupported flag: $1"
|
||||
;;
|
||||
|
|
@ -151,12 +151,6 @@ if [ "$remote" != "" ]; then
|
|||
|
||||
else
|
||||
|
||||
# Print usage if no queries were given
|
||||
if [ "${#queries[@]}" == 0 ]; then
|
||||
echo -ne "No strm session running on ${text_bold}$remote${text_reset}, please provide a query\n"
|
||||
exit
|
||||
fi
|
||||
|
||||
# Invert fullscreen argument
|
||||
if [ "$fullscreen" == false ]; then
|
||||
remote_arguments+=("-f")
|
||||
|
|
@ -176,11 +170,6 @@ if ! command -v mpv &>/dev/null; then
|
|||
error "mpv was not found, please install it"
|
||||
fi
|
||||
|
||||
# Print usage if no queries were given
|
||||
if [ "${#queries[@]}" == 0 ]; then
|
||||
print_usage
|
||||
fi
|
||||
|
||||
# If no media directory was set load config file
|
||||
if [ "$media_directories" == "" ]; then
|
||||
|
||||
|
|
@ -202,6 +191,47 @@ if [ "$tmp_playback_directory" != "" ]; then
|
|||
playback_directory="$tmp_playback_directory"
|
||||
fi
|
||||
|
||||
# Synchronize playback directory
|
||||
if [ "$list" == false ] && [ "$playback_directory" != "" ] && [ "$tidy" == false ]; then
|
||||
|
||||
# Make local playback directory if not existent
|
||||
mkdir -p "$HOME/.cache/strm"
|
||||
|
||||
# Get connection string and remote directory
|
||||
IFS="/" read -r connection_string directory <<< "$playback_directory"
|
||||
|
||||
# Correct empty connection string
|
||||
if [ "$connection_string" == "" ]; then
|
||||
connection_string="localhost"
|
||||
fi
|
||||
|
||||
# Check validity of directory
|
||||
if [ "$directory" == "" ]; then
|
||||
error "Not a valid playback directory ($playback_directory)"
|
||||
fi
|
||||
|
||||
# Add leading and trailing slash to directory if missing
|
||||
[[ "$directory" != /*/ ]] && directory="/$directory/"
|
||||
|
||||
# Make remote directory if not existent
|
||||
ssh -o ConnectTimeout=10 "$connection_string" "mkdir -p $directory"
|
||||
|
||||
rsync_directory="$connection_string:$directory"
|
||||
|
||||
# Synchronize remote to local
|
||||
rsync -az --delete "$rsync_directory" "$HOME/.cache/strm/"
|
||||
fi
|
||||
|
||||
# Check queries
|
||||
if [ "${#queries[@]}" == 0 ]; then
|
||||
if [ "$playback_directory" != "" ] && test -f "$HOME/.cache/strm/strm_later" && [ "$tidy" == false ]; then
|
||||
queries="$(<$HOME/.cache/strm/strm_later)"
|
||||
IFS=" " read -a queries <<< "$queries"
|
||||
else
|
||||
print_usage
|
||||
fi
|
||||
fi
|
||||
|
||||
# Read media directories
|
||||
IFS="," read -a media_directories <<< "$media_directories"
|
||||
|
||||
|
|
@ -239,7 +269,7 @@ for media_directory in "${media_directories[@]}"; do
|
|||
|
||||
# Check validity of directory
|
||||
if [ "$directory" == "" ]; then
|
||||
error "Not a valid media directory: $media_directory"
|
||||
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"
|
||||
|
|
@ -295,6 +325,9 @@ done
|
|||
# Play results if --list flag not set
|
||||
if [ "$list" == false ]; then
|
||||
|
||||
# Save arguments for later call
|
||||
echo "${queries[@]}" > "$HOME/.cache/strm/strm_later"
|
||||
|
||||
# Print controls
|
||||
if [ "$is_remote_call" == true ]; then
|
||||
print_remote_controls
|
||||
|
|
@ -310,41 +343,18 @@ if [ "$list" == false ]; then
|
|||
if [ "$shuffle" == true ]; then
|
||||
mpv_arguments+=("--shuffle")
|
||||
fi
|
||||
if [ "$neat" == true ]; then
|
||||
if [ "$tidy" == true ]; then
|
||||
mpv_arguments+=("--no-resume-playback")
|
||||
elif [ "$playback_directory" != "" ]; then
|
||||
|
||||
# Make local playback directory if not existent
|
||||
mkdir -p "$HOME/.cache/strm"
|
||||
|
||||
# Get connection string and remote directory
|
||||
IFS="/" read -r connection_string directory <<< "$playback_directory"
|
||||
|
||||
# Add leading and trailing slash to directory if missing
|
||||
[[ "$directory" != /*/ ]] && directory="/$directory/"
|
||||
|
||||
# Correct empty connection string
|
||||
if [ "$connection_string" == "" ]; then
|
||||
connection_string="localhost"
|
||||
fi
|
||||
|
||||
# Make remote directory if not existent
|
||||
ssh -o ConnectTimeout=10 "$connection_string" "mkdir -p $directory"
|
||||
|
||||
# Synchronize remote to local
|
||||
rsync -az --delete "$connection_string:$directory" "$HOME/.cache/strm/"
|
||||
|
||||
# Add mpv argument
|
||||
mpv_arguments+=("--save-position-on-quit")
|
||||
|
||||
fi
|
||||
|
||||
# Play all remote files
|
||||
mpv --msg-level=all=error,statusline=status --watch-later-directory="$HOME/.cache/strm" --term-status-msg='${playlist-pos-1}/${playlist-count} - ${time-pos}/${duration} - \e[1m${metadata/artist:}${?metadata/artist: - }${metadata/album:}${?metadata/album: - }${metadata/title:}${!metadata/title:${filename/no-ext}}\e[0m' "${mpv_arguments[@]}" "${sftp_results[@]}"
|
||||
|
||||
# Synchronize playback directory back if not neat and directory is set
|
||||
if [ "$neat" == false ] && [ "$playback_directory" != "" ]; then
|
||||
rsync -az --delete "$HOME/.cache/strm/" "$connection_string:$directory"
|
||||
# Synchronize playback directory back if not tidy and directory is set
|
||||
if [ "$tidy" == false ] && [ "$playback_directory" != "" ]; then
|
||||
rsync -az --delete "$HOME/.cache/strm/" "$rsync_directory"
|
||||
fi
|
||||
|
||||
fi
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue