miniatura 0.3.3 → 0.6.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
- SHA1:
3
- metadata.gz: aebe9d9b53b477af6ced6fa88cb192c80d44e949
4
- data.tar.gz: f122166ef6ab98f459f2a15782e7f0865817a0d1
2
+ SHA256:
3
+ metadata.gz: b64b736961cca4c381da24644a7dabfbe157406ccfc8299ba90c978d725d65c9
4
+ data.tar.gz: dff8ea8f1f98ff9e23d42a4f2279169cbed0b43db2fca534d1193f079e53ad97
5
5
  SHA512:
6
- metadata.gz: 7def9c36609659c7b6f3a7fa7850739ae3d6ef427d8832e37b3e4f77a4cbd221ad5acbc446489c5be3ce0b8133a1ae447a104f6d9defc74c58de6b912176c085
7
- data.tar.gz: 1598d2901924eabdc6df743a9a49d1a14576820e7dd6a46cab86ba39e61c3c0b1086f7466dd64354ac6279cee926167f9f999fc668c402f869c966e721e61531
6
+ metadata.gz: 53bbae3adfd914425d677645610eb4b76a7996ac954de7fa9b3a490dbe1ba4ba9db964068693548e786f83016a78c0a6e8b286af727fd47693bf730f209def74
7
+ data.tar.gz: d36384e59bc4c712b51133558ff668dadc794226d38da0459cfa771a750d59b64f24761003f0a57688ac317e2e2cb1bc5205b9aa214da772aaa1b1924ec9f797
data/.gitignore CHANGED
@@ -7,3 +7,4 @@
7
7
  /pkg/
8
8
  /spec/reports/
9
9
  /tmp/
10
+ /.idea/
@@ -1,69 +1,84 @@
1
- require "open3"
2
- require "miniatura/version"
3
- require "miniatura/options"
4
- require "miniatura/logger"
5
- require "miniatura/generate_command"
1
+ require 'open3'
2
+ require 'miniatura/version'
3
+ require 'miniatura/options'
4
+ require 'miniatura/logger'
5
+ require 'miniatura/generate_command'
6
6
 
7
7
  module Miniatura
8
- def generate_thumb options = {}
8
+ def generate_thumb(options = {})
9
+ @exit_code, @error = nil
10
+ raise Errno::ENOENT unless File.exist?(current_path)
9
11
  options[:file_extension] ||= 'jpeg'
10
- options[:logger] = Rails.logger
11
- size = options[:size]
12
- video = MiniExiftool.new(current_path)
13
- orientation = video.rotation
14
12
  options[:rotate] = 0
15
- image_width, image_height = video_dimension(orientation, video.imagewidth, video.imageheight, size)
16
- options[:size] = "#{image_width.to_i}" + "x" + "#{image_height.to_i}"
17
- tmp_path = File.join( File.dirname(current_path), "tmpfile.#{options[:file_extension]}")
18
- thumbnail = GenerateCommand.new(current_path, tmp_path)
19
- cmd = thumbnail.generate_command(options)
20
- logger = Miniatura::Logger.new(options).logger
21
- logger.info("Running command: #{cmd}")
22
- exit_code, error = nil
23
- raise Errno::ENOENT unless File.exist?(current_path)
24
- Open3.popen3(cmd) do |stdin, stdout, stderr, wait_thr|
25
- error = stderr.read
26
- exit_code = wait_thr.value
27
- end
28
- handle_exit_code(exit_code, error, logger)
13
+ options[:size] = determine_thumb_dimension_ratio_from_uploaded_video(options[:size])
14
+ tmp_path = generate_temp_file(options[:file_extension])
15
+ cmd = generate_command_for_thumbnail(options, tmp_path)
16
+ show_logs(cmd)
17
+ execute_command(cmd)
18
+ handle_exit_code(@exit_code, @error)
29
19
  File.rename tmp_path, current_path
30
20
  end
31
21
 
32
22
  private
33
23
 
34
- # def video_rotation orientation
35
- # case orientation
36
- # when 0
37
- # return 0
38
- # when 90
39
- # return 0
40
- # when 180
41
- # return 180
42
- # when 270
43
- # return 0
44
- # end
45
- # end
24
+ def determine_thumb_dimension_ratio_from_uploaded_video(size)
25
+ video = MiniExiftool.new(current_path)
26
+ orientation = video.rotation
27
+ image_width, image_height = video_dimension(orientation, video.imagewidth, video.imageheight, size)
28
+ return "#{image_width.to_i}" + 'x' + "#{image_height.to_i}"
29
+ end
46
30
 
