Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/ruby
- old_song = ""
- old_status=""
- `mkdir ~/.cover`
- while true
- sleep 2
- current_status = `mpc status | tail -n 2 | head -n 1`.match(/\[([^\]]*)\]/).to_s
- current_song = `mpc current`.chomp
- if current_song != old_song && current_status == "[playing]"
- #delete temp contents
- `rm ~/.cover/*`
- old_song = current_song
- current_song = File.join(`echo -n $HOME`,"/Music/", `mpc --format %file% | head -n 1`.chomp)
- current_path = File.dirname(current_song)
- #if cover file
- if `find "#{current_path}" -iname cover\*`!=""
- cover =`find "#{current_path}" -iname cover\* | head -n 1`.chomp
- #if embed cover
- else
- `ffmpeg -i "#{current_song}" ~/.cover/FRONT_COVER.jpeg`
- cover = File.join(`echo -n $HOME`,"/.cover/FRONT_COVER.jpeg")
- end
- #No idea how to solve this, previous image gets cached. Need a random filename
- random = (0...50).map { ('a'..'z').to_a[rand(26)] }.join
- `convert "#{cover}" -resize 80x80 ~/.cover/#{random}.png`
- #sending notification
- cover = "~/.cover/#{random}.png"
- title = `mpc current -f %title%`.chomp
- artist = `mpc current -f %artist%`.chomp
- album = `mpc current -f %album%`.chomp
- duration = `mpc current -f %time%`.chomp
- sleep 0.3
- `notify-send "\n#{title}" "#{artist} - #{album}\n\n#{duration}" -i #{cover} --hint int:transient:1`
- end
- #pause/resume notification
- if current_status != old_status
- old_status = current_status
- puts current_status
- if current_status == "[playing]"
- `notify-send "\n#{title}" "#{artist} - #{album}\n\n#{duration}" -i #{cover} --hint int:transient:1`
- end
- end
- end
Add Comment
Please, Sign In to add comment