av 0.1.2 → 0.4.0

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: b3a866330bd9c784df99f3235220e5184973215f
4
- data.tar.gz: 671c46357af67d353a607948e6bdc03beefb2962
3
+ metadata.gz: 2680b92872fd043f4f223ccaad0d7b667c8e9e51
4
+ data.tar.gz: 29f2a2d421492496ba12f0942845cefe817069eb
5
5
  SHA512:
6
- metadata.gz: 5aa51d99ae99ae7aeb65287030b91a30eb16665ae8f582b2625e6816771c09d166129c854a99877db4aff1882d8620699ef6f1e3f3ca9022d552dbb27678ba8e
7
- data.tar.gz: b4b7714fd9163a4178116e04ba38e693dcae73de65132a38cc9ecbe512ab2bcc9f2257e2ac1cc6190ba318680020599b9cec98ce855f10c0f048d1d00d651129
6
+ metadata.gz: 94ed1426a502750e3e2b8e336d89805f64ef6f136655adf5caa37596d6689762e1b9f5952f7b9bdbb192f9ab96d6e3c4582eca0a373baa49d357da774af50947
7
+ data.tar.gz: ce444930d672df1b1c5805909bde0c9934ac84c95538d437ccadf939a8f41dfeb667334e2ae67d9b477e9602c8b85d1e2dd72aeb143a48faf85c161fc76e61bb
data/lib/av.rb CHANGED
@@ -1,15 +1,25 @@
1
1
  require "av/version"
2
2
  require "av/exceptions"
3
+ require "av/logger"
3
4
  require "av/cli"
4
5
  require "av/param_hash"
5
6
  require "av/commands/ffmpeg"
6
7
  require "av/commands/avconv"
7
8
  require "cocaine"
9
+ require "av/engine" if defined?(Rails)
8
10
 
9
11
  module Av
10
12
  extend self
13
+ extend Logger
14
+
15
+ def options
16
+ @options ||= {
17
+ log: false
18
+ }
19
+ end
11
20
 
12
21
  def cli(options = {})
22
+ @options = options unless options.empty?
13
23
  ::Av::Cli.new(options)
14
24
  end
15
25
 
@@ -21,8 +31,4 @@ module Av
21
31
  raise Av::CommandError, "error while running command #{line}: #{e}"
22
32
  end
23
33
  end
24
-
25
- def log message
26
- puts "[AV] #{message}"
27
- end
28
34
  end
@@ -104,8 +104,8 @@ module Av
104
104
  if line =~ /Video:(.*)/
105
105
  v = $1.to_s
106
106
  size = v.match(/\d{3,5}x\d{3,5}/).to_s
107
- meta[:size] = size
108
- meta[:aspect] = size.split('x').first.to_f / size.split('x').last.to_f
107
+ meta[:size] = size unless size.empty?
108
+ meta[:aspect] = size.split('x').first.to_f / size.split('x').last.to_f if meta[:size]
109
109
  end
110
110
  # Matching Duration: 00:01:31.66, start: 0.000000, bitrate: 10404 kb/s
111
111
  if line =~ /Duration:(\s.?(\d*):(\d*):(\d*\.\d*))/
@@ -115,7 +115,7 @@ module Av
115
115
  meta[:rotate] = $1.to_i
116
116
  end
117
117
  end
118
- meta
118
+ meta unless meta.empty?
119
119
  end
120
120
 
121
121
  def output_format format
@@ -0,0 +1,7 @@
1
+ module Av
2
+ class Engine < ::Rails::Engine
3
+ initializer 'av.logger' do
4
+ Av.logger = ::Rails.logger
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,17 @@
1
+ require "logger"
2
+
3
+ module Av
4
+ module Logger
5
+ def log message
6
+ logger.info "[AV] #{message}" if options[:log]
7
+ end
8
+
9
+ def logger
10
+ @logger ||= ::Logger.new(STDOUT)
11
+ end
12
+
13
+ def logger=(logger)
14
+ @logger = logger
15
+ end
16
+ end
17
+ end
@@ -1,3 +1,3 @@
1
1
  module Av
2
- VERSION = "0.1.2"
2
+ VERSION = "0.4.0"
3
3
  end
@@ -5,10 +5,19 @@ describe Av::Commands::Base do
5
5
  let(:source) { File.new(Dir.pwd + '/spec/support/assets/sample.mp4').path }
6
6
 
7
7
  describe '.identify' do
8
- let(:meta) { subject.identify source }
8
+ describe 'supported files' do
9
+ let(:meta) { subject.identify source }
9
10
 
10
- it { expect(meta).to be_a Hash }
11
- it { expect(meta.keys).to include :size, :fps, :length, :aspect }
11
+ it { expect(meta).to be_a Hash }
12
+ it { expect(meta.keys).to include :size, :fps, :length, :aspect }
13
+ end
14
+
15
+ describe 'unsupported files' do
16
+ let(:unsupported) { File.new(Dir.pwd + '/spec/support/assets/image.png').path }
17
+ let(:meta) { subject.identify unsupported }
18
+
19
+ it { expect(meta).to be_nil }
20
+ end
12
21
  end
13
22
 
14
23
  describe '.add_input_param' do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: av
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Omar Abdel-Wahab
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-11 00:00:00.000000000 Z
11
+ date: 2014-09-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -85,7 +85,9 @@ files:
85
85
  - lib/av/commands/avconv.rb
86
86
  - lib/av/commands/base.rb
87
87
  - lib/av/commands/ffmpeg.rb
88
+ - lib/av/engine.rb
88
89
  - lib/av/exceptions.rb
90
+ - lib/av/logger.rb
89
91
  - lib/av/param_hash.rb
90
92
  - lib/av/version.rb
91
93
  - spec/av/av_spec.rb
@@ -93,6 +95,7 @@ files:
93
95
  - spec/av/base_spec.rb
94
96
  - spec/av/ffmpeg_spec.rb
95
97
  - spec/spec_helper.rb
98
+ - spec/support/assets/image.png
96
99
  - spec/support/assets/sample.mp4
97
100
  homepage: https://github.com/ruby-av
98
101
  licenses:
@@ -124,4 +127,5 @@ test_files:
124
127
  - spec/av/base_spec.rb
125
128
  - spec/av/ffmpeg_spec.rb
126
129
  - spec/spec_helper.rb
130
+ - spec/support/assets/image.png
127
131
  - spec/support/assets/sample.mp4