#!/bin/bash shopt -s globstar source $HOME/.config/clerk/config export mpd_artist=albumartist clerk_updater & album_temp=$(cat $HOME/.config/clerk/album.cache) tracks_temp=$(cat $HOME/.config/clerk/tracks.cache) last_temp=$(cat $HOME/.config/clerk/last.cache) updateCache() { clerk_updater & } dplayPrompt () { menu=("Q Exit Clerk" "---" "1 Play random Album" "2 Play random Songs" "---" "3 Current Artist" "4 Current Queue" "5 Browse Library" "6 Manage Playlists" "---" "7 Options" "8 Ratings" "9 Lookup" "0 Playback") prompt() { printf "%s\n" "$@" | dmenu_t -p "MPD Menu > " } case "$(prompt "${menu[@]}")" in 1*) playRandomAlbum ;; 2*) playRandomTracks ;; 3*) currentPrompt ;; 4*) dplayQueue ;; 5*) browseLibPrompt ;; 6*) managePlaylists ;; 7*) dplayOptionsPrompt ;; 8*) ratingPrompt ;; 9*) infoPrompt ;; 0*) playbackPrompt ;; Q) exit ;; *) exit esac } playbackPrompt () { menu=("0 Return to Main Menu" "---" "1 Toggle Playback" "2 Next Song" "3 Prev Song" "4 Stop" "5 Clear Playlist") prompt() { printf "%s\n" "$@" | dmenu_t -p "Playback > " } case "$(prompt "${menu[@]}")" in 1*) mpc toggle && playbackPrompt;; 2*) mpc next && playbackPrompt ;; 3*) mpc prev && playbackPrompt ;; 4*) mpc stop && playbackPrompt ;; 5*) mpc clear && dplayPrompt ;; 0*) dplayPrompt ;; *) exit ;; esac } lastFM () { # Some Variables to clean up the code if [[ $ssh_lastfm == 1 ]]; then mpds_check="$(ssh $ssh_host -q -t 'bash -c "pgrep mpdscribble"')" if [ -n "$mpds_check" ]; then ssh $ssh_host -q -t 'bash -c "killall mpdscribble"' && notify-send "MPD" "LastFM Scrobbling Disabled" else ssh $ssh_host -q 'mpdscribble' && notify-send "MPD" "LastFM Scrobbling Enabled" fi else if pgrep mpdscribble then killall mpdscribble && notify-send "MPD" "LastFM Scrobbling Disabled" else mpdscribble && notify-send "MPD" "LastFM Scrobbling Enabled" fi fi } lastFMCheck () { # Some Variables to clean up the code if ((ssh_lastfm)); then mpds_check="$(ssh $ssh_host -q -t 'bash -c "pgrep mpdscribble"')" if [ -n "$mpds_check" ]; then echo "lastfm: off" else echo "lastfm: on" fi else if pgrep mpdscribble then echo "lastfm: on" else echo "lastfm: off" fi fi } browseFilesystem () { usefile() { realpath="$(realpath "$selection")" MPD_HOST="$mpd_socket" mpc add ""file://"$realpath""" } comboadd() { for i in **/*.{mp3,ogg,flac,wma,mp4,aac,mpc,m4a,wv}; do realpath="$(realpath "$i")" MPD_HOST="$mpd_socket" mpc add ""file://"$realpath""" done } chose() { if [[ -d "$selection" ]]; then cd "$selection" dirs="$(find . -maxdepth 1 \( ! -regex '.*/\..*' \) -type d | cut -c 3- | sort -u)" files="$(find -maxdepth 1 -type f -regex ".*/.*\.\(flac\|mp3\|ogg\|m4a\|wav\|wv\|mpc\|wma\|aac\)" | cut -c 3- | sort -u)" selection="$(echo -e "0 Return to Library Menu\n---\n1 Add all music files\n---\n..$(echo "$dirs")\n$(echo "$files")" | dmenu_t -p "$(realpath .) > ")" chose elif [[ "$selection" == "1 Add all music files" ]]; then comboadd elif [[ "$selection" == "0 Return to Library Menu" ]]; then browseLibPrompt elif [[ "$selection" == "" ]]; then exit else usefile fi } cd ~ dirs="$(find . -maxdepth 1 \( ! -regex '.*/\..*' \) -type d | cut -c 3- | sort -u)" files="$(find -maxdepth 1 -type f -regex ".*/.*\.\(flac\|mp3\|ogg\|m4a\|wav\|wv\|mpc\|wma\|aac\)" | cut -c 3- | sort -u)" selection="$(echo -e "0 Return to Library Menu\n---\n1 Add all music files\n---\n..$(echo "$dirs")\n$(echo "$files")" | dmenu_t -p "$(realpath .) > ")" chose } currentPrompt () { menu=("0 Return to Main Menu" "---" "1 Albums" "2 Tracks") prompt() { printf "%s\n" "$@" | dmenu_t -p "$(mpc current --format '%artist%') > " } case "$(prompt "${menu[@]}")" in 1*) currentAlbums ;; 2*) currentTracks ;; 0*) dplayPrompt ;; *) exit esac } ratingPrompt () { menu=("Q Return to Main Menu" "---" "1 Rate current Album" "2 Load Rated Albums" "3 Load Random Rated Album" "---" "4 Rate current Track" "5 Load Rated Tracks" "6 Load Random Rated Tracks" "---" "0 Love current Song on LastFM") prompt() { printf "%s\n" "$@" | dmenu_t -p "Ratings > " } case "$(prompt "${menu[@]}")" in 1*) rateAlbum ;; 2*) loadRatedAlbums ;; 3*) loadRandomRating ;; 4*) rateTrack ;; 5*) loadRatedTracks ;; 6*) loadRandomRatedTracks ;; 0*) lastfm-mpd-cli love > /dev/null && notify-send "MPD" "Loved $(mpc current -f '%title%') on LastFM" ;; Q*) dplayPrompt ;; *) exit esac } killDB () { rm -f $HOME/.config/clerk/ratings.db } infoPrompt () { menu=("0 Return to Main Menu" "---" "1 Artist Info" "2 Album Info" "3 Current Track Lyrics" "4 Current Track Tags") prompt() { printf "%s\n" "$@" | dmenu_t -p "MPD Menu > " } case "$(prompt "${menu[@]}")" in # 1*) surfraw yubnub allmusic $(mpc current -f %artist%) ;; 1*) artistinfo ;; 2*) surfraw yubnub allmusic $(mpc current -f %album%) ;; # 3*) surfraw yubnub google $(mpc current -f %title%) $(mpc current -f %artist%) lyrics ;; 3*) lyrics ;; 4*) currentTag ;; 0*) dplayPrompt ;; *) exit esac } lyrics () { rm -f $HOME/.config/clerk/current.txt glyrc lyrics -a "$(mpc current --format '%artist%')" -t "$(mpc current --format '%title%')" -w "$HOME/.config/clerk/current.txt" fold "$HOME/.config/clerk/current.txt" -w 50 -s | dmenu_t -p "$(mpc current --format '%artist% - %title%') Lyrics >" } artistinfo () { rm -f $HOME/.config/clerk/artist.txt glyrc artistbio -a "$(mpc current --format '%artist%')" -w "$HOME/.config/clerk/artist.txt" fold "$HOME/.config/clerk/artist.txt" -s -w 50 | dmenu_t -p "$(mpc current --format '%artist% - %title%') Lyrics >" } currentTag () { declare -i seen=0 while read line do seen=1 if [[ "$line" == "0 Return to Main Menu" ]]; then dplayPrompt elif [[ "$line" == "Show all Tags" ]]; then readComments elif [[ "$line" == "" ]]; then return fi done < <(echo -e "0 Return to Main Menu\n---\nShow all Tags\n---\n$(mpc current --format "Artist: %artist%\nAlbum: %album%\nDate: %date%\nTrack: %track%\nTitle: %title%")" | dmenu_t -p 'Current Song > ') if [[ $seen = 0 ]] then exit fi } readComments () { declare -i seen=0 while read line do seen=1 if [[ "$line" == "0 Return to Main Menu" ]]; then dplayPrompt elif [[ "$line" == "Show Tags" ]]; then currentTag elif [[ "$line" == "" ]]; then return fi done < <(echo -e "0 Return to Main Menu\n---\nShow Tags\n---\n$(mpc current --format '%file%' | mppc readcomments)" | dmenu_t -p 'Current Song > ') if [[ $seen = 0 ]] then exit fi } dplayOptionsPrompt () { export status="$(mpc status)" single=$(echo "$status" | tail -1 | awk -F ':' '{ print $5 }' | cut -d ' ' -f 2) random=$(echo "$status" | tail -1 | awk -F ':' '{ print $4 }' | cut -d ' ' -f 2) consume=$(echo "$status" | tail -1 | awk -F ':' '{ print $6 }' | cut -d ' ' -f 2) repeat=$(echo "$status" | tail -1 | awk -F ':' '{ print $3 }' | cut -d ' ' -f 2) if [[ -a /tmp/mpd-sima.pid ]]; then export sima=on else export sima=off fi if [[ "$ssh_lastfm" == "1" ]]; then mpds_check="$(ssh $ssh_host -q -t 'bash -c "pgrep mpdscribble"')" if [ -n "$mpds_check" ]; then export scrobble=on else export scrobble=off fi else if pgrep mpdscribble then export scrobble=on else export scrobble=off fi fi export rgain="$(mpc replaygain | cut -d ' ' -f 2)" replayGain () { if [[ $(mpc replaygain | cut -d ' ' -f 2) == album ]]; then mpc replaygain track > /dev/null && export rgain="track" elif [[ $(mpc replaygain | cut -d ' ' -f 2) == track ]]; then mpc replaygain off > /dev/null && export rgain="off" elif [[ $(mpc replaygain | cut -d ' ' -f 2) == off ]]; then mpc replaygain album > /dev/null && export rgain="album" fi } menu=("Q Return to Main Menu" "---" "1 Random: $(echo $random)" "2 Repeat: $(echo $repeat)" "3 Single Mode: $(echo $single)" "4 Consume Mode: $(echo $consume)" "5 Replaygain: $(echo $rgain)" "6 Scrobbling: $(echo $scrobble)" "7 Similar Artists Mode: $(echo $sima)" "---" "8 Set Crossfade $(mpc crossfade | cut -d ':' -f2)" "9 Manage Outputs" "0 Number of Random Songs: $(echo $value)") prompt() { printf "%s\n" "$@" | dmenu_t -p "MPD Options > " } case "$(prompt "${menu[@]}")" in 1*) mpc random && dplayOptionsPrompt ;; 2*) mpc repeat && dplayOptionsPrompt ;; 3*) mpc single && dplayOptionsPrompt ;; 4*) mpc consume && dplayOptionsPrompt ;; 5*) replayGain && dplayOptionsPrompt ;; 6*) lastFM && dplayOptionsPrompt ;; 7*) mpdSima && dplayOptionsPrompt ;; 8*) crossfadePrompt ;; 9*) outputPrompt ;; 0*) optionRandomPrompt ;; Q*) dplayPrompt ;; *) exit esac } mpdSima () { if [[ -a /tmp/mpd-sima.pid ]]; then kill $(cat /tmp/mpd-sima.pid) sleep 1 else mpd-sima -d -p /tmp/mpd-sima.pid sleep 1 fi } optionRandomPrompt() { number="$(echo " " | dmenu_t -p 'Set No. of Songs for random Songs > ')" sed -i "s/value=.*/value="$number"/" $HOME/.config/clerk/config export value="$number" dplayOptionsPrompt } crossfadePrompt () { menu=("0: Return to Main Menu" "---" "0" "1" "2" "3" "4" "5") prompt() { printf "%s\n" "$@" | dmenu_t -p "Crossfade > " } case "$(prompt "${menu[@]}")" in 0) mpc crossfade 0 && dplayOptionsPrompt ;; 1) mpc crossfade 1 && dplayOptionsPrompt ;; 2) mpc crossfade 2 && dplayOptionsPrompt ;; 3) mpc crossfade 3 && dplayOptionsPrompt ;; 4) mpc crossfade 4 && dplayOptionsPrompt ;; 5) mpc crossfade 5 && dplayOptionsPrompt ;; 0:*) dplayOptionsPrompt ;; *) exit esac } managePlaylists () { menu=("0 Return to Main Menu" "---" "1 Load Playlist" "2 Save Playlist" "3 Load RSS Feed" "4 Crop Playlist" "---" "5 Suspend Playlist" "6 Resume Playlist" "---" "7 Clear Playlist") prompt() { printf "%s\n" "$@" | dmenu_t -p "Crossfade > " } case "$(prompt "${menu[@]}")" in 0*) dplayPrompt ;; 1*) dplayQueueLoad ;; 2*) dplayQueueSave ;; 3*) loadRSS ;; 4*) mpc crop && dplayQueue ;; 5*) suspendPlaylist ;; 6*) resumePlaylist ;; 7*) mpc clear ;; *) exit esac } loadRSS () { mpc clear podcast=$(echo -e "0 Return to Playlist Menu\n---\n$(cat $HOME/.config/clerk/podcasts | cut -d '\' -f1)" | dmenu_t -p "Choose Podcast > ") if [[ $podcast == "0 Return to Playlist Menu" ]]; then managePlaylists else mpc load $(grep "$podcast" $HOME/.config/clerk/podcasts | cut -d '\' -f2) episode=$(mpc playlist --format "%position%$seperator%artist%$seperator%title%" | dmenu_t -p "Choose Episode > ") POS=$(echo "$episode" | awk -F "$seperator" '{ print $1 }') mpc play "$POS" fi } suspendPlaylist () { playing=$(! mpc status | grep 'playing\|paused') time=$(mpc status | sed '2!d' | sed 's;/.:.*;;;s;.* ;;') position=$(mpc current --format '%position%') if [[ -z "$playing" ]]; then notify-send "clerk" "mpd is not playing, no state to suspend" else mpc rm suspended mpc save suspended rm -f $HOME/.config/clerk/suspend echo "pos="$position"" >> $HOME/.config/clerk/suspend echo "time="$time"" >> $HOME/.config/clerk/suspend if [[ "$stop_after_suspend" == yes ]]; then mpc stop else echo " " fi notify-send "Clerk" "Playlist suspended" managePlaylists fi } resumePlaylist () { http=$(! mpc current --format %file% | grep 'http://') source $HOME/.config/clerk/suspend mpc clear mpc load suspended mpc play $pos mpc toggle sleep 2 mpc seek "$time" mpc toggle notify-send "Clerk" "Resumed last-suspended Playlist" managePlaylists } dplayQueue () { displayRofi () { if [[ $backend == "rofi" ]]; then dmenu_t -dmenu -p "Queue > " -l $(calc $(mpc current -f %position%) + 3) elif [[ $backend == "dmenu" ]]; then dmenu_t -p "Queue > " fi } while read TRACKDISPLAY do TITLE=$(echo "$TRACKDISPLAY" | awk -F "$seperator" '{ print $3 }') ARTIST=$(echo "$TRACKDISPLAY" | awk -F "$seperator" '{ print $2 }') POS=$(echo "$TRACKDISPLAY" | awk -F "$seperator" '{ print $1 }') if [[ "$TRACKDISPLAY" == "0 Return to Main Menu" ]]; then dplayPrompt elif [[ "$TRACKDISPLAY" == "Mode: Play" ]]; then dplayQueueDelete else mpc play $POS; fi done < <(export seperator=$seperator; echo -e "0 Return to Main Menu\n---\nMode: Play\n---\n$(mpc playlist --format "%position%$seperator%artist%$seperator%title%")" | displayRofi) exit } dplayQueueDelete () { while read TRACKDISPLAY do TITLE=$(echo "$TRACKDISPLAY" | awk -F "$seperator" '{ print $3 }') ARTIST=$(echo "$TRACKDISPLAY" | awk -F "$seperator" '{ print $2 }') POS=$(echo "$TRACKDISPLAY" | awk -F "$seperator" '{ print $1 }') if [[ "$TRACKDISPLAY" == "0 Return to Main Menu" ]]; then dplayPrompt elif [[ "$TRACKDISPLAY" == "Mode: Delete" ]]; then dplayQueue elif [[ "$TRACKDISPLAY" == "Manage Playlists" ]]; then managePlaylists else mpc del $POS; dplayQueueDelete fi done < <(export seperator=$seperator; echo -e "0 Return to Main Menu\n---\nMode: Delete\n---\nManage Playlists\n---\n$(mpc playlist --format "%position%$seperator%artist%$seperator%title%")" | dmenu_t -p "Queue > ") exit } dplayQueueLoad () { playlist=$(echo -e "0 Return to Playlist Menu\n---\n$(mpc lsplaylists)" | dmenu_t -p "Load Playlist > ") if [[ "$playlist" == "0 Return to Playlist Menu" ]]; then dplayQueue else mpc clear mpc load "$playlist" && dplayQueue fi } dplayQueueSave () { while read playlists do if [[ "$playlists" == "0 Return to Main Menu" ]]; then dplayPrompt elif [[ "$playlists" == "Save new Playlist" ]]; then playlist=$(echo "" | dmenu_t -p "Type Name for Playlist > ") if [[ "$playlist" == "" ]]; then dplayQueueSave else mpc save "$playlist" dplayQueue fi else playlist=$(echo -e "0 Return to Playlist Menu\n---\nYes\nNo" | dmenu_t -p "Overwrite Playlist? > ") if [[ "$playlist" == "Yes" ]]; then mpc rm "$playlists" mpc save "$playlists" elif [[ "$playlist" == "No" ]]; then playlist=$(echo "" | dmenu_t -p "Type Name for Playlist > ") if [[ "$playlist" == "" ]]; then dplayQueue else mpc save "$playlist" dplayQueue fi fi fi done < <(echo -e "0 Return to Main Menu\n---\nSave new Playlist\n---\n$(mpc lsplaylists)" | dmenu_t -p "Chose Playlist > ") exit } outputPrompt () { menu="$(echo -e "0 Return to Options Menu\n---\n$(mpc outputs)" | dmenu_t -p "Outputs > ")"; if [[ "$menu" == "0 Return to Options Menu" ]] then dplayOptionsPrompt; else mpc toggleoutput $(echo "$menu" | awk '{print $2}'); notify-send "MPD" "$(echo "$menu" | sed -e 's/enabled$/disabled/;ta;s/disabled$/enabled/;:a;')"; fi } currentAlbums () { ARTIST=$(mpc current -f %artist%) while read ALBUM do ALBUM_FINAL=$(echo "$ALBUM" | awk -F "$seperator" '{print $2}') DATE=$(echo "$ALBUM" | awk -F "$seperator" '{print $1}') if [[ "$ALBUM" == "0 Return to current Artist Menu" ]]; then currentPrompt; else if [[ "$ALBUM" == "Adding Mode: Add" ]]; then currentAlbumsInsert else mpc search "$mpd_artist" "$ARTIST" album "$ALBUM_FINAL" date "$DATE" | mpc add fi fi done < <(echo -e "0 Return to current Artist Menu\n---\nAdding Mode: Add\n---\n$(mppc search artist "$ARTIST" --format "{date}$seperator{album}" | sort | uniq)" | dmenu_t -p "Albums by $(mpc current --format '%artist%') > ") } currentAlbumsInsert () { ARTIST=$(mpc current -f %artist%) while read ALBUM do ALBUM_FINAL=$(echo "$ALBUM" | awk -F "$seperator" '{print $2}') DATE=$(echo "$ALBUM" | awk -F "$seperator" '{print $1}') if [[ "$ALBUM" == "0 Return to current Artist Menu" ]]; then currentPrompt; else if [[ "$ALBUM" == "Adding Mode: Insert" ]]; then currentAlbumsReplace else mpc search "$mpd_artist" "$ARTIST" album "$ALBUM_FINAL" date "$DATE" | mpc insert fi fi done < <(echo -e "0 Return to current Artist Menu\n---\nAdding Mode: Insert\n---\n$(mppc search artist "$ARTIST" --format "{date}$seperator{album}" | sort | uniq)" | dmenu_t -p "Albums by $(mpc current --format '%artist%') > ") } currentAlbumsReplace () { ARTIST=$(mpc current -f %artist%) while read ALBUM do ALBUM_FINAL=$(echo "$ALBUM" | awk -F "$seperator" '{print $2}') DATE=$(echo "$ALBUM" | awk -F "$seperator" '{print $1}') if [[ "$ALBUM" == "0 Return to current Artist Menu" ]]; then currentPrompt; else if [[ "$ALBUM" == "Adding Mode: Replace" ]]; then currentAlbums else mpc clear && mpc search "$mpd_artist" "$ARTIST" album "$ALBUM_FINAL" date "$DATE" | mpc add && mpc play fi fi done < <(echo -e "0 Return to current Artist Menu\n---\nAdding Mode: Replace\n---\n$(mppc search artist "$ARTIST" --format "{date}$seperator{album}" | sort | uniq)" | dmenu_t -p "Albums by $(mpc current --format '%artist%') > ") } currentTracks () { while read TRACK do TITLE=$(echo "$TRACK" | awk -F "$seperator" '{print $3}') ALBUM=$(echo "$TRACK" | awk -F "$seperator" '{print $1}') TRACKNUMBER=$(echo "$TRACK" | awk -F "$seperator" '{print $2}') if [ "$TRACK" = "0 Return to current Artist Menu" ]; then currentPrompt; else if [[ "$TRACK" == "Adding Mode: Add" ]]; then currentTracksInsert else mpc findadd album "$ALBUM" title "$TITLE" track "$TRACKNUMBER" fi fi done < <(echo -e "0 Return to current Artist Menu\n---\nAdding Mode: Add\n---\n$(mppc search artist "$(mpc current -f %artist%)" --format "{album}$seperator{track}$seperator{title}")" | dmenu_t -p "Tracks by $(mpc current --format '%artist%') > ") } currentTracksInsert () { export status="$(mpc status)" random=$(echo "$status" | tail -1 | awk -F ':' '{ print $4 }' | cut -d ' ' -f 2) while read TRACK do TITLE=$(echo "$TRACK" | awk -F "$seperator" '{print $3}') ALBUM=$(echo "$TRACK" | awk -F "$seperator" '{print $1}') TRACKNUMBER=$(echo "$TRACK" | awk -F "$seperator" '{print $2}') if [ "$TRACK" = "0 Return to current Artist Menu" ]; then currentPrompt; else if [[ "$TRACK" == "Adding Mode: Insert" ]]; then currentTracks else if [[ "$random" == "off" ]]; then mpc find album "$ALBUM" title "$TITLE" track "$TRACKNUMBER" | mpc insert else mpc find album "$ALBUM" title "$TITLE" track "$TRACKNUMBER" | mpc add echo "$(( $(mpc playlist|wc -l) - 1 ))" | mppc prio fi fi fi done < <(echo -e "0 Return to current Artist Menu\n---\nAdding Mode: Insert\n---\n$(mppc search artist "$(mpc current -f %artist%)" --format "{album}$seperator{track}$seperator{title}")" | dmenu_t -p "Tracks by $(mpc current --format '%artist%') > ") } escapeSql() { echo ${1//\'/\'\'} } rateAlbum () { rating="$(seq 10 | dmenu_t -p "Select Album Rating: > ")" if [[ $rating == "" ]]; then exit else artist="$(mpc current -f '%artist%')" album="$(mpc current -f '%album%')" date="$(mpc current -f '%date%')" mpc find artist "$artist" album "$album" date "$date" track "01" | while read line; do mpc sticker "$(echo ${line})" set albumrating ${rating} done mpc find artist "$artist" album "$album" date "$date" track "1" | while read line; do mpc sticker "$(echo ${line})" set albumrating ${rating} done mpc find artist "$artist" album "$album" date "$date" track "1" disc "2" | while read line; do mpc sticker "$(echo ${line})" delete albumrating done mpc find artist "$artist" album "$album" date "$date" track "1" disc "02" | while read line; do mpc sticker "$(echo ${line})" delete albumrating done if [[ "$music_dir_access" == "yes" ]]; then cd "$music_path" cd "$(dirname "$(mpc current -f %file%)")" if [[ "$(pwd)" == */"$cd_divider"* ]]; then cd .. fi rm -f "$(mpc current -f "%$mpd_artist%--%date%--%album%").albumrating" echo "artist=${artist}" >> "$(mpc current -f "%$mpd_artist%--%date%--%album%").albumrating" echo "album=${album}" >> "$(mpc current -f "%$mpd_artist%--%date%--%album%").albumrating" echo "date=${date}" >> "$(mpc current -f "%$mpd_artist%--%date%--%album%").albumrating" echo "albumrating=$rating/10" >> "$(mpc current -f "%$mpd_artist%--%date%--%album%").albumrating" fi notify-send "clerk" "rated $(echo ${artist} - ${album}) with $(echo ${rating})" fi } rateTrack () { rating="$(seq 10 | dmenu_t -p "Select Track Rating: > ")" if [[ $rating == "" ]]; then exit else mpc sticker "$(mpc current -f '%file%')" set rating "$rating" if [[ "$music_dir_access" == "yes" ]]; then cd "$music_path" cd "$(dirname "$(mpc current -f %file%)")" if [[ "$(pwd)" == */"$cd_divider"* ]]; then cd .. fi touch track.ratings sed -i "/$(mpc current -f '%title%')/d" track.ratings echo "${rating}\\$(mpc current -f "%artist%\%track%\%title%\%date%\%album%")" >> track.ratings fi notify-send "clerk" "rated $(mpc current) with $(echo ${rating})" fi } instantRateTrack () { mpc sticker "$(mpc current -f '%file%')" set rating "$rating" if [[ "$music_dir_access" == "yes" ]]; then cd "$music_path" cd "$(dirname "$(mpc current -f %file%)")" if [[ "$(pwd)" == */"$cd_divider"* ]]; then cd .. fi touch track.ratings sed -i "/$(mpc current -f '%title%')/d" track.ratings echo "$rating\\$(mpc current -f "%artist%\%track%\%title%\%date%\%album%")" >> track.ratings fi } loadRatedAlbums () { rating="$(seq 10 | dmenu_t -p "Minimum Rating > ")" if [[ $rating == "" ]]; then exit else albums="$(while read -a line; do dirname "${line[*]}"; done <<< "$(mpc sticker "" find albumrating | grep -E "albumrating=$rating")" | sed 's/\/\CD.*//g' | sort | uniq | dmenu_t -p "Choose Album")" if [[ $albums == "" ]]; then exit else mpc clear && mpc add "$albums" && mpc play fi fi } loadRatedTracks () { rating="$(seq 10 | dmenu_t -p "Rating > ")" if [ rating = "" ]; then exit else cd $HOME/.config/clerk mpc clear songs="$(mpc sticker "" find rating | grep -E "rating=$rating" | awk -F ':' '{ print $1 }')" echo "$songs" | mpc add mpc play fi } loadRandomRatedTracks () { number="$(echo " " | dmenu_t -p "Number of Songs > " | xargs echo)" rating="$(seq 10 | dmenu_t -p "Minimum Rating > ")" if [ rating = "" ]; then exit else cd $HOME/.config/clerk mpc clear songs="$(mpc sticker "" find rating | grep -E "rating=$rating|rating=$(echo $(( $rating + 1 )))|rating=$(echo $(( $rating + 2 )))|rating=$(echo $(( $rating + 3 )))|rating=$(echo $(( $rating + 4 )))" | awk -F ':' '{ print $1 }')" echo "$songs" | shuf -n $number | mpc add mpc play rm -f /tmp/clerk_tracklist fi } loadRandomRating () { rating="$(seq 10 | dmenu_t -p "Minimum Rating > ")" if [ rating = "" ]; then exit else album="$(while read -a line; do dirname "${line[*]}"; done <<< "$(mpc sticker "" find albumrating | grep -E "albumrating=$rating|albumrating=$(echo $(( $rating+1 )))|albumrating=$(echo $(( $rating+2 )))|albumrating=$(echo $(( $rating+3 )))|albumrating=$(echo $(( $rating+4 )))|albumrating=$(echo $(( $rating+5 )))|albumrating=$(echo $(( $rating+6 )))")" | sed 's/\/\CD.*//g' | shuf -n1)" mpc clear && mpc add "$album" && mpc play fi } playRandomAlbum () { mpc clear artist="$(mpc list "$mpd_artist" | shuf -n 1)" album="$(mpc list album "$mpd_artist" "$artist" | shuf -n 1)" mpc find album "$album" "$mpd_artist" "$artist" | mpc add && mpc play } playRandomTracks () { mpc clear artist="$(mpc list "$random_artist" | shuf -n 1)" album="$(mpc list album "$random_artist" "$artist" | shuf -n 1)" title="$(mpc list title album "$album" "$random_artist" "$artist" | shuf -n 1)" mpc find album "$album" "$random_artist" "$artist" title "$title" | mpc add mpc play n=0; while (( n++ < $value -1 )); do artist="$(mpc list "$random_artist" | shuf -n 1)" album="$(mpc list album "$random_artist" "$artist" | shuf -n 1)" title="$(mpc list title album "$album" "$random_artist" "$artist" | shuf -n 1)" mpc find album "$album" "$random_artist" "$artist" title "$title" | mpc add done mpc play } addLastMod() { declare -i seen=0 while read ALBUM do seen=1 if [[ "$ALBUM" == "0 Return to Main Menu" ]] then dplayPrompt else if [[ "$ALBUM" == "Adding Mode: Add" ]] then insertLastMod else artist=$(echo "$ALBUM" | awk -F "$seperator" '{print $2}') date=$(echo "$ALBUM" | awk -F "$seperator" '{print $1}') album=$(echo "$ALBUM" | awk -F "$seperator" '{print $3}') mppc searchadd date "$date" album "$album" $mpd_artist "$artist" fi fi done < <(echo -e "0 Return to Main Menu\n---\nAdding Mode: Add\n---\n$(echo "$last_temp")" | dmenu_t -dmenu -p "Choose recent album > ") exit } insertLastMod() { declare -i seen=0 while read ALBUM do seen=1 if [[ "$ALBUM" == "0 Return to Main Menu" ]] then dplayPrompt else if [[ "$ALBUM" == "Adding Mode: Insert" ]] then replaceLastMod else export MPD_HOST=127.0.0.1 artist=$(echo "$ALBUM" | awk -F "$seperator" '{print $2}') date=$(echo "$ALBUM" | awk -F "$seperator" '{print $1}') album=$(echo "$ALBUM" | awk -F "$seperator" '{print $3}') mppc search date "$date" album "$album" $mpd_artist "$artist" | mpc insert fi fi done < <(echo -e "0 Return to Main Menu\n---\nAdding Mode: Insert\n---\n$(echo "$last_temp")" | dmenu_t -dmenu -p "Choose Album > ") exit } replaceLastMod() { declare -i seen=0 while read ALBUM do seen=1 if [[ "$ALBUM" == "0 Return to Main Menu" ]] then dplayPrompt else if [[ "$ALBUM" == "Adding Mode: Replace" ]] then addLastMod else artist=$(echo "$ALBUM" | awk -F "$seperator" '{print $2}') date=$(echo "$ALBUM" | awk -F "$seperator" '{print $1}') album=$(echo "$ALBUM" | awk -F "$seperator" '{print $3}') mpc clear && mppc searchadd date "$date" album "$album" $mpd_artist "$artist" && mpc play fi fi done < <(echo -e "0 Return to Main Menu\n---\nAdding Mode: Replace\n---\n$(echo "$last_temp")" | dmenu_t -dmenu -p "Choose Album > ") exit } AddAlbumTags() { declare -i seen=0 while read TRACK do seen=1 if [[ "$TRACK" == "0 Return to Main Menu" ]] then dplayPrompt else if [[ "$TRACK" == "Adding Mode: Add" ]] then InsertAlbumTags else artist=$(echo "$TRACK" | awk -F "$seperator" '{print $1}') date=$(echo "$TRACK" | awk -F "$seperator" '{print $3}') album=$(echo "$TRACK" | awk -F "$seperator" '{print $2}') mppc searchadd date "$date" album "$album" $mpd_artist "$artist" fi fi done < <(echo -e "0 Return to Main Menu\n---\nAdding Mode: Add\n---\n$(echo "$album_temp")" | dmenu_t -dmenu -p "Choose Album > ") if [[ $seen = 0 ]] then exit fi } InsertAlbumTags() { while read TRACK do if [[ "$TRACK" = "0 Return to Main Menu" ]] then dplayPrompt else if [[ "$TRACK" == "Adding Mode: Insert" ]] then ReplaceAlbumTags else artist=$(echo "$TRACK" | awk -F "$seperator" '{print $1}') date=$(echo "$TRACK" | awk -F "$seperator" '{print $3}') album=$(echo "$TRACK" | awk -F "$seperator" '{print $2}') mpc search date "$date" album "$album" $mpd_artist "$artist" | mpc insert fi fi done < <(echo -e "0 Return to Main Menu\n---\nAdding Mode: Insert\n---\n$(echo "$album_temp")" | dmenu_t -dmenu -p "Choose Album > ") } ReplaceAlbumTags() { declare -i seen=0 while read TRACK do seen=1 if [[ "$TRACK" = "0 Return to Main Menu" ]] then dplayPrompt else if [[ "$TRACK" == "Adding Mode: Replace" ]] then AddAlbumTags else artist=$(echo "$TRACK" | awk -F "$seperator" '{print $1}') date=$(echo "$TRACK" | awk -F "$seperator" '{print $3}') album=$(echo "$TRACK" | awk -F "$seperator" '{print $2}') mpc clear && mpc findadd date "$date" album "$album" $mpd_artist "$artist" && mpc play fi fi done < <(echo -e "0 Return to Main Menu\n---\nAdding Mode: Replace\n---\n$(echo "$album_temp")" | dmenu_t -dmenu -p "Choose Album > ") if [[ $seen = 0 ]] then exit fi } AddTrackTags() { while read TRACK do if [[ "$TRACK" == "0 Return to Main Menu" ]] then dplayPrompt else if [[ "$TRACK" == "Adding Mode: Add" ]] then InsertTrackTags else artist=$(echo "$TRACK" | awk -F "$seperator" '{print $1}') album=$(echo "$TRACK" | awk -F "$seperator" '{print $4}') track=$(echo "$TRACK" | awk -F "$seperator" '{print $2}') title=$(echo "$TRACK" | awk -F "$seperator" '{print $3}') mpc findadd artist "$artist" album "$album" title "$title" if [[ "$add_auto_play" ]]; then mpc play $(mpc playlist | wc -l) fi fi fi done < <(echo -e "0 Return to Main Menu\n---\nAdding Mode: Add\n---\n$(echo "$tracks_temp")"| dmenu_t -dmenu -p "Choose Track > ") } InsertTrackTags() { random="$(mpc status | tail -1 | awk -F ':' '{ print $4 }' | cut -d ' ' -f 2)" while read TRACK do echo $random if [[ "$TRACK" == "0 Return to Main Menu" ]] then dplayPrompt else if [[ "$TRACK" == "Adding Mode: Insert" ]] then ReplaceTrackTags else if [[ "$random" == "off" ]]; then artist=$(echo "$TRACK" | awk -F "$seperator" '{print $1}') album=$(echo "$TRACK" | awk -F "$seperator" '{print $4}') track=$(echo "$TRACK" | awk -F "$seperator" '{print $2}') title=$(echo "$TRACK" | awk -F "$seperator" '{print $3}') mpc find artist "$artist" album "$album" title "$title" | mpc insert else artist=$(echo "$TRACK" | awk -F "$seperator" '{print $1}') album=$(echo "$TRACK" | awk -F "$seperator" '{print $4}') track=$(echo "$TRACK" | awk -F "$seperator" '{print $2}') title=$(echo "$TRACK" | awk -F "$seperator" '{print $3}') mpc findadd artist "$artist" album "$album" title "$title" echo $(( $(mpc playlist|wc -l) - 1 )) | mppc prio fi fi fi done < <(echo -e "0 Return to Main Menu\n---\nAdding Mode: Insert\n---\n$(echo "$tracks_temp")"| dmenu_t -dmenu -p "Choose Track > ") } ReplaceTrackTags() { while read TRACK do if [[ "$TRACK" == "0 Return to Main Menu" ]] then dplayPrompt else if [[ "$TRACK" == "Adding Mode: Add" ]] then AddTrackTags else artist=$(echo "$TRACK" | awk -F "$seperator" '{print $1}') album=$(echo "$TRACK" | awk -F "$seperator" '{print $4}') track=$(echo "$TRACK" | awk -F "$seperator" '{print $2}') title=$(echo "$TRACK" | awk -F "$seperator" '{print $3}') mpc clear && mpc findadd artist "$artist" album "$album" title "$title" mpc play fi fi done < <(echo -e "0 Return to Main Menu\n---\nAdding Mode: Add\n---\n$(echo "$tracks_temp")"| dmenu_t -dmenu -p "Choose Track > ") } AddTrackFlat() { declare -i seen=0 while read TRACK do seen=0 if [[ "$TRACK" == "0 Return to Main Menu" ]] then dplayPrompt else if [[ "$TRACK" == "Adding Mode: Add Flat" ]] then InsertTrackFlat else mpc add "$TRACK" fi fi done < <(echo -e "0 Return to Main Menu\n---\nAdding Mode: Add Flat\n---\n$(mpc listall)" | dmenu_t -dmenu -p "Choose Track > ") if [[ $seen = 0 ]]; then exit fi } InsertTrackFlat() { declare -i seen=0 while read TRACK do seen=0 if [[ "$TRACK" == "0 Return to Main Menu" ]] then dplayPrompt else if [[ "$TRACK" == "Adding Mode: Insert Flat" ]] then ReplaceTrackTags else if [[ "$random" == "off" ]]; then mpc insert "$TRACK" else mpc add "$TRACK" echo "$(( $(mpc playlist|wc -l) - 1 ))" | ./mppc prio fi fi fi done < <(echo -e "0 Return to Main Menu\n---\nAdding Mode: Insert Flat\n---\n$(mpc listall)" | dmenu_t -dmenu -p "Choose Track > ") if [[ $seen = 0 ]]; then exit fi } ReplaceTrackFlat() { declare -i seen=0 while read TRACK do seen=0 if [[ "$TRACK" == "0 Return to Main Menu" ]] then dplayPrompt else if [[ "$TRACK" == "Adding Mode: Add Flat" ]] then AddTrackFlat else mpc clear && mpc add "$TRACK" && mpc play fi fi done < <(echo -e "0 Return to Main Menu\n---\nAdding Mode: Add Flat\n---\n$(mpc listall)" | dmenu_t -dmenu -p "Choose Track > ") if [[ $seen = 0 ]]; then exit fi } browseDate() { date=$(echo -e "0 Return to Main Menu\n---\n$(mpc list date | tac)" | dmenu_t -dmenu -p "Choose Date > ") if [[ "$date" == "0 Return to Main Menu" ]] then dplayPrompt else browseDateAdd fi } browseDateAdd() { declare -i seen=0 while read select do seen=1 if [[ "$select" == "0 Return to Date Menu" ]] then browseDate else artist=$(echo "$select" | awk -F "$seperator" '{print $1}') album=$(echo "$select" | awk -F "$seperator" '{print $2}') if [[ "$select" == "Add All" ]]; then mpc findadd date "$date" elif [[ "$select" == "Replace All" ]]; then mpc clear && mpc findadd date "$date" && mpc play elif [[ "$select" == "Adding Mode: Add" ]]; then browseDateInsert else mpc findadd artist "$artist" album "$album" fi fi done < <(echo -e "0 Return to Date Menu\n---\nAdding Mode: Add\n---\nAdd All\nReplace All\n---\n$(mppc find date "$date" --format "{$mpd_artist}$seperator{album}" | uniq)" | dmenu_t -dmenu -p "Select Album > ") if [[ $seen = 0 ]] then exit fi } browseDateInsert() { declare -i seen=0 while read select do seen=1 if [[ "$select" == "0 Return to Date Menu" ]] then browseDate else artist=$(echo "$select" | awk -F "$seperator" '{print $1}') album=$(echo "$select" | awk -F "$seperator" '{print $2}') if [[ "$select" == "Add All" ]]; then mpc findadd date "$date" elif [[ "$select" == "Replace All" ]]; then mpc clear && mpc findadd date "$date" && mpc play elif [[ "$select" == "Adding Mode: Insert" ]]; then browseDateReplace else mpc find artist "$artist" album "$album" | mpc insert fi fi done < <(echo -e "0 Return to Date Menu\n---\nAdding Mode: Insert\n---\nAdd All\nReplace All\n---\n$(mppc find date "$date" --format "{$mpd_artist}$seperator{album}" | uniq)" | dmenu_t -dmenu -p "Select Album > ") if [[ $seen = 0 ]] then exit fi } browseDateReplace() { while read select do if [[ "$select" == "0 Return to Date Menu" ]] then browseDate else artist=$(echo "$select" | awk -F "$seperator" '{print $1}') album=$(echo "$select" | awk -F "$seperator" '{print $2}') if [[ "$select" == "Add All" ]]; then mpc findadd date "$date" elif [[ "$select" == "Replace All" ]]; then mpc clear && mpc findadd date "$date" && mpc play elif [[ "$select" == "Adding Mode: Replace" ]]; then browseDateAdd else mpc clear && mpc findadd artist "$artist" album "$album" && mpc play fi fi done < <(echo -e "0 Return to Date Menu\n---\nAdding Mode: Replace\n---\nAdd All\nReplace All\n---\n$(mppc find date "$date" --format "{$mpd_artist}$seperator{album}" | uniq)" | dmenu_t -dmenu -p "Select Album > ") } browseLibPrompt() { menu=("0 Return to Main Menu" "---" "1 Browse by Artist" "2 Browse by Date" "3 Browse by Genre" "4 Browse by Folders" "5 Browse latest additions" "6 Browse local Filesystem" "---" "7 Choose Albums" "8 Choose Track" "---" "9 Update Album/Track Cache") prompt() { printf "%s\n" "$@" | dmenu_t -p "Library Menu > " } case "$(prompt "${menu[@]}")" in 1*) browseArtist ;; 2*) browseDate ;; 3*) browseGenre ;; 4*) browseFolders ;; 6*) browseFilesystem ;; 7*) AddAlbumTags ;; 8*) AddTrackTags ;; 9*) updateCache && browseLibPrompt ;; 0*) dplayPrompt ;; 5*) addLastMod ;; *) exit esac } browseFolders () { folder=$(echo -e "0 Return to Browse Menu\n---\nAdd current\nInsert current\nReplace current\n---\n$(mpc ls "")" | dmenu_t -p "Choose Folder > ") if [[ "$folder" == "" ]]; then exit elif [[ "$folder" == "0 Return to Browse Menu" ]]; then browseLibPrompt elif [[ "$folder" == "Add current" ]]; then mpc add "$current" exit elif [[ "$folder" == "Insert current" ]]; then mpc insert "$current" exit elif [[ "$folder" == "Replace current" ]]; then mpc clear && mpc add "$current" && mpc play exit fi while true; do current="$folder" folder=$(echo -e "0 Return to Folders Menu\n---\nAdd current\nInsert current\nReplace current\n---\n$(mpc ls "$folder")" | dmenu_t -p "Choose folder > ") if [[ "$folder" == "Add current" ]]; then mpc add "$current" exit elif [[ "$folder" == "Insert current" ]]; then mpc insert "$current" exit elif [[ "$folder" == "Replace current" ]]; then mpc clear && mpc add "$current" && mpc play exit elif [[ "$folder" == "0 Return to Folders Menu" ]]; then browseFolders elif [[ "$folder" == "" ]]; then exit fi done } browseAlbum() { ALBUMS=$(mppc list album "$ARTIST") declare -i seen=0 while read ALBUM do seen=1 ALBUM_FINAL=$(echo "$ALBUM" | awk -F "$seperator" '{ print $2 }') DATE=$(echo "$ALBUM" | awk -F "$seperator" '{ print $1 }') if [[ "$ALBUM" == "0 Return to Artist Menu" ]] then browseArtist elif [[ "$ALBUM" == "Replace All" ]] then mpc clear && mppc findadd artist "$ARTIST" && mpc play elif [[ "$ALBUM" == "Add All" ]] then mppc findadd artist "$ARTIST" elif [[ "$ALBUM" == "Insert All" ]] then mppc find artist "$ARTIST" --format '{file}'| mpc insert else browseTrack fi done < <(echo -e "0 Return to Artist Menu\n---\nReplace All\nAdd All\nInsert All\n---\n$(mppc find artist "$ARTIST" --format "{date}$seperator{album}" | sort | uniq)" | dmenu_t -dmenu -p "Choose Album > ") if [[ $seen = 0 ]] then exit fi } browseTrack() { declare -i seen=0 while read TRACK do seen=1 TRACKFINAL=$(echo "$TRACK" | awk -F "$seperator" '{ print $2 }') if [[ "$TRACK" = "0 Return to Album Menu" ]] then browseAlbum elif [[ "$TRACK" == "Replace All" ]] then mpc clear && mppc findadd artist "$ARTIST" album "$ALBUM_FINAL" date "$DATE" && mpc play elif [[ "$TRACK" == "Add All" ]] then mppc findadd artist "$ARTIST" album "$ALBUM_FINAL" date "$DATE" elif [[ "$TRACK" == "Insert All" ]] then mppc find artist "$ARTIST" album "$ALBUM_FINAL" date "$DATE" --format '{file}' | mpc insert else if [[ $(mpc playlist) == "" ]]; then mppc findadd artist "$ARTIST" album "$ALBUM_FINAL" date "$DATE" title "$TRACKFINAL" && mpc play else mppc findadd artist "$ARTIST" album "$ALBUM_FINAL" date "$DATE" title "$TRACKFINAL" fi fi done < <(echo -e "0 Return to Album Menu\n---\nReplace All\nAdd All\nInsert All\n---\n$(mppc find artist "$ARTIST" album "$ALBUM_FINAL" --format "{track}$seperator{title}")" | dmenu_t -dmenu -p "Chose Track > ") if [[ $seen = 0 ]]; then exit fi } browseArtist() { declare -i seen=0 while read ARTIST do seen=1 export ARTIST="$ARTIST" if [[ "$ARTIST" == "0 Return to Main Menu" ]] then dplayPrompt elif [[ "$ARTIST" == "Replace All" ]] then mpc clear && mpc add / && mpc play elif [[ "$ARTIST" == "Add All" ]] then mpc add / elif [[ "$ARTIST" == "Insert All" ]] then mpc insert / else browseAlbum fi done < <(echo -e "0 Return to Main Menu\n---\nAdd All\nInsert all\nReplace all\n---\n$(mppc list artist)" | dmenu_t -dmenu -p "Choose Artist > ") if [[ $seen = 0 ]] then exit fi } browseGenre() { declare -i seen=0 while read GENRE do seen=1 export GENRE="$GENRE" if [[ "$GENRE" == "0 Return to Main Menu" ]] then dplayPrompt else browseGenre2 fi done < <(echo -e "0 Return to Main Menu\n---\n$(mppc list genre)" | dmenu_t -dmenu -p "Choose Genre > ") if [[ $seen = 0 ]] then exit fi } browseGenre2() { declare -i seen=0 while read ALBUM do seen=1 export GENRE="$GENRE" if [[ "$ALBUM" == "0 Return to Genre Menu" ]] then browseGenre elif [[ "$ALBUM" == "Replace All" ]] then mpc clear && mpc findadd genre "$GENRE" && mpc play elif [[ "$ALBUM" == "Add All" ]] then mpc findadd genre "$GENRE" elif [[ "$ALBUM" == "Insert All" ]] then mpc find genre "$GENRE" | mpc insert else ALBUM=$(echo "$ALBUM" | awk -F "$seperator" '{ print $2 }') mpc findadd album "$ALBUM" genre "$GENRE" && mpc play fi done < <(echo -e "0 Return to Genre Menu\n---\nAdd All\nInsert all\nReplace all\n---\n$(mppc search genre "$GENRE" --format "{$mpd_artist}$seperator{album}$seperator({date})" | sort | uniq)" | dmenu_t -dmenu -p "Choose Album > ") if [[ $seen = 0 ]] then exit fi } ################################################################################ if [[ "$backend" == "rofi" ]] then function dmenu_t () { rofi -dmenu $(echo "$rofiopts") "$@" } elif [[ "$backend" == "dmenu" ]] then function dmenu_t () { dmenu -l 15 "$@" } elif [[ "$backend" == "slmenu" ]] then function dmenu_t () { slmenu -l 15 "$@" } fi while :; do case $1 in --add) if [[ ! $2 ]]; then echo "Missing argument for --add" echo "Possible values: track, album, latest" elif [[ $2 == track ]]; then AddTrackTags elif [[ $2 == album ]]; then AddAlbumTags elif [[ $2 == latest ]]; then addLastMod fi break ;; --insert) if [[ ! $2 ]]; then echo "Missing argument for --insert" echo "Possible values: track, album, latest" elif [[ $2 == track ]]; then InsertTrackTags elif [[ $2 == album ]]; then InsertAlbumTags elif [[ $2 == latest ]]; then insertLastMod fi break ;; --replace) if [[ ! $2 ]]; then echo "Missing argument for --replace" echo "Possible values: track, album, latest" elif [[ $2 == track ]]; then ReplaceTrackTags elif [[ $2 == album ]]; then ReplaceAlbumTags elif [[ $2 == latest ]]; then replaceLastMod fi break ;; --rate) if [[ ! $2 ]]; then echo "Missing arguemtn for --rate" echo "Possible values: track, album, instant" echo "Launching rating menu" ratingPrompt elif [[ $2 == track ]]; then rateTrack elif [[ $2 == album ]]; then rateAlbum elif [[ $2 == instant ]]; then if [[ ! $3 ]]; then echo "Missing argument for --rate instant" echo "Please define rating between 1-10" else export rating="$3" instantRateTrack fi elif [[ $2 == load ]]; then mpc clear && mpc sticker "" find rating | grep -E "rating=6|rating=7|rating=8|rating=9|rating=10" | awk -F ':' '{print $1}' | shuf -n $value | mpc add && mpc play fi break ;; --random) if [[ ! $2 ]]; then echo "Missing argument for --random" echo "Possible values: track, album" elif [[ $2 == track ]]; then playRandomTracks elif [[ $2 == album ]]; then playRandomAlbum fi break ;; --current) currentTag break ;; --browse) if [[ ! $2 ]]; then echo "Missing argument for --browse" echo "Possible values: artist, date, genre, folder, system" elif [[ $2 == artist ]]; then browseArtist elif [[ $2 == date ]]; then browseDate elif [[ $2 == genre ]]; then browseGenre elif [[ $2 == system ]]; then browseFilesystem elif [[ $2 == folder ]]; then browseFolders fi break ;; --update) updateCache break ;; --queue) if [[ ! $2 ]]; then echo "Missing argument for --queue" echo "Possible values: show, delete, suspend, resume" elif [[ $2 == show ]]; then dplayQueue elif [[ $2 == delete ]]; then dplayQueueDelete elif [[ $2 == suspend ]]; then suspendPlaylist elif [[ $2 == resume ]]; then resumePlaylist fi break ;; --rss) loadRSS break ;; --playlist) managePlaylists break ;; --lastfm) if [[ ! $2 ]]; then echo "Missing argument for --lastfm" echo "Possible values: toggle, check, love" elif [[ $2 == toggle ]]; then lastFM elif [[ $2 == check ]]; then lastFMCheck elif [[ $2 == love ]]; then lastfm-mpd-cli love > /dev/null && notify-send "MPD" "Loved $(mpc current -f '%title%') on LastFM" fi break ;; --help|-h) echo "---" echo "clerk: the mpd UI that needs typing" echo "Copyright © 2013 - 2014 Rasmus Steinke" echo "---" echo "General" echo " --help, -h this help message" echo " --current show currently playing track" echo " --update update album/track caches" echo "" echo "Library" echo " --add adds selection at the end of the queue" echo " --insert inserts selection after playing song" echo " --replace replaces queue with selection" echo " --browse browse library" echo " --random play random track or album" echo "" echo "Playlist" echo " --queue manage current queue" echo " --playlist manage playlists" echo " --rss load podcast" echo " (podcast should be placed in ~/.config/clerk/podcasts" echo " with format NAME \ URL)" echo "" echo "Ratings" echo " --rate rate albums or tracks" echo " "load" adds random rated tracks to queue" echo "LastFM" echo " --lastfm toggle or check last.fm status, love current track" break ;; *) dplayPrompt ;; esac shift done