add functionality to call strm on remote

This commit is contained in:
Denis Lehmann 2021-05-02 10:32:14 +02:00
parent a7cf70f28d
commit 0d77a98509
2 changed files with 59 additions and 3 deletions

View file

@ -51,6 +51,7 @@
- List remote files by query - List remote files by query
- Play remote files via mpv - Play remote files via mpv
- Query multiple remote directories with one command - Query multiple remote directories with one command
- Play remote files on other machines (need to have *strm* installed)
You can access your local machine also via SSH, so every occurrence of /remote/ in the list can be replaced with /local/. You can access your local machine also via SSH, so every occurrence of /remote/ in the list can be replaced with /local/.
@ -84,9 +85,11 @@
OPTIONS OPTIONS
-h, --help Show this help message -h, --help Show this help message
-c, --config CONFIG_FILE Path to config file (default: ~/.config/strm/strm.config) -c, --config CONFIG_FILE Path to config file (default: ~/.config/strm/strm.config)
-f, --fullscreen Play video files in fullscreen
-l, --list List files instead of playing -l, --list List files instead of playing
-m, --media-directories MEDIA_DIRECTORIES Use given media directories, config is ignored -m, --media-directories MEDIA_DIRECTORIES Use given media directories, config is ignored
-o, --or Use a logical OR for queries (default: AND) -o, --or Use a logical OR for queries (default: AND)
-r, --remote SSH_CONNECTION_STRING Execute strm with other given arguments on remote machine (-f is set by default)
-s, --shuffle Play files in random order -s, --shuffle Play files in random order
EXAMPLES EXAMPLES
@ -101,6 +104,7 @@
- =LEFT= and =RIGHT= :: Seek backward/forward. - =LEFT= and =RIGHT= :: Seek backward/forward.
- =p= and =SPACE= :: Pause (pressing again unpauses). - =p= and =SPACE= :: Pause (pressing again unpauses).
- =<= and =>= :: Go backward/forward in the playlist. - =<= and =>= :: Go backward/forward in the playlist.
- =f= :: Toggle fullscreen.
- =q= :: Stop playing and quit. - =q= :: Stop playing and quit.
- =Q= :: Like =q=, but store the current playback position. - =Q= :: Like =q=, but store the current playback position.
Playing the same file later will resume at the old playback position if possible. Playing the same file later will resume at the old playback position if possible.
@ -109,6 +113,19 @@
Just make sure you always quit with =Q=. Just make sure you always quit with =Q=.
To clear all stored positions remove the directory (=~/.config/mpv/watch_later=). To clear all stored positions remove the directory (=~/.config/mpv/watch_later=).
*** The =--remote== flag
The =--remote= flag executes *strm* on another machine and passes all other arguments to it.
For this, *strm* needs to be installed and configured on the remote machine.
If you pass the =--media-directories= flag it doesn't need to be configured but make sure your arguments are correct from the point of view of the remote machine.
The =--fullscreen= is inverted when playing on a remote machine.
It is set by default and not set if you explicitly pass it.
The remote =$DISPLAY= variable is set to =:0= by default which should fit most setups.
If you wish to change this you have to adjust the script in line 131.
** Configuration ** Configuration
If the =--media-directories= argument is not set, the script looks for a configuration file with the following content: If the =--media-directories= argument is not set, the script looks for a configuration file with the following content:

45
strm
View file

