diff options
-rwxr-xr-x | clerk | 195 |
1 files changed, 73 insertions, 122 deletions
@@ -179,33 +179,6 @@ updateDB () { #sqlite3 ../ratings.db "insert into albums (date, artist, album, directory, rating) values ('$date', '$artist', '$album', '$directory', '$rating')" done done - for line in *.ratings; do - if grep "^rating=" "$line" > /dev/null; then - albumartist=$(grep "^albumartist=" "$line" | cut -d '=' -f2- ) - date=$(grep "^date=" "$line" | cut -d '=' -f2-) - album=$(grep "^album=" "$line" | cut -d '=' -f2-) - rating_split=$(grep "^rating=" "$line" | cut -d "=" -f2-) - echo "$rating_split" | while read ratings; do - rating=$(echo "$ratings" | cut -d '/' -f1) - rating_max=$(echo "$ratings" | cut -d '/' -f2) - title_split="$(echo "$ratings" | cut -d ' ' -f2-)" - artist="$(echo "$title_split" | awk -F '--' '{ print $1 }')" - title="$(echo "$title_split" | awk -F '--' '{ print $3 }')" - tracknumber="$(echo "$title_split" | awk -F '--' '{ print $2 }')" - date=${date//\'/\\\'} - artist=${artist//\'/\\\'} - album=${album//\'/\\\'} - title=${title//\'\\\'} - rating=${rating//\'/\\\'} - echo "$title" - echo "artist=${artist}" - echo "title=${title}" - echo "date=${date}" - echo "rating=${rating}" - sqlite3 ../ratings.db "insert or replace into tracks (date, artist, album, title, tracknumber, rating) values ('$date', '$artist', '$album', '$title', '$tracknumber', '$rating')" - done - fi - done ratingPrompt } @@ -646,101 +619,86 @@ escapeSql() { echo ${1//\'/\'\'} } +#rateAlbum () { +# if [[ "$mpd_artist" == "albumartist" ]]; then +# albumartist="$(mpc current -f %albumartist%)" +# elif [[ "$mpd_artist" == "artist" ]]; then +# albumartist="$(mpc current -f %artist%)" +# fi +# albumartist="$(mpc current -f %artist%)" +# album="$(mpc current -f %album%)" +# date="$(mpc current -f %date%)" +# rating="$(seq $maxratings | dmenu_t -p "Select Rating: > ")" +# date=$(escapeSql "$date") +# artist=$(escapeSql "$artist") +# album=$(escapeSql "$album") +# rating=$(escapeSql "$rating") +# +# if [[ $rating == "" ]]; then +# exit +# else +# cd $HOME/.config/clerk/ratings +# if [[ -a "$(mpc current -f "%$mpd_artist%--%date%--%album%").ratings" ]]; then +# echo "Ratings file present, using it" +# else +# echo "artist="$(mpc current --format %artist%)"" >> "$(mpc current -f "%$mpd_artist%--%date%--%album%").ratings" +# echo "album="$(mpc current --format %album%)"" >> "$(mpc current -f "%$mpd_artist%--%date%--%album%").ratings" +# echo "date="$(mpc current --format %date%)"" >> "$(mpc current -f "%$mpd_artist%--%date%--%album%").ratings" +# fi +# if grep "album_rating=" "$(mpc current -f "%artist%--%date%--%album%").ratings" > /dev/null; then +# sed -i "/album_rating/d" "$(mpc current -f "%$mpd_artist%--%date%--%album%").ratings" +# echo "Album already rated. Changing Rating" +# fi +# echo "album_rating=$rating/$maxratings" >> "$(mpc current -f "%$mpd_artist%--%date%--%album%").ratings" +# if [[ "$music_dir_access" == "yes" ]]; then +# cd "$music_path" +# cd "$(dirname "$(mpc current -f %file%)")" +# if [[ "$(pwd)" == */"$cd_divider"* ]]; then +# cd .. +# fi +# cp $HOME/.config/clerk/ratings/"$(mpc current -f "%$mpd_artist%--%date%--%album%").ratings" . +# fi +# cd $HOME/.config/clerk/ratings +# notify-send "clerk" "Rated $(mpc current -f "%$mpd_artist% - %album%") with $rating/$maxratings" +# sqlite3 ../ratings.db "insert or replace into albums (date, artist, album, rating) values ('$date', '$albumartist', '$album', '$rating')" +# fi +# ratingPrompt +#} +# rateAlbum () { - if [[ "$mpd_artist" == "albumartist" ]]; then - albumartist="$(mpc current -f %albumartist%)" - elif [[ "$mpd_artist" == "artist" ]]; then - albumartist="$(mpc current -f %artist%)" - fi - albumartist="$(mpc current -f %artist%)" - album="$(mpc current -f %album%)" - date="$(mpc current -f %date%)" - rating="$(seq $maxratings | dmenu_t -p "Select Rating: > ")" - date=$(escapeSql "$date") - artist=$(escapeSql "$artist") - album=$(escapeSql "$album") - rating=$(escapeSql "$rating") + rating="$(seq $track_maxratings | dmenu_t -p "Select Rating: > ")" if [[ $rating == "" ]]; then exit else - cd $HOME/.config/clerk/ratings - if [[ -a "$(mpc current -f "%$mpd_artist%--%date%--%album%").ratings" ]]; then - echo "Ratings file present, using it" - else - echo "artist="$(mpc current --format %artist%)"" >> "$(mpc current -f "%$mpd_artist%--%date%--%album%").ratings" - echo "album="$(mpc current --format %album%)"" >> "$(mpc current -f "%$mpd_artist%--%date%--%album%").ratings" - echo "date="$(mpc current --format %date%)"" >> "$(mpc current -f "%$mpd_artist%--%date%--%album%").ratings" - fi - if grep "album_rating=" "$(mpc current -f "%artist%--%date%--%album%").ratings" > /dev/null; then - sed -i "/album_rating/d" "$(mpc current -f "%$mpd_artist%--%date%--%album%").ratings" - echo "Album already rated. Changing Rating" - fi - echo "album_rating=$rating/$maxratings" >> "$(mpc current -f "%$mpd_artist%--%date%--%album%").ratings" - if [[ "$music_dir_access" == "yes" ]]; then - cd "$music_path" - cd "$(dirname "$(mpc current -f %file%)")" - if [[ "$(pwd)" == */"$cd_divider"* ]]; then - cd .. - fi - cp $HOME/.config/clerk/ratings/"$(mpc current -f "%$mpd_artist%--%date%--%album%").ratings" . - fi - cd $HOME/.config/clerk/ratings - notify-send "clerk" "Rated $(mpc current -f "%$mpd_artist% - %album%") with $rating/$maxratings" - sqlite3 ../ratings.db "insert or replace into albums (date, artist, album, rating) values ('$date', '$albumartist', '$album', '$rating')" + artist="$(mpc current -f '%artist%')" + album="$(mpc current -f '%album%')" + date="$(mpc current -f '%date%')" + mpc search artist "$artist" album "$album" date "$date" | while read line; do + mpc sticker "$line" set albumrating "$rating" + done fi - ratingPrompt } rateTrack () { - artist="$(mpc current -f %artist%)" - album="$(mpc current -f %album%)" - if [[ "$mpd_artist" == "albumartist" ]]; then - albumartist="$(mpc current -f %albumartist%)" - elif [[ "$mpd_artist" == "artist" ]]; then - albumartist="$(mpc current -f %artist%)" - fi - date="$(mpc current -f %date%)" - title="$(mpc current -f %title%)" - tracknumber="$(mpc current -f %track%)" rating="$(seq $track_maxratings | dmenu_t -p "Select Rating: > ")" - date=$(escapeSql "$date") - artist=$(escapeSql "$artist") - album=$(escapeSql "$album") - directory=$(escapeSql "$directory") - rating=$(escapeSql "$rating") - title=$(escapeSql "$title") if [[ $rating == "" ]]; then exit else - cur_file="$(basename "$(mpc current -f %track%-%title%)")" - cd $HOME/.config/clerk/ratings - if [[ -a "$(mpc current -f %$mpd_artist%--%date%--%album%).ratings" ]]; then - echo "Ratings file present, using it" - else - echo "albumartist="$albumartist"" >> "$(mpc current -f %$mpd_artist%--%date%--%album%).ratings" - echo "album="$album"" >> "$(mpc current -f %$mpd_artist%--%date%--%album%).ratings" - echo "date="$date"" >> "$(mpc current -f %$mpd_artist%--%date%--%album%).ratings" - fi - if grep "$cur_file" "$(mpc current -f %$mpd_artist%--%date%--%album%).ratings" > /dev/null; then - sed -i "/$cur_file/d" "$(mpc current -f %$mpd_artist%--%date%--%album%).ratings" - echo "File already rated. Changing Rating..." - fi - echo "rating=${rating}/${track_maxratings} ${artist}--${tracknumber}--${title}" >> "$(mpc current -f %$mpd_artist%--%date%--%album%).ratings" - fi - if [[ "$music_dir_access" == "yes" ]]; then - cd "$music_path" - cd "$(dirname "$(mpc current -f %file%)")" - if [[ "$(pwd)" == */"$cd_divider"* ]]; then - cd .. + 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%")" >> track.ratings fi - cp $HOME/.config/clerk/ratings/"$(mpc current -f %$mpd_artist%--%date%--%album%).ratings" . - fi - cd $HOME/.config/clerk/ratings - notify-send "clerk" "Rated $(mpc current -f "%artist% - %title%") with $rating/$track_maxratings" - sqlite3 ../ratings.db "insert or replace into tracks (date, artist, album, title, tracknumber, rating) values ('$date', '$artist', '$album', '$title', '$tracknumber', '$rating')" ratingPrompt + fi } @@ -777,13 +735,14 @@ loadRatedTracks () { else cd $HOME/.config/clerk mpc clear - tracks="$(echo -e ".separator \" $seperator \"\nselect artist, album, date, \"title\" from tracks where rating = "$rating" order by artist;" | sqlite3 ratings.db)" + tracks="$(echo -e ".separator \" $seperator \"\nselect artist, date, album, tracknumber, \"title\" from tracks where rating = "$rating" order by artist;" | sqlite3 ratings.db)" echo "$tracks" | while read tracks; do artist=$(echo "$tracks" | awk -F " $seperator " '{ print $1 }') - album=$(echo "$tracks" | awk -F " $seperator " '{ print $2 }') - date=$(echo "$tracks" | awk -F " $seperator " '{ print $3 }') - title=$(echo "$tracks" | awk -F " $seperator " '{ print $4 }') - mpc find artist "$artist" album "$album" title "$title" date "$date" | shuf -n $value | mpc add + album=$(echo "$tracks" | awk -F " $seperator " '{ print $3 }') + date=$(echo "$tracks" | awk -F " $seperator " '{ print $2 }') + tracknumber=$(echo "$tracks" | awk -F " $seperator " '{ print $4 }') + title=$(echo "$tracks" | awk -F " $seperator " '{ print $5 }') + mpc find artist "$artist" album "$album" title "$title" track "$tracknumber" date "$date" | shuf -n $value | mpc add done mpc play fi @@ -797,16 +756,8 @@ loadRandomRatedTracks () { else cd $HOME/.config/clerk mpc clear - tracks="$(echo -e ".separator \" $seperator \"\nselect artist, album, date, title from tracks where rating >= "$rating";" | sqlite3 ratings.db)" - echo "$tracks" | while read tracks; do - touch /tmp/clerk_tracklist - artist=$(echo "$tracks" | awk -F " $seperator " '{ print $1 }') - album=$(echo "$tracks" | awk -F " $seperator " '{ print $2 }') - date=$(echo "$tracks" | awk -F " $seperator " '{ print $3 }') - title=$(echo "$tracks" | awk -F " $seperator " '{ print $4 }') - mppc find artist "$artist" album "$album" date "$date" title "$title" --format '{file}' >> /tmp/clerk_tracklist - done - cat /tmp/clerk_tracklist | shuf -n $number | mpc add + 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 @@ -1466,7 +1417,7 @@ elif [[ "$1" == "-rs" ]]; then elif [[ "$1" == "-show" ]]; then currentTag elif [[ "$1" == "-lrated" ]]; then - mpc clear && for ((i=4; i<="5"; i++)); do mpc find comment "$i" | shuf | head -n "$value" | mpc add; done && mpc play + mpc clear && mpc sticker / find rating | grep -E "rating=3|rating=4|rating=5" | awk -F ':' '{print $1}' | shuf -n $value | mpc add && mpc play elif [[ "$1" == "-library" ]]; then browseArtist elif [[ "$1" == "-update" ]]; then |