make_playlist()

rework make_playlist() with fzf
This commit is contained in:
2023-02-16 10:08:56 +01:00
parent 507ca63f0e
commit 93d9959bac

View File

@@ -49,6 +49,15 @@ if (! type fzf > /dev/null 2>&1); then fzf_bin=0
else fzf_bin=1 else fzf_bin=1
fi fi
if ! command -v mediainfo &> /dev/null; then
echo "Install mediainfo to display media tags !"
echo -e "${italic}brew install mediainfo${reset}"
mediainfo=false
else
mediainfo=true
fi
fzf_args=( fzf_args=(
--height=8 --height=8
--with-nth=2.. --with-nth=2..
@@ -769,13 +778,6 @@ play_local_audio_file() {
param="$*" param="$*"
if ! command -v mediainfo &> /dev/null; then
echo "Install mediainfo to display media tags !"
echo -e "${italic}brew install mediainfo${reset}"
mediainfo=false
else
mediainfo=true
fi
if [ -n "$param" ]; then # fichier passé en param if [ -n "$param" ]; then # fichier passé en param
@@ -898,8 +900,8 @@ play_local_audio_dir() {
else else
if [ $fzf_bin -eq 1 ]; then if [ $fzf_bin -eq 1 ]; then
header=" Choose a target speaker for this alarm" #header=" Choose a target speaker for this alarm"
prompt="Choose a target speaker for this alarm: " #prompt="Choose a target speaker for this alarm: "
fzf_music_folder_args=( fzf_music_folder_args=(
--border --border
@@ -1034,58 +1036,97 @@ make_playlist() {
# GNU bash, version 3.2.57(1)-release-(x86_64-apple-darwin20) # GNU bash, version 3.2.57(1)-release-(x86_64-apple-darwin20)
#read -e -p "Choose folder to create playlist from: " folder #read -e -p "Choose folder to create playlist from: " folder
# GNU bash, version 5.1.4(1)-release (x86_64-apple-darwin19.6.0) (brew install bash) # GNU bash, version 5.1.4(1)-release (x86_64-apple-darwin19.6.0) (brew install bash)
read -e -i "$HOME/Music/" -p "Choose folder to create playlist from: " folder
if [ -d "$folder" ]; then fzf_bin=1
read -e -p "Include subfolder ? (y/n) " sub if [ $fzf_bin -eq 1 ]; then
fzf_playlist_args=(
--multi
--border
)
if [ "$sub" == "y" ] || [ "$sub" == "Y" ]; then radio_uri+=([*No change*]="_")
#m3u=$(echo "$fp" | awk -F"/" '{print $NF}')
if [[ "$OSTYPE" == "darwin"* ]]; then list=$(find -E "$folder" -iregex ".*\.(mp3|mp4|m4a|aac|flac|ogg|wma|wav)" | sort)
else list=$(find "$folder" -iregex ".*\.\(mp3\|mp4\|m4a\|aac\|flac\|ogg\|wma\|wav\)" | sort); fi
else
if [[ "$OSTYPE" == "darwin"* ]]; then list=$(find -E "$folder" -maxdepth 1 -iregex ".*\.(mp3|mp4|m4a|aac|flac|ogg|wma|wav)" | sort)
else list=$(find "$folder" -maxdepth 1 -iregex ".*\.\(mp3\|mp4\|m4a\|aac\|flac\|ogg\|wma\|wav\)" | sort); fi
fi
while [ true ] ; do volume=$(find /Volumes $HOME -maxdepth 1 -type d -not -path '*/\.*' -print 2> /dev/null | fzf --prompt="Select a folder !" --header="ESC to quit !")
read -t 10 -e -p "Give a name to the playlist (without extension): " pl_name music=$(find $volume -type f \( -name "*.mp3" -o -name "*.mp4" -o -name "*.m4a" -o -name "*.aac" -o -name "*.flac" -o -name "*.ogg" -o -name "*.wma" -o -name "*.wav" \) -print 2> /dev/null | fzf "${fzf_playlist_args[@]}" --prompt="Select some music files!" --header="Tab / Shift+Tab to select and Enter")
if [ -n "$pl_name" ] ; then liste_pl="$music"
break ; fi
else
echo "Waiting for a name !" if [ -z "$liste_pl" ]; then
while :
do
echo -e "${underline}Enter audio folder path${reset} (.mp3|.mp4|.m4a|.aac|.flac|.ogg|.wma|.wav): "
read -e -i "$HOME/Music/" -p "Choose folder to create playlist from: " folder_pl
if [ -d "$folder_pl" ]; then
read -e -p "Include subfolder ? (y/n) " sub
if [ "$sub" == "y" ] || [ "$sub" == "Y" ]; then
if [[ "$OSTYPE" == "darwin"* ]]; then liste_pl=$(find -E "$folder_pl" -iregex ".*\.(mp3|mp4|m4a|aac|flac|ogg|wma|wav)" | sort)
else liste_pl=$(find "$folder_pl" -iregex ".*\.\(mp3\|mp4\|m4a\|aac\|flac\|ogg\|wma\|wav\)" | sort); fi
else
if [[ "$OSTYPE" == "darwin"* ]]; then liste_pl=$(find -E "$folder_pl" -maxdepth 1 -iregex ".*\.(mp3|mp4|m4a|aac|flac|ogg|wma|wav)" | sort)
else liste_pl=$(find "$folder_pl" -maxdepth 1 -iregex ".*\.\(mp3\|mp4\|m4a\|aac\|flac\|ogg\|wma\|wav\)" | sort); fi
fi
if [ -n "$liste_pl" ]; then
audio_dir="$folder_pl"
break
else echo "No audio files founds !"
fi
fi fi
echo
done done
fi
plst="$pl_name.m3u" echo -e "\n${greenbold}Tracks to record on playlist...${reset}"
printf "#EXTM3U\n" > "$plst" printf " \e[4m%-2s\e[0m \e[4m%-25s\e[0m \e[4m%-35s\e[0m \e[4m%-35s\e[0m \e[4m%-12s\e[0m \e[4m%-10s\e[0m \n" "N°" "Artist" "Track" "Album" "Duration" "Year"
echo "$list" >> "$plst"
i=1
read -e -p "Do you want to edit $plst ? (y/n) " edit while IFS= read -r line; do
if [ "$edit" == "y" ] || [ "$edit" == "Y" ]; then if [ -f "$line" ]; then
[ -n $EDITOR ] && $EDITOR "$plst" || nano "$plst" #echo "$line"
[ "$mediainfo" = true ] && minfo "$line" "$i" || echo "mediainfo=false"
local _x="$album"
[ "$_x" != "$_y" ] && display_cover_art "$line"
local _y="$_x"
else echo "not a file!"
fi fi
((i++))
done <<< "$liste_pl"
echo
# Extract album art from .mp3 while [ true ] ; do
# ffmpeg -hide_banner -loglevel error -i 01.\ Portez\ vos\ croix.mp3 -s 300x300 album_art.jpg read -t 10 -e -p "Give a name to the playlist (without extension): " pl_name
if [ -n "$pl_name" ] ; then
read -e -p "Do you want to play $plst ? (y/n) " play break ;
if [ "$play" == "y" ] || [ "$play" == "Y" ]; then else
playing="Playing the ${bold_under}$plst${reset}${underline} playlist..." echo -e "\nWaiting for a name !"
echo -e "\n${underline}$playing${reset}"
pls=$(cat "$plst")
echo -e "\n$pls\n"
### BUG: bloc menu avec CTRL-C ###
echo -e "Hit CTRL-C to exit playlist \n"
sonos $loc $device play_m3u "$plst" pi
fi fi
done
else plst="$pl_name.m3u"
echo "Folder $folder doesn't exist !'"
printf "#EXTM3U\n" > "$plst"
echo "$liste_pl" >> "$plst"
read -e -p "Do you want to edit $plst ? (y/n) " edit
if [ "$edit" == "y" ] || [ "$edit" == "Y" ]; then
[ -n $EDITOR ] && $EDITOR "$plst" || nano "$plst"
fi
read -e -p "Do you want to play $plst ? (y/n) " play
if [ "$play" == "y" ] || [ "$play" == "Y" ]; then
playing="Playing the ${bold_under}$plst${reset}${underline} playlist..."
echo -e "\n${underline}$playing${reset}"
pls=$(cat "$plst")
echo -e "\n$pls\n"
### BUG: bloc menu avec CTRL-C ###
echo -e "Hit CTRL-C to exit playlist \n"
sonos $loc $device play_m3u "$plst" pi
fi fi
} }