#!/usr/bin/env bash
# Desc: Wrapper for mpv that accepts directory or file paths via posargs or stdin lines
# Usage: bkmpv2 [DIR]
-# Version: 0.1.0
+# Version: 0.2.1
# Depends: GNU Parallel, GNU Bash v5.1.16, mpv v0.34.1, bc v1.07.1
# Ref/Attrib: [1] Tange, Ole. GNU Parallel with Bash Array. 2019-03-24. https://unix.stackexchange.com/a/508365/411854
# Example: find $HOME/Music -type d | bkmpv2
# Note: Does not follow symlinks
# Find settings
-firegex=".+\(aac\|aif\|aiff\|flac\|m4a\|mp3\|mp4\|ogg\|opus\|wav\)$"; # update according to `find . -type f | grep -Eo "\.([[:alnum:]])+$" | sort -u`
+firegex=".+\(aac\|aif\|aiff\|flac\|m4a\|mp3\|mp4\|ogg\|opus\|wav\)$"; # POSIX regex for find. Update according to `find . -type f | grep -Eo "\.([[:alnum:]])+$" | sort -u`
+file_regex=".+(aac|aif|aiff|flac|m4a|mp3|mp4|ogg|opus|wav)$"; # extended regex for Bash.
fsize="10k"; # default: minimum "10k"
fdepth_posarg="10"; # find depth for positional arguments
fdepth_stdin="1"; # find depth for stdin
if [[ ! -d "$1" ]]; then return 1; fi;
must find "$1" -maxdepth "$fdepth" -type f -iregex "$firegex" -size +"$fsize";
}; # print file list to stdout from dir with script parameters
+check_files() {
+ # Desc: Applies $file_regex to files specified by path
+ # Input: var: file_regex
+ # array: files_stdin
+ # Output: array: files_stdin
+ local file;
+ declare -a filtered_files_stdin;
+
+ for file in "${files_stdin[@]}"; do
+ if [[ "$file" =~ $file_regex ]]; then
+ filtered_files_stdin+=("$file");
+ fi;
+ done;
+ files_stdin=("${filtered_files_stdin[@]}");
+}; # apply $firegex to files_stdin array
main() {
# Input: var: firegex find iregex file name pattern
# var: fsize find minimum file siz
done < <( read_stdin; read_psarg "$@"; );
yell "STATUS:$SECONDS:Read stdin and psargs.";
+ # Apply the $file_regex to $files_stdin array
+ check_files;
+
# Catch all arrays empty
if [[ "${#dirs_stdin[@]}" -le 0 ]] && \
[[ "${#dirs_psarg[@]}" -le 0 ]] && \
cmd_args+=("--audio-display=no"); # disable video for audio files
cmd_args+=("--vid=no"); # donʼt show video track
cmd_args+=("--image-display-duration=0"); # don't show album art
- cmd_args+=("--af=scaletempo=stride=15:overlap=1:search=15"); # improve scrubbing
cmd_args+=("--playlist=$list_paths_files_tmp"); # read playlist
declare -p cmd_args; # debug
## Execute command