cover-feh-mpd.sh 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. #!/bin/env bash
  2. set -euo pipefail # bash strict mode
  3. # https://github.com/zoefiri/mpdvis
  4. musicdir="/home/zoe/music" #set this to your MPD music dir
  5. displaysize="300x300" #size of albumart window
  6. trap "kill $$" SIGINT
  7. ############
  8. #extract art
  9. extract(){
  10. rm /tmp/albumart.png
  11. song=$(mpc -f %file% | head -1)
  12. ffmpeg -i "$musicdir/$song" /tmp/albumart.png
  13. mv /tmp/albumart.png /tmp/albumart
  14. }
  15. redraw(){
  16. clear
  17. echo -ne "\033[9999B"
  18. }
  19. dlimg(){
  20. mkdir /tmp/gimages
  21. rm /tmp/gimages/*
  22. google_images_download -n -k "$1" -o /tmp/gimages -l 15
  23. }
  24. display(){
  25. source "$(ueberzug library)"
  26. ImageLayer 0< <(
  27. ImageLayer::add [identifier]="example0" [x]="1" [y]="1" [width]="$(($cols/2))" [path]="$1"
  28. ImageLayer::remove [identifier]="example0"
  29. sleep 5
  30. )
  31. }
  32. if [ "$1" = "dl" ]
  33. then
  34. if [ ! -f /bin/ueberzug ] ; then echo ueberzug is not installed!
  35. else
  36. cols=$(tput cols)
  37. source "$(ueberzug library)"
  38. song=$(mpc -f "%file%" | head -1 | cut -d '/' -f 1)
  39. album=$(mpc -f "%artist% %album%" | head -1)
  40. redraw
  41. dlimg "$album album art"
  42. for FILE in /tmp/gimages/*
  43. do
  44. printf "n + next image\ns + select image as new albumart\nq + quit\n\e[1m>\e[0m "
  45. ImageLayer 0< <( ImageLayer::add [identifier]="albumart" [x]="1" [y]="1" [width]="$(($cols/2))" [path]="$FILE" 2>/dev/null
  46. read -r option
  47. echo $option > /tmp/option
  48. ImageLayer::remove [identifier]="albumart") 2>/dev/null
  49. read -r option < /tmp/option
  50. echo $option
  51. [ "$option" = "q" ] && echo fuck && exit
  52. [ "$option" = "s" ] && echo fuck && cp "$FILE" "$musicdir/$song" && exit
  53. echo $option
  54. echo FUCK
  55. redraw
  56. done
  57. exit
  58. fi
  59. fi
  60. #################
  61. #display albumart
  62. [[ -f /tmp/albumart ]] && feh -B black -R 2 --scale-down --g "$displaysize" /tmp/albumart &
  63. [[ -f /tmp/albumart ]] && disown %1
  64. for pid in $(ps -ef | grep "mpdvis" | awk '{print $2}')
  65. do
  66. [ "$pid" != $$ ] && kill $pid
  67. done
  68. #################
  69. #if ran with 0 arg, put current album art into /tmp/albumart
  70. while true
  71. do
  72. songdir=$(mpc -f %file% | head -1 | cut -d '/' -f 1)
  73. if [ -f "$musicdir/$songdir/"*".png" ]
  74. then
  75. rm /tmp/albumart
  76. ln -s "$musicdir"/"${songdir%%/*}"/*.png /tmp/albumart
  77. fi
  78. if [ -f "/home/zoe/music/$songdir/"*".jpg" ]
  79. then
  80. rm /tmp/albumart
  81. ln -s "$musicdir"/"${songdir%%/*}"/*.jpg /tmp/albumart
  82. else
  83. extract
  84. fi
  85. mpc current --wait
  86. done