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
145 changes: 73 additions & 72 deletions rofi-mpd
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -6,61 +6,62 @@ ESC_ACTION="break"
# source configuration file for rofi if exists

ROFI="rofi -dmenu -p 'Search:'"
MPDPORT=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 $MPDPORT playlist | wc -l)" == "0" ]; then
mpc -p $MPDPORT add "$1"

#there is no current song so mpd is stopped
#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
elif [ -z "$(mpc -p $MPDPORT current)" ]; then
mpc -p $MPDPORT play
CUR_POS=$(mpc -p $MPDPORT | tail -2 | head -1 | awk '{print $2}' | sed 's/#//' | awk -F/ '{print $1}')
END_POS=$(mpc -p $MPDPORT playlist | wc -l)
mpc -p $MPDPORT add "$1"
mpc -p $MPDPORT move $(($END_POS+1)) $(($CUR_POS+1))
mpc -p $MPDPORT 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 $MPDPORT | tail -2 | head -1 | awk '{print $2}' | sed 's/#//' | awk -F/ '{print $1}')
END_POS=$(mpc -p $MPDPORT playlist | wc -l)
mpc -p $MPDPORT add "$1"
mpc -p $MPDPORT 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 $MPDPORT playlist | wc -l)" == "0" ]; then
mpc -p $MPDPORT add "$1"
mpc -p $MPDPORT play

#there is no current song so mpd is stopped
#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))
elif [ -z "$(mpc -p $MPDPORT current)" ]; then
mpc -p $MPDPORTplay
CUR_POS=$(mpc -p $MPDPORT | tail -2 | head -1 | awk '{print $2}' | sed 's/#//' | awk -F/ '{print $1}')
END_POS=$(mpc -p $MPDPORT playlist | wc -l)
mpc -p $MPDPORT add "$1"
mpc -p $MPDPORT move $(($END_POS+1)) $(($CUR_POS+1))
mpc -p $MPDPORT 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 $MPDPORT | tail -2 | head -1 | awk '{print $2}' | sed 's/#//' | awk -F/ '{print $1}')
END_POS=$(mpc -p $MPDPORT playlist | wc -l)
mpc -p $MPDPORT add "$1"
mpc -p $MPDPORT move $(($END_POS+1)) $(($CUR_POS+1))
mpc -p $MPDPORT play $(($CUR_POS+1))
fi
}

Expand All @@ -70,39 +71,39 @@ case $1 in

while true; do

ARTIST="$(mpc -p 6601 list artist | sort -f | $ROFI)";
ARTIST="$(mpc 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 $MPDPORT 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 $MPDPORT current)
mpc -p $MPDPORT clear
mpc -p $MPDPORT find artist "$ARTIST" | mpc -p $MPDPORT add
if [ -n "$CUR_SONG" ]; then mpc -p $MPDPORT play; fi
$ESC_ACTION
elif [ "$ALBUM" = "add all" ]; then
mpc -p 6601 find artist "$ARTIST" | mpc -p 6601 add
mpc -p $MPDPORT find artist "$ARTIST" | mpc -p $MPDPORT add
$ESC_ACTION
fi

while true; do

TITLES=$(mpc -p 6601 list title artist "$ARTIST" album "$ALBUM")
TITLES=$(mpc -p $MPDPORT 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 $MPDPORT current)
mpc -p $MPDPORT clear;
mpc -p $MPDPORT find artist "$ARTIST" album "$ALBUM" | mpc -p $MPDPORT add
if [ -n "$CUR_SONG" ]; then mpc -p $MPDPORT play; fi
$ESC_ACTION
elif [ "$TITLE" = "add all" ]; then
mpc -p 6601 find artist "$ARTIST" album "$ALBUM" | mpc -p 6601 add
mpc -p $MPDPORT find artist "$ARTIST" album "$ALBUM" | mpc -p $MPDPORT add
$ESC_ACTION

fi
Expand All @@ -116,22 +117,22 @@ case $1 in
;;

"add after current and play")
addaftercurrentandplay "$(mpc -p 6601 find artist "$ARTIST" album "$ALBUM" title "$TITLE" | head -1 )"
addaftercurrentandplay "$(mpc -p $MPDPORT 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 $MPDPORT 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 $MPDPORT current)
mpc -p $MPDPORT clear
mpc -p $MPDPORT find artist "$ARTIST" album "$ALBUM" title "$TITLE" | head -1 | mpc -p $MPDPORT add
if [ -n "$CUR_SONG" ]; then mpc -p $MPDPORT play; fi
;;

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

esac
Expand All @@ -144,51 +145,51 @@ case $1 in

-t|--track)

TITLE=$(mpc -p 6601 list title | sort -f | $ROFI)
TITLE=$(mpc -p $MPDPORT list title | sort -f | $ROFI)
if [ "$TITLE" = "" ]; then exit; fi

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

-p|--playlist)
PLAYLIST=$(mpc -p 6601 lsplaylists | $ROFI);
PLAYLIST=$(mpc -p $MPDPORT 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 $MPDPORT current)
mpc -p $MPDPORT clear
mpc -p $MPDPORT load "$PLAYLIST";
if [ -n "$CUR_SONG" ]; then mpc -p $MPDPORT play; fi
;;

-j|--jump)

TITLE=$(mpc -p 6601 playlist | $ROFI);
TITLE=$(mpc -p $MPDPORT 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 $MPDPORT playlist | grep -n "$TITLE" | awk -F: '{print $1}')
mpc -p $MPDPORT play $POS;
;;

-l|--longplayer)

while true; do

ALBUM=$(mpc -p 6601 list album | sort -f | $ROFI);
ALBUM=$(mpc -p $MPDPORT 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 $MPDPORT 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 $MPDPORT current)
mpc -p $MPDPORT clear;
mpc -p $MPDPORT find album "$ALBUM" | mpc -p $MPDPORT add
if [ -n "$CUR_SONG" ]; then mpc -p $MPDPORT play; fi
$ESC_ACTION
elif [ "$TITLE" = "add all" ]; then
mpc -p 6601 find album "$ALBUM" | mpc -p 6601 add
mpc -p $MPDPORT find album "$ALBUM" | mpc -p $MPDPORT add
$ESC_ACTION

fi
Expand All @@ -202,22 +203,22 @@ case $1 in
;;

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

"add after current")
addaftercurrent "$(mpc -p 6601 find album "$ALBUM" title "$TITLE" | head -1 )"
addaftercurrent "$(mpc -p $MPDPORT 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 $MPDPORT current)
mpc -p $MPDPORT clear
mpc -p $MPDPORT find album "$ALBUM" title "$TITLE" | head -1 | mpc -p $MPDPORT add
if [ -n "$CUR_SONG" ]; then mpc -p $MPDPORT play; fi
;;

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

esac
Expand Down