You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

43 lines
994 B
Bash

#!/bin/bash
path_to_script="${HOME}/Dropbox/Code/pick_music/pick-music.py"
# Filetypes to exclude in playlist loading
exclude='jpg,jpeg,m3u,txt,log'
exclude_re="$(echo "${exclude}\$" | sed 's/,/\|/g')"
# Filename for temp playlist
picks="/tmp/picks"
playlist="/tmp/music.m3u"
# Test if cmus is running
if ! cmus-remote -C >/dev/null 2>&1 ; then
echo >&2 "cmus is not running"
exit 1
fi
# Get random picks. If incorrect args provided, exit with error
if ! python3 "$path_to_script" "$@" > "$picks"; then
exit 1
fi
# For each folder from the random picker
cat "$picks" | while read -r pick; do
for file in "$pick"/*.*; do
if [[ ! "$file" =~ $exclude_re ]]; then
echo "$file"
fi
done
done > "$playlist"
# Clear existing playlist
cmus-remote -C "view playlist"
cmus-remote -c
cmus-remote -C "win-next"
cmus-remote -c
# Add new playlist
cmus-remote "$playlist"
# Start playing the new playlist
cmus-remote -C "player-next-album"
cmus-remote -p