mediakit 0.0.9 → 0.0.10

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 575608c79c6aefb71acac345ee3216f2ce8291d6
4
- data.tar.gz: 0fdf5b24e11a8b2f9218a1e63b3b9473ca2a0884
3
+ metadata.gz: e69a57c2b1c2be72c69e94c1b49a7039a1942dbf
4
+ data.tar.gz: f384688fb09a6175228e424ec1700273b5831978
5
5
  SHA512:
6
- metadata.gz: f79fbba7a247c1fc51b31c906e96b98cc28331e7a6cd68e6eb76a93dba763384966c0f2ec1fab2afde66da7e5d71398d5dd6a4527cedc135fcb190391e44e60e
7
- data.tar.gz: 24e596222c852222c8a1fd5366b2225c1e0360524975fb4f7539ef2c3ed79bd520f4f83103bdc9abf15bf55aff7670e490aaa250a8b2186b0a2573d9f2ac2634
6
+ metadata.gz: 4447c23bfcc32517c129afc8214516ee3b9eee786acec729f31b34c37ea1b7136b0cd70f78dabe98ccccf47a5cf4df303b9a9dec228c37561ad481404d8c4cdd
7
+ data.tar.gz: 3400a0614adf0534f43b2965053b1bba5e0d89c1758cd5e8572e46a15e4d01f5c05a21fffa91753bf4a271f9e7ec866604cbfba723b36fd3bc49ba465c6ca9d3
data/README.md CHANGED
@@ -12,14 +12,15 @@ I've design this library for following purpose.
12
12
 
13
13
  Currently you can use low-level inteface of mediakit!
14
14
 
15
- * [ ] low-level interface
15
+ * [x] low-level interface
16
16
  * [x] execute command for ffmpeg
17
17
  * [x] unit testing supports (fake driver)
18
18
  * [x] nice command setting
19
19
  * [x] read timeout setting
20
20
  * [x] shell escape for security
21
- * [ ] logger support
22
- * [ ] ffmpeg instropection (support formats, codecs, encoders, decoders..)
21
+ * [x] ffmpeg instropection (retrive supported formats, codecs, encoders and decoders)
22
+ * [x] logger support
23
+ * [ ] low-level ffprobe interface
23
24
  * [ ] high-level interface for ffmpeg
24
25
  * [ ] low-level interface for sox
25
26
  * [ ] high-level interface for sox
@@ -2,6 +2,7 @@ require 'open3'
2
2
  require 'thread'
3
3
  require 'timeout'
4
4
  require 'cool.io'
5
+ require 'logger'
5
6
  require 'mediakit/utils/shell_escape'
6
7
 
7
8
  module Mediakit
@@ -14,9 +15,12 @@ module Mediakit
14
15
 
15
16
  DEFAULT_READ_TIMEOUT_INTERVAL = 30
16
17
 
17
- def initialize(timeout: nil, nice: 0)
18
+ attr_reader(:logger)
19
+
20
+ def initialize(timeout: nil, nice: 0, logger: nil)
18
21
  @timeout = timeout
19
22
  @nice = nice
23
+ @logger = logger || Logger.new(STDOUT)
20
24
  end
21
25
 
22
26
  # @overload run(command, *args)
@@ -62,7 +66,6 @@ module Mediakit
62
66
  raise(error)
63
67
  ensure
64
68
  teardown_watchers
65
- loop_thread.join if loop_thread
66
69
  end
67
70
 
68
71
  [@out_watcher.data, @err_watcher.data, exit_status]
@@ -84,9 +87,8 @@ module Mediakit
84
87
 
85
88
  def setup_watchers(stdout, stderr)
86
89
  @timer = TimeoutTimer.new(@timeout, Thread.current)
87
- @out_watcher = IOWatcher.new(stdout) { @timer.update }
88
- @err_watcher = IOWatcher.new(stderr) { @timer.update }
89
-
90
+ @out_watcher = IOWatcher.new(stdout) { |data| @timer.update; logger.info(data) }
91
+ @err_watcher = IOWatcher.new(stderr) { |data| @timer.update; logger.error(data) }
90
92
  @loop = Coolio::Loop.new
91
93
  @out_watcher.attach(@loop)
92
94
  @err_watcher.attach(@loop)
@@ -98,8 +100,8 @@ module Mediakit
98
100
  rescue => e
99
101
  # workaround for ambiguous RuntimeError
100
102
  # TODO: replace logger method
101
- warn(e.message)
102
- warn(e.backtrace)
103
+ logger.warn(e.message)
104
+ logger.warn(e.backtrace.join("\n"))
103
105
  end
104
106
 
105
107
  def teardown_watchers
@@ -107,12 +109,15 @@ module Mediakit
107
109
  @out_watcher.close if @out_watcher && !@out_watcher.closed?
108
110
  @err_watcher.close if @err_watcher && !@err_watcher.closed?
109
111
  @loop.stop if @loop.has_active_watchers?
112
+ rescue RuntimeError => e
113
+ logger.warn(e.message)
114
+ logger.warn(e.backtrace.join("\n"))
110
115
  end
111
116
 
112
117
  def force_kill_process(pid)
113
118
  Process.kill('SIGKILL', pid)
114
- rescue Errno::ESRCH
115
- warn 'already killedd'
119
+ rescue Errno::ESRCH => e
120
+ logger.warn("fail SIGKILL pid=#{pid} - #{e.message}, #{e.backtrace.join("\n")}")
116
121
  end
117
122
 
118
123
  class IOWatcher < Coolio::IO
@@ -126,7 +131,7 @@ module Mediakit
126
131
 
127
132
  def on_read(data)
128
133
  @data << data
129
- @block.call(self)
134
+ @block.call(data)
130
135
  end
131
136
 
132
137
  def on_close
@@ -1,3 +1,3 @@
1
1
  module Mediakit
2
- VERSION = "0.0.9"
2
+ VERSION = "0.0.10"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mediakit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9
4
+ version: 0.0.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - ainame