Guest User

cover.sh

a guest
Jan 7th, 2013
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.79 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. #Grep player info
  4.  
  5. PLAYER=$(qdbus | grep -m1 org.mpris.[^M])
  6.  
  7. META=$(qdbus $PLAYER /Player org.freedesktop.MediaPlayer.GetMetadata)
  8. TITLE=$(echo "$META" | grep title)
  9. TITLE=${TITLE:7}
  10. ARTIST=$(echo "$META" | grep artist)
  11. ARTIST=${ARTIST:8}
  12. STATE=$(qdbus --literal $PLAYER /Player GetStatus)
  13. STATE=${STATE:18:1}
  14. COVER=$(echo "$META" /Player GetMetadata | grep arturl )
  15. ART=${COVER:15}
  16. SPATH=${ART%/*}
  17. IMAGE=${COVER##*/}
  18. LENGHT=${#TITLE}
  19.  
  20. #Defining icon and text size/alignment
  21.  
  22. if [ "$LENGHT" > "15" ]; then
  23. TITLE="${TITLE:0:9}..."
  24. elif [ "$LENGHT" > "20" ]; then
  25. TITLE="...${TITLE:10:9}"
  26. fi
  27.  
  28. ICON_SIZE=150
  29. TEXT_ALIGN="center"
  30.  
  31. #Control buttons
  32.  
  33.  
  34. #PAUSE="<a href=\"`$exec qdbus org.mpris.clementine /Player org.freedesktop.MediaPlayer.Pause`\">Pause</a>"
  35. #PREV="<a href=\"`$exec qdbus org.mpris.clementine /Player org.freedesktop.MediaPlayer.Prev`\">Prev</a>"
  36. #NEXT="<a href=\"`$exec qdbus org.mpris.clementine /Player org.freedesktop.MediaPlayer.Next`\">Next</a>"
  37.  
  38.  
  39. #Path to the icon
  40.  
  41. icon()
  42. {
  43. ICON="${SPATH}/${IMAGE}"
  44. echo $ICON
  45. }
  46.  
  47. #The css code part
  48.  
  49.  
  50. fontstyle()
  51. {
  52.  
  53. BORDER="border: solid #B4C1D3 1px;"
  54. BACKGROUND="background: #D7DDE6;"
  55. FONTSIZE="font-size: 7.5pt;"
  56. FONTFAMILY="font-family: consolas;"
  57. FDECO="text-decoration:none;"
  58. FONTCOLOR="/*color:silver;*/"
  59. FSTYLE=$(echo "$BORDER $BACKGROUND $FONTSIZE $FONTFAMILY $FDECO $FONTCOLOR")
  60. echo $FSTYLE
  61.  
  62. }
  63.  
  64. imagestyle()
  65. {
  66.  
  67. IBORDER="/*border:1px solid black;*/"
  68. MARGIN="margin:0px;"
  69. PADDING="padding:5px;"
  70. WIDTH="width:300px;"
  71. FLOAT="float:right;"
  72. IMGSTYLE=$(echo "$IBORDER $MARGIN $PADDING $WIDTH $FLOAT")
  73. echo $IMGSTYLE
  74.  
  75. }
  76.  
  77. IMGSTYLE="$(imagestyle $code)"
  78. FSTYLE="$(fontstyle $code)"
  79.  
  80.  
  81. #State plus visualization in the shell
  82.  
  83. if [ "${STATE%,}" == "1" ]; then
  84. ICON="$(icon $code)"
  85. TEXT=$(echo -n ${TEXT} - pausa -)
  86. REPLY="${REPLY}<td>"
  87.  
  88. elif [ "${STATE%,}" == "2" ]; then
  89. ICON="$(icon $code)"
  90. TEXT=$(echo -n ${TEXT} stop)
  91. REPLY="${REPLY}<td>"
  92.  
  93. elif [ "${STATE%,}" == "0" ]; then
  94. ICON="$(icon $code)"
  95. TEXT=$(echo -n ${TEXT} - Sto eseguendo -)
  96. REPLY="${REPLY}<td>"
  97.  
  98. elif [ "${STATE%,}" == "0" ]; then
  99. ICON="$(icon $code)"
  100. TEXT=$(echo -n ${TEXT}" "$TEXT )
  101. REPLY="${REPLY}<td>"
  102.  
  103. fi
  104.  
  105. #The html/css final output
  106.  
  107. #REPLY="${REPLY}<div align=\"${TEXT_ALIGN}\"style=\"${FSTYLE} \">${PREV}&nbsp;${PAUSE}&nbsp;${NEXT}</td>"
  108. REPLY="${REPLY}<div style=\"${IMGSTYLE}\"> <img src=\"${ICON}\" width=\"${ICON_SIZE}\"></td>"
  109. REPLY="${REPLY}<div align=\"${TEXT_ALIGN}\"style=\"${FSTYLE}\">${TEXT}</td>"
  110. REPLY="${REPLY}<div align=\"${TEXT_ALIGN}\"style=\"${FSTYLE}\">${TITLE}</td>"
  111. REPLY="${REPLY}<div align=\"${TEXT_ALIGN}\"style=\"${FSTYLE}\">${ARTIST}</td>"
  112. REPLY="${REPLY}</td>"
  113.  
  114. #Control visualization when player is opened/closed
  115.  
  116. if [ "$ICON" != "" ]; then
  117. echo "$REPLY"
  118. else
  119. return 0;
  120. fi
Advertisement
Add Comment
Please, Sign In to add comment