make a playlist by fuzzy finding
a script that uses fzf
to search for songs, gives options for what to name and where to save a new .m3u playlist, and starts playing it immediately if you want.
my reason for making this was that i had completely rearranged the structure of my music folder and had several playlists where i had the titles of the songs but not the full paths. this made remaking one take like 3 minutes for a hundred songs which i am very pleased with, it's also fun for throwing little things together. download a copy here.
#! /bin/bash
CYN='\033[0;36m' # cyan
WHT='\033[0m' # white/default color
makeplaylist() {
echo -e "${CYN}now, add songs. the track order will be the order you select them in."
sleep 2
echo -e "${CYN}to select or deselect a song press TAB, when you're done, press ENTER."
sleep 4
find $HOME/Music ! -name '*.png' ! -name '*.jpg' ! -name '*.jpeg' ! -name '*.m3u' ! -name '.DS_Store' -type f -print | fzf --multi --preview='ffprobe -v error -print_format default=nw=1:nk=0 -show_entries format_tags=title,artist,album {} | sed "s/TAG://" | sed "s/=/ : /" | sort -r' | cat > "$destination/$filename.m3u"
echo -e "${WHT}..."
sleep 1
echo -e "${CYN}playlist created!"
sleep 1
echo -e "${CYN}open with default .m3u player?${WHT}"
sleep 1
PS3='-> '
options=("yes" "no")
select opt in "${options[@]}"
do
case $opt in
"yes")
nohup xdg-open "$destination/$filename.m3u" 0/dev/null 2>/dev/null &
echo -e "${CYN}enjoy your playlist!"
exit
;;
"no")
echo -e "${CYN}enjoy your playlist!"
exit
;;
*) echo -e "${WHT}$REPLY ${CYN}is not an option, try again.${WHT}";;
esac
done
}
echo -e "${CYN}welcome to the fuzzy playlist maker!"
sleep 1
read -p "$(echo -e "${CYN}filename for playlist? (spaces are okay)${WHT}")
-> " filename
echo -e "${CYN}okay, it will be named ${WHT}$filename.m3u."
sleep 1
echo -e "${CYN}save to ${WHT}~/Music/Playlists ${CYN}or somewhere else?${WHT}"
PS3='-> '
options=("yes" "somewhere else")
select opt in "${options[@]}"
do
case $opt in
"yes")
destination=$HOME/Music/Playlists
makeplaylist
;;
"somewhere else")
read -p "$(echo -e "${CYN}please type the full path:${WHT}")
-> " destination
echo -e "${CYN}okay, it will be created in ${WHT}$destination."
sleep 1
makeplaylist
;;
*) echo -e "${WHT}$REPLY ${CYN}is not an option, try again.${WHT}";;
esac
done
CYN='\033[0;36m' # cyan
WHT='\033[0m' # white/default color
makeplaylist() {
echo -e "${CYN}now, add songs. the track order will be the order you select them in."
sleep 2
echo -e "${CYN}to select or deselect a song press TAB, when you're done, press ENTER."
sleep 4
find $HOME/Music ! -name '*.png' ! -name '*.jpg' ! -name '*.jpeg' ! -name '*.m3u' ! -name '.DS_Store' -type f -print | fzf --multi --preview='ffprobe -v error -print_format default=nw=1:nk=0 -show_entries format_tags=title,artist,album {} | sed "s/TAG://" | sed "s/=/ : /" | sort -r' | cat > "$destination/$filename.m3u"
echo -e "${WHT}..."
sleep 1
echo -e "${CYN}playlist created!"
sleep 1
echo -e "${CYN}open with default .m3u player?${WHT}"
sleep 1
PS3='-> '
options=("yes" "no")
select opt in "${options[@]}"
do
case $opt in
"yes")
nohup xdg-open "$destination/$filename.m3u" 0/dev/null 2>/dev/null &
echo -e "${CYN}enjoy your playlist!"
exit
;;
"no")
echo -e "${CYN}enjoy your playlist!"
exit
;;
*) echo -e "${WHT}$REPLY ${CYN}is not an option, try again.${WHT}";;
esac
done
}
echo -e "${CYN}welcome to the fuzzy playlist maker!"
sleep 1
read -p "$(echo -e "${CYN}filename for playlist? (spaces are okay)${WHT}")
-> " filename
echo -e "${CYN}okay, it will be named ${WHT}$filename.m3u."
sleep 1
echo -e "${CYN}save to ${WHT}~/Music/Playlists ${CYN}or somewhere else?${WHT}"
PS3='-> '
options=("yes" "somewhere else")
select opt in "${options[@]}"
do
case $opt in
"yes")
destination=$HOME/Music/Playlists
makeplaylist
;;
"somewhere else")
read -p "$(echo -e "${CYN}please type the full path:${WHT}")
-> " destination
echo -e "${CYN}okay, it will be created in ${WHT}$destination."
sleep 1
makeplaylist
;;
*) echo -e "${WHT}$REPLY ${CYN}is not an option, try again.${WHT}";;
esac
done