carrierwave-ffmpeg-audio 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a68717a0a6899d9a74dda9d21ad37c31325da81a
4
+ data.tar.gz: 5f669a1691876d3d1563d0232e4467bd1159eb18
5
+ SHA512:
6
+ metadata.gz: 5370d6e83424fa645d648f1597c8e6f3330c7100b814a8613945a9f9e7669f8ea0c032c4f877a6411237b1412b1a9b6c2bd29dd3b9d9c87e292f93a225d52fcb
7
+ data.tar.gz: 9c8c0739e3eac48551badfab6a887587b52edcd9188d85668bff724cff26b9771c14c7a00a41dbf8869e840b59807d79f7955aa54882888bac6da465ce9be9b9
data/.DS_Store ADDED
Binary file
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.3.1
7
+ before_install: gem install bundler -v 1.17.3
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in carrierwave-ffmpeg-audio.gemspec
6
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,57 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ carrierwave-ffmpeg-audio (0.1.0)
5
+ carrierwave (>= 0.10.0)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ activemodel (5.2.3)
11
+ activesupport (= 5.2.3)
12
+ activesupport (5.2.3)
13
+ concurrent-ruby (~> 1.0, >= 1.0.2)
14
+ i18n (>= 0.7, < 2)
15
+ minitest (~> 5.1)
16
+ tzinfo (~> 1.1)
17
+ carrierwave (1.3.1)
18
+ activemodel (>= 4.0.0)
19
+ activesupport (>= 4.0.0)
20
+ mime-types (>= 1.16)
21
+ concurrent-ruby (1.1.5)
22
+ diff-lcs (1.3)
23
+ i18n (1.6.0)
24
+ concurrent-ruby (~> 1.0)
25
+ mime-types (3.2.2)
26
+ mime-types-data (~> 3.2015)
27
+ mime-types-data (3.2019.0331)
28
+ minitest (5.11.3)
29
+ rake (10.5.0)
30
+ rspec (3.8.0)
31
+ rspec-core (~> 3.8.0)
32
+ rspec-expectations (~> 3.8.0)
33
+ rspec-mocks (~> 3.8.0)
34
+ rspec-core (3.8.0)
35
+ rspec-support (~> 3.8.0)
36
+ rspec-expectations (3.8.3)
37
+ diff-lcs (>= 1.2.0, < 2.0)
38
+ rspec-support (~> 3.8.0)
39
+ rspec-mocks (3.8.0)
40
+ diff-lcs (>= 1.2.0, < 2.0)
41
+ rspec-support (~> 3.8.0)
42
+ rspec-support (3.8.0)
43
+ thread_safe (0.3.6)
44
+ tzinfo (1.2.5)
45
+ thread_safe (~> 0.1)
46
+
47
+ PLATFORMS
48
+ ruby
49
+
50
+ DEPENDENCIES
51
+ bundler (~> 1.17)
52
+ carrierwave-ffmpeg-audio!
53
+ rake (~> 10.0)
54
+ rspec (~> 3.0)
55
+
56
+ BUNDLED WITH
57
+ 1.17.3
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 Kyle Reeves
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,39 @@
1
+ # Carrierwave::Ffmpeg::Audio
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/carrierwave/ffmpeg/audio`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'carrierwave-ffmpeg-audio'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install carrierwave-ffmpeg-audio
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/carrierwave-ffmpeg-audio.
36
+
37
+ ## License
38
+
39
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "carrierwave/ffmpeg/audio"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,30 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "carrierwave/ffmpeg/audio/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "carrierwave-ffmpeg-audio"
8
+ spec.version = CarrierWave::Ffmpeg::Audio::VERSION
9
+ spec.authors = ["Kyle Reeves"]
10
+ spec.email = ["kyreeves@icloud.com"]
11
+ spec.summary = %q{CarrierWave Audio Conversion}
12
+ spec.description = %q{FFMPEG wrapper for CarrierWave uploader that allows audio file conversion and watermarking}
13
+ spec.homepage = "https://github.com/kyreeves/carrierwave-ffmpeg-audio"
14
+ spec.license = "MIT"
15
+
16
+ # Specify which files should be added to the gem when it is released.
17
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
18
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
19
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
20
+ end
21
+ spec.bindir = "exe"
22
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
+ spec.require_paths = ["lib"]
24
+
25
+ spec.add_dependency "carrierwave", ">= 0.10.0"
26
+
27
+ spec.add_development_dependency "bundler", "~> 1.17"
28
+ spec.add_development_dependency "rake", "~> 10.0"
29
+ spec.add_development_dependency "rspec", "~> 3.0"
30
+ end
@@ -0,0 +1,37 @@
1
+ require "carrierwave"
2
+ require "carrierwave/ffmpeg/audio/version"
3
+ require "carrierwave/ffmpeg/audio/processor"
4
+
5
+ module CarrierWave
6
+ module Ffmpeg
7
+ module Audio
8
+ extend ActiveSupport::Concern
9
+
10
+ module ClassMethods
11
+ def convert options={}
12
+ process convert: [ options ]
13
+ end
14
+
15
+ def watermark options={}
16
+ process watermark: [ options ]
17
+ end
18
+ end
19
+
20
+ def convert options={}
21
+ cache_stored_file! if !cached?
22
+
23
+ audio_filename = Processor.convert(current_path, options)
24
+ File.rename audio_filename, current_path
25
+ self.file.instance_variable_set(:@content_type, "audio/mpeg3")
26
+ end
27
+
28
+ def watermark options={}
29
+ cache_stored_file! if !cached?
30
+
31
+ audio_filename = Processor.watermark(current_path, options)
32
+ File.rename audio_filename, current_path
33
+ self.file.instance_variable_set(:@content_type, "audio/mpeg3")
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,49 @@
1
+ require "fileutils"
2
+
3
+ module CarrierWave
4
+ module Ffmpeg
5
+ module Audio
6
+ class Processor
7
+ DefaultOptions = {
8
+ bit_rate: "128k",
9
+ sample_rate: "44100",
10
+ }
11
+
12
+ # Scope these under Processor so you can catch the ones generated by just this class.
13
+ class RuntimeError < ::RuntimeError;end;
14
+ class ArgumentError < ::ArgumentError;end;
15
+
16
+ class << self
17
+ def convert(source, options)
18
+ options = DefaultOptions.merge(options)
19
+ final_filename = tmp_filename(source: source, format: "mp3")
20
+ system "ffmpeg -i #{source} -c:a libmp3lame -ab #{options[:bit_rate]} -ar #{options[:sample_rate]} #{final_filename}"
21
+ final_filename
22
+ end
23
+
24
+ def watermark(source, options)
25
+ options = DefaultOptions.merge(options)
26
+ watermark_file_path = options[:watermark_file]
27
+
28
+ raise ArgumentError.new("No watermark filename given, must be a path to an existing sound file.") unless watermark_file_path
29
+ raise RuntimeError.new("Watermark file '#{watermark_file_path}' not found.") unless File.exist?(watermark_file_path)
30
+
31
+ final_filename = tmp_filename(source: source, format: "mp3", prefix: "wtmk")
32
+ system "ffmpeg -i #{source} -i #{watermark_file_path} -filter_complex amerge -c:a libmp3lame -ab #{options[:bit_rate]} -ar #{options[:sample_rate]} #{final_filename}"
33
+
34
+ final_filename
35
+ end
36
+
37
+ private
38
+
39
+ # Generate a temporary filename
40
+ def tmp_filename source:, format:, prefix: nil
41
+ ext = File.extname(source)
42
+ source_filename_without_ext = File.basename(source, ext)
43
+ File.join File.dirname(source), "tmp#{prefix.present? ? '_' + prefix : ''}_#{source_filename_without_ext}_#{Time.now.to_i}.#{format}"
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,7 @@
1
+ module CarrierWave
2
+ module Ffmpeg
3
+ module Audio
4
+ VERSION = "0.1.1"
5
+ end
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,116 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: carrierwave-ffmpeg-audio
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Kyle Reeves
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-05-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: carrierwave
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 0.10.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 0.10.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.17'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.17'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ description: FFMPEG wrapper for CarrierWave uploader that allows audio file conversion
70
+ and watermarking
71
+ email:
72
+ - kyreeves@icloud.com
73
+ executables: []
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".DS_Store"
78
+ - ".gitignore"
79
+ - ".rspec"
80
+ - ".travis.yml"
81
+ - Gemfile
82
+ - Gemfile.lock
83
+ - LICENSE.txt
84
+ - README.md
85
+ - Rakefile
86
+ - bin/console
87
+ - bin/setup
88
+ - carrierwave-ffmpeg-audio.gemspec
89
+ - lib/carrierwave/ffmpeg/audio.rb
90
+ - lib/carrierwave/ffmpeg/audio/processor.rb
91
+ - lib/carrierwave/ffmpeg/audio/version.rb
92
+ homepage: https://github.com/kyreeves/carrierwave-ffmpeg-audio
93
+ licenses:
94
+ - MIT
95
+ metadata: {}
96
+ post_install_message:
97
+ rdoc_options: []
98
+ require_paths:
99
+ - lib
100
+ required_ruby_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ required_rubygems_version: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ requirements: []
111
+ rubyforge_project:
112
+ rubygems_version: 2.5.1
113
+ signing_key:
114
+ specification_version: 4
115
+ summary: CarrierWave Audio Conversion
116
+ test_files: []