Advertisement
Guest User

Untitled

a guest
Jun 3rd, 2016
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. function extract_XML_value() {
  4. # $1 entity name
  5. # $2 string to find
  6. echo -n "$2" | egrep -o "<$1>[^<]+" | sed -e "s/<$1>//"
  7. }
  8.  
  9. artist=`mpc -f '%artist%' current | sed -e "s/\\ /+/g"`
  10. album=`mpc -f '%album%' current | sed -e "s/\\ /+/g"`
  11.  
  12. lastfm_key="5c74acc7a4b3db44a25e75ff8fc89543"
  13. url="ws.audioscrobbler.com"
  14. path="/2.0/?method=album.getinfo&api_key=$lastfm_key&artist=$artist&album=$album"
  15.  
  16. f_image_extralarge="$artist""_""$album""_""xl.png"
  17.  
  18. image_dir="/home/xqwutaitezr/music/covers"
  19.  
  20. function retrieve () {
  21. _ret=$(wget "$url$path" -O -)
  22.  
  23. mkdir -p $image_dir
  24. image_extralarge=$(extract_XML_value 'image size="extralarge"' "$_ret" 2>/dev/null)
  25.  
  26. [[ "$image_extralarge" != "" ]] && [[ ! -f "$image_dir/$f_image_extralarge" ]] && wget "$image_extralarge" -O "$image_dir/$f_image_extralarge" > /dev/null
  27. }
  28.  
  29. if [[ $(mpc status | grep "playing" | wc -l ) -gt 0 ]]
  30. then
  31. if [[ ! -f "$image_dir/$f_image_extralarge" ]]
  32. then
  33. retrieve
  34. fi
  35. ahoviewer $image_dir/$f_image_extralarge &
  36. fi
  37.  
  38. echo $f_image_extralarge
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement