Various plugin improvements

This commit is contained in:
Arun Prakash Jana 2020-04-27 00:05:11 +05:30
parent babf379a74
commit eec0e6d18e
3 changed files with 13 additions and 15 deletions

View file

@ -10,7 +10,7 @@ GUIPLAYER="${GUIPLAYER}"
NUMTRACKS="${NUMTRACKS:-100}"
if [ ! -z "$GUIPLAYER" ]; then
find . -type f \( -iname "*.mp3" -o -iname "*.flac" -o -iname "*.m4a" -o -iname "*.webm" -o -iname "*.wma" \) | shuf | head -n "$NUMTRACKS" | xargs -d "\n" "$GUIPLAYER" > /dev/null 2>&1 &
find . -type f \( -iname "*.mp3" -o -iname "*.flac" -o -iname "*.m4a" -o -iname "*.webm" -o -iname "*.wma" \) | shuf -n "$NUMTRACKS" | xargs -d "\n" "$GUIPLAYER" > /dev/null 2>&1 &
# detach the player
sleep 1
@ -26,7 +26,7 @@ elif which mocp >/dev/null 2>&1; then
state=$(mocp -i | grep "State:" | cut -d' ' -f2)
if [ "$state" = 'PLAY' ]; then
# add up to 100 random audio files
find . -type f \( -iname "*.mp3" -o -iname "*.flac" -o -iname "*.m4a" -o -iname "*.webm" -o -iname "*.wma" \) | shuf | head -n "$NUMTRACKS" | xargs -d "\n" mocp -a
find . -type f \( -iname "*.mp3" -o -iname "*.flac" -o -iname "*.m4a" -o -iname "*.webm" -o -iname "*.wma" \) | shuf -n "$NUMTRACKS" | xargs -d "\n" mocp -a
exit
fi
fi
@ -35,7 +35,7 @@ elif which mocp >/dev/null 2>&1; then
mocp -c
# add up to 100 random audio files
find . -type f \( -iname "*.mp3" -o -iname "*.flac" -o -iname "*.m4a" -o -iname "*.webm" -o -iname "*.wma" \) | shuf | head -n "$NUMTRACKS" | xargs -d "\n" mocp -a
find . -type f \( -iname "*.mp3" -o -iname "*.flac" -o -iname "*.m4a" -o -iname "*.webm" -o -iname "*.wma" \) | shuf -n "$NUMTRACKS" | xargs -d "\n" mocp -a
# start playing
mocp -p

View file

@ -4,14 +4,18 @@
# Opens in $VISUAL or $EDITOR if text
# Opens other type of files with xdg-open
#
# Requires: fzf/fzy, xdg-open
# Requires: fd/find, fzf/fzy/skim, xdg-open
#
# Shell: POSIX compliant
# Author: Arun Prakash Jana
if which fzf >/dev/null 2>&1; then
cmd="$FZF_DEFAULT_COMMAND"
if which fd >/dev/null 2>&1; then
[ -z "$cmd" ] && cmd="fd -t f 2>/dev/null"
else
[ -z "$cmd" ] && cmd="find . -type f 2>/dev/null"
fi
entry="$(eval "$cmd" | fzf --delimiter / --nth=-1 --tiebreak=begin --info=hidden)"
# To show only the file name
# entry=$(find . -type f 2>/dev/null | fzf --delimiter / --with-nth=-1 --tiebreak=begin --info=hidden)

View file

@ -7,6 +7,7 @@
# - appends tracks and exits is MOC is running, else clears playlist and adds tracks
# - to randomize the order of files appended to the playlist, set SHUFFLE=1
# if you add a directory with many files when SHUFFLE=1 is set, it might take a very long time to finish!
# - max 100 files are added
#
# Shell: POSIX compliant
# Author: Arun Prakash Jana, ath3
@ -30,20 +31,13 @@ mocp_add ()
for entry in $arr
do
if [ -d "$entry" ]; then
arr2=$arr2$(find "$entry" -type f)
else
arr2=$arr2$(find "$entry" -type f \( ! -iname "*.m3u" ! -iname "*.pls" \))
elif echo "$entry" | grep -qv '\.m3u$\|\.pls$' ; then
arr2=$(printf "%s\n%s" "$entry" "$arr2")
fi
done
arr2=$(echo "$arr2" | awk 'BEGIN{srand();}{print rand()"\t"$0}' | sort -k1 -n | cut -f2-)
for entry in $arr2
do
if [ -f "$entry" ] && echo "$entry" | grep -qv '\.m3u$\|\.pls$' ; then
mocp -a "$entry"
fi
done
echo "$arr2" | shuf -n 100 | xargs -d "\n" mocp -a
else
if [ "$resp" = "y" ]; then
xargs < "$selection" -0 mocp -a