music.sh (2042B)
1 #!/usr/bin/env sh 2 3 # Music playing script 4 5 MUSIC_DIR="$HOME/Music" 6 FAVOURITES_DIR="$MUSIC_DIR/Favourites" 7 8 # Technically these first 4 are unnecessary, could just bind directly to the command 9 # but I like it all being in one file 10 if [ "$1" = "--toggle-pause" ]; then 11 mocp --toggle-pause 12 exit 13 elif [ "$1" = "--quit" ]; then 14 mocp --stop 15 exit 16 elif [ "$1" = "--next" ]; then 17 mocp --next 18 exit 19 elif [ "$1" = "--previous" ]; then 20 mocp --previous 21 exit 22 elif [ "$1" = "--favourite" ]; then 23 song="$(mocp -i | grep "File:" | sed 's/File: //g')" 24 echo "$song" | grep -q "CurrentPlaylist/" && exit 25 favourite_path="$(echo "$song" | sed "s|$MUSIC_DIR/||g")" 26 favourite_dir="$(dirname "$favourite_path")" 27 mkdir -p "$FAVOURITES_DIR/${favourite_dir}" 28 ln -sf "$song" "$FAVOURITES_DIR/${favourite_path}" 29 notify-send "Added to favourites" 30 exit 31 elif [ "$1" = "--get-song" ]; then 32 song="$(mocp -i 2> /dev/null | awk '/^Title:/ {S1 = ""; printf $0}')" 33 [ "$song" = "" ] && echo "None" && exit 34 echo "$song" 35 exit 36 fi 37 38 # Start mocp if not running, and set mode to shuffle 39 if ! pgrep mocp; then 40 mocp -S 41 mocp -t shuffle 42 fi 43 44 # If mocp is currently playing music, just notify-send the song title 45 if ! mocp -i | grep -q "State: STOP"; then 46 notify-send "$(mocp -i | grep "Title: " | sed 's/Title: //g')" 47 exit 48 fi 49 50 # Ask for playlist 51 playlist="$(ls "$MUSIC_DIR" | sed 's/\([A-Z][a-z]\)/ \1/g' | sed 's/\([a-z]\)\([0-9]\)/\1 \2/g' | sed 's/^ //g' | dmenu -p "Select Playlist:" -l 10)" 52 playlist_path="$MUSIC_DIR/$(echo "$playlist" | sed 's/ //g')" 53 54 # Check for sub playlists 55 if find "$playlist_path" -mindepth 1 -type d | grep -q ""; then 56 playlist="$(ls "$playlist_path" | sed 's/\([A-Z][a-z]\)/ \1/g' | sed 's/\([a-z]\)\([0-9]\)/\1 \2/g' | sed 's/^ //g' | awk 'BEGIN {RS = ""} {print "All Songs\n"$0}' | dmenu -p "Select Playlist:" -l 10)" 57 # If all songs, don't change playlist path 58 if ! [ "$playlist" = "All Songs" ]; then 59 playlist_path="$playlist_path/$(echo "$playlist" | sed 's/ //g')" 60 fi 61 fi 62 63 mocp --clear 64 mocp --append "$playlist_path" 65 mocp --play