-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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