bvwack 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +7 -0
- data/bin/bvwack +3 -0
- data/bvwack.gemspec +19 -0
- data/lib/bvwack/bvwack_version.rb +3 -0
- data/lib/bvwack/convert.rb +216 -0
- data/lib/bvwack.rb +1 -0
- metadata +55 -0
data/Rakefile
ADDED
data/bin/bvwack
ADDED
data/bvwack.gemspec
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
$LOAD_PATH.push File.expand_path("../lib/bvwack", __FILE__)
|
2
|
+
require "bvwack_version"
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.name = "bvwack"
|
6
|
+
s.version = BVWack::VERSION
|
7
|
+
s.platform = Gem::Platform::RUBY
|
8
|
+
s.authors = ["Robie Lutsey"]
|
9
|
+
s.email = ["robie 0x55D in dec at gmail dit com"]
|
10
|
+
s.homepage = ""
|
11
|
+
s.summary = %q{bvwack will wack it's way your pile of unconverted video files.'}
|
12
|
+
s.description = %q{Super simple utility to help you convert all your videos to iPad ready files.}
|
13
|
+
s.requirements = ['ffmpeg and a libx264-slow.ffpreset (possibly in your ~/.ffmpeg/ directory.) Google is your friend.']
|
14
|
+
s.rubyforge_project = "bvwack"
|
15
|
+
s.required_ruby_version = '>=1.9'
|
16
|
+
s.files = Dir['**/**']
|
17
|
+
s.executables = ["bvwack"]
|
18
|
+
s.has_rdoc = false
|
19
|
+
end
|
@@ -0,0 +1,216 @@
|
|
1
|
+
require 'optparse'
|
2
|
+
|
3
|
+
DEFAULT_CONVERT_BASE_DIR = "/Volumes/thundar/media/video"
|
4
|
+
DEFAULT_CLEAN_BASE_DIR = "/Volumes/thundar/media/converted"
|
5
|
+
FFMPEG_OPTS = "-acodec aac -ac 2 -ab 160k -s 1024x768 -vcodec libx264 -vpre slow -vpre iPod640 -vb 1200k -f mp4 -threads 2 -strict experimental"
|
6
|
+
help_text = "
|
7
|
+
Usage: bvwack <options>
|
8
|
+
|
9
|
+
Default action is equivalent to bvwack -n 2
|
10
|
+
|
11
|
+
Options:
|
12
|
+
-b BASE_DIR, --base-dir BASE_DIR Set BASE_DIR instead of /Volumes/thundar/media/video
|
13
|
+
-d, --dry-run Do a dry run. Prints proposed commands to STDOUT.
|
14
|
+
-c, --clean-up Instead of converting, move all converted files to /Volumes/thundar/media/converted/[old-path]
|
15
|
+
-n #, --num-files # Number of videos to batch.
|
16
|
+
-l, --list_converted Lists files that have been converted but not cleaned. Useful for vierifying successful conversion.
|
17
|
+
|
18
|
+
Notes: By default this will not work for you. You must change DEFAULT_CONVERT_BASE_DIR
|
19
|
+
and DEFAULT_CLEAN_BASE_DIR to something that exists on your system. Do not let
|
20
|
+
the clean dir be a subdirectory of base dir or you'll be sad. I have set the
|
21
|
+
FFMPEG options to use only 2 threads. This allows me to use my laptop while
|
22
|
+
converting things. If you just want to hog through video try setting -threads 0
|
23
|
+
in FFMPEG_OPTS.
|
24
|
+
|
25
|
+
Examples:
|
26
|
+
bvwack -dw Shows proposed commands for 2 videos
|
27
|
+
bvwack -w -b somedir/anotherdir -n 5 Converts 5 videos under somedir/anotherdir
|
28
|
+
bvwack -c -n 10 Moves 10 already converted mkv or avi files to /Volumes/thundar/medai/converted/[od-path]"
|
29
|
+
|
30
|
+
options = { }
|
31
|
+
option_parser = OptionParser.new do |opts|
|
32
|
+
opts.on("-d", "--dry-run") do
|
33
|
+
options[:dry_run] = true
|
34
|
+
end
|
35
|
+
|
36
|
+
opts.on("-b BASE_DIR", "--base-dir BASE_DIR") do |base_dir|
|
37
|
+
options[:base_dir] = base_dir
|
38
|
+
end
|
39
|
+
|
40
|
+
opts.on("-c", "--clean-up") do
|
41
|
+
options[:clean_up] = true
|
42
|
+
end
|
43
|
+
|
44
|
+
opts.on("-n NUM_FILES", "--num-files NUM_FILES", Integer) do |num_files|
|
45
|
+
options[:num_files] = num_files
|
46
|
+
end
|
47
|
+
|
48
|
+
opts.on("-h", "--help") do
|
49
|
+
options[:help] = true
|
50
|
+
end
|
51
|
+
|
52
|
+
opts.on("-l", "--list-converted") do
|
53
|
+
options[:list_converted] = true
|
54
|
+
end
|
55
|
+
|
56
|
+
opts.on("-w", "--wack") do
|
57
|
+
options[:wack] = true
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def convert(path_to_file)
|
62
|
+
`ffmpeg -i #{path_to_file} #{FFMPEG_OPTS} #{path_to_file.gsub(/mkv$|avi$/, "ipad.mp4")}`
|
63
|
+
end
|
64
|
+
|
65
|
+
def dry_run(path_to_file)
|
66
|
+
puts "ffmpeg -i #{path_to_file} #{FFMPEG_OPTS} #{path_to_file.gsub(/mkv$|avi$/, "ipad.mp4")}\n\n"
|
67
|
+
end
|
68
|
+
|
69
|
+
|
70
|
+
def get_files(args)
|
71
|
+
if args[0]
|
72
|
+
args.each do |path|
|
73
|
+
if File.file?(path)
|
74
|
+
@paths << path
|
75
|
+
else
|
76
|
+
puts "#{path} is not a real file. Skipping. Try single-quoting the path if it is spacey or ugly."
|
77
|
+
end
|
78
|
+
end
|
79
|
+
else
|
80
|
+
puts "Specify the file(s) to convert: ./media/dir/dir/file1.mkv <'./media/dir/dir name/file(2).avi'>"
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
@converted_files = { }
|
85
|
+
@not_converted_files = { }
|
86
|
+
|
87
|
+
def get_all_files(base_dir = DEFAULT_CONVERT_BASE_DIR)
|
88
|
+
Dir.chdir(base_dir)
|
89
|
+
converted_files = Dir.glob(File.join("**", "*ipad.mp4"))
|
90
|
+
converted_files.each do |i|
|
91
|
+
@converted_files[File.basename(i, ".ipad.mp4")] = i
|
92
|
+
end
|
93
|
+
not_converted_files = Dir.glob(File.join("**", "*.{mkv,avi}"))
|
94
|
+
not_converted_files.each do |i|
|
95
|
+
if File.basename(i).split(".").last == "mkv"
|
96
|
+
@not_converted_files[File.basename(i, ".mkv")] = i
|
97
|
+
elsif File.basename(i).split(".").last == "avi"
|
98
|
+
@not_converted_files[File.basename(i, ".avi")] = i
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
@to_convert = []
|
104
|
+
|
105
|
+
def get_unconverted_files(converted_files, not_converted_files)
|
106
|
+
(not_converted_files.keys - converted_files.keys).each do |key|
|
107
|
+
@to_convert << @not_converted_files[key]
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
def clean_up
|
112
|
+
if @to_clean.length > 0
|
113
|
+
key = @to_clean.pop
|
114
|
+
filename = @not_converted_files[key]
|
115
|
+
dirname = File.dirname(@not_converted_files[key])
|
116
|
+
#puts %Q{mkdir -p "/Volumes/thundar/media/video/converted/#{dirname}" && mv "#{filename}" "/Volumes/thundar/media/video/converted/#{filename}"}
|
117
|
+
#puts "This would mv #{@converted_files[key]} /Volumes/thundar/media/video/converted/#{@converted_files[key]}"
|
118
|
+
`mkdir -p "#{DEFAULT_CLEAN_BASE_DIR}/#{dirname}" && mv "#{filename}" "#{DEFAULT_CLEAN_BASE_DIR}/#{filename}"`
|
119
|
+
else
|
120
|
+
puts "No more files to clean. Hooray!"
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
def dry_clean_up
|
125
|
+
if @to_clean.length > 0
|
126
|
+
key = @to_clean.pop
|
127
|
+
filename = @not_converted_files[key]
|
128
|
+
dirname = File.dirname(@not_converted_files[key])
|
129
|
+
puts %Q{mkdir -p "#{DEFAULT_CLEAN_BASE_DIR}/#{dirname}" && mv "#{filename}" "#{DEFAULT_CLEAN_BASE_DIR}/#{filename}"\n\n}
|
130
|
+
else
|
131
|
+
puts "No more files to clean. Hooray!"
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
def list_converted
|
136
|
+
while @to_clean
|
137
|
+
#if @to_clean.length > 0
|
138
|
+
key = @to_clean.pop
|
139
|
+
converted_filename = @converted_files[key]
|
140
|
+
old_filename = @not_converted_files[key]
|
141
|
+
dirname = File.dirname(@not_converted_files[key])
|
142
|
+
puts "Converted file:\n"
|
143
|
+
puts "in Directory #{dirname}"
|
144
|
+
p `ls -lh #{converted_filename}`
|
145
|
+
p `ls -lh #{old_filename}`
|
146
|
+
puts %Q{To test run: open "#{converted_filename}"}
|
147
|
+
puts "\n\n"
|
148
|
+
#end
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
|
153
|
+
option_parser.parse!
|
154
|
+
puts options.inspect
|
155
|
+
if options[:base_dir]
|
156
|
+
basedir = options[:base_dir]
|
157
|
+
get_all_files(basedir)
|
158
|
+
else
|
159
|
+
get_all_files
|
160
|
+
end
|
161
|
+
|
162
|
+
get_unconverted_files(@converted_files, @not_converted_files)
|
163
|
+
@to_clean = @not_converted_files.keys & @converted_files.keys
|
164
|
+
|
165
|
+
if options[:num_files]
|
166
|
+
limit = (options[:num_files] - 1).to_i
|
167
|
+
else
|
168
|
+
limit = 2
|
169
|
+
end
|
170
|
+
|
171
|
+
case
|
172
|
+
when options[:wack] == TRUE && options[:clean_up] == TRUE
|
173
|
+
puts("Error! -w (--wack) and -c (--clean-up) cannot be used simultaneously.")
|
174
|
+
when options[:list_converted] == TRUE
|
175
|
+
list_converted
|
176
|
+
when options[:dry_run] == TRUE && options[:clean_up] == TRUE
|
177
|
+
(0..limit).each do
|
178
|
+
dry_clean_up
|
179
|
+
end
|
180
|
+
when options[:clean_up] == TRUE
|
181
|
+
(0..limit).each do
|
182
|
+
puts "I would have run clean_up"
|
183
|
+
#clean_up
|
184
|
+
end
|
185
|
+
when options[:dry_run] == TRUE && options[:wack] == TRUE
|
186
|
+
(0..limit).each do |i|
|
187
|
+
file = @to_convert[i]
|
188
|
+
dry_run(file)
|
189
|
+
end
|
190
|
+
when options[:wack] == TRUE
|
191
|
+
(0..limit).each do |i|
|
192
|
+
file = @to_convert[i]
|
193
|
+
puts "I would have run convert(file)"
|
194
|
+
#convert(file)
|
195
|
+
end
|
196
|
+
else
|
197
|
+
puts help_text
|
198
|
+
end
|
199
|
+
|
200
|
+
=begin
|
201
|
+
(0..limit).each do |i|
|
202
|
+
file = @to_convert[i]
|
203
|
+
if options[:dry_run] == TRUE
|
204
|
+
|
205
|
+
else
|
206
|
+
if options[:clean_up] == TRUE
|
207
|
+
puts "I would have run clean_up"
|
208
|
+
#clean_up
|
209
|
+
else
|
210
|
+
puts "I would have run convert(file)"
|
211
|
+
#convert(file)
|
212
|
+
end
|
213
|
+
end
|
214
|
+
end
|
215
|
+
end
|
216
|
+
=end
|
data/lib/bvwack.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bvwack/convert"
|
metadata
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: bvwack
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Robie Lutsey
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-02-21 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: Super simple utility to help you convert all your videos to iPad ready
|
15
|
+
files.
|
16
|
+
email:
|
17
|
+
- robie 0x55D in dec at gmail dit com
|
18
|
+
executables:
|
19
|
+
- bvwack
|
20
|
+
extensions: []
|
21
|
+
extra_rdoc_files: []
|
22
|
+
files:
|
23
|
+
- bin/bvwack
|
24
|
+
- bvwack.gemspec
|
25
|
+
- lib/bvwack/bvwack_version.rb
|
26
|
+
- lib/bvwack/convert.rb
|
27
|
+
- lib/bvwack.rb
|
28
|
+
- Rakefile
|
29
|
+
homepage: ''
|
30
|
+
licenses: []
|
31
|
+
post_install_message:
|
32
|
+
rdoc_options: []
|
33
|
+
require_paths:
|
34
|
+
- lib
|
35
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
36
|
+
none: false
|
37
|
+
requirements:
|
38
|
+
- - ! '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.9'
|
41
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
43
|
+
requirements:
|
44
|
+
- - ! '>='
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0'
|
47
|
+
requirements:
|
48
|
+
- ffmpeg and a libx264-slow.ffpreset (possibly in your ~/.ffmpeg/ directory.) Google
|
49
|
+
is your friend.
|
50
|
+
rubyforge_project: bvwack
|
51
|
+
rubygems_version: 1.8.10
|
52
|
+
signing_key:
|
53
|
+
specification_version: 3
|
54
|
+
summary: bvwack will wack it's way your pile of unconverted video files.'
|
55
|
+
test_files: []
|