Skip to content

Instantly share code, notes, and snippets.

@KeenS
Last active December 21, 2015 12:58
Show Gist options
  • Save KeenS/6308894 to your computer and use it in GitHub Desktop.
Save KeenS/6308894 to your computer and use it in GitHub Desktop.
A script for playing BGM and notify the title of BGM now playing. You are to have `BGM.list` of a file which lists filenames you want to play in music directory.
#!/usr/bin/env ruby -Ku
# _*_ coding:UTF-8 _*_
require 'mplayer-ruby'
require 'libnotify'
class MPlayer::Slave
def now_playing
summary = ""
summary += get(:meta_title).chomp
summary += " -- " + get(:meta_artist).chomp
body = "NowPlaying"
Libnotify.show(body: body, summary: summary)
end
end
music = "/your/path/to/music/directory/"
playlist = File.read( music + "BGM.list").split("\n").map{|f| music + f }.shuffle
player = MPlayer::Slave.new playlist
player.loop
Signal.trap(:INT) {player.quit;exit}
Signal.trap(:KILL) {player.quit;exit}
player.now_playing
while line = player.stdout.gets
player.now_playing if line =~ /playback/
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment