add ignore files functionality
This commit is contained in:
parent
508f6e55fd
commit
e972c596c9
3 changed files with 68 additions and 11 deletions
20
README.org
20
README.org
|
|
@ -95,6 +95,7 @@
|
||||||
-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
|
-f, --fullscreen Play video files in fullscreen
|
||||||
|
-i, --ignore-files IGNORE_FILES Ignore given filenames
|
||||||
-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)
|
||||||
|
|
@ -119,10 +120,11 @@
|
||||||
- =f= :: Toggle fullscreen.
|
- =f= :: Toggle fullscreen.
|
||||||
- =q= :: Stop playing and quit.
|
- =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.
|
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.
|
Otherwise 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.
|
The last query arguments are saved if a =playback_directory= is set and the =--list= flag is not set.
|
||||||
If you want to resume playback at a later time, it is sufficient to call =strm= without arguments.
|
If you want to resume playback at a later time, it is sufficient to call =strm= without arguments.
|
||||||
|
Use the =--tidy= flag to not resume playback.
|
||||||
|
|
||||||
Resuming playback of a file over multiple machines is only possible if all machines are configured with the same =media_directory= path for the file.
|
Resuming playback of a file over multiple machines is only possible if all machines are configured with the same =media_directory= path for the file.
|
||||||
This is due to the fact that mpv stores the playback positions based on the filename hash, which in the case of remote files is the entire file path.
|
This is due to the fact that mpv stores the playback positions based on the filename hash, which in the case of remote files is the entire file path.
|
||||||
|
|
@ -177,6 +179,14 @@
|
||||||
# remote-machine/home/alice/strm
|
# remote-machine/home/alice/strm
|
||||||
# bob@another-machine/home/bob/strm
|
# bob@another-machine/home/bob/strm
|
||||||
playback_directory=""
|
playback_directory=""
|
||||||
|
|
||||||
|
# Ignored filenames as comma separated list.
|
||||||
|
# This can be glob patterns and matching is done case-insensitive.
|
||||||
|
#
|
||||||
|
# Examples:
|
||||||
|
# cover.jpg
|
||||||
|
# *.jpg,*.png
|
||||||
|
ignore_files=""
|
||||||
#+end_src
|
#+end_src
|
||||||
|
|
||||||
An example configuration file can be found in the repository.
|
An example configuration file can be found in the repository.
|
||||||
|
|
@ -184,8 +194,8 @@
|
||||||
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.
|
||||||
|
|
||||||
The flags =--media-directories= and =--playback-directory= are used in favour of configuration parameters and can be used with the same syntax as described above.
|
The flags =--media-directories=, =--playback-directory= and =--ignore-files= are used in favour of configuration parameters and can be used with the same syntax as described above.
|
||||||
Be aware that if the =--media-directories= flag is given, no configuraion file is loaded (even if explicitly set with =--config=) and thus the configured =playback_directory= is not used.
|
Be aware that if the =--media-directories= flag is given, no configuraion file is loaded (even if explicitly set with =--config=) and thus the configured =playback_directory= and =ignore_files= is not used.
|
||||||
In this case use additionally the =--playback-directory= flag with the same value from your config file.
|
In this case use additionally the =--playback-directory= and =--ignore-files= flags with the same value from your config file.
|
||||||
|
|
||||||
The local directory to which and from which the playback positions are synchronized is =$HOME/.cache/strm=.
|
The local directory to which and from which the playback positions are synchronized is =$HOME/.cache/strm=.
|
||||||
|
|
|
||||||
49
strm
49
strm
|
|
@ -1,8 +1,8 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
# Text formatting variables
|
# Text formatting variables
|
||||||
text_reset="\e[0m"
|
|
||||||
text_bold="\e[1m"
|
text_bold="\e[1m"
|
||||||
|
text_reset="\e[0m"
|
||||||
|
|
||||||
function print_usage {
|
function print_usage {
|
||||||
echo "Usage: strm [OPTIONS] QUERIES ... [OPTIONS]"
|
echo "Usage: strm [OPTIONS] QUERIES ... [OPTIONS]"
|
||||||
|
|
@ -13,6 +13,7 @@ function print_usage {
|
||||||
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 " -f, --fullscreen Play video files in fullscreen"
|
||||||
|
echo " -i, --ignore-files IGNORE_FILES Ignore given filenames"
|
||||||
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)"
|
||||||
|
|
@ -54,6 +55,7 @@ queries=()
|
||||||
quit=""
|
quit=""
|
||||||
remote=""
|
remote=""
|
||||||
remote_arguments=()
|
remote_arguments=()
|
||||||
|
tmp_ignore_files=""
|
||||||
tmp_playback_directory=""
|
tmp_playback_directory=""
|
||||||
shuffle=false
|
shuffle=false
|
||||||
|
|
||||||
|
|
@ -76,6 +78,15 @@ while (( "$#" )); do
|
||||||
-h|--help)
|
-h|--help)
|
||||||
print_usage
|
print_usage
|
||||||
;;
|
;;
|
||||||
|
-i|--ignore-files)
|
||||||
|
if [ -n "$2" ] && [ "${2:0:1}" != "-" ]; then
|
||||||
|
tmp_ignore_files="$2"
|
||||||
|
remote_arguments+=("$1" "$2")
|
||||||
|
shift 2
|
||||||
|
else
|
||||||
|
error "Argument for '$1' is missing"
|
||||||
|
fi
|
||||||
|
;;
|
||||||
--is-remote-call)
|
--is-remote-call)
|
||||||
is_remote_call=true
|
is_remote_call=true
|
||||||
shift
|
shift
|
||||||
|
|
@ -202,6 +213,11 @@ if [ "$tmp_playback_directory" != "" ]; then
|
||||||
playback_directory="$tmp_playback_directory"
|
playback_directory="$tmp_playback_directory"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Override ignore files if argument set
|
||||||
|
if [ "$tmp_ignore_files" != "" ]; then
|
||||||
|
ignore_files="$tmp_ignore_files"
|
||||||
|
fi
|
||||||
|
|
||||||
# Synchronize playback directory
|
# Synchronize playback directory
|
||||||
if [ "$list" == false ] && [ "$playback_directory" != "" ]; then
|
if [ "$list" == false ] && [ "$playback_directory" != "" ]; then
|
||||||
|
|
||||||
|
|
@ -250,19 +266,42 @@ fi
|
||||||
# Read media directories
|
# Read media directories
|
||||||
IFS="," read -a media_directories <<< "$media_directories"
|
IFS="," read -a media_directories <<< "$media_directories"
|
||||||
|
|
||||||
|
# Read ignore files
|
||||||
|
IFS="," read -a ignore_files <<< "$ignore_files"
|
||||||
|
|
||||||
# Construct find argument array
|
# Construct find argument array
|
||||||
# Ignore hidden files and directories and list only files and symlinks
|
|
||||||
find_arguments=("-not" "-path" "'*/\.*'" "-type" "f,l")
|
# List only files and symlinks
|
||||||
|
find_arguments=("-type" "f,l")
|
||||||
|
|
||||||
|
# Ignore hidden files and directories
|
||||||
|
find_arguments+=("!" "-path" "'*/\.*'")
|
||||||
|
|
||||||
|
# Ignore additional given filenames case-insensitive
|
||||||
|
if [ "${#ignore_files[@]}" -ge 1 ]; then
|
||||||
|
find_arguments+=("-and" "!" "\(")
|
||||||
|
for i in "${!ignore_files[@]}"; do
|
||||||
|
if [ "$i" -ge 1 ]; then
|
||||||
|
find_arguments+=("-or")
|
||||||
|
fi
|
||||||
|
find_arguments+=("-iname" "'${ignore_files[$i]}'")
|
||||||
|
done
|
||||||
|
find_arguments+=("\)")
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Add queries
|
||||||
|
find_arguments+=("-and" "\(")
|
||||||
for i in "${!queries[@]}"; do
|
for i in "${!queries[@]}"; do
|
||||||
|
|
||||||
# If -o flag is set and more than one query is given, add a logical OR
|
# If -o flag is set and more than one query is given, add a logical OR
|
||||||
if [ "$or" == true ] && [ "$i" -ge 1 ]; then
|
if [ "$or" == true ] && [ "$i" -ge 1 ]; then
|
||||||
find_arguments+=("-o" "-not" "-path" "'*/\.*'" "-type" "f,l")
|
find_arguments+=("-or")
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Use the ipath argument to search case-insensitive and surround query with wildcards
|
# Use the ipath argument to search case-insensitive and surround query with wildcards
|
||||||
find_arguments+=("-ipath" "'*${queries[$i]}*'")
|
find_arguments+=("-ipath" "'*${queries[$i]}*'")
|
||||||
done
|
done
|
||||||
|
find_arguments+=("\)")
|
||||||
|
|
||||||
# Initialize result arrays
|
# Initialize result arrays
|
||||||
sftp_results=()
|
sftp_results=()
|
||||||
|
|
@ -381,7 +420,7 @@ if [ "$list" == false ]; then
|
||||||
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[@]}"
|
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[@]}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Synchronize playback directory back if not tidy and directory is set
|
# Synchronize playback directory back if directory is set
|
||||||
if [ "$playback_directory" != "" ]; then
|
if [ "$playback_directory" != "" ]; then
|
||||||
|
|
||||||
# Get connection string and remote directory
|
# Get connection string and remote directory
|
||||||
|
|
|
||||||
10
strm.config
10
strm.config
|
|
@ -25,4 +25,12 @@ media_directories=""
|
||||||
# /home/alice/.strm
|
# /home/alice/.strm
|
||||||
# remote-machine/home/alice/strm
|
# remote-machine/home/alice/strm
|
||||||
# bob@another-machine/home/bob/strm
|
# bob@another-machine/home/bob/strm
|
||||||
playback_directory=""
|
playback_directory=""
|
||||||
|
|
||||||
|
# Ignored filenames as comma separated list.
|
||||||
|
# This can be glob patterns and matching is done case-insensitive.
|
||||||
|
#
|
||||||
|
# Examples:
|
||||||
|
# cover.jpg
|
||||||
|
# *.jpg,*.png
|
||||||
|
ignore_files=""
|
||||||
Loading…
Add table
Add a link
Reference in a new issue