Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
209 changes: 105 additions & 104 deletions rofi-mpd
Original file line number Diff line number Diff line change
Expand Up @@ -6,132 +6,133 @@ ESC_ACTION="break"
# source configuration file for rofi if exists

ROFI="rofi -dmenu -p 'Search:'"
PORT="6600"

addaftercurrent(){

#playlist is empty, just add the song
if [ "$(mpc -p 6601 playlist | wc -l)" == "0" ]; then
mpc -p 6601 add "$1"
if [ "$(mpc -p $PORT playlist | wc -l)" == "0" ]; then
mpc -p $PORT add "$1"

#there is no current song so mpd is stopped
#it seems to be impossible to determine the current songs' position when
#it seems to be impossible to determine the current songs' position when
#mpd is stopped, so just add to the end
elif [ -z "$(mpc -p 6601 current)" ]; then
mpc -p 6601 play
CUR_POS=$(mpc -p 6601 | tail -2 | head -1 | awk '{print $2}' | sed 's/#//' | awk -F/ '{print $1}')
END_POS=$(mpc -p 6601 playlist | wc -l)
mpc -p 6601 add "$1"
mpc -p 6601 move $(($END_POS+1)) $(($CUR_POS+1))
mpc -p 6601 stop

#at least 1 song is in the playlist, determine the position of the
elif [ -z "$(mpc -p $PORT current)" ]; then
mpc -p $PORT play
CUR_POS=$(mpc -p $PORT | tail -2 | head -1 | awk '{print $2}' | sed 's/#//' | awk -F/ '{print $1}')
END_POS=$(mpc -p $PORT playlist | wc -l)
mpc -p $PORT add "$1"
mpc -p $PORT move $(($END_POS+1)) $(($CUR_POS+1))
mpc -p $PORT stop

#at least 1 song is in the playlist, determine the position of the
#currently played song and add $1 after it
else

CUR_POS=$(mpc -p 6601 | tail -2 | head -1 | awk '{print $2}' | sed 's/#//' | awk -F/ '{print $1}')
END_POS=$(mpc -p 6601 playlist | wc -l)
mpc -p 6601 add "$1"
mpc -p 6601 move $(($END_POS+1)) $(($CUR_POS+1))
CUR_POS=$(mpc -p $PORT | tail -2 | head -1 | awk '{print $2}' | sed 's/#//' | awk -F/ '{print $1}')
END_POS=$(mpc -p $PORT playlist | wc -l)
mpc -p $PORT add "$1"
mpc -p $PORT move $(($END_POS+1)) $(($CUR_POS+1))
fi
}
addaftercurrentandplay(){

#playlist is empty, just add the song
if [ "$(mpc -p 6601 playlist | wc -l)" == "0" ]; then
mpc -p 6601 add "$1"
mpc -p 6601 play
if [ "$(mpc -p $PORT playlist | wc -l)" == "0" ]; then
mpc -p $PORT add "$1"
mpc -p $PORT play

#there is no current song so mpd is stopped
#it seems to be impossible to determine the current songs' position when
#it seems to be impossible to determine the current songs' position when
#mpd is stopped, so just add to the end
elif [ -z "$(mpc -p 6601 current)" ]; then
mpc -p 6601play
CUR_POS=$(mpc -p 6601 | tail -2 | head -1 | awk '{print $2}' | sed 's/#//' | awk -F/ '{print $1}')
END_POS=$(mpc -p 6601 playlist | wc -l)
mpc -p 6601 add "$1"
mpc -p 6601 move $(($END_POS+1)) $(($CUR_POS+1))
mpc -p 6601 play $(($CUR_POS+1))

#at least 1 song is in the playlist, determine the position of the
elif [ -z "$(mpc -p $PORT current)" ]; then
mpc -p $PORTplay
CUR_POS=$(mpc -p $PORT | tail -2 | head -1 | awk '{print $2}' | sed 's/#//' | awk -F/ '{print $1}')
END_POS=$(mpc -p $PORT playlist | wc -l)
mpc -p $PORT add "$1"
mpc -p $PORT move $(($END_POS+1)) $(($CUR_POS+1))
mpc -p $PORT play $(($CUR_POS+1))

#at least 1 song is in the playlist, determine the position of the
#currently played song and add $1 after it
else

CUR_POS=$(mpc -p 6601 | tail -2 | head -1 | awk '{print $2}' | sed 's/#//' | awk -F/ '{print $1}')
END_POS=$(mpc -p 6601 playlist | wc -l)
mpc -p 6601 add "$1"
mpc -p 6601 move $(($END_POS+1)) $(($CUR_POS+1))
mpc -p 6601 play $(($CUR_POS+1))
CUR_POS=$(mpc -p $PORT | tail -2 | head -1 | awk '{print $2}' | sed 's/#//' | awk -F/ '{print $1}')
END_POS=$(mpc -p $PORT playlist | wc -l)
mpc -p $PORT add "$1"
mpc -p $PORT move $(($END_POS+1)) $(($CUR_POS+1))
mpc -p $PORT play $(($CUR_POS+1))
fi
}

