Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- #####################################################################
- ####### G15 Amarok Plugin Plus v1.0 (released under GPL 2.0) ########
- #####################################################################
- # Author: Robert Riemann #
- # Report bugs and requests to: robert.riemann@physik.hu-berlin.de #
- # Requires: g15composer, amarok with dcop #
- #####################################################################
- # The script shows the meta info to the actual track of amarok #
- # meta infos on screen: title, artist, album, current-/total-time, #
- # rating, bitrate and filetype #
- #####################################################################
- # Check installation of g15composer
- if [ -z $(which g15composer) ]; then
- echo 'g15composer could not be found. Aborting.'
- exit 1
- fi
- # Read Options
- while getopts ":hp:s:" opt; do
- case $opt in
- p ) if [ -p $opt ]; then
- pipe=$OPTARG
- else
- echo "$opt wasn't found or is no pipe. Aborting."
- exit 1
- fi;;
- s ) if [ -n $OPTARG ]; then
- speed=$OPTARG
- else
- echo "Speed has to be a positive number (real). Aborting."
- exit 1
- fi;;
- ? ) echo -e 'Usage:\tamarok_script_plus.sh [-h] [-p Pipe] [-s speed]'
- echo -e '\t-h : Print this help'
- echo -e '\t-p : Sets pipe to use (default: /tmp/g15amarokpluginplus'
- echo -e '\t-s : Set speed to refresh the screen (in seconds, values like 0.5 are possible)'
- exit 1;;
- esac
- done
- # Set standard values for pipe ( /tmp/g15amarokpluginplus ) and speed ( 1 second )
- pipe=${pipe:-'/tmp/g15amarokpluginplus'}
- speed=${speed:-1}
- # Check for an already running g15composer with our pipe - Normally there is'nt one
- composer_pid=$(pgrep -f -x "g15composer $pipe")
- if [ -z $composer_pid ]; then
- g15composer $pipe & composer_pid=$!
- fi
- echo "g15composer - PID: $composer_pid"
- # Get control about the signals to stop the g15composer and remove the pipe
- trap "kill $composer_pid; rm $pipe; exit" HUP INT QUIT FPE KILL TERM
- # Startposition for scrolling the title/band/album
- post="0"
- posb="0"
- posa="0"
- # Counts time for showing volume change message
- timer="0"
- # volume change message will be shown screentimes times. ex.: 3 seconds / 1 seconds -> 3 times. ex.: 2 / 0.3 -> 6
- screentime=$(echo "3/$speed"| bc)
- # Main loop, which refreshs every speed seconds the screen
- while true; do
- read -t $speed amarok_stdin
- amarok_stdin_last=${amarok_stdin:-$amarok_stdin_last}
- # Shows the volume change message
- if [ $(($timer)) -gt 0 ] || [ "${amarok_stdin%:*}" = "volumeChange" ]; then
- if [ $(( $timer )) -gt 0 ] && [ $(( $timer )) -lt $(( $screentime )) ]; then
- timer=$(( $timer - 1 ))
- else
- timer=$(( $screentime - 1 ))
- fi
- cat > $pipe << EOF # Reads the following lines up to EOF and sends it to our pipe
- MC 1
- PB 0 0 159 42
- TO 1 2 2 1 "Volume"
- DB 10 20 149 30 1 ${amarok_stdin_last#* } 100 2
- TO 1 32 2 1 "${amarok_stdin_last#* }%"
- MC 0
- EOF
- # Show the meta infos if amarok is'nt stopped
- elif [ $(dcop amarok player status) != 0 ]; then
- # Prepares the scrolling of title, artist/band and album
- title=$(dcop amarok player title)
- if [ ${#title} -gt 16 ] && [ $((${#title} - $post)) -gt 0 ] && [ "$title" = "$titlelast" ]; then
- post=$((post + 1)); else post="0"; fi; titlelast=$title
- artist=$(dcop amarok player artist)
- if [ ${#artist} -gt 16 ] && [ $((${#artist} - $posb)) -gt 0 ] && [ "$artist" = "$artistlast" ]; then
- posb=$((posb + 1)); else posb="0"; fi; artistlast=$artist
- album=$(dcop amarok player album)
- if [ ${#album} -gt 16 ] && [ $((${#album} - $posa)) -gt 0 ] && [ "$album" = "$albumlast" ]; then
- posa=$((posa + 1)); else posa="0"; fi; albumlast=$album
- rating=$(dcop amarok player rating)
- bitrate=$(dcop amarok player bitrate)
- cat > $pipe << EOF # Reads the following lines up to EOF and sends it to our pipe
- MC 1
- TO 2 2 1 0 "Piste "
- TO 31 2 2 0 "${title:$post:16}"
- DB 0 11 159 11 1 $(dcop amarok player trackCurrentTime) $(dcop amarok player trackTotalTime) 1
- TO 2 15 1 0 "Groupe "
- TO 31 15 2 0 "${artist:$posb:16}"
- TO 2 24 1 0 "Album "
- TO 31 24 2 0 "${album:$posa:16}"
- DL 1 32 158 32 1
- TO 2 34 1 0 "$(dcop amarok player currentTime)/$(dcop amarok player totalTime)"
- #TO 2 34 1 1 "rating:$(printf "%2d" $rating)"
- TO 2 34 1 2 "$(dcop amarok player type)${bitrate:+"/($bitrate)"}"
- PB 0 0 159 42
- MC 0
- EOF
- # Shows the amarok stopped status screen
- else
- cat > $pipe << EOF # Reads the following lines up to EOF and sends it to our pipe
- MC 1
- PB 0 0 159 42
- TO 1 2 2 1 "Pas de Lecture"
- MC 0
- EOF
- fi
- unset amarok_stdin
- done
Add Comment
Please, Sign In to add comment