diff --git a/README.org b/README.org index c648735..f9dab69 100644 --- a/README.org +++ b/README.org @@ -95,6 +95,7 @@ -h, --help Show this help message -c, --config CONFIG_FILE Path to config file (default: ~/.config/strm/strm.config) -f, --fullscreen Play video files in fullscreen + -i, --ignore-files IGNORE_FILES Ignore given filenames -l, --list List files instead of playing -m, --media-directories MEDIA_DIRECTORIES Use given media directories, config is ignored -o, --or Use a logical OR for queries (default: AND) @@ -119,10 +120,11 @@ - =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 =--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. + 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. 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 # bob@another-machine/home/bob/strm 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 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=. 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. - 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. - In this case use additionally the =--playback-directory= flag with the same value from your config file. + 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= and =ignore_files= is not used. + 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=. diff --git a/strm b/strm index cc0670d..41d1360 100755 --- a/strm +++ b/strm @@ -1,8 +1,8 @@ #!/usr/bin/env bash # Text formatting variables -text_reset="\e[0m" text_bold="\e[1m" +text_reset="\e[0m" function print_usage { echo "Usage: strm [OPTIONS] QUERIES ... [OPTIONS]" @@ -13,6 +13,7 @@ function print_usage { echo " -h, --help Show this help message" echo " -c, --config CONFIG_FILE Path to config file (default: ~/.config/strm/strm.config)" 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 " -m, --media-directories MEDIA_DIRECTORIES Use given media directories, config is ignored" echo " -o, --or Use a logical OR for queries (default: AND)" @@ -54,6 +55,7 @@ queries=() quit="" remote="" remote_arguments=() +tmp_ignore_files="" tmp_playback_directory="" shuffle=false @@ -76,6 +78,15 @@ while (( "$#" )); do -h|--help) 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=true shift @@ -202,6 +213,11 @@ if [ "$tmp_playback_directory" != "" ]; then playback_directory="$tmp_playback_directory" fi +# Override ignore files if argument set +if [ "$tmp_ignore_files" != "" ]; then + ignore_files="$tmp_ignore_files" +fi + # Synchronize playback directory if [ "$list" == false ] && [ "$playback_directory" != "" ]; then @@ -250,19 +266,42 @@ fi # Read media directories IFS="," read -a media_directories <<< "$media_directories" +# Read ignore files +IFS="," read -a ignore_files <<< "$ignore_files" + # 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 # If -o flag is set and more than one query is given, add a logical OR if [ "$or" == true ] && [ "$i" -ge 1 ]; then - find_arguments+=("-o" "-not" "-path" "'*/\.*'" "-type" "f,l") + find_arguments+=("-or") fi # Use the ipath argument to search case-insensitive and surround query with wildcards find_arguments+=("-ipath" "'*${queries[$i]}*'") done +find_arguments+=("\)") # Initialize result arrays 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[@]}" fi - # Synchronize playback directory back if not tidy and directory is set + # Synchronize playback directory back if directory is set if [ "$playback_directory" != "" ]; then # Get connection string and remote directory diff --git a/strm.config b/strm.config index a18efaa..1980f2b 100644 --- a/strm.config +++ b/strm.config @@ -25,4 +25,12 @@ media_directories="" # /home/alice/.strm # remote-machine/home/alice/strm # bob@another-machine/home/bob/strm -playback_directory="" \ No newline at end of file +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="" \ No newline at end of file