add multiple media directories
This commit is contained in:
parent
21462dcbc8
commit
1b2faea6a4
3 changed files with 98 additions and 79 deletions
40
README.org
40
README.org
|
|
@ -47,13 +47,14 @@
|
||||||
#+begin_src text
|
#+begin_src text
|
||||||
Usage: strm [OPTIONS] QUERY ... [OPTIONS]
|
Usage: strm [OPTIONS] QUERY ... [OPTIONS]
|
||||||
|
|
||||||
Stream media over SSH.
|
Stream media files over SSH.
|
||||||
|
|
||||||
OPTIONS
|
OPTIONS
|
||||||
-h, --help Show this help message
|
-h, --help Show this help message
|
||||||
-c, --config CONFIG_FILE Path to config file
|
-c, --config CONFIG_FILE Path to config file
|
||||||
-l, --list List files instead of playing
|
-l, --list List files instead of playing
|
||||||
-s, --shuffle Play files in random order
|
-m, --media-directories MEDIA_DIRECTORIES Use given media directories, config is ignored
|
||||||
|
-s, --shuffle Play files in random order
|
||||||
|
|
||||||
EXAMPLES
|
EXAMPLES
|
||||||
strm -l . # List all available files
|
strm -l . # List all available files
|
||||||
|
|
@ -71,30 +72,23 @@
|
||||||
|
|
||||||
** Configuration
|
** Configuration
|
||||||
|
|
||||||
The scripts expects a configuration file with the following content:
|
If the =--media-directories= argument is not set, the scripts looks for a configuration file with the following content:
|
||||||
|
|
||||||
#+begin_src sh
|
#+begin_src sh
|
||||||
# SSH connection string
|
# Media directories on remote machines of the following form:
|
||||||
|
#
|
||||||
|
# <SSH connection string><absolute_path_to_media_directory>
|
||||||
|
#
|
||||||
|
# Multiple media directories can be set with a comma (,) as delimiter.
|
||||||
|
#
|
||||||
# Examples:
|
# Examples:
|
||||||
# remote # Current user at hostname 'remote' on port 22
|
# localhost/home/bob/videos
|
||||||
# user@10.0.0.1 # 'user' at address '10.0.0.1' on port 22
|
# remote-machine/home/bob/music
|
||||||
# user@10.0.0.1:600 # 'user' at address '10.0.0.1' on port 600
|
# bob@another-machine/media/movies,bob@10.0.0.1/home/bob/series
|
||||||
connection_string=""
|
media_directories=""
|
||||||
|
|
||||||
# Absolute path to media directory on remote machine
|
|
||||||
# Example:
|
|
||||||
# /home/<user>/video
|
|
||||||
media_directory=""
|
|
||||||
#+end_src
|
#+end_src
|
||||||
|
|
||||||
An example configuration file can be found in =./strm.config=.
|
An example configuration file can be found in =./strm.config=.
|
||||||
|
|
||||||
The default path of the configuration is =$HOME/.config/strm/strm.config=.
|
The default path of the configuration is =$HOME/.config/strm/strm.config=.
|
||||||
You can use the =--config= flag to set another configuration file.
|
You can use the =--config= flag to set another configuration file.
|
||||||
This is useful if you are using multiple remote machines or different media folders.
|
|
||||||
One can set e.g. aliases for different streaming resources:
|
|
||||||
|
|
||||||
#+begin_src sh
|
|
||||||
alias mstrm="strm -c <path_to_music_config>"
|
|
||||||
alias vstrm="strm -c <path_to_video_config>"
|
|
||||||
#+end_src
|
|
||||||
|
|
|
||||||
117
strm
117
strm
|
|
@ -6,10 +6,11 @@ function print_usage {
|
||||||
echo "Stream media files over SSH."
|
echo "Stream media files over SSH."
|
||||||
echo
|
echo
|
||||||
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"
|
echo " -c, --config CONFIG_FILE Path to config file"
|
||||||
echo " -l, --list List files instead of playing"
|
echo " -l, --list List files instead of playing"
|
||||||
echo " -s, --shuffle Play files in random order"
|
echo " -m, --media-directories MEDIA_DIRECTORIES Use given media directories, config is ignored"
|
||||||
|
echo " -s, --shuffle Play files in random order"
|
||||||
echo
|
echo
|
||||||
echo "EXAMPLES"
|
echo "EXAMPLES"
|
||||||
echo " strm -l . # List all available files"
|
echo " strm -l . # List all available files"
|
||||||
|
|
@ -20,13 +21,13 @@ function print_usage {
|
||||||
|
|
||||||
function error {
|
function error {
|
||||||
echo "ERROR: $1" >&2
|
echo "ERROR: $1" >&2
|
||||||
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
# Check if mpv is installed
|
# Check if mpv is installed
|
||||||
if ! command -v mpv &>/dev/null
|
if ! command -v mpv &>/dev/null
|
||||||
then
|
then
|
||||||
echo "mpv was not found, please install it"
|
error "mpv was not found, please install it"
|
||||||
exit 1
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Set default values
|
# Set default values
|
||||||
|
|
@ -34,6 +35,7 @@ config="$HOME/.config/strm/strm.config"
|
||||||
list=false
|
list=false
|
||||||
shuffle=false
|
shuffle=false
|
||||||
query=""
|
query=""
|
||||||
|
media_directories=""
|
||||||
|
|
||||||
# Parse arguments
|
# Parse arguments
|
||||||
while (( "$#" )); do
|
while (( "$#" )); do
|
||||||
|
|
@ -44,7 +46,6 @@ while (( "$#" )); do
|
||||||
shift 2
|
shift 2
|
||||||
else
|
else
|
||||||
error "Argument for $1 is missing"
|
error "Argument for $1 is missing"
|
||||||
exit 1
|
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
-h|--help)
|
-h|--help)
|
||||||
|
|
@ -54,6 +55,14 @@ while (( "$#" )); do
|
||||||
list=true
|
list=true
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
|
-m|--media-directories)
|
||||||
|
if [ -n "$2" ] && [ "${2:0:1}" != "-" ]; then
|
||||||
|
media_directories="$2"
|
||||||
|
shift 2
|
||||||
|
else
|
||||||
|
error "Argument for $1 is missing"
|
||||||
|
fi
|
||||||
|
;;
|
||||||
-s|--shuffle)
|
-s|--shuffle)
|
||||||
shuffle=true
|
shuffle=true
|
||||||
shift
|
shift
|
||||||
|
|
@ -65,38 +74,60 @@ while (( "$#" )); do
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
# Read config file
|
# Print usage if no query was given
|
||||||
if test -f "$config"; then
|
|
||||||
. "$config"
|
|
||||||
else
|
|
||||||
error "Config file not found ($config)"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Check validity of variables
|
|
||||||
config_valid=true
|
|
||||||
if [ "$connection_string" == "" ]; then
|
|
||||||
error "Connection string is missing"
|
|
||||||
config_valid=false
|
|
||||||
fi
|
|
||||||
if [ "$media_directory" == "" ]; then
|
|
||||||
error "Media directory is missing"
|
|
||||||
config_valid=false
|
|
||||||
else
|
|
||||||
# Check if media directory has trailing slash and add it if missing
|
|
||||||
[[ "$media_directory" != */ ]] && media_directory="$media_directory/"
|
|
||||||
fi
|
|
||||||
if [ "$config_valid" == false ]; then
|
|
||||||
echo "Please check your config file ($config)"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
if [ "$query" == "" ]; then
|
if [ "$query" == "" ]; then
|
||||||
print_usage
|
print_usage
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Get search results from remote
|
# If no media directory was set load config file
|
||||||
# Look for paths matching given queries in visible directories, listing only filenames and links
|
if [ "$media_directories" == "" ]; then
|
||||||
mapfile -t results < <(ssh "$connection_string" find "$media_directory" -not -path \"*/\.*\" -type l,f -ipath "$query\*" | sort)
|
|
||||||
|
# Read config file
|
||||||
|
if test -f "$config"; then
|
||||||
|
. "$config"
|
||||||
|
else
|
||||||
|
error "Config file not found ($config)"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Throws error if still no media directory set
|
||||||
|
if [ "$media_directories" == "" ]; then
|
||||||
|
error "No media directory specified"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Read media directories
|
||||||
|
IFS="," read -a media_directories <<< "$media_directories"
|
||||||
|
|
||||||
|
# Initialize result arrays
|
||||||
|
sftp_results=()
|
||||||
|
print_results=()
|
||||||
|
|
||||||
|
# Get results from every media directory
|
||||||
|
for media_directory in "${media_directories[@]}"; do
|
||||||
|
|
||||||
|
tmp_sftp_results=()
|
||||||
|
tmp_print_results=()
|
||||||
|
|
||||||
|
# Get connection string and remote directory
|
||||||
|
IFS="/" read -r connection_string directory <<< "$media_directory"
|
||||||
|
|
||||||
|
# Add leading and trailing slash to directory if missing
|
||||||
|
[[ "$directory" != /*/ ]] && directory="/$directory/"
|
||||||
|
|
||||||
|
|
||||||
|
# Get search results from remote
|
||||||
|
# Look for paths matching given queries in visible directories, listing only filenames and links
|
||||||
|
mapfile -t tmp_results < <(ssh "$connection_string" find "$directory" -not -path \"*/\.*\" -type l,f -ipath "$query\*" | sort)
|
||||||
|
|
||||||
|
# Build SFTP strings and printable strings
|
||||||
|
for i in "${!tmp_results[@]}"; do
|
||||||
|
tmp_sftp_results["$i"]="sftp://$connection_string${tmp_results[$i]}"
|
||||||
|
tmp_print_result="${tmp_results[$i]}"
|
||||||
|
tmp_print_results["$i"]="${tmp_print_result/$directory/}"
|
||||||
|
done
|
||||||
|
sftp_results=("${sftp_results[@]}" "${tmp_sftp_results[@]}")
|
||||||
|
print_results=("${print_results[@]}" "${tmp_print_results[@]}")
|
||||||
|
done
|
||||||
|
|
||||||
# List files
|
# List files
|
||||||
if [ "$list" == false ]; then
|
if [ "$list" == false ]; then
|
||||||
|
|
@ -106,25 +137,19 @@ if [ "$list" == false ]; then
|
||||||
echo -e "Playing the following files:\n"
|
echo -e "Playing the following files:\n"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
for i in "${!results[@]}"; do
|
for result in "${print_results[@]}"; do
|
||||||
res="${results[$i]}"
|
echo "$result"
|
||||||
echo "${res/$media_directory/}"
|
|
||||||
done
|
done
|
||||||
|
|
||||||
# Play results if --list flag not set
|
# Play results if --list flag not set
|
||||||
if [ "$list" == false ]; then
|
if [ "$list" == false ]; then
|
||||||
|
|
||||||
# Build SFTP strings
|
|
||||||
for i in "${!results[@]}"; do
|
|
||||||
results["$i"]="sftp://$connection_string${results[$i]}"
|
|
||||||
done
|
|
||||||
|
|
||||||
echo
|
echo
|
||||||
|
|
||||||
# Play all remote files
|
# Play all remote files
|
||||||
if [ "$shuffle" == true ]; then
|
if [ "$shuffle" == true ]; then
|
||||||
mpv --shuffle "${results[@]}"
|
mpv --shuffle "${sftp_results[@]}"
|
||||||
else
|
else
|
||||||
mpv "${results[@]}"
|
mpv "${sftp_results[@]}"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
|
||||||
20
strm.config
20
strm.config
|
|
@ -1,11 +1,11 @@
|
||||||
# SSH connection string
|
# Media directories on remote machines of the following form:
|
||||||
|
#
|
||||||
|
# <SSH connection string><absolute_path_to_media_directory>
|
||||||
|
#
|
||||||
|
# Multiple media directories can be set with a comma (,) as delimiter.
|
||||||
|
#
|
||||||
# Examples:
|
# Examples:
|
||||||
# remote # Current user at hostname 'remote' on port 22
|
# localhost/home/bob/videos
|
||||||
# user@10.0.0.1 # 'user' at address '10.0.0.1' on port 22
|
# remote-machine/home/bob/music
|
||||||
# user@10.0.0.1:600 # 'user' at address '10.0.0.1' on port 600
|
# bob@another-machine/media/movies,bob@10.0.0.1/home/bob/series
|
||||||
connection_string=""
|
media_directories=""
|
||||||
|
|
||||||
# Absolute path to media directory on remote machine
|
|
||||||
# Example:
|
|
||||||
# /home/<user>/video
|
|
||||||
media_directory=""
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue