#1. PLAY NU MPV |
Published: 2025-09-27 [Sat] 02:22, by |
https://x0.at/30jh.png #!/bin/bash # ┏━┓╻ ┏━┓╻ ╻┏┓╻╻ ╻┏┳┓┏━┓╻ ╻ USAGE: playnumpv <days> # ┣━┛┃ ┣━┫┗┳┛┃┗┫┃ ┃┃┃┃┣━┛┃┏┛ (where days = number of days to # ╹ ┗━╸╹ ╹ ╹ ╹ ╹┗━┛╹ ╹╹ ┗┛ search back for newer media files) # Check if argument is provided if [ -z "$1" ] || [[ ! "$1" =~ ^[0-9]+$ ]]; then echo "Usage: $0 <days>" exit 1 fi # Create a temporary playlist file in a safe location playlist=$(mktemp) || { echo "Failed to create temporary file"; exit 1; } # Set trap to clean up temporary file on exit trap 'rm -f "$playlist"' EXIT # Get absolute path of the playlist to exclude it from search abs_playlist=$(realpath "$playlist") # Find all media files modified in the last $1 days and add them to the playlist # Using absolute paths to avoid issues with relative paths find "$PWD" -type f -regextype posix-extended -regex '.*\.(mp3|flac|opus|ogg|m4a|wav|nsf|mod|xm)' \ -mtime -"${1}" ! -path "$abs_playlist" -print0 | \ sort -z | \ tr '\0' '\n' > "$playlist" # Check if any files were found if [ ! -s "$playlist" ]; then echo "No files found newer than ${1} days."; exit 0 fi # Count the number of files in the playlist file_count=$(wc -l < "$playlist") echo "Found $file_count files to play." # Play playlist with mpv using unbuffer to maintain terminal connection # and process substitution to capture output without breaking stdin unbuffer -p mpv --shuffle --term-osd=auto --osd-level=2 --no-audio-display \ --playlist="$playlist" 2>&1 > >(grep -E "Playing") < /dev/tty |