#!/usr/bin/env bash shopt -s globstar # check for config files if [[ ! -f $HOME/.config/clerk/config ]] && [[ ! -f /etc/clerk ]]; then echo "Error: could not find configuration file \"$HOME/.config/clerk/config\"" echo "You can use the provided example configuration file (config.clerk), copy it to the above location and edit it to your needs." exit fi # read global config, if present if [[ -f /etc/clerk ]]; then source /etc/clerk fi # read local config file if [[ -f $HOME/.config/clerk/config ]]; then source $HOME/.config/clerk/config fi # check for clerk_helper config. Create if needed. if [[ -f $HOME/.config/clerk/helper_config ]]; then : else echo "[global]" > $HOME/.config/clerk/helper_config echo "separator = " $separator "" >> $HOME/.config/clerk/helper_config echo "music_path = "$music_path"" >> $HOME/.config/clerk/helper_config echo " " >> $HOME/.config/clerk/helper_config echo "[updater]" >> $HOME/.config/clerk/helper_config echo "change_db = xxx" >> $HOME/.config/clerk/helper_config fi echo "$backend" # check for scrobbler if [[ $scrobbler == mpdas ]]; then export scrobbler="mpdas -d" export scrobbler_kill="mpdas" elif [[ $scrobbler == mpdscribble ]]; then export scrobbler_kill="mpdscribble" fi # check if clerk_helper process is running. if it isn't update cache files, if # needed if [[ $(ps x| grep clerk_helper | head -1 | grep -v 'grep') ]]; then : else clerk_helper update & fi export separator="$separator" # load cache files into variables to speed up access loadCacheAlbums () { if [[ -f $HOME/.config/clerk/albums.cache.json ]]; then album_temp=$(clerk_helper getAlbums) fi } loadCacheLatest () { if [[ -f $HOME/.config/clerk/albums.cache.json ]]; then last_temp=$(clerk_helper getLatest | awk -F "${separator}" '{ print $1 ENVIRON["separator"] $2 ENVIRON["separator"] $3 }') fi } loadCacheTracks () { if [[ -f $HOME/.config/clerk/tracks.cache.json ]]; then #tracks_temp=$(cat $HOME/.config/clerk/tracks.cache) tracks_temp=$(clerk_helper getTracks) fi } # Use GNU coreutils on OSX sed=$([[ "$OSTYPE" == "darwin"* ]] && echo 'gsed' || echo 'sed') shuf=$([[ "$OSTYPE" == "darwin"* ]] && echo 'gshuf' || echo 'shuf') tac=$([[ "$OSTYPE" == "darwin"* ]] && echo 'gtac' || echo 'tac') updateCache() { rm -f $HOME/.config/clerk/*.cache clerk_helper createcache } # main Menu dplayPrompt () { if [[ -z $(mpc status | grep "/") ]]; then song="No Song is playing" else song=$(mpc current) fi menu=("Q Exit Clerk" "---" "${toggle}: Toggle Playback, ${prev}: Prev, ${next}: Next, ${stop}: Stop" "---" "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") menu=$(printf "%s\n" "${menu[@]}" | rofi -dmenu -lines 17 -u 2 -p "Now Playing: ${song} > ") val=$? if [[ $val -eq 10 ]]; then mpc toggle dplayPrompt elif [[ $val -eq 11 ]]; then mpc prev dplayPrompt elif [[ $val -eq 12 ]]; then mpc next dplayPrompt elif [[ $val -eq 13 ]]; then mpc stop dplayPrompt fi if [[ "$menu" == "Q Exit Clerk" ]]; then exit elif [[ "$menu" == "1 Play random Album" ]]; then playRandomAlbum elif [[ "$menu" == "2 Play random Songs" ]]; then playRandomTracks elif [[ "$menu" == "3 Current Artist" ]]; then currentMenu elif [[ "$menu" == "4 Current Queue" ]]; then dplayQueue elif [[ "$menu" == "5 Browse Library" ]]; then browseLibPrompt elif [[ "$menu" == "6 Manage Playlists" ]]; then managePlaylists elif [[ "$menu" == "7 Options" ]]; then dplayOptionsPrompt elif [[ "$menu" == "8 Ratings" ]]; then ratingPrompt elif [[ "$menu" == "9 Lookup" ]]; then infoPrompt elif [[ -z "$menu" ]]; then exit fi } # start/stop scrobbler. locally or remote lastFM () { # Some Variables to clean up the code if [[ $ssh_lastfm == 1 ]]; then mpds_check="$(ssh $ssh_host -q -t "pgrep $scrobbler_kill")" if [ -n "$mpds_check" ]; then ssh $ssh_host -q -t "killall $scrobbler_kill" && notify-send "MPD" "LastFM Scrobbling Disabled" else ssh $ssh_host -q "$scrobbler" && notify-send "MPD" "LastFM Scrobbling Enabled" fi else if pgrep $scrobbler_kill then killall $scrobbler_kill && notify-send "MPD" "LastFM Scrobbling Disabled" else $scrobbler && 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 "pgrep $scrobbler_kill")" if [ -n "$mpds_check" ]; then echo "lastfm: off" else echo "lastfm: on" fi else if pgrep $scrobbler_kill then echo "lastfm: on" else echo "lastfm: off" fi fi } # function to browse local filesystem. # Only works, if music_dir is accessible locally 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 } # Show Albums and Tracks by currently playing artist currentMenu () { albums=$(clerk_helper getartistalbums "$(mpc current -f '%artist%')") titles=$(clerk_helper getartisttracks "$(mpc current -f '%artist%')") if [[ -z $(mpc current) ]]; then menu=$(echo -e "0 Return to Main Menu" | rofi -dmenu -p "No Music is playing") else current=$(mpc current -f '%artist%') menu=("0 Return to Main Menu" "---" "${add}: Add, ${insert}: Insert, ${replace}: Replace" "---" "$albums" "---" "$titles") fi if [[ -z $line ]]; then menu_temp=$(printf "%s\n" "${menu[@]}" | rofi -dmenu -format "i:s" -u 2 -p "Other Music by ${current} > ") else menu_temp=$(printf "%s\n" "${menu[@]}" | rofi -dmenu -l $(( $line + 1 )) -format "i:s" -u 2 -p "Other Music by ${current} > ") fi # for some reason directly defining $val wasnt working. Using a # temporary variable instead. tempval=$? val=$tempval menu="${menu_temp#*:}" albumartist=$(mpc current -f '%albumartist%') artist=$(mpc current -f '%artist%') unset line export line="${menu_temp%:*}" # checking for exit codes. if [[ $menu == "(Album)"* ]]; then if [[ $val -eq 11 ]]; then mpc find album "$(echo "$menu" | awk -F "$separator" '{ print $2 }')" albumartist "${albumartist}" | mpc insert elif [[ $val -eq 0 || $val -eq 12 ]]; then mpc clear mpc find album "$(echo ${menu} | awk -F "$separator" '{ print $2 }')" albumartist "${albumartist}" | mpc add mpc play elif [[ $val -eq 10 ]]; then mpc find album "$(echo ${menu} | awk -F "$separator" '{ print $2 }')" albumartist "${albumartist}" | mpc add elif [[ $val -eq 1 ]]; then exit fi currentMenu elif [[ $menu == "(Song)"* ]]; then if [[ $val -eq 11 ]]; then mpc find track "$(echo ${menu} | awk -F ') ' '{ print $2 }' | awk -F "$separator" '{ print $1 }')" title "$(echo "$menu" | awk -F "$separator" '{ print $2 }')" artist "${artist}" | mpc insert elif [[ $val -eq 12 ]]; then mpc clear mpc find track "$(echo ${menu} | awk -F ') ' '{ print $2 }' | awk -F "$separator" '{ print $1 }')" title "$(echo "$menu" | awk -F "$separator" '{ print $2 }')" artist "${artist}" | mpc add mpc play elif [[ $val -eq 0 || $val -eq 10 ]]; then mpc find track "$(echo ${menu} | awk -F ') ' '{ print $2 }' | awk -F "$separator" '{ print $1 }')" title "$(echo "$menu" | awk -F "$separator" '{ print $2 }')" artist "${artist}" | mpc add elif [[ $val -eq 1 ]]; then exit fi currentMenu elif [[ -z "$menu" ]]; then exit elif [[ "$menu" == "${add}: Add, ${insert}: Insert, ${replace}: Replace" ]]; then currentMenu elif [[ $menu == "0 Return to Main Menu" ]]; then dplayPrompt fi } # rating menu 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" "---" "7 Love current Song on LastFM" "---" "0 Backup/Restore") prompt() { printf "%s\n" "$@" | dmenu_t -p "Ratings > " } case "$(prompt "${menu[@]}")" in 1*) rateAlbum ;; 2*) loadRatedAlbums ;; 3*) loadRandomRating ;; 4*) rateTrack ;; 5*) loadRatedTracks ;; 6*) loadRandomRatedTracks ;; 7*) loveLast ;; 0*) backupPrompt ;; Q*) dplayPrompt ;; *) exit esac } # create rating json files from mpd sticker database and vice versa backupPrompt () { menu=("0 Return to Ratings Menu" "---" "1 Backup Album Ratings to File" "2 Backup Track Ratings to File" "---" "3 Restore Ratings from File") prompt() { printf "%s\n" "$@" | dmenu_t -p "Backup/Restore > " } case "$(prompt "${menu[@]}")" in 1*) clerk_helper importalbumratings & ;; 2*) clerk_helper importtrackratings & ;; 3*) clerk_helper sendstickers & ;; 0*) ratingPrompt ;; *) exit esac } # if mpdas is used use mpc to love track on last.fm. otherwise try # lastfm-mpd-cli loveLast () { if [[ "$scrobbler" == "mpdscribble" ]]; then lastfm-mpd-cli love > /dev/null && notify-send "MPD" "Loved $(mpc current -f '%title%') on LastFM" && exit elif [[ "$scrobbler" == "mpdas" ]]; then mpc sendmessage mpdas love fi } 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%) && exit;; # 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 } # read all tags from file. Note that mpd can only read vorbiscomment properly 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%' | clerk_helper readcomments)" | dmenu_t -p 'Current Song > ') if [[ $seen = 0 ]] then exit fi } # Messy options menu. dplayOptionsPrompt () { # define variables to be used in menu 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 "pgrep $scrobbler_kill")" if [ -n "$mpds_check" ]; then export scrobble=on else export scrobble=off fi else if pgrep $scrobbler_kill 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 } # toggle similar artist playback 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 } # function to change number of random songs in config file 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 } # read list of available podcasts. Not using mpd playlists, because mpd does # not support custom names for urls. format of podcast in file is "Name \ URL" 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%$separator%artist%$separator%title%" | dmenu_t -p "Choose Episode > ") POS=$(echo "$episode" | awk -F "$separator" '{ print $1 }') mpc play "$POS" fi } # suspend current playlist. playlist, song id and play-position are saved to # $HOME/.config/clerk/suspend suspendPlaylist () { playing=$(! mpc status | grep 'playing\|paused') time=$(mpc status | $sed '2!d;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 } # read $HOME/.config/clerk/suspend and restore playlist. Then start playing # from same position that was saved in suspend file 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 } # Play or delete items from current Queue dplayQueue () { while true; do if [[ -z $POS ]]; then TRACKDISPLAY=("0 Return to Main Menu" "---" "${play}: Play, ${delete}: Delete" "---" "$(mpc playlist --format "%position%$separator%artist%$separator%title%")") else # check if POS is a number. if it is, add 4 to it. POS is later # exported from song ID in playlist. re='^[0-9]+$' if [[ "$POS" =~ $re ]]; then POS=$(( $POS + 4 )) else POS=0 fi TRACKDISPLAY=("0 Return to Main Menu" "---" "${play}: Play, ${delete}: Delete" "---" "$(mpc playlist --format "%position%$separator%artist%$separator%title%")") fi TRACKDISPLAY=$(printf "%s\n" "${TRACKDISPLAY[@]}" | rofi -dmenu -l $POS -u 2 -p "Current Queue > ") tempval=$? val=$tempval TITLE=$(echo "$TRACKDISPLAY" | awk -F "$separator" '{ print $3 }') ARTIST=$(echo "$TRACKDISPLAY" | awk -F "$separator" '{ print $2 }') export POS=$(echo "$TRACKDISPLAY" | awk -F "$separator" '{ print $1 }') if [[ "$TRACKDISPLAY" == "0 Return to Main Menu" ]]; then dplayPrompt elif [[ -z "$TRACKDISPLAY" ]]; then exit elif [[ "$TRACKDISPLAY" == "${play}: Play, ${delete}: Delete" ]]; then dplayQueue else if [[ $val -eq 11 ]]; then mpc del $POS elif [[ $val -eq 0 || $val -eq 10 ]]; then mpc play $POS; fi fi done } # show all mpd playlists and load them to queue 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 managePlaylists else mpc clear mpc load "$playlist" && dplayQueue fi } # save current playlist to playlist file. 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 } # enable/disable outputs 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 } # rate any album rateAlbum () { rating="$(seq 10 | dmenu_t -p "Select Album Rating: > ")" if [[ $rating == "" ]]; then exit else # check if rateartist was defined, if it wasn't use currently playing # track for rating, otherwise use what was delivered in the rate* # variables. if [[ -z "$rateartist" ]]; then export disc=${disc}; export track=${track}; clerk_helper ratealbum "$(mpc current -f '%albumartist%')" "$(mpc current -f '%album%')" "$(mpc current -f '%date%')" "${rating}" else export disc=${disc}; export track=${track}; clerk_helper ratealbum "${rateartist}" "${ratealbum}" "${ratedate}" "${rating}" notify-send "clerk" "rated ${rateartist} - ${ratealbum} with ${rating}" fi fi } rateTrack () { rating="$(seq 10 | dmenu_t -p "Select Track Rating: > ")" if [[ $rating == "" ]]; then exit else if [[ -z "$rateartist" ]]; then export rating=${rating} rateartist=$(mpc current -f '%artist%') ratetitle=$(mpc current -f '%title%') ratetrack=$(mpc current -f '%track%') ratealbum=$(mpc current -f '%album%') clerk_helper ratetrack "${rateartist}" "${ratealbum}" "${ratetrack}" "${ratetitle}" "${rating}" notify-send "clerk" "rated $(mpc current) with $(echo ${rating})" else clerk_helper ratetrack "${rateartist}" "${ratealbum}" "${ratetrack}" "${ratetitle}" "${rating}" notify-send "clerk" "rated ${rateartist} - ${ratetitle} with $(echo ${rating})" fi fi } # function to instantly rate a track without a submenu. rating is defined on # commandline instantRateTrack () { export rating=${rating}; clerk_helper ratetrack "${rateartist}" "${ratealbum}" "${ratetrack}" "${ratetitle}" "${rating}" notify-send "clerk" "rated $(mpc current) with $(echo ${rating})" } # load rated albums with minimum rating of xx 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 | awk -F 'rating=' '{ print $2 }')" 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 } # load random album. Make sure to make each sub item random. this way each # artist has equal chances of being played, no matter how many albums it has. playRandomAlbum () { mpc clear > /dev/null artist="$(mpc list "albumartist" | $shuf -n 1)" album="$(mpc list album "albumartist" "$artist" | $shuf -n 1)" mpc find album "$album" "albumartist" "$artist" | mpc add && mpc play > /dev/null } # same for tracks, no artist should be preferred because it has more tracks. playRandomTracks () { mpc clear > /dev/null 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 > /dev/null 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 > /dev/null exit } addLastMod() { if [[ -z $last_temp ]]; then loadCacheLatest else echo "re-using album list from memory" fi menu=("0 Return to Main Menu" "---" "${add}: Add, ${insert}: Insert, ${replace}: Replace (Default)" "---" "${last_temp}") if [[ -z $line ]]; then TRACK_TEMP=$(printf "%s\n" "${menu[@]}" | dmenu_t -dmenu -format "i:s" -u 2 -p "Chose Album > ") else TRACK_TEMP=$(printf "%s\n" "${menu[@]}" | dmenu_t -dmenu -l $(( $line + 1 )) -format "i:s" -u 2 -p "Chose Album > ") fi val=$? TRACK="${TRACK_TEMP#*:}" export line="$(echo ${TRACK_TEMP} | awk -F ':' '{ print $1}')" if [[ "$TRACK" == "0 Return to Main Menu" ]] then dplayPrompt elif [[ -z "$TRACK" ]]; then exit elif [[ "$TRACK" == "${add}: Add, ${insert}: Insert, ${replace}: Replace (Default)" ]]; then addLastMod else artist=$(echo "$TRACK" | awk -F "$separator" '{print $2}') date=$(echo "$TRACK" | awk -F "$separator" '{print $1}') album=$(echo "$TRACK" | awk -F "$separator" '{print $3}') if [[ $val -eq 11 ]]; then echo "return code is 12" mpc search date "$date" album "$album" albumartist "$artist" | mpc insert elif [[ $val -eq 0 || $val -eq 12 ]]; then echo "return code is 13" mpc clear && mpc search date "$date" album "$album" albumartist "$artist" | mpc add mpc play elif [[ $val -eq 10 ]]; then mpc search date "$date" album "$album" albumartist "$artist" | mpc add elif [[ $val -eq 1 ]]; then exit fi addLastMod fi } AddAlbumTags() { if [[ -z $album_temp ]]; then loadCacheAlbums export album_temp=${album_temp} echo "\$album_temp not set, reading..." else export album_temp=${album_temp} echo "Re-Using \$album_temp" fi menu=("0 Return to Main Menu" "---" "${add}: Add, ${insert}: Insert, ${replace}: Replace (Default), ${rate}: Rate" "---" "${album_temp}") if [[ -z $line ]]; then TRACK_TEMP=$(printf "%s\n" "${menu[@]}" | dmenu_t -dmenu -format "i:s" -u 2 -p "Chose Album > ") else TRACK_TEMP=$(printf "%s\n" "${menu[@]}" | dmenu_t -dmenu -l $(( $line + 1 )) -format "i:s" -u 2 -p "Chose Album > ") fi val=$? TRACK="${TRACK_TEMP#*:}" unset line export line="${TRACK_TEMP%:*}" if [[ "$TRACK" == "0 Return to Main Menu" ]] then AddAlbumTags elif [[ -z "$TRACK" ]]; then exit elif [[ "$TRACK" == "${add}: Add, ${insert}: Insert, ${replace}: Replace (Default), ${rate}: Rate" ]]; then AddAlbumTags else artist=$(echo "$TRACK" | awk -F "$separator" '{print $1}') date=$(echo "$TRACK" | awk -F "$separator" '{print $2}') album=$(echo "$TRACK" | awk -F "$separator" '{print $3}') if [[ $val -eq 11 ]]; then echo "return code is 1" mpc find date "$date" album "$album" albumartist "$artist" | mpc insert elif [[ $val -eq 0 || $val -eq 12 ]]; then echo "return code is 2" mpc clear && mpc find date "$date" album "$album" albumartist "$artist" | mpc add mpc play elif [[ $val -eq 13 ]]; then if [[ -n $(mpc find -f '%disc%' albumartist "${artist}" album "${album}" date "${date}") ]]; then disc=$(mpc find -f '%disc%' albumartist "${artist}" album "${album}" date "${date}" | head -1) else disc="" fi if [[ -n $(mpc find track "1" albumartist "${artist}" album "${album}" date "${date}") ]]; then track="1" else track="01" fi disc=${disc} track=${track} rateartist="${artist}" ratealbum="${album}" ratedate="${date}" rateAlbum elif [[ $val -eq 10 ]]; then mpc search date "$date" album "$album" albumartist "$artist" | mpc add elif [[ $val -eq 1 ]]; then exit fi AddAlbumTags fi } AddTrackTags() { if [[ -z $tracks_temp ]]; then loadCacheTracks > /dev/null else echo "re-using track list from memory" # unset tracks_temp # export tracks_temp=${tracks_temp} > /dev/null fi menu=("0 Return to Main Menu" "---" "${add}: Add | ${insert}: Insert | ${replace}: Replace | ${rate}: Rate" "---" "${tracks_temp}") if [[ -z $line ]]; then TRACK_TEMP=$(printf "%s\n" "${menu[@]}" | dmenu_t -dmenu -format "i:s" -u 2 -p "Choose Track > ") else TRACK_TEMP=$(printf "%s\n" "${menu[@]}" | dmenu_t -dmenu -format "i:s" -l $(( $line + 1 )) -u 2 -p "Choose Track > ") fi val=$? TRACK="${TRACK_TEMP#*:}" export line="$(echo ${TRACK_TEMP} | awk -F ':' '{ print $1}')" if [[ "$TRACK" == "0 Return to Main Menu" ]] then dplayPrompt elif [[ -z "$TRACK" ]]; then exit elif [[ "$TRACK" == "${add}: Add | ${insert}: Insert | ${replace}: Replace | ${rate}: Rate" ]]; then AddTrackTags else artist=$(echo "$TRACK" | awk -F "$separator" '{print $1}') album=$(echo "$TRACK" | awk -F "$separator" '{print $4}') track=$(echo "$TRACK" | awk -F "$separator" '{print $2}') title=$(echo "$TRACK" | awk -F "$separator" '{print $3}') if [[ $val -eq 11 ]]; then mpc find artist "$artist" album "$album" title "$title" | mpc insert elif [[ $val -eq 12 ]]; then mpc clear mpc findadd artist "$artist" album "$album" title "$title" mpc play elif [[ $val -eq 0 || $val -eq 10 ]]; then mpc findadd artist "$artist" album "$album" title "$title" if [[ "$add_auto_play" == yes ]]; then mpc play $(mpc playlist | wc -l) fi elif [[ $val -eq 13 ]]; then rateartist="${artist}" ratealbum="${album}" ratetrack="${track}" ratetitle="${title}" rateTrack elif [[ $val -eq 1 ]]; then exit fi AddTrackTags 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() { menu=("0 Return to Date Menu" "---" "Alt+1: Add Album | Alt+2: Insert Album | Alt+3: Replace Album" "Alt+4: Add All | Alt+5: Insert All | Alt+6: Replace All" "---" "$(mpc --format "%albumartist%$separator%album%" find date "$date" | uniq)") if [[ -z $line ]]; then select_temp=$(printf "%s\n" "${menu[@]}" | rofi -dmenu -format "i:s" -u 2-3 -p "Select Album > ") else select_temp=$(printf "%s\n" "${menu[@]}" | rofi -dmenu -l $(( $line + 1 )) -format "i:s" -u 2-3 -p "Select Album > ") fi val=$? select="${select_temp#*:}" unset line export line="${select_temp%:*}" echo "$line" artist=$(echo "$select" | awk -F "$separator" '{print $1}') album=$(echo "$select" | awk -F "$separator" '{print $2}') if [[ "$val" -eq 13 ]]; then mpc findadd date "$date" browseDateAdd elif [[ "$val" -eq 15 ]]; then mpc clear && mpc findadd date "$date" && mpc play browseDateAdd elif [[ "$val" -eq 14 ]]; then mpc find date "$date" | mpc insert browseDateAdd fi if [[ "$select" == "0 Return to Date Menu" ]] then browseDate else if [[ "$val" -eq 10 ]]; then mpc findadd date "$date" artist "$artist" album "$album" browseDateAdd elif [[ "$val" -eq 11 ]]; then mpc find date "$date" artist "$artist" album "$album" | mpc insert browseDateAdd elif [[ "$val" -eq 12 || "$val" -eq 0 ]]; then mpc clear && mpc findadd date "$date" artist "$artist" album "$album" && mpc play browseDateAdd elif [[ "$val" -eq 1 ]]; then exit fi fi } 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=$(mpc list album artist "$ARTIST") ALBUM=("0 Return to Artist Menu" "---" "Alt+1: Add Album | Alt+2: Insert Album | Alt+3: Replace Album (Default)" "Alt+4: Add All | Alt+5: Insert All | Alt+6: Replace All" "---" "$(mpc --format "%date%$separator%album%" find artist "$ARTIST" | sort | uniq)") if [[ -z $line ]]; then ALBUM_TEMP=$(printf "%s\n" "${ALBUM[@]}" | dmenu_t -dmenu -format "i:s" -u 2-3 -p "Choose Album > ") else ALBUM_TEMP=$(printf "%s\n" "${ALBUM[@]}" | dmenu_t -dmenu -l $(( $line + 1 )) -format "i:s" -u 2-3 -p "Choose Album > ") fi val=$? ALBUM="${ALBUM_TEMP#*:}" ALBUM_FINAL=$(echo "$ALBUM" | awk -F "$separator" '{ print $2 }') DATE=$(echo "$ALBUM" | awk -F "$separator" '{ print $1 }') unset line export line="${ALBUM_TEMP%:*}" if [[ "$val" -eq 10 ]]; then export ALBUM_FINAL=$(echo "$ALBUM" | awk -F "$separator" '{ print $2 }') export DATE=$(echo "$ALBUM" | awk -F "$separator" '{ print $1 }') mpc find artist "$ARTIST" date "$DATE" album "$ALBUM_FINAL" | mpc add browseAlbum elif [[ "$val" -eq 11 ]]; then export ALBUM_FINAL=$(echo "$ALBUM" | awk -F "$separator" '{ print $2 }') export DATE=$(echo "$ALBUM" | awk -F "$separator" '{ print $1 }') mpc find artist "$ARTIST" date "$DATE" album "$ALBUM_FINAL" | mpc insert browseAlbum elif [[ "$val" -eq 12 ]]; then export ALBUM_FINAL=$(echo "$ALBUM" | awk -F "$separator" '{ print $2 }') export DATE=$(echo "$ALBUM" | awk -F "$separator" '{ print $1 }') mpc clear mpc find artist "$ARTIST" date "$DATE" album "$ALBUM_FINAL" | mpc add mpc play browseAlbum elif [[ "$val" -eq 15 ]]; then export ALBUM_FINAL=$(echo "$ALBUM" | awk -F "$separator" '{ print $2 }') export DATE=$(echo "$ALBUM" | awk -F "$separator" '{ print $1 }') mpc clear && mpc find artist "$ARTIST" | mpc add && mpc play elif [[ "$val" -eq 13 ]]; then export ALBUM_FINAL=$(echo "$ALBUM" | awk -F "$separator" '{ print $2 }') export DATE=$(echo "$ALBUM" | awk -F "$separator" '{ print $1 }') mpc find artist "$ARTIST" | mpc add elif [[ "$val" -eq 14 ]]; then export ALBUM_FINAL=$(echo "$ALBUM" | awk -F "$separator" '{ print $2 }') export DATE=$(echo "$ALBUM" | awk -F "$separator" '{ print $1 }') mpc find artist "$ARTIST" | mpc insert elif [[ "$val" -eq 0 ]]; then if [[ "$ALBUM" == "0 Return to Artist Menu" ]]; then browseArtist else export ALBUM_FINAL=$(echo "$ALBUM" | awk -F "$separator" '{ print $2 }') export DATE=$(echo "$ALBUM" | awk -F "$separator" '{ print $1 }') browseTrack fi elif [[ "$val" -eq 1 ]]; then exit fi exit } browseTrack() { TRACK=("0 Return to Album Menu" "---" "Alt+1: Add Track (Default) | Alt+2: Insert Track | Alt+3: Replace Track" "Alt+4: Add All | Alt+5: Insert All | Alt+6: Replace All" "---" "$(mpc --format "%track%$separator%title%" find artist "$ARTIST" album "$ALBUM_FINAL")") if [[ -z $line ]]; then TRACK_TEMP=$(printf "%s\n" "${TRACK[@]}" | dmenu_t -dmenu -u 2-3 -format "i:s" -p "Chose Track > ") else TRACK_TEMP=$(printf "%s\n" "${TRACK[@]}" | dmenu_t -dmenu -l $(( $line + 1 )) -u 2-3 -format "i:s" -p "Chose Track > ") fi val=$? TRACK="${TRACK_TEMP#*:}" TRACKFINAL=$(echo "$TRACK" | awk -F "$separator" '{ print $2 }') unset line export line="${TRACK_TEMP%:*}" if [[ "$val" -eq 10 ]]; then mpc find artist "$ARTIST" album "$ALBUM_FINAL" date "$DATE" title "$TRACKFINAL" | mpc add browseTrack elif [[ "$val" -eq 11 ]]; then mpc find artist "$ARTIST" album "$ALBUM_FINAL" date "$DATE" title "$TRACKFINAL" | mpc insert browseTrack elif [[ "$val" -eq 12 ]]; then mpc clear mpc find artist "$ARTIST" album "$ALBUM_FINAL" date "$DATE" title "$TRACKFINAL" | mpc add mpc play browseTrack elif [[ "$val" -eq 15 ]]; then mpc clear && mpc find artist "$ARTIST" album "$ALBUM_FINAL" date "$DATE" |mpc add && mpc play elif [[ "$val" -eq 13 ]]; then mpc find artist "$ARTIST" album "$ALBUM_FINAL" date "$DATE" | mpc add elif [[ "$val" -eq 14 ]]; then mpc find artist "$ARTIST" album "$ALBUM_FINAL" date "$DATE" | mpc insert elif [[ "$val" -eq 1 ]]; then exit elif [[ "$val" -eq 0 ]]; then if [[ "$TRACK" = "0 Return to Album Menu" ]]; then browseAlbum else if [[ -z $(mpc playlist) ]]; then mpc find artist "$ARTIST" album "$ALBUM_FINAL" date "$DATE" title "$TRACKFINAL" | mpc add && mpc play else mpc find artist "$ARTIST" album "$ALBUM_FINAL" date "$DATE" title "$TRACKFINAL" | mpc add fi fi fi } browseArtist() { ARTIST=$(echo -e "0 Return to Main Menu\n---\n$(mpc list artist)" | dmenu_t -dmenu -p "Choose Artist > ") val=$? export ARTIST="$ARTIST" if [[ "$ARTIST" == "0 Return to Main Menu" ]]; then dplayPrompt elif [[ "$val" -eq 0 ]]; then export ARTIST="$ARTIST" browseAlbum elif [[ "$val" -eq 1 ]]; 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$(mpc 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 "$separator" '{ 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$(mpc search genre "$GENRE" --format "{albumartist}$separator{album}$separator({date})" | sort | uniq)" | dmenu_t -dmenu -p "Choose Album > ") if [[ $seen = 0 ]] then exit fi } saveAlbumToPlaylist() { declare -i seen=0 while read TRACK do seen=1 if [[ "$TRACK" == "0 Return to Main Menu" ]] then dplayPrompt else artist=$(echo "$TRACK" | awk -F "$separator" '{print $1}') date=$(echo "$TRACK" | awk -F "$separator" '{print $2}') album=$(echo "$TRACK" | awk -F "$separator" '{print $3}') mpc search date "$date" album "$album" albumartist "$artist" | clerk_helper saveto fi done < <(echo -e "0 Return to Main Menu\n---\n$(echo "$album_temp")" | dmenu_t -dmenu -p "Save Album to Playlist > ") if [[ $seen = 0 ]] then exit fi } saveLatestToPlaylist() { declare -i seen=0 while read TRACK do seen=1 if [[ "$TRACK" == "0 Return to Main Menu" ]] then dplayPrompt else artist=$(echo "$TRACK" | awk -F "$separator" '{print $2}') date=$(echo "$TRACK" | awk -F "$separator" '{print $1}') album=$(echo "$TRACK" | awk -F "$separator" '{print $3}') mpc search date "$date" album "$album" albumartist "$artist" | clerk_helper saveto fi done < <(echo -e "0 Return to Main Menu\n---\n$(echo "$last_temp")" | dmenu_t -dmenu -p "Save Album to Playlist > ") if [[ $seen = 0 ]] then exit fi } saveTrackToPlaylist() { declare -i seen=0 while read TRACK do seen=1 if [[ "$TRACK" == "0 Return to Main Menu" ]] then dplayPrompt else artist=$(echo "$TRACK" | awk -F "$separator" '{print $1}') track=$(echo "$TRACK" | awk -F "$separator" '{print $2}') album=$(echo "$TRACK" | awk -F "$separator" '{print $4}') title=$(echo "$TRACK" | awk -F "$separator" '{print $5}') mpc search track "$track" album "$album" title "$title" albumartist "$artist" | clerk_helper saveto fi done < <(echo -e "0 Return to Main Menu\n---\n$(echo "$tracks_temp")" | dmenu_t -dmenu -p "Save Track to Playlist > ") if [[ $seen = 0 ]] then exit fi } ################################################################################ function dmenu_t () { rofi -dmenu $(echo "$rofiopts") "$@" } 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 ;; --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 ;; --backup) if [[ ! $2 ]]; then echo "Missing argument for --backup" echo "Possible values: track, album" elif [[ $2 == track ]]; then backupTrackRatings elif [[ $2 == album ]]; then backupAlbumRatings fi break ;; --restore) if [[ ! $2 ]]; then echo "Missing argument for --restore" echo "Possible values: track, album" elif [[ $2 == track ]]; then restoreTrackRatings elif [[ $2 == album ]]; then restoreAlbumRatings 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 ;; --manage) managePlaylists ;; --playlist) if [[ $2 == savealbum ]]; then saveAlbumToPlaylist elif [[ $2 == savelast ]]; then saveLatestToPlaylist elif [[ $2 == savetrack ]]; then saveTrackToPlaylist fi 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 if [[ scrobbler=mpdscribble ]]; then lastfm-mpd-cli love > /dev/null && notify-send "MPD" "Loved $(mpc current -f '%title%') on LastFM" elif [[ scrobbler=mpdas ]]; then mpc sendmessage mpdas love fi fi break ;; --help|-h) echo "---" echo "clerk: rofi/dmenu based MPD Interface" echo "Copyright © 2013 - 2015 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 " --browse browse library" echo " --random play random track or album" echo "" echo "Playlist" echo " --queue manage current queue" echo " --manage manage playlists" echo " --playlist save selection to playlist \"clerk\"" 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 "" echo " --backup restore album or track ratings." echo " make sure that music_path is set and that it's accessible by clerk" echo " ONLY USE, WHEN YOUR RATINGS FILES ARE 100% valid!" echo "" echo "LastFM" echo " --lastfm toggle or check last.fm status, love current track" break ;; *) dplayPrompt ;; esac shift done