Class: Kaede::Notifier
- Inherits:
-
Object
- Object
- Kaede::Notifier
- Defined in:
- lib/kaede/notifier.rb
Instance Method Summary collapse
- #available_disk ⇒ Object
- #format_title(program) ⇒ Object
- #in_gigabyte(size) ⇒ Object
-
#initialize ⇒ Notifier
constructor
A new instance of Notifier.
- #notify_after_record(program) ⇒ Object
- #notify_before_record(program) ⇒ Object
- #notify_exception(exception, program) ⇒ Object
-
#record_path(program) ⇒ Object
FIXME: duplicate.
- #ts_filesize(program) ⇒ Object
- #tweet(text) ⇒ Object
Constructor Details
Instance Method Details
#available_disk ⇒ Object
52 53 54 55 |
# File 'lib/kaede/notifier.rb', line 52 def available_disk _, avail = `#{Kaede.config.statvfs} #{Kaede.config.record_dir}`.chomp.split(/\s/, 2).map(&:to_i) in_gigabyte(avail) end |
#format_title(program) ⇒ Object
34 35 36 37 38 39 40 41 |
# File 'lib/kaede/notifier.rb', line 34 def format_title(program) buf = "#{program.channel_name}で「#{program.title}" if program.count buf += " ##{program.count}" end buf += " #{program.subtitle}」" buf end |
#in_gigabyte(size) ⇒ Object
57 58 59 |
# File 'lib/kaede/notifier.rb', line 57 def in_gigabyte(size) size / (1024 * 1024 * 1024) end |
#notify_after_record(program) ⇒ Object
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/kaede/notifier.rb', line 15 def notify_after_record(program) tweet( sprintf( "%sを録画した。ファイルサイズ約%.2fGB。残り約%dGB\n", format_title(program), ts_filesize(program), available_disk, ) ) end |
#notify_before_record(program) ⇒ Object
11 12 13 |
# File 'lib/kaede/notifier.rb', line 11 def notify_before_record(program) tweet("#{format_title(program)}を録画する") end |
#notify_exception(exception, program) ⇒ Object
26 27 28 29 30 31 32 |
# File 'lib/kaede/notifier.rb', line 26 def notify_exception(exception, program) msg = "#{program.title}(PID #{program.pid}) の録画中に #{exception.class} で失敗した……" if @twitter_target msg = "@#{@twitter_target} #{msg}" end tweet(msg) end |
#record_path(program) ⇒ Object
FIXME: duplicate
48 49 50 |
# File 'lib/kaede/notifier.rb', line 48 def record_path(program) Kaede.config.record_dir.join("#{program.tid}_#{program.pid}.ts") end |
#ts_filesize(program) ⇒ Object
43 44 45 |
# File 'lib/kaede/notifier.rb', line 43 def ts_filesize(program) in_gigabyte(record_path(program).size.to_f) end |
#tweet(text) ⇒ Object
61 62 63 64 65 66 67 68 69 70 |
# File 'lib/kaede/notifier.rb', line 61 def tweet(text) return unless @twitter Thread.start do begin @twitter.update(text) rescue Exception => e $stderr.puts "Failed to tweet: #{text}: #{e.class}: #{e.}" end end end |