audio_dicer 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +54 -0
- data/Rakefile +2 -0
- data/audio_dicer.gemspec +23 -0
- data/bin/audio_dicer +6 -0
- data/lib/audio_dicer.rb +24 -0
- data/lib/audio_dicer/context.rb +27 -0
- data/lib/audio_dicer/context/album.rb +24 -0
- data/lib/audio_dicer/runner.rb +58 -0
- data/lib/audio_dicer/version.rb +3 -0
- metadata +84 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: e91320f1b8769dcd669d1ac0010cbf6f60e8e09a
|
4
|
+
data.tar.gz: 91b9e83e0758339e27fabb115907edb2a5ed6df7
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 3768288e2a8a7af807faf72c44418fff1ff7cd143fc5359c0423a215796a7418451429004e5abd8b393b48901b6f3773e1cb5805125bf668532a0cc0f8b36499
|
7
|
+
data.tar.gz: f558beb0013312c764c4636a473f3206745483499b9ec62556216377334bebe6d1455c44bc43c0a2f6173c750c7d4ff1e065fa94b042e931db33a9e81f056658
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Michael Coyne
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
# AudioDicer
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Dependencies
|
6
|
+
|
7
|
+
You'll need the following programs for `audio_dicer` to function:
|
8
|
+
|
9
|
+
apt-get install mplayer lame mp3splt
|
10
|
+
|
11
|
+
## Installation
|
12
|
+
|
13
|
+
Add this line to your application's Gemfile:
|
14
|
+
|
15
|
+
gem 'audio_ripper'
|
16
|
+
|
17
|
+
And then execute:
|
18
|
+
|
19
|
+
$ bundle
|
20
|
+
|
21
|
+
Or install it yourself as:
|
22
|
+
|
23
|
+
$ gem install audio_ripper
|
24
|
+
|
25
|
+
## Usage
|
26
|
+
|
27
|
+
Here's a quick example of how the DSL works. You must first specify, a
|
28
|
+
`source` and optional `bitrate`. Next you can define one more `album` with one
|
29
|
+
or more `track` each.
|
30
|
+
|
31
|
+
source 'your-video.mp4'
|
32
|
+
bitrate 196
|
33
|
+
|
34
|
+
album do
|
35
|
+
artist 'Dr. Dog'
|
36
|
+
name 'Juan's Basement'
|
37
|
+
|
38
|
+
track 'Say Something', '2:20', '5:36'
|
39
|
+
track 'Worst Trip', '9:50', '12:55'
|
40
|
+
track "Ain't it Strange", '15:27', '20:05'
|
41
|
+
track 'Die Die Die', '22:00', '25:55'
|
42
|
+
end
|
43
|
+
|
44
|
+
Now to run the program, simply execute:
|
45
|
+
|
46
|
+
audio_dicer my_script.rb
|
47
|
+
|
48
|
+
## Contributing
|
49
|
+
|
50
|
+
1. Fork it ( https://github.com/[my-github-username]/audio_ripper/fork )
|
51
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
52
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
53
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
54
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/audio_dicer.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'audio_dicer/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "audio_dicer"
|
8
|
+
spec.version = AudioDicer::VERSION
|
9
|
+
spec.authors = ["mikeycgto"]
|
10
|
+
spec.email = ["mikeycgto@gmail.com"]
|
11
|
+
spec.summary = %q{DSL to convert videos into a set of tagged MP3s}
|
12
|
+
spec.description = %q{With this simple DSL, convert video files into one or more tagged MP3s}
|
13
|
+
spec.homepage = "http://github.com/mikeycgto/audio_dicer"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
end
|
data/bin/audio_dicer
ADDED
data/lib/audio_dicer.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'audio_dicer/version'
|
2
|
+
require 'audio_dicer/context'
|
3
|
+
require 'audio_dicer/context/album'
|
4
|
+
require 'audio_dicer/runner'
|
5
|
+
require 'fileutils'
|
6
|
+
|
7
|
+
module AudioDicer
|
8
|
+
def self.expand_relative_file(file)
|
9
|
+
File.expand_path(file, Dir.pwd)
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.load(filename)
|
13
|
+
File.open(expand_relative_file(filename)) do |file|
|
14
|
+
execute file.read, filename
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.execute(script, filename = nil)
|
19
|
+
ctx = Context.new
|
20
|
+
ctx.instance_eval script
|
21
|
+
|
22
|
+
Runner.new(ctx).run
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module AudioDicer
|
2
|
+
class Context
|
3
|
+
attr_reader :source_options, :albums
|
4
|
+
|
5
|
+
def initialize
|
6
|
+
@albums = []
|
7
|
+
@source_options = {}
|
8
|
+
end
|
9
|
+
|
10
|
+
def source(source)
|
11
|
+
@source_options.update source: source
|
12
|
+
end
|
13
|
+
|
14
|
+
def bitrate(bitrate)
|
15
|
+
@source_options.update bitrate: bitrate
|
16
|
+
end
|
17
|
+
|
18
|
+
def album(&block)
|
19
|
+
album = Album.new
|
20
|
+
album.instance_eval(&block)
|
21
|
+
|
22
|
+
@albums << album
|
23
|
+
end
|
24
|
+
|
25
|
+
alias :disc :album
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module AudioDicer
|
2
|
+
class Context
|
3
|
+
class Album
|
4
|
+
attr_reader :options, :tracks
|
5
|
+
|
6
|
+
def initialize
|
7
|
+
@tracks = []
|
8
|
+
@options = {}
|
9
|
+
end
|
10
|
+
|
11
|
+
def artist(artist)
|
12
|
+
@options.update(artist: artist);
|
13
|
+
end
|
14
|
+
|
15
|
+
def name(name)
|
16
|
+
@options.update(name: name)
|
17
|
+
end
|
18
|
+
|
19
|
+
def track(title, *time)
|
20
|
+
@tracks << { title: title, time: time }
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
module AudioDicer
|
2
|
+
class Runner
|
3
|
+
attr_reader :ctx
|
4
|
+
|
5
|
+
def initialize(ctx)
|
6
|
+
@ctx = ctx
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.bin_available?(name)
|
10
|
+
end
|
11
|
+
|
12
|
+
# kind of lame but w/e
|
13
|
+
def expand_relative_file(*args)
|
14
|
+
AudioDicer.expand_relative_file(*args)
|
15
|
+
end
|
16
|
+
|
17
|
+
def run
|
18
|
+
src_opts = ctx.source_options
|
19
|
+
|
20
|
+
# First convert the video to a wav
|
21
|
+
puts '[*] Extracting audio'
|
22
|
+
system "mplayer -really-quiet -vc null -vo null -nocorrect-pts -ao pcm:waveheader #{expand_relative_file src_opts[:source]}"
|
23
|
+
|
24
|
+
abort '[!] mplayer failed' unless File.exist?(expand_relative_file('audiodump.wav'))
|
25
|
+
|
26
|
+
# Now convert that to one big mp3
|
27
|
+
puts '[*] Convert WAV to MP3'
|
28
|
+
system "lame -h -b #{src_opts[:bitrate] || 192} audiodump.wav audiodump.mp3"
|
29
|
+
|
30
|
+
abort '[!] lame failed' unless File.exist?(expand_relative_file('audiodump.mp3'))
|
31
|
+
|
32
|
+
# Now split that mp3 using out data
|
33
|
+
ctx.albums.each do |album|
|
34
|
+
opts = album.options
|
35
|
+
|
36
|
+
puts "[*] Spliting #{album.tracks.size} tracks"
|
37
|
+
|
38
|
+
# TODO allow stop to be optional (even splits)
|
39
|
+
# TODO allow last track to use EOF
|
40
|
+
album.tracks.each.with_index do |track, index|
|
41
|
+
start, stop = track[:time].map { |t| t.sub ':', '.' }
|
42
|
+
tags = "@a=#{opts[:artist].inspect},@b=#{opts[:name].inspect},@t=#{track[:title].inspect}"
|
43
|
+
|
44
|
+
system "mp3splt -Qf -g [#{tags}] -o '#{index+1} @a - @t' audiodump.mp3 #{start} #{stop}"
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
# Now cleanup
|
49
|
+
puts '[*] Complete!'
|
50
|
+
|
51
|
+
rescue SystemExit => e
|
52
|
+
# Always clean up potental trash
|
53
|
+
File.unlink(*%w[wav mp3].map { |ext| "audiodump.#{ext}" }) rescue nil
|
54
|
+
|
55
|
+
raise e # raise to exit
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
metadata
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: audio_dicer
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- mikeycgto
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-08-09 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.6'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.6'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: With this simple DSL, convert video files into one or more tagged MP3s
|
42
|
+
email:
|
43
|
+
- mikeycgto@gmail.com
|
44
|
+
executables:
|
45
|
+
- audio_dicer
|
46
|
+
extensions: []
|
47
|
+
extra_rdoc_files: []
|
48
|
+
files:
|
49
|
+
- Gemfile
|
50
|
+
- LICENSE.txt
|
51
|
+
- README.md
|
52
|
+
- Rakefile
|
53
|
+
- audio_dicer.gemspec
|
54
|
+
- bin/audio_dicer
|
55
|
+
- lib/audio_dicer.rb
|
56
|
+
- lib/audio_dicer/context.rb
|
57
|
+
- lib/audio_dicer/context/album.rb
|
58
|
+
- lib/audio_dicer/runner.rb
|
59
|
+
- lib/audio_dicer/version.rb
|
60
|
+
homepage: http://github.com/mikeycgto/audio_dicer
|
61
|
+
licenses:
|
62
|
+
- MIT
|
63
|
+
metadata: {}
|
64
|
+
post_install_message:
|
65
|
+
rdoc_options: []
|
66
|
+
require_paths:
|
67
|
+
- lib
|
68
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
69
|
+
requirements:
|
70
|
+
- - ">="
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: '0'
|
73
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - ">="
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
requirements: []
|
79
|
+
rubyforge_project:
|
80
|
+
rubygems_version: 2.2.2
|
81
|
+
signing_key:
|
82
|
+
specification_version: 4
|
83
|
+
summary: DSL to convert videos into a set of tagged MP3s
|
84
|
+
test_files: []
|