Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- #Grep player info
- PLAYER=$(qdbus | grep -m1 org.mpris.[^M])
- META=$(qdbus $PLAYER /Player org.freedesktop.MediaPlayer.GetMetadata)
- TITLE=$(echo "$META" | grep title)
- TITLE=${TITLE:7}
- ARTIST=$(echo "$META" | grep artist)
- ARTIST=${ARTIST:8}
- STATE=$(qdbus --literal $PLAYER /Player GetStatus)
- STATE=${STATE:18:1}
- COVER=$(echo "$META" /Player GetMetadata | grep arturl )
- ART=${COVER:15}
- SPATH=${ART%/*}
- IMAGE=${COVER##*/}
- LENGHT=${#TITLE}
- #Defining icon and text size/alignment
- if [ "$LENGHT" > "15" ]; then
- TITLE="${TITLE:0:9}..."
- elif [ "$LENGHT" > "20" ]; then
- TITLE="...${TITLE:10:9}"
- fi
- ICON_SIZE=150
- TEXT_ALIGN="center"
- #Control buttons
- #PAUSE="<a href=\"`$exec qdbus org.mpris.clementine /Player org.freedesktop.MediaPlayer.Pause`\">Pause</a>"
- #PREV="<a href=\"`$exec qdbus org.mpris.clementine /Player org.freedesktop.MediaPlayer.Prev`\">Prev</a>"
- #NEXT="<a href=\"`$exec qdbus org.mpris.clementine /Player org.freedesktop.MediaPlayer.Next`\">Next</a>"
- #Path to the icon
- icon()
- {
- ICON="${SPATH}/${IMAGE}"
- echo $ICON
- }
- #The css code part
- fontstyle()
- {
- BORDER="border: solid #B4C1D3 1px;"
- BACKGROUND="background: #D7DDE6;"
- FONTSIZE="font-size: 7.5pt;"
- FONTFAMILY="font-family: consolas;"
- FDECO="text-decoration:none;"
- FONTCOLOR="/*color:silver;*/"
- FSTYLE=$(echo "$BORDER $BACKGROUND $FONTSIZE $FONTFAMILY $FDECO $FONTCOLOR")
- echo $FSTYLE
- }
- imagestyle()
- {
- IBORDER="/*border:1px solid black;*/"
- MARGIN="margin:0px;"
- PADDING="padding:5px;"
- WIDTH="width:300px;"
- FLOAT="float:right;"
- IMGSTYLE=$(echo "$IBORDER $MARGIN $PADDING $WIDTH $FLOAT")
- echo $IMGSTYLE
- }
- IMGSTYLE="$(imagestyle $code)"
- FSTYLE="$(fontstyle $code)"
- #State plus visualization in the shell
- if [ "${STATE%,}" == "1" ]; then
- ICON="$(icon $code)"
- TEXT=$(echo -n ${TEXT} - pausa -)
- REPLY="${REPLY}<td>"
- elif [ "${STATE%,}" == "2" ]; then
- ICON="$(icon $code)"
- TEXT=$(echo -n ${TEXT} stop)
- REPLY="${REPLY}<td>"
- elif [ "${STATE%,}" == "0" ]; then
- ICON="$(icon $code)"
- TEXT=$(echo -n ${TEXT} - Sto eseguendo -)
- REPLY="${REPLY}<td>"
- elif [ "${STATE%,}" == "0" ]; then
- ICON="$(icon $code)"
- TEXT=$(echo -n ${TEXT}" "$TEXT )
- REPLY="${REPLY}<td>"
- fi
- #The html/css final output
- #REPLY="${REPLY}<div align=\"${TEXT_ALIGN}\"style=\"${FSTYLE} \">${PREV} ${PAUSE} ${NEXT}</td>"
- REPLY="${REPLY}<div style=\"${IMGSTYLE}\"> <img src=\"${ICON}\" width=\"${ICON_SIZE}\"></td>"
- REPLY="${REPLY}<div align=\"${TEXT_ALIGN}\"style=\"${FSTYLE}\">${TEXT}</td>"
- REPLY="${REPLY}<div align=\"${TEXT_ALIGN}\"style=\"${FSTYLE}\">${TITLE}</td>"
- REPLY="${REPLY}<div align=\"${TEXT_ALIGN}\"style=\"${FSTYLE}\">${ARTIST}</td>"
- REPLY="${REPLY}</td>"
- #Control visualization when player is opened/closed
- if [ "$ICON" != "" ]; then
- echo "$REPLY"
- else
- return 0;
- fi
Advertisement
Add Comment
Please, Sign In to add comment