#!/usr/bin/env bash shopt -s globstar source $HOME/.config/clerk/config 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" if [[ $scrobbler == mpdas ]]; then export scrobbler="mpdas -d" export scrobbler_kill="mpdas" elif [[ $scrobbler == mpdscribble ]]; then export scrobbler_kill="mpdscribble" fi export mpd_artist=albumartist if [[ $(ps x| grep clerk_helper | head -1 | grep -v 'grep') ]]; then : else clerk_helper update & fi album_temp=$(cat $HOME/.config/clerk/album.cache) tracks_temp=$(cat $HOME/.config/clerk/tracks.cache) last_temp=$(cat $HOME/.config/clerk/last.cache) # 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 update & } 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 "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 } 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" "---" "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 } backupPrompt () { menu=("0 Return to Ratings Menu" "---" "1 Backup Album Ratings to Files" "2 Backup Track Ratings to Files" "---" "3 Restore Album Ratings from Files" "4 Restore Track Ratings from Files") prompt() { printf "%s\n" "$@" | dmenu_t -p "Backup/Restore > " } case "$(prompt "${menu[@]}")" in 1*) backupAlbumRatings ;; 2*) backupTrackRatings ;; 3*) restoreAlbumRatings ;; 4*) restoreTrackRatings ;; 0*) ratingPrompt ;; *) exit esac } backupTrackRatings () { cd ${music_path} rm -f **/track.ratings mpc clear mpc sticker "" find rating | awk -F ': rating=' '{ print $1 }' | while read line; do mpc add "$line" done mpc playlist -f "%artist%${separator}%track%${separator}%title%${separator}%date%${separator}%album%${separator}%file%" | while read line; do artist=$(echo ${line} | awk -F "${separator}" '{ print $1 }') track=$(echo ${line} | awk -F "${separator}" '{ print $2 }') title=$(echo ${line} | awk -F "${separator}" '{ print $3 }') date=$(echo ${line} | awk -F "${separator}" '{ print $4 }') album=$(echo ${line} | awk -F "${separator}" '{ print $5 }') file=$(echo ${line} | awk -F "${separator}" '{ print $6 }') rating=$(mpc sticker "$file" get rating | awk -F 'rating=??' '{ print $2 }') cd "$music_path" cd "$(dirname "$(echo "$file")")" touch track.ratings echo "${rating}${separator}${artist}${separator}${track}${separator}${title}${separator}${date}${separator}${album}" >> track.ratings done } backupAlbumRatings () { cd ${music_path} rm -f **/album.rating mpc clear mpc sticker "" find albumrating | awk -F ': albumrating=' '{ print $1 }' | while read line; do mpc add "$line" done mpc playlist -f "%artist%${separator}%track%${separator}%title%${separator}%date%${separator}%album%${separator}%file%" | while read line; do artist=$(echo ${line} | awk -F "${separator}" '{ print $1 }') track=$(echo ${line} | awk -F "${separator}" '{ print $2 }') title=$(echo ${line} | awk -F "${separator}" '{ print $3 }') date=$(echo ${line} | awk -F "${separator}" '{ print $4 }') album=$(echo ${line} | awk -F "${separator}" '{ print $5 }') file=$(echo ${line} | awk -F "${separator}" '{ print $6 }') rating=$(mpc sticker "$file" get albumrating | awk -F 'rating=??' '{ print $2 }') cd "$music_path" cd "$(dirname "$(echo "$file")")" touch album.rating echo "${rating}${separator}${artist}${separator}${track}${separator}${title}${separator}${date}${separator}${album}" >> album.rating done } restoreTrackRatings () { clerk_helper --restoretracks } restoreAlbumRatings () { mpc clear cd "${music_path}" cat **/album.rating | while read line; do artist=$(echo "${line}" | awk -F "${separator}" '{ print $2 }') album=$(echo "${line}" | awk -F "${separator}" '{ print $6 }') track=$(echo "${line}" | awk -F "${separator}" '{ print $3 }') title=$(echo "${line}" | awk -F "${separator}" '{ print $4 }') date=$(echo "${line}" | awk -F "${separator}" '{ print $5 }') mpc search artist "${artist}" album "${album}" track "${track}" title "${title}" date "${date}" | mpc add done mpc playlist -f "%artist%${separator}%album%${separator}%track%${separator}%title%${separator}%file%" | while read line; do artist=$(echo "${line}" | awk -F "${separator}" '{ print $1 }') album=$(echo "${line}" | awk -F "${separator}" '{ print $2 }') track=$(echo "${line}" | awk -F "${separator}" '{ print $3 }') title=$(echo "${line}" | awk -F "${separator}" '{ print $4 }') file=$(echo "${line}" | awk -F "${separator}" '{ print $5 }') cd "${music_path}"/"$(dirname "$(echo "${file}")")" if [[ "$(pwd)" == */"$cd_divider"* ]]; then cd .. fi rating=$(grep "${title}" album.rating | grep "${album}" | grep "${track}" | awk -F "${separator}" '{ print $1 }') mpc sticker "${file}" set albumrating "${rating}" done } 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 } 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%) && 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 } 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 } 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 "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 } 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%$separator%artist%$separator%title%" | dmenu_t -p "Choose Episode > ") POS=$(echo "$episode" | awk -F "$separator" '{ print $1 }') mpc play "$POS" fi } 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 } 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 $(( $(mpc current -f %position%) + 3 )) elif [[ $backend == "dmenu" ]]; then dmenu_t -p "Queue > " fi } while read TRACKDISPLAY do TITLE=$(echo "$TRACKDISPLAY" | awk -F "$separator" '{ print $3 }') ARTIST=$(echo "$TRACKDISPLAY" | awk -F "$separator" '{ print $2 }') POS=$(echo "$TRACKDISPLAY" | awk -F "$separator" '{ print $1 }') if [[ "$TRACKDISPLAY" == "0 Return to Main Menu" ]]; then dplayPrompt elif [[ "$TRACKDISPLAY" == "Mode: Play" ]]; then dplayQueueDelete else mpc play $POS; fi done < <(export separator=$separator; echo -e "0 Return to Main Menu\n---\nMode: Play\n---\n$(mpc playlist --format "%position%$separator%artist%$separator%title%")" | displayRofi) exit } dplayQueueDelete () { while read TRACKDISPLAY do TITLE=$(echo "$TRACKDISPLAY" | awk -F "$separator" '{ print $3 }') ARTIST=$(echo "$TRACKDISPLAY" | awk -F "$separator" '{ print $2 }') POS=$(echo "$TRACKDISPLAY" | awk -F "$separator" '{ 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 separator=$separator; echo -e "0 Return to Main Menu\n---\nMode: Delete\n---\nManage Playlists\n---\n$(mpc playlist --format "%position%$separator%artist%$separator%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 "$separator" '{print $2}') DATE=$(echo "$ALBUM" | awk -F "$separator" '{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$(mpc --format "%date%$separator%album%" search artist "$ARTIST" | 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 "$separator" '{print $2}') DATE=$(echo "$ALBUM" | awk -F "$separator" '{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$(mpc --format "%date%$separator%album%" search artist "$ARTIST" | 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 "$separator" '{print $2}') DATE=$(echo "$ALBUM" | awk -F "$separator" '{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$(mpc --format "%date%$separator%album%" search artist "$ARTIST" | sort | uniq)" | dmenu_t -p "Albums by $(mpc current --format '%artist%') > ") } currentTracks () { while read TRACK do TITLE=$(echo "$TRACK" | awk -F "$separator" '{print $3}') ALBUM=$(echo "$TRACK" | awk -F "$separator" '{print $1}') TRACKNUMBER=$(echo "$TRACK" | awk -F "$separator" '{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$(mpc --format "%album%$separator%track%$separator%title%" search artist "$(mpc current -f %artist%)")" | 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 "$separator" '{print $3}') ALBUM=$(echo "$TRACK" | awk -F "$separator" '{print $1}') TRACKNUMBER=$(echo "$TRACK" | awk -F "$separator" '{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 ))" | clerk_helper prio fi fi fi done < <(echo -e "0 Return to current Artist Menu\n---\nAdding Mode: Insert\n---\n$(mpc --format "%album%$separator%track%$separator%title%" search artist "$(mpc current -f %artist%)")" | 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%')" tutke="$(mpc current -f '%title')" file="$(mpc current -f '%file%')" 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%)")" rm -f album.rating echo "${rating}${separator}$(mpc current -f "%artist%${separator}%track%${separator}%title%${separator}%date%${separator}%album%")" >> album.rating 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}${separator}$(mpc current -f "%artist%${separator}%track%${separator}%title%${separator}%date%${separator}%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}${separator}$(mpc current -f "%artist%${separator}%track%${separator}%title%${separator}%date%${separator}%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 | 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 } 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 exit } 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 "$separator" '{print $2}') date=$(echo "$ALBUM" | awk -F "$separator" '{print $1}') album=$(echo "$ALBUM" | awk -F "$separator" '{print $3}') mpc find date "$date" album "$album" $mpd_artist "$artist" | mpc add 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 "$separator" '{print $2}') date=$(echo "$ALBUM" | awk -F "$separator" '{print $1}') album=$(echo "$ALBUM" | awk -F "$separator" '{print $3}') mpc find 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 "$separator" '{print $2}') date=$(echo "$ALBUM" | awk -F "$separator" '{print $1}') album=$(echo "$ALBUM" | awk -F "$separator" '{print $3}') mpc clear && mpc find date "$date" album "$album" $mpd_artist "$artist" | mpc add && 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 "$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" $mpd_artist "$artist" | mpc add 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 "$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" $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 "$separator" '{print $1}') date=$(echo "$TRACK" | awk -F "$separator" '{print $2}') album=$(echo "$TRACK" | awk -F "$separator" '{print $3}') 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 "$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}') 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 "$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}') mpc find artist "$artist" album "$album" title "$title" | mpc insert 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}') mpc findadd artist "$artist" album "$album" title "$title" echo $(( $(mpc playlist|wc -l) - 1 )) | clerk_helper 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: Replace" ]] 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}') 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: Replace\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 ))" | clerk_helper 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 "$separator" '{print $1}') album=$(echo "$select" | awk -F "$separator" '{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$(mpc --format "%$mpd_artist%$separator%album%" find date "$date" | 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 "$separator" '{print $1}') album=$(echo "$select" | awk -F "$separator" '{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$(mpc --format "%$mpd_artist%$separator%album%" find date "$date" | 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 "$separator" '{print $1}') album=$(echo "$select" | awk -F "$separator" '{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$(mpc --format "%$mpd_artist%$separator%album%" find date "$date" | 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=$(mpc list album "$ARTIST") declare -i seen=0 while read ALBUM do seen=1 ALBUM_FINAL=$(echo "$ALBUM" | awk -F "$separator" '{ print $2 }') DATE=$(echo "$ALBUM" | awk -F "$separator" '{ print $1 }') if [[ "$ALBUM" == "0 Return to Artist Menu" ]] then browseArtist elif [[ "$ALBUM" == "Replace All" ]] then mpc clear && mpc find artist "$ARTIST" | mpc add && mpc play elif [[ "$ALBUM" == "Add All" ]] then mpc find artist "$ARTIST" | mpc add elif [[ "$ALBUM" == "Insert All" ]] then mpc find artist "$ARTIST" | mpc insert else browseTrack fi done < <(echo -e "0 Return to Artist Menu\n---\nReplace All\nAdd All\nInsert All\n---\n$(mpc --format "%date%$separator%album%" find artist "$ARTIST" | 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 "$separator" '{ print $2 }') if [[ "$TRACK" = "0 Return to Album Menu" ]] then browseAlbum elif [[ "$TRACK" == "Replace All" ]] then mpc clear && mpc find artist "$ARTIST" album "$ALBUM_FINAL" date "$DATE" |mpc add && mpc play elif [[ "$TRACK" == "Add All" ]] then mpc find artist "$ARTIST" album "$ALBUM_FINAL" date "$DATE" | mpc add elif [[ "$TRACK" == "Insert All" ]] then mpc find artist "$ARTIST" album "$ALBUM_FINAL" date "$DATE" | mpc insert else if [[ $(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 done < <(echo -e "0 Return to Album Menu\n---\nReplace All\nAdd All\nInsert All\n---\n$(mpc --format "%track%$separator%title%" find artist "$ARTIST" album "$ALBUM_FINAL")" | dmenu_t -dmenu -p "Chose Track > ") if [[ $seen = 0 ]]; then exit fi exit } 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$(mpc 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$(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 "{$mpd_artist}$separator{album}$separator({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 ;; --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 ;; --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 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 " --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 "" echo " --backup backup album or track ratings." echo " make sure that music_path is set and that it's accessible by clerk" 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