paperclip-wav-mp3 0.0.0 → 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/README.md +67 -2
- data/lib/paperclip-wav-mp3.rb +1 -34
- data/lib/paperclip_processors/ffmpeg_wav_to_mp3.rb +31 -0
- data/paperclip-wav-mp3.gemspec +4 -4
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2da064bd68c4a179944fa82f40ce9f209f7f1106
|
4
|
+
data.tar.gz: e02f88277385e48ba457ee04917faa425e7b8e9f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 238ae23e5cf0dd3cdb44fb5137e65c9b2114de3f1ec9115dc4e5216c951958feaabb8b7544bc65385e8585bde776ddc0733eac29bbdc25541f264db2a0c4a630
|
7
|
+
data.tar.gz: 43b90893c3e0ad6e5198740fe1fda04f2392fd28a887c3feac67597801ed5b113716203ee18c7971a9046f887c2677334029f16bb2a04f3432e5965f6733760b
|
data/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
*.gem
|
data/README.md
CHANGED
@@ -1,4 +1,69 @@
|
|
1
|
-
paperclip-wav-mp3
|
2
|
-
|
1
|
+
# paperclip-wav-mp3 [![Gem Version](https://badge.fury.io/rb/paperclip-wav-mp3.png)](http://badge.fury.io/rb/paperclip-wav-mp3)
|
2
|
+
|
3
|
+
|
3
4
|
|
4
5
|
Paperclip processor to convert .wav files to .mp3 using ffmpeg
|
6
|
+
|
7
|
+
## Requirements
|
8
|
+
|
9
|
+
### Paperclip
|
10
|
+
|
11
|
+
This is a processor written for the quite excellent [Paperclip](https://github.com/thoughtbot/paperclip) gem by [ThoughtBot](https://github.com/thoughtbot). You will need to be using Paperclip to use it.
|
12
|
+
|
13
|
+
### FFmpeg
|
14
|
+
|
15
|
+
FFmpeg is used to convert WAV audio to MP3. It must be installed within your environment and available on your PATH.
|
16
|
+
|
17
|
+
#### OS X
|
18
|
+
|
19
|
+
If you're developing on OS X, you can install FFmpeg using homebrew:
|
20
|
+
|
21
|
+
```
|
22
|
+
brew install ffmpeg
|
23
|
+
```
|
24
|
+
|
25
|
+
#### Ubuntu Linux
|
26
|
+
|
27
|
+
I've not tested on other linux distributions, but you can install FFmpeg and the required codecs with the following:
|
28
|
+
|
29
|
+
```
|
30
|
+
apt-get install ffmpeg libavcodec-extra-52 libavdevice-extra-52 libavfilter-extra-0 libavformat-extra-52 libavutil-extra-49 libpostproc-extra-51 libswscale-extra-0
|
31
|
+
```
|
32
|
+
|
33
|
+
## Installation
|
34
|
+
|
35
|
+
This processor is distributed as a gem, which is how it should be used in your app.
|
36
|
+
|
37
|
+
Include the gem in your Gemfile:
|
38
|
+
|
39
|
+
```
|
40
|
+
gem 'paperclip-wav-mp3', '~> 0.0'
|
41
|
+
```
|
42
|
+
|
43
|
+
Once you've installed the gem, update the model which uses Paperclip to attach audio to add the processor:
|
44
|
+
|
45
|
+
```
|
46
|
+
class Voicemail < ActiveRecord::Base
|
47
|
+
has_attached_file :audio,
|
48
|
+
styles: { mp3: {} },
|
49
|
+
processors: [:ffmpeg_wav_to_mp3]
|
50
|
+
end
|
51
|
+
```
|
52
|
+
|
53
|
+
Now, when you attach a new `WAV` audio file, you will also create an `MP3` version.
|
54
|
+
|
55
|
+
To generate the missing `MP3` versions for files you've already attached you can use this paperclip rake task:
|
56
|
+
|
57
|
+
```
|
58
|
+
rake paperclip:refresh:missing_styles
|
59
|
+
```
|
60
|
+
|
61
|
+
## Contributing
|
62
|
+
|
63
|
+
Feel free to raise any issues you have [here](https://github.com/pacso/paperclip-wav-mp3/issues), or if you're feeling generous then just send a [pull request](https://github.com/pacso/paperclip-wav-mp3/compare/) with your new feature/bugfix.
|
64
|
+
|
65
|
+
## License
|
66
|
+
|
67
|
+
Copyright (c) 2014 Jon Pascoe.
|
68
|
+
|
69
|
+
This is free software and may be redistributed under the terms and conditions of The MIT License (MIT). Full details are available in the LICENSE file.
|
data/lib/paperclip-wav-mp3.rb
CHANGED
@@ -1,34 +1 @@
|
|
1
|
-
require '
|
2
|
-
|
3
|
-
module Paperclip
|
4
|
-
class FfmpegWav2Mp3 < Processor
|
5
|
-
|
6
|
-
attr_accessor :file, :params, :format
|
7
|
-
|
8
|
-
def initialize(file, options = {}, attachment = nil)
|
9
|
-
super
|
10
|
-
@file = file
|
11
|
-
@params = options[:params]
|
12
|
-
@current_format = File.extname(@file.path)
|
13
|
-
@basename = File.basename(@file.path, @current_format)
|
14
|
-
@format = options[:format]
|
15
|
-
end
|
16
|
-
|
17
|
-
def make
|
18
|
-
src = @file
|
19
|
-
dst = Tempfile.new([@basename, @format ? ".#{@format}" : '' ])
|
20
|
-
|
21
|
-
begin
|
22
|
-
parameters = []
|
23
|
-
parameters << @params
|
24
|
-
parameters << ":source"
|
25
|
-
parameters << ":dest"
|
26
|
-
parameters = parameters.flatten.compact.join(' ').strip.squeeze(' ')
|
27
|
-
success = Paperclip.run('ffmpeg', parameters, :source => File.expand_path(src.path), :dest => File.expand_path(dst.path))
|
28
|
-
rescue PaperclipCommandLineError => e
|
29
|
-
raise PaperclipError, "There was an error converting #{@basename} to mp3"
|
30
|
-
end
|
31
|
-
dst
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
1
|
+
require 'paperclip_processors/ffmpeg_wav_to_mp3'
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'paperclip'
|
2
|
+
|
3
|
+
module Paperclip
|
4
|
+
class FfmpegWavToMp3 < Processor
|
5
|
+
|
6
|
+
attr_accessor :file, :params, :format
|
7
|
+
|
8
|
+
def initialize(file, options = {}, attachment = nil)
|
9
|
+
super
|
10
|
+
@file = file
|
11
|
+
@params = options[:params] || '-y -i'
|
12
|
+
@current_format = File.extname(@file.path)
|
13
|
+
@basename = File.basename(@file.path, @current_format)
|
14
|
+
@format = options[:format] || 'mp3'
|
15
|
+
end
|
16
|
+
|
17
|
+
def make
|
18
|
+
source = @file
|
19
|
+
output = Tempfile.new([@basename, @format ? ".#{@format}" : '' ])
|
20
|
+
|
21
|
+
begin
|
22
|
+
parameters = [@params, ':source', ':dest'].flatten.compact.join(' ').strip.squeeze(' ')
|
23
|
+
Paperclip.run('ffmpeg', parameters, :source => File.expand_path(source.path), :dest => File.expand_path(output.path))
|
24
|
+
rescue PaperclipCommandLineError
|
25
|
+
raise PaperclipError, "There was an error converting #{@basename} to mp3"
|
26
|
+
end
|
27
|
+
|
28
|
+
output
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
data/paperclip-wav-mp3.gemspec
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'paperclip-wav-mp3'
|
3
|
-
s.version = '0.0.
|
4
|
-
s.
|
3
|
+
s.version = '0.0.1'
|
4
|
+
s.author = 'Jon Pascoe'
|
5
5
|
s.email = 'jon.pascoe@me.com'
|
6
6
|
s.homepage = 'https://github.com/pacso/paperclip-wav-mp3'
|
7
7
|
s.summary = 'Paperclip WAV to MP3 Processor'
|
@@ -12,6 +12,6 @@ Gem::Specification.new do |s|
|
|
12
12
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
13
13
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
14
14
|
s.require_paths = ["lib"]
|
15
|
-
|
15
|
+
|
16
16
|
s.license = 'MIT'
|
17
|
-
end
|
17
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: paperclip-wav-mp3
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jon Pascoe
|
@@ -30,9 +30,11 @@ executables: []
|
|
30
30
|
extensions: []
|
31
31
|
extra_rdoc_files: []
|
32
32
|
files:
|
33
|
+
- .gitignore
|
33
34
|
- LICENSE
|
34
35
|
- README.md
|
35
36
|
- lib/paperclip-wav-mp3.rb
|
37
|
+
- lib/paperclip_processors/ffmpeg_wav_to_mp3.rb
|
36
38
|
- paperclip-wav-mp3.gemspec
|
37
39
|
homepage: https://github.com/pacso/paperclip-wav-mp3
|
38
40
|
licenses:
|