Guest User

Untitled

a guest
Feb 19th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.65 KB | None | 0 0
  1. #!/bin/bash
  2. #####################################################################
  3. ####### G15 Amarok Plugin Plus v1.0 (released under GPL 2.0) ########
  4. #####################################################################
  5. # Author: Robert Riemann #
  6. # Report bugs and requests to: robert.riemann@physik.hu-berlin.de #
  7. # Requires: g15composer, amarok with dcop #
  8. #####################################################################
  9. # The script shows the meta info to the actual track of amarok #
  10. # meta infos on screen: title, artist, album, current-/total-time, #
  11. # rating, bitrate and filetype #
  12. #####################################################################
  13.  
  14. # Check installation of g15composer
  15. if [ -z $(which g15composer) ]; then
  16. echo 'g15composer could not be found. Aborting.'
  17. exit 1
  18. fi
  19.  
  20. # Read Options
  21. while getopts ":hp:s:" opt; do
  22. case $opt in
  23. p ) if [ -p $opt ]; then
  24. pipe=$OPTARG
  25. else
  26. echo "$opt wasn't found or is no pipe. Aborting."
  27. exit 1
  28. fi;;
  29. s ) if [ -n $OPTARG ]; then
  30. speed=$OPTARG
  31. else
  32. echo "Speed has to be a positive number (real). Aborting."
  33. exit 1
  34. fi;;
  35. ? ) echo -e 'Usage:\tamarok_script_plus.sh [-h] [-p Pipe] [-s speed]'
  36. echo -e '\t-h : Print this help'
  37. echo -e '\t-p : Sets pipe to use (default: /tmp/g15amarokpluginplus'
  38. echo -e '\t-s : Set speed to refresh the screen (in seconds, values like 0.5 are possible)'
  39. exit 1;;
  40. esac
  41. done
  42.  
  43. # Set standard values for pipe ( /tmp/g15amarokpluginplus ) and speed ( 1 second )
  44. pipe=${pipe:-'/tmp/g15amarokpluginplus'}
  45. speed=${speed:-1}
  46.  
  47. # Check for an already running g15composer with our pipe - Normally there is'nt one
  48. composer_pid=$(pgrep -f -x "g15composer $pipe")
  49. if [ -z $composer_pid ]; then
  50. g15composer $pipe & composer_pid=$!
  51. fi
  52. echo "g15composer - PID: $composer_pid"
  53.  
  54. # Get control about the signals to stop the g15composer and remove the pipe
  55. trap "kill $composer_pid; rm $pipe; exit" HUP INT QUIT FPE KILL TERM
  56.  
  57. # Startposition for scrolling the title/band/album
  58. post="0"
  59. posb="0"
  60. posa="0"
  61.  
  62. # Counts time for showing volume change message
  63. timer="0"
  64.  
  65. # volume change message will be shown screentimes times. ex.: 3 seconds / 1 seconds -> 3 times. ex.: 2 / 0.3 -> 6
  66. screentime=$(echo "3/$speed"| bc)
  67.  
  68. # Main loop, which refreshs every speed seconds the screen
  69. while true; do
  70. read -t $speed amarok_stdin
  71. amarok_stdin_last=${amarok_stdin:-$amarok_stdin_last}
  72.  
  73. # Shows the volume change message
  74. if [ $(($timer)) -gt 0 ] || [ "${amarok_stdin%:*}" = "volumeChange" ]; then
  75. if [ $(( $timer )) -gt 0 ] && [ $(( $timer )) -lt $(( $screentime )) ]; then
  76. timer=$(( $timer - 1 ))
  77. else
  78. timer=$(( $screentime - 1 ))
  79. fi
  80. cat > $pipe << EOF # Reads the following lines up to EOF and sends it to our pipe
  81. MC 1
  82. PB 0 0 159 42
  83. TO 1 2 2 1 "Volume"
  84. DB 10 20 149 30 1 ${amarok_stdin_last#* } 100 2
  85. TO 1 32 2 1 "${amarok_stdin_last#* }%"
  86. MC 0
  87. EOF
  88.  
  89. # Show the meta infos if amarok is'nt stopped
  90. elif [ $(dcop amarok player status) != 0 ]; then
  91. # Prepares the scrolling of title, artist/band and album
  92. title=$(dcop amarok player title)
  93. if [ ${#title} -gt 16 ] && [ $((${#title} - $post)) -gt 0 ] && [ "$title" = "$titlelast" ]; then
  94. post=$((post + 1)); else post="0"; fi; titlelast=$title
  95. artist=$(dcop amarok player artist)
  96. if [ ${#artist} -gt 16 ] && [ $((${#artist} - $posb)) -gt 0 ] && [ "$artist" = "$artistlast" ]; then
  97. posb=$((posb + 1)); else posb="0"; fi; artistlast=$artist
  98. album=$(dcop amarok player album)
  99. if [ ${#album} -gt 16 ] && [ $((${#album} - $posa)) -gt 0 ] && [ "$album" = "$albumlast" ]; then
  100. posa=$((posa + 1)); else posa="0"; fi; albumlast=$album
  101.  
  102. rating=$(dcop amarok player rating)
  103. bitrate=$(dcop amarok player bitrate)
  104.  
  105. cat > $pipe << EOF # Reads the following lines up to EOF and sends it to our pipe
  106. MC 1
  107. TO 2 2 1 0 "Piste "
  108. TO 31 2 2 0 "${title:$post:16}"
  109. DB 0 11 159 11 1 $(dcop amarok player trackCurrentTime) $(dcop amarok player trackTotalTime) 1
  110. TO 2 15 1 0 "Groupe "
  111. TO 31 15 2 0 "${artist:$posb:16}"
  112. TO 2 24 1 0 "Album "
  113. TO 31 24 2 0 "${album:$posa:16}"
  114. DL 1 32 158 32 1
  115. TO 2 34 1 0 "$(dcop amarok player currentTime)/$(dcop amarok player totalTime)"
  116. #TO 2 34 1 1 "rating:$(printf "%2d" $rating)"
  117. TO 2 34 1 2 "$(dcop amarok player type)${bitrate:+"/($bitrate)"}"
  118. PB 0 0 159 42
  119. MC 0
  120. EOF
  121.  
  122. # Shows the amarok stopped status screen
  123. else
  124. cat > $pipe << EOF # Reads the following lines up to EOF and sends it to our pipe
  125. MC 1
  126. PB 0 0 159 42
  127. TO 1 2 2 1 "Pas de Lecture"
  128. MC 0
  129. EOF
  130. fi
  131. unset amarok_stdin
  132.  
  133. done
Add Comment
Please, Sign In to add comment