@ -12,9 +12,11 @@ function print_usage {
echo "OPTIONS" echo "OPTIONS"
echo " -h, --help Show this help message" echo " -h, --help Show this help message"
echo " -c, --config CONFIG_FILE Path to config file (default: ~/.config/strm/strm.config)" echo " -c, --config CONFIG_FILE Path to config file (default: ~/.config/strm/strm.config)"
echo " -f, --fullscreen Play video files in fullscreen"
echo " -l, --list List files instead of playing" echo " -l, --list List files instead of playing"
echo " -m, --media-directories MEDIA_DIRECTORIES Use given media directories, config is ignored" echo " -m, --media-directories MEDIA_DIRECTORIES Use given media directories, config is ignored"
echo " -o, --or Use a logical OR for queries (default: AND)" echo " -o, --or Use a logical OR for queries (default: AND)"
echo " -r, --remote SSH_CONNECTION_STRING Execute strm with other given arguments on remote machine (-f is set by default)"
echo " -s, --shuffle Play files in random order" echo " -s, --shuffle Play files in random order"
echo echo
echo "EXAMPLES" echo "EXAMPLES"
@ -41,11 +43,14 @@ fi
# Set default values # Set default values
config="$HOME/.config/strm/strm.config" config="$HOME/.config/strm/strm.config"
fullscreen=false
list=false list=false
or=false
shuffle=false
queries=()
media_directories="" media_directories=""
or=false
queries=()
remote=""
remote_arguments=()
shuffle=false
# Parse arguments # Parse arguments
while (( "$#" )); do while (( "$#" )); do
@ -53,21 +58,28 @@ while (( "$#" )); do
-c|--config) -c|--config)
if [ -n "$2" ] && [ "${2:0:1}" != "-" ]; then if [ -n "$2" ] && [ "${2:0:1}" != "-" ]; then
config="$2" config="$2"
remote_arguments+=("$1" "$2")
shift 2 shift 2
else else
error "Argument for $1 is missing" error "Argument for $1 is missing"
fi fi
;; ;;
-f|--fullscreen)
fullscreen=true
shift
;;
-h|--help) -h|--help)
print_usage print_usage
;; ;;
-l|--list) -l|--list)
list=true list=true
remote_arguments+=("$1")
shift shift
;; ;;
-m|--media-directories) -m|--media-directories)
if [ -n "$2" ] && [ "${2:0:1}" != "-" ]; then if [ -n "$2" ] && [ "${2:0:1}" != "-" ]; then
media_directories="$2" media_directories="$2"
remote_arguments+=("$1" "$2")
shift 2 shift 2
else else
error "Argument for $1 is missing" error "Argument for $1 is missing"
@ -75,10 +87,20 @@ while (( "$#" )); do
;; ;;
-o|--or) -o|--or)
or=true or=true
remote_arguments+=("$1")
shift shift
;; ;;
-r|--remote)
if [ -n "$2" ] && [ "${2:0:1}" != "-" ]; then
remote="$2"
shift 2
else
error "Argument for $1 is missing"
fi
;;
-s|--shuffle) -s|--shuffle)
shuffle=true shuffle=true
remote_arguments+=("$1")
shift shift
;; ;;
-*|--*=) -*|--*=)
@ -86,6 +108,7 @@ while (( "$#" )); do
;; ;;
*) *)
queries+=("$1") queries+=("$1")
remote_arguments+=("$1")
shift shift
;; ;;
esac esac
@ -96,6 +119,19 @@ if [ "${#queries[@]}" == 0 ]; then
print_usage print_usage
fi fi
# Execute strm on remote if argument set
if [ "$remote" != "" ]; then
# Invert fullscreen argument
if [ "$fullscreen" == false ]; then
remote_arguments+=("-f")
fi
# Execute strm on remote machine
ssh -t "$remote" "DISPLAY=:0 strm ${remote_arguments[@]}; echo"
exit
fi
# If no media directory was set load config file # If no media directory was set load config file
if [ "$media_directories" == "" ]; then if [ "$media_directories" == "" ]; then
@ -197,6 +233,9 @@ if [ "$list" == false ]; then
if [ "$shuffle" == true ]; then if [ "$shuffle" == true ]; then
mpv_arguments+=("--shuffle") mpv_arguments+=("--shuffle")
fi fi
if [ "$fullscreen" == true ]; then
mpv_arguments+=("--fullscreen")
fi
# Play all remote files # Play all remote files
mpv --msg-level=all=error,statusline=status --term-status-msg='${playlist-pos-1}/${playlist-count} - ${time-pos}/${duration} - \e[1m${metadata/artist:}${?metadata/artist: - }${metadata/title:}${!metadata/title:${filename/no-ext}}\e[0m' "${mpv_arguments[@]}" "${sftp_results[@]}" mpv --msg-level=all=error,statusline=status --term-status-msg='${playlist-pos-1}/${playlist-count} - ${time-pos}/${duration} - \e[1m${metadata/artist:}${?metadata/artist: - }${metadata/title:}${!metadata/title:${filename/no-ext}}\e[0m' "${mpv_arguments[@]}" "${sftp_results[@]}"