boom (1464B)
1 #!/usr/bin/env sh 2 3 # Description: Play random music (MP3, FLAC, M4A, WEBM, WMA) from current dir. 4 # 5 # Dependencies: mocp (or custom) 6 # 7 # Note: You may want to set GUIPLAYER. 8 # 9 # Shell: POSIX compliant 10 # Author: Arun Prakash Jana 11 12 GUIPLAYER="${GUIPLAYER:-""}" 13 NUMTRACKS="${NUMTRACKS:-100}" 14 15 if [ -n "$GUIPLAYER" ]; then 16 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 & 17 18 # detach the player 19 sleep 1 20 elif type mocp >/dev/null 2>&1; then 21 cmd=$(pgrep -x mocp 2>/dev/null) 22 ret=$cmd 23 24 if [ -z "$ret" ]; then 25 # start MOC server 26 mocp -S 27 mocp -o shuffle 28 else 29 # mocp running, check if it's playing 30 state=$(mocp -i | grep "State:" | cut -d' ' -f2) 31 if [ "$state" = 'PLAY' ]; then 32 # add up to 100 random audio files 33 find . -type f \( -iname "*.mp3" -o -iname "*.flac" -o -iname "*.m4a" -o -iname "*.webm" -o -iname "*.wma" \) | head -n "$NUMTRACKS" | xargs -d "\n" mocp -a 34 exit 35 fi 36 fi 37 38 # clear MOC playlist 39 mocp -c 40 mocp -o shuffle 41 42 # add up to 100 random audio files 43 find . -type f \( -iname "*.mp3" -o -iname "*.flac" -o -iname "*.m4a" -o -iname "*.webm" -o -iname "*.wma" \) | head -n "$NUMTRACKS" | xargs -d "\n" mocp -a 44 45 # start playing 46 mocp -p 47 else 48 printf "moc missing" 49 read -r _ 50 fi