case $1 in

-a|--artist)

while true; do

ARTIST="$(mpc -p 6601 list artist | sort -f | $ROFI)";
ARTIST="$(mpc -p $PORT list artist | sort -f | $ROFI)";
if [ "$ARTIST" = "" ]; then $ESC_ACTION; fi

while true; do

ALBUMS=$(mpc -p 6601 list album artist "$ARTIST" | sort -f);
ALBUMS=$(mpc -p $PORT list album artist "$ARTIST" | sort -f);
ALBUM=$(echo -e "replace all\nadd all\n--------------------------\n$ALBUMS" | $ROFI);
if [ "$ALBUM" = "" ]; then $ESC_ACTION;

elif [ "$ALBUM" = "replace all" ]; then
CUR_SONG=$(mpc -p 6601 current)
mpc -p 6601 clear
mpc -p 6601 find artist "$ARTIST" | mpc -p 6601 add
if [ -n "$CUR_SONG" ]; then mpc -p 6601 play; fi
CUR_SONG=$(mpc -p $PORT current)
mpc -p $PORT clear
mpc -p $PORT find artist "$ARTIST" | mpc -p $PORT add
if [ -n "$CUR_SONG" ]; then mpc -p $PORT play; fi
$ESC_ACTION
elif [ "$ALBUM" = "add all" ]; then
mpc -p 6601 find artist "$ARTIST" | mpc -p 6601 add
elif [ "$ALBUM" = "add all" ]; then
mpc -p $PORT find artist "$ARTIST" | mpc -p $PORT add
$ESC_ACTION
fi

while true; do
TITLES=$(mpc -p 6601 list title artist "$ARTIST" album "$ALBUM")

TITLES=$(mpc -p $PORT list title artist "$ARTIST" album "$ALBUM")
TITLE=$(echo -e "replace all\nadd all\n--------------------------\n$TITLES" | $ROFI);
if [ "$TITLE" = "" ]; then $ESC_ACTION
elif [ "$TITLE" = "replace all" ]; then
CUR_SONG=$(mpc -p 6601 current)
mpc -p 6601 clear;
mpc -p 6601 find artist "$ARTIST" album "$ALBUM" | mpc -p 6601 add
if [ -n "$CUR_SONG" ]; then mpc -p 6601 play; fi
CUR_SONG=$(mpc -p $PORT current)
mpc -p $PORT clear;
mpc -p $PORT find artist "$ARTIST" album "$ALBUM" | mpc -p $PORT add
if [ -n "$CUR_SONG" ]; then mpc -p $PORT play; fi
$ESC_ACTION
elif [ "$TITLE" = "add all" ]; then
mpc -p 6601 find artist "$ARTIST" album "$ALBUM" | mpc -p 6601 add
mpc -p $PORT find artist "$ARTIST" album "$ALBUM" | mpc -p $PORT add
$ESC_ACTION

fi

while true; do
DEC=$(echo -e "add after current and play\nadd after current\nreplace\nadd at the end" | $ROFI);
case $DEC in
case $DEC in

"")
$ESC_ACTION
;;

"add after current and play")
addaftercurrentandplay "$(mpc -p 6601 find artist "$ARTIST" album "$ALBUM" title "$TITLE" | head -1 )"
addaftercurrentandplay "$(mpc -p $PORT find artist "$ARTIST" album "$ALBUM" title "$TITLE" | head -1 )"
;;

"add after current")
addaftercurrent "$(mpc -p 6601 find artist "$ARTIST" album "$ALBUM" title "$TITLE" | head -1 )"
addaftercurrent "$(mpc -p $PORT find artist "$ARTIST" album "$ALBUM" title "$TITLE" | head -1 )"
;;

"replace")
CUR_SONG=$(mpc -p 6601 current)
mpc -p 6601 clear
mpc -p 6601 find artist "$ARTIST" album "$ALBUM" title "$TITLE" | head -1 | mpc -p 6601 add
if [ -n "$CUR_SONG" ]; then mpc -p 6601 play; fi
CUR_SONG=$(mpc -p $PORT current)
mpc -p $PORT clear
mpc -p $PORT find artist "$ARTIST" album "$ALBUM" title "$TITLE" | head -1 | mpc -p $PORT add
if [ -n "$CUR_SONG" ]; then mpc -p $PORT play; fi
;;

"add at the end")
mpc -p 6601 find artist "$ARTIST" album "$ALBUM" title "$TITLE" | head -1 | mpc -p 6601 add
mpc -p $PORT find artist "$ARTIST" album "$ALBUM" title "$TITLE" | head -1 | mpc -p $PORT add
;;

esac
Expand All @@ -143,81 +144,81 @@ case $1 in
;;

-t|--track)
TITLE=$(mpc -p 6601 list title | sort -f | $ROFI)

