vollbremsung 0.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ NmFlZDEyNzA5YWQ0NTdlZWQyMzc2ODA0ODkyMGY5NDQzZDE1NjBkNQ==
5
+ data.tar.gz: !binary |-
6
+ ODVmMDRiNTkwMDlmOTg4OWNkNDUxNzgxY2UxMDhjMTQ4NDE2ZGFiNw==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ NDQzYTk3NzllODgzNjdkNzNiZDQ2NTVmNWY3MDZkNTY2YzI2NmQxNmMzYmU1
10
+ MzA0YWU0OTQwNTJlMWJlOTg5ZWJhZWZiZTg1YjBjYzg4Y2U1ODQ3NzE4ODI1
11
+ ZGI4NWYwMDZkZDI4MzYxNTYzNGU3MDIzNjkxYTFmMDdjNjViMjM=
12
+ data.tar.gz: !binary |-
13
+ NDVhOTNkMGI1NDgxM2U3ZDA1NmY0NWQ1NjI3YmY1M2IzYThhODJiOWIxNjVh
14
+ ZGM1MzIwNTFlYjk5ZmYyZmJjZjQyOTNkNjA1MjM3NmQ0Yzg1N2RmOTgyMDVl
15
+ NjhmZTVlYjMxMWVmODhiOTI0ZDIzMDMyYTExZDliODdjNjc3ZDg=
@@ -0,0 +1,34 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /test/tmp/
9
+ /test/version_tmp/
10
+ /tmp/
11
+
12
+ ## Specific to RubyMotion:
13
+ .dat*
14
+ .repl_history
15
+ build/
16
+
17
+ ## Documentation cache and generated files:
18
+ /.yardoc/
19
+ /_yardoc/
20
+ /doc/
21
+ /rdoc/
22
+
23
+ ## Environment normalisation:
24
+ /.bundle/
25
+ /lib/bundler/man/
26
+
27
+ # for a library or gem, you might want to ignore these files since the code is
28
+ # intended to run in multiple environments; otherwise, check them in:
29
+ # Gemfile.lock
30
+ # .ruby-version
31
+ # .ruby-gemset
32
+
33
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
34
+ .rvmrc
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in vollbremsung.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2014 Maximilian Irro
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 all
13
+ 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 THE
21
+ SOFTWARE.
@@ -0,0 +1,4 @@
1
+ vollbremsung
2
+ ============
3
+
4
+ Handbrake bulk encoding tool
File without changes
@@ -0,0 +1,218 @@
1
+ #!/usr/bin/env ruby
2
+ # -*- encoding : utf-8 -*-
3
+
4
+ require 'mkmf' # part of stdlib
5
+ require 'open3'
6
+ require 'json'
7
+ require 'handbrake'
8
+ require 'vollbremsung'
9
+
10
+ def log(msg)
11
+ puts Time.new.strftime("%Y-%m-%d %H:%M:%S") + " #{msg}"
12
+ end
13
+
14
+ def ffprobe(file)
15
+ stdout,stderr,status = Open3.capture3("ffprobe -v quiet -print_format json -show_format -show_streams \"#{file}\"")
16
+ if status.success?
17
+ return JSON.parse(stdout)
18
+ else
19
+ STDERR.puts stderr
20
+ return nil
21
+ end
22
+ end
23
+
24
+ options = {}
25
+ begin
26
+ require 'optparse'
27
+ OptionParser.new do |opts|
28
+ opts.banner = Vollbremsung::USAGE
29
+ opts.separator ""
30
+
31
+ opts.on("-d", "--delete", "Delete source files after successful encoding") do |flag|
32
+ options[:delete] = true
33
+ end
34
+
35
+ opts.on("-m", "--move", "Move source files to <FILENAME>.old after successful encoding") do |flag|
36
+ options[:move] = true
37
+ end
38
+
39
+ opts.on("-r", "--recursive", "Process all file in subdirectories recursively as well") do |flag|
40
+ options[:recursive] = true
41
+ end
42
+
43
+ opts.on("-t", "--title", "Set the mp4 title to the filename") do |flag|
44
+ options[:title] = true
45
+ end
46
+
47
+ opts.on_tail("-h", "--help", "Show this message") do
48
+ puts opts
49
+ exit
50
+ end
51
+ end.parse! # do the parsing. do it now!
52
+ rescue LoadError
53
+ puts "Option parsing not supported on your system. All options will be ignored."
54
+ puts "To enable support run 'gem install optparse'"
55
+ options[:delete] = false
56
+ options[:move] = false
57
+ options[:recursive] = false
58
+ options[:title] = false
59
+ end
60
+
61
+
62
+ if ARGV[0].nil?
63
+ puts "No target directory provided."
64
+ puts Vollbremsung::USAGE
65
+ exit 1
66
+ end
67
+
68
+ TARGET_PATH = ARGV[0]
69
+
70
+ unless File.exists?(TARGET_PATH)
71
+ puts "The target path you provided does not exists."
72
+ exit 1
73
+ end
74
+
75
+ if options[:move] && options[:delete]
76
+ puts "--delete (-d) and --move (-m) are mutually exclusive - choose one!"
77
+ puts "It is not possible to delete and move the source files at the same time."
78
+ exit 1
79
+ end
80
+
81
+ unless find_executable('HandbrakeCLI') || find_executable('HandBrakeCLI')
82
+ puts "It seems you do not have HandbrakeCLI installed or it is not available in your $PATH."
83
+ puts "Install it an run again"
84
+ exit 1
85
+ end
86
+
87
+ unless find_executable 'ffprobe'
88
+ puts "It seems you do not have ffprobe installed or it is not available in your $PATH."
89
+ puts "ffprobe is part of ffmpeg. Install it for your system and run again."
90
+ exit 1
91
+ end
92
+
93
+ File.delete 'mkmf.log' # find_executable seems to create such file in case executable is not found
94
+
95
+ #StreamStruct = Struct.new(:count,:names)
96
+
97
+ #HANDBRAKE_OPTIONS = "--encoder x264 --quality 20.0 --aencode faac -B 160 --mixdown dpl2 --arate Auto -D 0.0 --format mp4 --markers --audio-copy-mask aac,ac3,dtshd,dts,mp3 --audio-fallback ffac3 --x264-preset veryfast --loose-anamorphic --modulus 2"
98
+
99
+ log "probing for target files..."
100
+ target_files = []
101
+ log "Files found:"
102
+ if File.directory?(TARGET_PATH)
103
+
104
+ scope = options[:recursive] ? "/**/*" : "/*"
105
+
106
+ Dir[TARGET_PATH + scope].sort.each do |file|
107
+ unless File.directory?(file)
108
+ if Vollbremsung::CONVERT_TYPES.include?(File.extname(file).downcase[1..-1])
109
+ puts "* " + file[TARGET_PATH.length+1..-1]
110
+ target_files << file
111
+ end
112
+ end
113
+ end
114
+
115
+ else
116
+ puts "* " + TARGET_PATH
117
+ target_files << File.absolute_path(TARGET_PATH)
118
+ end
119
+
120
+ target_files.each do |infile|
121
+
122
+ metadata = ffprobe(infile)
123
+ if metadata.nil?
124
+ log "ERROR retrieving metadata -- skipping this file"
125
+ next
126
+ end
127
+
128
+ astreams = Vollbremsung::StreamDescr.new
129
+ sstreams = Vollbremsung::StreamDescr.new
130
+
131
+ metadata['streams'].each do |stream|
132
+ case stream['codec_type']
133
+ when 'audio'
134
+ astreams.count += 1
135
+ astreams.names << stream['tags']['title'] unless stream['tags'].nil? || stream['tags']['title'].nil?
136
+ when 'subtitle'
137
+ sstreams.count += 1
138
+ sstreams.names << stream['tags']['title'] unless stream['tags'].nil? || stream['tags']['title'].nil?
139
+ else
140
+ # this is attachment stuff, like typefonts --> ignore
141
+ end
142
+ end
143
+
144
+
145
+ infile_basename = File.basename(infile)
146
+ infile_basename_noext = File.basename(infile, File.extname(infile)) # without ext
147
+ infile_dirname = File.dirname(infile)
148
+ infile_path_noext = File.join(infile_dirname, infile_basename_noext)
149
+ infile_relative_path = #File.directory?(TARGET_PATH) ? infile[TARGET_PATH.length+1..-1] : File.basename(TARGET_PATH)
150
+ if File.directory?(TARGET_PATH)
151
+ infile[TARGET_PATH.length+1..-1]
152
+ else
153
+ File.basename(TARGET_PATH)
154
+ end
155
+
156
+ outfile = "#{infile_path_noext}.mp4"
157
+
158
+ log "processing: #{infile_relative_path}"
159
+
160
+ #%x( #{HANDBRAKE_CLI} #{HANDBRAKE_OPTIONS} --audio #{(1..astreams.count).to_a.join(',')} --aname #{astreams.names.join(',')} --subtitle #{(1..sstreams.count).to_a.join(',')} -i \"#{infile}\" -o \"#{outfile}\" 2>&1 )
161
+
162
+ success = false
163
+ begin
164
+ HandBrake::CLI.new.input(infile).encoder('x264').quality('20.0').aencoder('faac').
165
+ ab('160').mixdown('dpl2').arate('Auto').drc('0.0').format('mp4').markers.
166
+ audio_copy_mask('aac,ac3,dtshd,dts,mp3').audio_fallback('ffac3').x264_preset('veryfast').
167
+ loose_anamorphic.modulus('2').audio((1..astreams.count).to_a.join(',')).aname(astreams.names.join(',')).
168
+ subtitle((1..sstreams.count).to_a.join(',')).output(outfile)
169
+
170
+ # if we make it here, encoding went well
171
+ log "SUCCESS: encoding done"
172
+ success = true
173
+ rescue
174
+ log "ERROR: Handbrake exited with an error"
175
+ end # HandBrake::CLI
176
+
177
+ if success
178
+ infile_size = File.size(infile)
179
+ outfile_size = File.size(outfile)
180
+
181
+ log "compression ratio: %.2f" % (outfile_size.to_f / infile_size.to_f)
182
+
183
+ if options[:title]
184
+ log "setting mp4 title"
185
+
186
+ infile_noext = File.join( File.dirname(infile), File.basename(infile,File.extname(infile)))
187
+ tmpfile = infile_noext + ".tmp.mp4"
188
+
189
+ %x( ffmpeg -i \"#{outfile}\" -metadata title=\"#{infile_basename_noext}\" #{Vollbremsung::FFMPEG_OPTIONS} \"#{tmpfile}\" 2>&1 )
190
+
191
+ if $?.exitstatus == 0
192
+ begin
193
+ File.delete outfile
194
+ File.rename tmpfile, outfile
195
+ rescue
196
+ log "ERROR: moving #{tmpfile} to #{outfile}"
197
+ end
198
+ else
199
+ log "ERROR: mp4 title could not be changed"
200
+ end
201
+ end # if options[:title]
202
+
203
+ if options[:move]
204
+ log "moving source file to *.old"
205
+ File.rename(infile, "#{infile}.old") rescue log "ERROR: renaming source file"
206
+ elsif options[:delete]
207
+ log "deleting source file"
208
+ File.delete(infile) rescue log "ERROR: deleting source file"
209
+ end
210
+
211
+ end # if success
212
+ end # target_files.each
213
+
214
+ if target_files.empty?
215
+ log "nothing to do"
216
+ else
217
+ log "all items processed"
218
+ end
@@ -0,0 +1,14 @@
1
+ module Vollbremsung
2
+
3
+ USAGE = "Usage: vollbremsung [options] <target>"
4
+ VERSION = '0.0.8'
5
+ CONVERT_TYPES = ['mkv','avi','mov','flv','mpg','wmv']
6
+ FFMPEG_OPTIONS = "-map 0 -acodec copy -vcodec copy -scodec copy"
7
+
8
+ class StreamDescr < Struct.new(:count,:names)
9
+ def initialize
10
+ super(0,[])
11
+ end
12
+ end
13
+
14
+ end
@@ -0,0 +1,23 @@
1
+ # encoding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'vollbremsung'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'vollbremsung'
8
+ spec.version = Vollbremsung::VERSION
9
+ spec.date = '2014-08-13'
10
+ spec.summary = "Handbrake bulk encoding tool"
11
+ spec.description = "Handbrake bulk encoding tool"
12
+ spec.author = "Maximilian Irro"
13
+ spec.email = 'max@disposia.org'
14
+ spec.files = `git ls-files -z`.split("\x0")
15
+ spec.executables = ['vollbremsung']
16
+ spec.homepage = 'https://github.com/mpgirro/vollbremsung'
17
+ spec.license = 'MIT'
18
+
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.required_ruby_version = '>= 1.9.3'
22
+ spec.add_dependency 'handbrake', '~> 0'
23
+ end
metadata ADDED
@@ -0,0 +1,66 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: vollbremsung
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.8
5
+ platform: ruby
6
+ authors:
7
+ - Maximilian Irro
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-08-13 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: handbrake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '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'
27
+ description: Handbrake bulk encoding tool
28
+ email: max@disposia.org
29
+ executables:
30
+ - vollbremsung
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - .gitignore
35
+ - Gemfile
36
+ - LICENSE
37
+ - README.md
38
+ - Rakefile
39
+ - bin/vollbremsung
40
+ - lib/vollbremsung.rb
41
+ - vollbremsung.gemspec
42
+ homepage: https://github.com/mpgirro/vollbremsung
43
+ licenses:
44
+ - MIT
45
+ metadata: {}
46
+ post_install_message:
47
+ rdoc_options: []
48
+ require_paths:
49
+ - lib
50
+ required_ruby_version: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: 1.9.3
55
+ required_rubygems_version: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ! '>='
58
+ - !ruby/object:Gem::Version
59
+ version: '0'
60
+ requirements: []
61
+ rubyforge_project:
62
+ rubygems_version: 2.4.1
63
+ signing_key:
64
+ specification_version: 4
65
+ summary: Handbrake bulk encoding tool
66
+ test_files: []