#!/usr/local/bin/ruby # ライセンスは...えーとどうしよう # なんでもいいんだけど(^^; 面倒だからGPL2にしときましょうか。 # 何か問題がある場合は ashie@homa.ne.jp までお願いします。 require 'gtk' require 'kconv' ############################################################################### # # RecCommand class # ############################################################################### class RecCommand def str () return @command end def regist () month_hash = {"01" => "Jan", "02" => "Feb", "03" => "Mar", "04" => "Apr", "05" => "May", "06" => "Jun", "07" => "Jul", "08" => "Aug", "09" => "Sep", "10" => "Oct", "11" => "Nov", "12" => "Dec"} regist_command = "echo \'" + @command + "\' | at " + @reserve.rec_start if @reserve.year =~ /(\d\d)(\d\d)/ year = $2 end regist_command += " " + month_hash[@reserve.month] + " " + @reserve.date print regist_command, "\n" system (regist_command) end def exec () end def kill () end end class VCR < RecCommand COMMAND = 'vcr' def initialize (reserve, filename) @reserve = reserve @filename = filename @command = COMMAND @command += ' -t ' + @reserve.rec_time.to_s + 'm' @command += ' -p ' + @reserve.station @command += ' ' + filename end end class Streamer < RecCommand end class NVrec < RecCommand end class RawCommand < RecCommand end ############################################################################### # # Reserve class # ############################################################################### class Reserve def initialize () end def station () return @station end def year () return @year end def month () return @month end def date () return @date end def title () return @title end def rec_start () return @rec_start end def rec_end () return @rec_end end def rec_time () if rec_start =~ /(\d\d):(\d\d)/ start_hour = $1.to_i start_min = $2.to_i end if rec_end =~ /(\d\d):(\d\d)/ end_hour = $1.to_i end_min = $2.to_i end if (end_hour < start_hour) end_hour += 24 end time = (end_hour * 60 + end_min) - (start_hour * 60 + start_min) return time end end class IEPG < Reserve include Kconv def initialize () end def parse_line (line) if line =~ /(.*?):(.*)/ key = $1.strip value = $2.strip case key when "station" @station = toeuc (value); when "year" @year = value when "month" @month = value when "date" @date = value when "start" @rec_start = value when "end" @rec_end = value when "program-title" @title = toeuc (value) end end end end class GCode < Reserve end ############################################################################### # # GUI class # ############################################################################### class GUI include Gtk def initialize () # ウィンドウ @window = Window.new (WINDOW_TOPLEVEL) @window.signal_connect ('destroy') { exit } vbox = VBox.new (false, 0) @window.add vbox vbox.show # CList @clist = CList.new (['キー', '値']) @clist.set_usize (300, 200) @clist.set_column_width 0, 100 vbox.pack_start @clist @clist.show # ファイルエントリ hbox = HBox.new (false, 0) label = Label.new ('ファイル:') @file_entry = Entry.new () hbox.pack_start label hbox.pack_start @file_entry vbox.pack_start hbox; hbox.show label.show @file_entry.show # コマンドエントリ hbox = HBox.new (false, 0) label = Label.new ('コマンド:') @command_entry = Entry.new () hbox.pack_start label hbox.pack_start @command_entry vbox.pack_start hbox; hbox.show label.show @command_entry.show # ボタンエリア hbox = HBox.new (false, 0) @ok_button = Button.new ("予約を登録...するフリをして本当に登録する") @ok_button.signal_connect ('clicked') { print "Reseve\n" @command.regist } @quit_button = Button.new ("終了") @quit_button.signal_connect ('clicked') { exit } hbox.pack_start @ok_button hbox.pack_start @quit_button vbox.pack_end hbox; hbox.show @ok_button.show @quit_button.show # Show Window @window.show end def set_reserve (reserve) @reserve = reserve @clist.append ["チャンネル", reserve.station] @clist.append ["タイトル", reserve.title] @clist.append ["日付", reserve.year + "/" + reserve.month + "/" + reserve.date] # なんちゅう変換しやがる... @clist.append ["怪死", reserve.rec_start] @clist.append ["終了", reserve.rec_end] @clist.append ["録画時間(min)", reserve.rec_time.to_s] self.set_filename self.set_command end def set_filename () text = ENV["HOME"] + "/" + "hoge.avi" @file_entry.set_text (text) end def filename () return @file_entry.get_text end def set_command () @command = VCR.new (@reserve, self.filename) @command_entry.set_text (@command.str) end end ############################################################################### # # main # ############################################################################### reserve = IEPG.new while gets () reserve.parse_line ($_) end gui = GUI.new() gui.set_reserve (reserve) Gtk.main