Guest User

Untitled

a guest
Jan 5th, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 1.57 KB | None | 0 0
  1. #!/usr/bin/ruby
  2. old_song = ""
  3. old_status=""
  4. `mkdir ~/.cover`
  5. while true
  6.     sleep 2
  7.     current_status = `mpc status | tail -n 2 | head -n 1`.match(/\[([^\]]*)\]/).to_s
  8.     current_song = `mpc current`.chomp
  9.  
  10.     if current_song != old_song && current_status == "[playing]"
  11.         #delete temp contents
  12.         `rm ~/.cover/*`
  13.         old_song = current_song
  14.         current_song = File.join(`echo -n $HOME`,"/Music/", `mpc --format %file% | head -n 1`.chomp)
  15.         current_path = File.dirname(current_song)
  16.         #if cover file
  17.         if `find "#{current_path}" -iname cover\*`!=""
  18.  
  19.             cover =`find "#{current_path}" -iname cover\* | head -n 1`.chomp
  20.         #if embed cover
  21.         else
  22.         `ffmpeg -i "#{current_song}" ~/.cover/FRONT_COVER.jpeg`
  23.         cover = File.join(`echo -n $HOME`,"/.cover/FRONT_COVER.jpeg")
  24.         end
  25.     #No idea how to solve this, previous image gets cached. Need a random filename
  26.     random = (0...50).map { ('a'..'z').to_a[rand(26)] }.join
  27.     `convert "#{cover}" -resize 80x80 ~/.cover/#{random}.png`
  28.     #sending notification
  29.     cover = "~/.cover/#{random}.png"
  30.     title = `mpc current -f %title%`.chomp
  31.     artist = `mpc current -f %artist%`.chomp
  32.     album = `mpc current -f %album%`.chomp
  33.     duration = `mpc current -f %time%`.chomp
  34.     sleep 0.3
  35.  
  36.     `notify-send "\n#{title}" "#{artist} - #{album}\n\n#{duration}" -i #{cover} --hint int:transient:1`
  37.     end
  38.     #pause/resume notification
  39.     if current_status != old_status
  40.         old_status = current_status
  41.         puts current_status
  42.         if current_status == "[playing]"
  43.             `notify-send "\n#{title}" "#{artist} - #{album}\n\n#{duration}" -i #{cover} --hint int:transient:1`
  44.         end
  45.     end
  46.  
  47.  
  48. end
Add Comment
Please, Sign In to add comment