mkvmuxer 0.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: aae6ef7d409e929b08c7fa1b83d605e6c2f364ca
4
+ data.tar.gz: fbdd28c2ed4cddf139d592a5f73813ee9259de22
5
+ SHA512:
6
+ metadata.gz: a08ceb977f2aff81ff05c00b222b3a0f2fdc3ec04917ff33a687e48791ef6b6007e2c11b59466b85723f4d1ea7c8278d6567790249b76a3b693d8f9137742035
7
+ data.tar.gz: 7ac00c8797a4a12bb7623f4d402710b8017fa19f843969d7a0381c20418d740e99b63e84d8b218ca26cfe8c8057bf03d34dd6808bf062f7f9fd07334986c9a10
data/bin/mkvmuxer ADDED
@@ -0,0 +1,10 @@
1
+ #! /usr/bin/env ruby
2
+ require 'mkvmuxer'
3
+
4
+ abort "Usage: #{$0} <path>" if ARGV.empty?
5
+ abort 'Folder not found.' unless File.directory? ARGV.first
6
+
7
+ mkvmuxer = MkvMuxer.new ARGV.first
8
+ mkvmuxer.prepare
9
+ mkvmuxer.merge!
10
+ mkvmuxer.apply_crc32!
@@ -0,0 +1,73 @@
1
+ #
2
+ # DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
3
+ # Version 2, December 2004
4
+ #
5
+ # DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
6
+ # TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
7
+ #
8
+ # 0. You just DO WHAT THE FUCK YOU WANT TO.
9
+ #
10
+
11
+ class MkvMuxer
12
+ attr_reader :command
13
+
14
+ def initialize(path, force = false)
15
+ path = path.gsub('\\', '/')
16
+
17
+ @command = ''
18
+ @mkv = Dir[File.join(path, '*.mkv')].first rescue nil
19
+ @ass = Dir[File.join(path, '*.ass')].first rescue nil
20
+ @chapters = Dir[File.join(path, '*.xml')].first rescue nil
21
+ @output = "#{@mkv}_"
22
+
23
+ @fonts = [].tap { |fonts|
24
+ %w(ttf ttc otf).each { |format| fonts << Dir[File.join(path, 'font*', "*.#{format}")] }
25
+ }.flatten.compact.uniq
26
+
27
+ raise Exception, 'No mkv or ass found' if !@mkv || !@ass
28
+ raise Exception, 'Target mkv already exists' if !force && File.exists?(@output)
29
+ end
30
+
31
+ def prepare(fonts = true, chapters = true)
32
+ options = []
33
+ options << { opt: '-o', val: @output }
34
+ options << { val: @mkv }
35
+ options << { val: @ass }
36
+ options << { opt: '--no-chapters --chapters', val: chapters } if @chapters
37
+
38
+ @fonts.each { |font|
39
+ options << { opt: '--attachment-mime-type', val: 'application/x-truetype-font' }
40
+ options << { opt: '--attach-file', val: font }
41
+ } if fonts
42
+
43
+ @command = [].tap { |cmd|
44
+ options.each { |option|
45
+ cmd << option[:opt] if option[:opt]
46
+ cmd << option[:val]
47
+ }
48
+ }
49
+ end
50
+
51
+ def merge!(mkvmerge = 'mkvmerge')
52
+ Open3.popen3(mkvmerge, *@command) do |stdin, stdout, stderr, wait_thr|
53
+ exit_code = wait_thr.value
54
+
55
+ if exit_code != 0
56
+ err = stderr.read.chomp
57
+ err = stdout.read.chomp if err.strip.empty?
58
+ raise Exception, err
59
+ end
60
+ end
61
+ end
62
+
63
+ def apply_crc32!
64
+ crc32 = MkvMuxer.crc32_of @output
65
+ FileUtils.move(@output, @output.gsub(/CRC32/, crc32)[0..-2])
66
+ end
67
+
68
+ class << self
69
+ def crc32_of(file)
70
+ File.open(file, 'rb') { |f| Zlib.crc32 f.read }.to_s(16)
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,13 @@
1
+ #
2
+ # DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
3
+ # Version 2, December 2004
4
+ #
5
+ # DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
6
+ # TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
7
+ #
8
+ # 0. You just DO WHAT THE FUCK YOU WANT TO.
9
+ #
10
+
11
+ class MkvMuxer
12
+ VERSION = '0.1'
13
+ end
data/lib/mkvmuxer.rb ADDED
@@ -0,0 +1,15 @@
1
+ #--
2
+ # DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
3
+ # Version 2, December 2004
4
+ #
5
+ # DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
6
+ # TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
7
+ #
8
+ # 0. You just DO WHAT THE FUCK YOU WANT TO.
9
+ #++
10
+ require 'fileutils'
11
+ require 'open3'
12
+ require 'zlib'
13
+
14
+ require 'mkvmuxer/mkvmuxer'
15
+ require 'mkvmuxer/version'
metadata ADDED
@@ -0,0 +1,77 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mkvmuxer
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.1'
5
+ platform: ruby
6
+ authors:
7
+ - Giovanni Capuano
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-04-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
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: Wrapper for mkvmerge (mkvtoolnix) to mux video, audio, subtitles, etc.
42
+ in a Matroska container.
43
+ email: webmaster@giovannicapuano.net
44
+ executables:
45
+ - mkvmuxer
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - lib/mkvmuxer/mkvmuxer.rb
50
+ - lib/mkvmuxer/version.rb
51
+ - lib/mkvmuxer.rb
52
+ - bin/mkvmuxer
53
+ homepage: http://www.giovannicapuano.net
54
+ licenses:
55
+ - WTFPL
56
+ metadata: {}
57
+ post_install_message:
58
+ rdoc_options: []
59
+ require_paths:
60
+ - lib
61
+ required_ruby_version: !ruby/object:Gem::Requirement
62
+ requirements:
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ required_rubygems_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ requirements: []
72
+ rubyforge_project:
73
+ rubygems_version: 2.0.3
74
+ signing_key:
75
+ specification_version: 4
76
+ summary: Wrapper for mkvmerge.
77
+ test_files: []