TITLE=$(mpc -p $PORT list title | sort -f | $ROFI)
if [ "$TITLE" = "" ]; then exit; fi
SONG=$(mpc -p 6601 find title "$TITLE" | head -1)

SONG=$(mpc -p $PORT find title "$TITLE" | head -1)
addaftercurrentandplay "$SONG"
;;

-p|--playlist)
PLAYLIST=$(mpc -p 6601 lsplaylists | $ROFI);
PLAYLIST=$(mpc -p $PORT lsplaylists | $ROFI);
if [ "$PLAYLIST" = "" ]; then exit; fi
CUR_SONG=$(mpc -p 6601 current)
mpc -p 6601 clear
mpc -p 6601 load "$PLAYLIST";
if [ -n "$CUR_SONG" ]; then mpc -p 6601 play; fi
CUR_SONG=$(mpc -p $PORT current)
mpc -p $PORT clear
mpc -p $PORT load "$PLAYLIST";
if [ -n "$CUR_SONG" ]; then mpc -p $PORT play; fi
;;

-j|--jump)
TITLE=$(mpc -p 6601 playlist | $ROFI);

TITLE=$(mpc -p $PORT playlist | $ROFI);
if [ "$TITLE" = "" ]; then exit; fi
POS=$(mpc -p 6601 playlist | grep -n "$TITLE" | awk -F: '{print $1}')
mpc -p 6601 play $POS;
POS=$(mpc -p $PORT playlist | grep -Fn "$TITLE" | awk -F: '{print $1}')
mpc -p $PORT play $POS;
;;

-l|--longplayer)

while true; do

ALBUM=$(mpc -p 6601 list album | sort -f | $ROFI);
ALBUM=$(mpc -p $PORT list album | sort -f | $ROFI);
if [ "$ALBUM" = "" ]; then $ESC_ACTION;
fi

while true; do
TITLES=$(mpc -p 6601 list title album "$ALBUM")

TITLES=$(mpc -p $PORT list title album "$ALBUM")
TITLE=$(echo -e "replace all\nadd all\n--------------------------\n$TITLES" | $ROFI);
if [ "$TITLE" = "" ]; then $ESC_ACTION
elif [ "$TITLE" = "replace all" ]; then
CUR_SONG=$(mpc -p 6601 current)
mpc -p 6601 clear;
mpc -p 6601 find album "$ALBUM" | mpc -p 6601 add
if [ -n "$CUR_SONG" ]; then mpc -p 6601 play; fi
CUR_SONG=$(mpc -p $PORT current)
mpc -p $PORT clear;
mpc -p $PORT find album "$ALBUM" | mpc -p $PORT add
if [ -n "$CUR_SONG" ]; then mpc -p $PORT play; fi
$ESC_ACTION
elif [ "$TITLE" = "add all" ]; then
mpc -p 6601 find album "$ALBUM" | mpc -p 6601 add
mpc -p $PORT find album "$ALBUM" | mpc -p $PORT add
$ESC_ACTION

fi

while true; do
DEC=$(echo -e "add after current and play\nadd after current\nreplace\nadd at the end" | $ROFI);
case $DEC in
case $DEC in

"")
$ESC_ACTION
;;

"add after current and play")
addaftercurrentandplay "$(mpc -p 6601 find album "$ALBUM" title "$TITLE" | head -1 )"
addaftercurrentandplay "$(mpc -p $PORT find album "$ALBUM" title "$TITLE" | head -1 )"
;;

"add after current")
addaftercurrent "$(mpc -p 6601 find album "$ALBUM" title "$TITLE" | head -1 )"
addaftercurrent "$(mpc -p $PORT find album "$ALBUM" title "$TITLE" | head -1 )"
;;

"replace")
CUR_SONG=$(mpc -p 6601 current)
mpc -p 6601 clear
mpc -p 6601 find album "$ALBUM" title "$TITLE" | head -1 | mpc -p 6601 add
if [ -n "$CUR_SONG" ]; then mpc -p 6601 play; fi
CUR_SONG=$(mpc -p $PORT current)
mpc -p $PORT clear
mpc -p $PORT find album "$ALBUM" title "$TITLE" | head -1 | mpc -p $PORT add
if [ -n "$CUR_SONG" ]; then mpc -p $PORT play; fi
;;

"add at the end")
mpc -p 6601 find album "$ALBUM" title "$TITLE" | head -1 | mpc -p 6601 add
mpc -p $PORT find album "$ALBUM" title "$TITLE" | head -1 | mpc -p $PORT add
;;

esac
Expand All @@ -231,14 +232,14 @@ case $1 in
echo "-a, --artist search for artist, then album, then title"
echo "-t, --track search for a single track in the whole database"
echo "-p, --playlist search for a playlist load it"
echo "-j, --jump jump to another song in the current playlist"
echo "-j, --jump jump to another song in the current playlist"
echo "-l, --longplayer search for album, then title"




;;

*)
echo "Usage: rofi-mpd [OPTION]"
echo "Try 'rofi-mpd --help' for more information."
Expand Down