47
- def video_dimension orientation, video_width, video_height, size
31
+ def video_dimension(orientation, video_width, video_height, size)
48
32
  case orientation
49
- when 0,180
50
- image_width = size
51
- ratio = size.to_f/video_width
52
- image_height = video_height * ratio
53
- else
54
- image_width = size
55
- ratio = size.to_f/video_height
56
- image_height = video_width * ratio
33
+ when 0, 180
34
+ image_width, image_height = find_width_and_height_of_landscape_video(video_width, video_height, size)
35
+ else
36
+ image_width, image_height = find_width_and_height_of_portrait_video(video_width, video_height, size)
57
37
  end
58
38
  return image_width, image_height
59
39
  end
60
40
 
61
- def handle_exit_code(exit_code, error, logger)
41
+ def find_width_and_height_of_portrait_video(video_width, video_height, size)
42
+ ratio = size.to_f/video_height
43
+ image_width = size
44
+ image_height = video_width * ratio
45
+ return image_width, image_height
46
+ end
47
+
48
+ def find_width_and_height_of_landscape_video(video_width, video_height, size)
49
+ ratio = size.to_f/video_width
50
+ image_width = size
51
+ image_height = video_height * ratio
52
+ return image_width, image_height
53
+ end
54
+
55
+ def generate_temp_file(file_extension)
56
+ File.join(File.dirname(current_path), "tmpfile.#{file_extension}")
57
+ end
58
+
59
+ def generate_command_for_thumbnail(options, temp_file_path)
60
+ thumbnail = GenerateCommand.new(current_path, temp_file_path)
61
+ return thumbnail.generate_command(options)
62
+ end
63
+
64
+ def show_logs(command)
65
+ logger = Miniatura::Logger.new.logger
66
+ logger.info("Running command: #{command}")
67
+ end
68
+
69
+ def execute_command(command)
70
+ Open3.popen3(command) do |stdin, stdout, stderr, wait_thr|
71
+ @error = stderr.read
72
+ @exit_code = wait_thr.value
73
+ end
74
+ end
75
+
76
+ def handle_exit_code(exit_code, error)
77
+ logger = Miniatura::Logger.new.logger
62
78
  if exit_code == 0
63
- logger.info "Success!"
79
+ logger.info 'Success!'
64
80
  else
65
81
  logger.error "Failure due to following error: #{error}"
66
82
  end
67
- exit_code
68
83
  end
69
84
  end
@@ -9,7 +9,7 @@ module Miniatura
9
9
  end
10
10
 
11
11
  # Generates ffmpeg command to create the thumbnail.
12
- def generate_command options = {}
12
+ def generate_command(options = {})
13
13
  options = Miniatura::Options.new(options)
