Files
q-tools/av/mpvmusic
2024-10-11 22:01:36 +03:00

91 lines
1.7 KiB
Bash
Executable File

#!/bin/bash
_list_audio_files() {
if [[ $recursive -eq 0 ]]; then
files=$( ls -p | grep -v /$ )
else
files=$( find . -type f )
fi
echo "$files" | \
grep -i -e \.mp3$ -e \.ogg$ -e \.flac$ | \
sort -V | \
awk '{print "'"$PWD"'/"$0}'
}
_print_audio_files() {
n=$( wc -l "$1" | awk '{print $1}' )
i=0
while read line; do
i=$(( i + 1 ))
printf "%s/%s %s\n" \
$i $n "$( basename "$line" )"
done < "$1"
}
_play() {
mpv \
--keep-open=no \
--audio-display=no \
--term-osd-bar \
--msg-level=ffmpeg/audio=fatal,ad=fatal \
--playlist="$1" $MPV_ARGS
}
echo ' -r recursive
MPV_ARGS=.. to pass them..
# MPV audio shortcuts'
qolop c Y
echo '
| Key | Command |
|:-------|:---------------------------|
| p | Pause |
| Q | Quit saving position |
| <-/-> | Seek 5 seconds |
| up/dn | Seek 60 seconds |
| < / > | Prev/Next file |
| [/] | Change speed |
| m | Mute |
| 9/0 | Modify volume |
| * / | Modify volume |
'
qolop c Z
recursive=0
for (( i=1; i<=$#; i++ )); do
[[ "${!i}" = "-r" ]] && {
recursive=1;
continue
}
done
if [[ -e "$1" ]]; then
if [[ "$1" = *".m3u8" ]]; then
_play "$1"
exit $?
fi
fi
playlistfile=$( mktemp )
if [[ $recursive -eq 1 ]]; then
_list_audio_files > "$playlistfile"
else
if [[ -n "$1" ]]; then
for (( i=1; i<=$#; i++ )); do
readlink -f "${!i}" >> "$playlistfile"
done
else
_list_audio_files > "$playlistfile"
fi
fi
_print_audio_files "$playlistfile"
if [[ -s "$playlistfile" ]]; then
_play "$playlistfile"
else
echo Playlist empty
fi
rm -f "$playlistfile"