14
14
  %Q(ffmpeg #{options.to_options} #{output_path} -i #{input_path})
15
15
  end
@@ -1,14 +1,9 @@
1
1
  module Miniatura
2
- class Logger
3
- attr_reader :logger
2
+ class Logger
3
+ attr_reader :logger
4
4
 
5
- def initialize options
6
- if options.has_key? :logger
7
- @logger = options[:logger]
8
- else
9
- @logger = Logger.new(STDOUT)
10
- @logger.level = Logger::INFO
11
- end
12
- end
13
- end
5
+ def initialize
6
+ @logger = Rails.logger
7
+ end
8
+ end
14
9
  end
@@ -1,42 +1,45 @@
1
1
  module Miniatura
2
2
  class Options
3
- #Options class to add various options to the ffmpeg command genrated.
3
+ #Options class to add various options to the ffmpeg command generated.
4
4
 
5
5
  CLI_KEY = {
6
- size: '-s',
7
- time_frame: '-ss',
8
- quality: '-q',
9
- file_extension: '-c'
6
+ size: '-s',
7
+ time_frame: '-ss',
8
+ quality: '-q',
9
+ file_extension: '-c'
10
10
  }
11
11
 
12
- def initialize options
13
- @ptions = options
12
+ def initialize(options)
13
+ @options = options
14
14
  end
15
15
 
16
16
  def to_options
17
- result = @ptions.map do |k, v|
18
- send(k.to_s, v)
19
- end
20
- result << "-vframes 1"
17
+ result = @options.map { |k, v| send(k.to_s, v) }
18
+ result << '-vframes 1'
21
19
  result.join(' ')
22
20
  end
23
21
 
24
- def file_extension value
22
+ def file_extension(value)
25
23
  case value
26
- when 'jpeg' then %Q(-c mjpeg)
27
- when 'png' then %Q(-c png)
28
- else
29
- ""
24
+ when 'jpeg'
25
+ '-c mjpeg'
26
+ when 'png'
27
+ '-c png'
28
+ else
29
+ ''
30
30
  end
31
31
  end
32
32
 
33
- def rotate value
33
+ def rotate(value)
34
34
  case value
35
- when 90 then %Q(-vf transpose=1)
36
- when 180 then %Q(-vf hflip )
37
- when 270 then %Q(-vf transpose=2)
38
- else
39
- ""
35
+ when 90
36
+ '-vf transpose=1'
37
+ when 180
38
+ '-vf hflip '
39
+ when 270
40
+ '-vf transpose=2'
41
+ else
42
+ ''
40
43
  end
41
44
  end
42
45
 
@@ -1,3 +1,3 @@
1
1
  module Miniatura
2
- VERSION = "0.3.3"
2
+ VERSION = '0.6.0'
3
3
  end
Binary file
@@ -4,23 +4,23 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
  require 'miniatura/version'
5
5
 
6
6
  Gem::Specification.new do |spec|
7
- spec.name = "miniatura"
7
+ spec.name = 'miniatura'
8
8
  spec.version = Miniatura::VERSION
9
- spec.authors = ["ssooraj"]
10
- spec.email = ["ssooraj7@gmail.com"]
9
+ spec.authors = ['ssooraj']
10
+ spec.email = ['ssooraj7@gmail.com']
11
11
 
12
- spec.summary = "Carrierwave Video Thumbnailer."
13
- spec.description = "Generates a thumbnail for carrierwave uploaded videos."
14
- spec.license = "MIT"
12
+ spec.summary = 'Carrierwave Video Thumbnailer.'
13
+ spec.description = 'Generates a thumbnail for carrierwave uploaded videos.'
14
+ spec.license = 'MIT'
15
15
 
16
16
  spec.files = `git ls-files`.split("\n")
17
- spec.bindir = "exe"
17
+ spec.bindir = 'exe'
18
18
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
- spec.require_paths = ["lib"]
19
+ spec.require_paths = ['lib']
20
20
 
21
- spec.add_development_dependency "bundler", "~> 1.13"
22
- spec.add_development_dependency "rake", "~> 10.5"
23
- spec.add_development_dependency "rspec", "~> 3.5"
24
- spec.add_development_dependency "carrierwave-video", "~> 0.5.6"
25
- spec.add_development_dependency "mini_exiftool", "~> 2.8"
21
+ spec.add_development_dependency 'bundler', '~> 2.2.7'
22
+ spec.add_development_dependency 'rake', '~> 13.0.3'
23
+ spec.add_development_dependency 'rspec', '~> 3.10.0'
24
+ spec.add_development_dependency 'carrierwave-video', '~> 0.6.0'
25
+ spec.add_development_dependency 'mini_exiftool', '~> 2.10.0'
26
26
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: miniatura
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.3
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - ssooraj
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-12-08 00:00:00.000000000 Z
11
+ date: 2021-01-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -16,70 +16,70 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.13'
19
+ version: 2.2.7
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '1.13'
26
+ version: 2.2.7
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '10.5'
33
+ version: 13.0.3
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '10.5'
40
+ version: 13.0.3
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '3.5'
47
+ version: 3.10.0
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '3.5'
54
+ version: 3.10.0
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: carrierwave-video
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: 0.5.6
61
+ version: 0.6.0
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: 0.5.6
68
+ version: 0.6.0
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: mini_exiftool
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: '2.8'
75
+ version: 2.10.0
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: '2.8'
82
+ version: 2.10.0
83
83
  description: Generates a thumbnail for carrierwave uploaded videos.
84
84
  email:
85
85
  - ssooraj7@gmail.com
@@ -102,6 +102,7 @@ files:
102
102
  - lib/miniatura/logger.rb
103
103
  - lib/miniatura/options.rb
104
104
  - lib/miniatura/version.rb
105
+ - miniatura-0.5.0.gem
105
106
  - miniatura.gemspec
106
107
  - spec/lib/generate_command_spec.rb
107
108
  - spec/lib/miniatura_spec.rb
@@ -126,8 +127,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
126
127
  - !ruby/object:Gem::Version
127
128
  version: '0'
128
129
  requirements: []
129
- rubyforge_project:
130
- rubygems_version: 2.5.2
130
+ rubygems_version: 3.2.3
131
131
  signing_key:
132
132
  specification_version: 4
133
133
  summary: Carrierwave Video Thumbnailer.