Class: MkvToolNix::Modules::MkvPropEdit

Inherits:
Object
  • Object
show all
Includes:
MkvModule
Defined in:
lib/mkvtoolnix/modules/mkvpropedit.rb

Overview

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from MkvModule

#call_cmd

Constructor Details

#initialize(bin_path) ⇒ MkvPropEdit

Returns a new instance of MkvPropEdit.



11
12
13
14
15
# File 'lib/mkvtoolnix/modules/mkvpropedit.rb', line 11

def initialize(bin_path)
  @bin_path = "#{bin_path}mkvpropedit"
  @abort_at_warning = false
  @disable_language_ietf = false
end

Instance Attribute Details

#abort_at_warning=(value) ⇒ Object (writeonly)

Sets the attribute abort_at_warning

Parameters:

  • value

    the value to set the attribute abort_at_warning to.



9
10
11
# File 'lib/mkvtoolnix/modules/mkvpropedit.rb', line 9

def abort_at_warning=(value)
  @abort_at_warning = value
end

#disable_language_ietf=(value) ⇒ Object (writeonly)

Sets the attribute disable_language_ietf

Parameters:

  • value

    the value to set the attribute disable_language_ietf to.



9
10
11
# File 'lib/mkvtoolnix/modules/mkvpropedit.rb', line 9

def disable_language_ietf=(value)
  @disable_language_ietf = value
end

Instance Method Details

#add_attachment(file, attachment_file, name = nil, description = nil, uid = nil, mime_type = nil, full_parse_mode: false) ⇒ Object

adds an attachment to the mkv file

Parameters:

  • file (String)

    path to the mkv file

  • attachment_file (String)

    path to the attachment file

  • name (String) (defaults to: nil)

    the attachment name, or nil to use the attachment’s file name

  • description (String) (defaults to: nil)

    attachments description

  • uid (String) (defaults to: nil)

    the uid to use, if nil, will be determined automatically

  • mime_type (String) (defaults to: nil)

    the files mime type. If nil, will be determined automatically

  • full_parse_mode (Boolean) (defaults to: false)

    sets full parse mod



143
144
145
146
147
148
149
150
151
152
153
154
155
# File 'lib/mkvtoolnix/modules/mkvpropedit.rb', line 143

def add_attachment(file, attachment_file, name = nil, description = nil, uid = nil, mime_type = nil,
                   full_parse_mode: false)
  cmd = [@bin_path]
  add_default_options(cmd, full_parse_mode)
  cmd << file
  cmd << '--attachment-name' << name unless name.nil?
  cmd << '--attachment-description' << description unless description.nil?
  cmd << '--attachment-mime-type' << mime_type unless mime_type.nil?
  cmd << '--attachment-uid' << uid unless uid.nil?
  cmd << '--add-attachment' << attachment_file

  call_cmd(cmd)
end

#add_track_statistics_tags(file, full_parse_mode: false) ⇒ Object

calculates and adds the statistics tags

Parameters:

  • file (String)

    path to the mkv file

  • full_parse_mode (Boolean) (defaults to: false)

    sets full parse mod



46
47
48
49
50
51
52
53
# File 'lib/mkvtoolnix/modules/mkvpropedit.rb', line 46

def add_track_statistics_tags(file, full_parse_mode: false)
  cmd = [@bin_path]
  add_default_options(cmd, full_parse_mode)
  cmd << file
  cmd << '--add-track-statistics-tags'

  call_cmd(cmd)
end

#delete_track_statistics_tags(file, full_parse_mode: false) ⇒ Object

deletes the track statistics tags

Parameters:

  • file (String)

    path to the mkv file

  • full_parse_mode (Boolean) (defaults to: false)

    sets full parse mod



32
33
34
35
36
37
38
39
40
# File 'lib/mkvtoolnix/modules/mkvpropedit.rb', line 32

def delete_track_statistics_tags(file, full_parse_mode: false)
  cmd = [@bin_path]
  cmd << '--parse-mode' << 'full' if full_parse_mode
  cmd << '--abort-on-warnings' if @abort_at_warning
  cmd << file
  cmd << '--delete-track-statistics-tags'

  call_cmd(cmd)
end

#remove_attachment(file, selector, full_parse_mode: false) ⇒ Object

removes an attachment of the mkv file

Parameters:

  • file (String)

    path to the mkv file

  • selector (String)

    a selector to determine which attachment(s) to remove. See MkvToolNix::PropEditSelector

  • full_parse_mode (Boolean) (defaults to: false)

    sets full parse mod



187
188
189
190
191
192
193
194
# File 'lib/mkvtoolnix/modules/mkvpropedit.rb', line 187

def remove_attachment(file, selector, full_parse_mode: false)
  cmd = [@bin_path]
  add_default_options(cmd, full_parse_mode)
  cmd << file
  cmd << '--delete-attachment' << selector

  call_cmd(cmd)
end

#remove_property(file, selector, properties, full_parse_mode: false) ⇒ Object

removes a property from the mkv file

Parameters:

  • file (String)

    path to the mkv file

  • selector (String)

    the info or track selector

  • properties (String, Property)

    a list containing a Property or a String (Property will be determined automatically)

  • full_parse_mode (Boolean) (defaults to: false)

    sets full parse mod



95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/mkvtoolnix/modules/mkvpropedit.rb', line 95

def remove_property(file, selector, properties, full_parse_mode: false)
  props = properties.map { |it| it.is_a?(Types::PropEdit::Property) ? it : find_property(it) }

  cmd = [@bin_path]
  add_default_options(cmd, full_parse_mode)
  cmd << file
  cmd << '--edit'
  cmd << selector
  props.each do |prop|
    raise Errors::MkvToolNixError, "Property is not removable: #{prop.property}" unless prop.removable

    cmd << '--delete'
    cmd << prop.property
  end

  call_cmd(cmd)
end

#replace_attachment(file, selector, attachment_file, name = nil, description = nil, uid = nil, mime_type = nil, full_parse_mode: false) ⇒ Object

replaces an attachment of the mkv file

Parameters:

  • file (String)

    path to the mkv file

  • selector (String)

    a selector to determine which attachment(s) to replace. See MkvToolNix::PropEditSelector

  • attachment_file (String)

    path to the attachment file

  • name (String) (defaults to: nil)

    the attachment name, or nil to use the attachment’s file name

  • description (String) (defaults to: nil)

    attachments description

  • uid (String) (defaults to: nil)

    the uid to use, if nil, will be determined automatically

  • mime_type (String) (defaults to: nil)

    the files mime type. If nil, will be determined automatically

  • full_parse_mode (Boolean) (defaults to: false)

    sets full parse mod



168
169
170
171
172
173
174
175
176
177
178
179
180
# File 'lib/mkvtoolnix/modules/mkvpropedit.rb', line 168

def replace_attachment(file, selector, attachment_file, name = nil, description = nil, uid = nil, mime_type = nil,
                       full_parse_mode: false)
  cmd = [@bin_path]
  add_default_options(cmd, full_parse_mode)
  cmd << file
  cmd << '--attachment-name' << name unless name.nil?
  cmd << '--attachment-description' << description unless description.nil?
  cmd << '--attachment-mime-type' << mime_type unless mime_type.nil?
  cmd << '--attachment-uid' << uid unless uid.nil?
  cmd << '--replace-attachment' << "#{selector}:#{attachment_file}"

  call_cmd(cmd)
end

#set_chapters(file, chapter_file, full_parse_mode: false) ⇒ Object

adds or replaces the given chapter file to the given mkv file. If the chapter file is empty (valid xml file, but the <chapter/> tag is empty), it removes the chapters from the mkv file

Parameters:

  • file (String)

    path to the mkv file

  • chapter_file (String)

    path to the chapter xml file

  • full_parse_mode (Boolean) (defaults to: false)

    sets full parse mod



61
62
63
64
65
66
67
68
69
# File 'lib/mkvtoolnix/modules/mkvpropedit.rb', line 61

def set_chapters(file, chapter_file, full_parse_mode: false)
  cmd = [@bin_path]
  add_default_options(cmd, full_parse_mode)
  cmd << file
  cmd << '--chapters'
  cmd << chapter_file

  call_cmd(cmd)
end

#set_property(file, selector, property, value, full_parse_mode: false) ⇒ Object

sets a property to the mkv file

Parameters:

  • file (String)

    path to the mkv file

  • selector (String)

    the info or track selector

  • property (String, Property)

    a Property or a String (Property will be determined automatically)

  • value (Any)

    the value to set

  • full_parse_mode (Boolean) (defaults to: false)

    sets full parse mod



120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'lib/mkvtoolnix/modules/mkvpropedit.rb', line 120

def set_property(file, selector, property, value, full_parse_mode: false)
  prop = property.is_a?(Types::PropEdit::Property) ? property : find_property(property)
  cmd = [@bin_path]
  add_default_options(cmd, full_parse_mode)
  cmd << file
  cmd << '--edit'
  cmd << selector
  cmd << '--set'
  # noinspection RubyNilAnalysis
  cmd << "#{prop.property}=#{value}"

  call_cmd(cmd)
end

#set_tags(file, tag_file, selector, full_parse_mode: false) ⇒ Object

sets the given tags to the tag field matching the given selector. A selector can either be all, global or for a specific track.

Parameters:

  • file (String)

    path to the mkv file

  • tag_file (String)

    path to the tag xml file

  • selector (String)

    the selector, all, global or a track selector

  • full_parse_mode (Boolean) (defaults to: false)

    sets full parse mod



78
79
80
81
82
83
84
85
86
# File 'lib/mkvtoolnix/modules/mkvpropedit.rb', line 78

def set_tags(file, tag_file, selector, full_parse_mode: false)
  cmd = [@bin_path]
  add_default_options(cmd, full_parse_mode)
  cmd << file
  cmd << '--tags'
  cmd << "#{selector}:#{tag_file}"

  call_cmd(cmd)
end

#update_attachment(file, selector, name = nil, description = nil, uid = nil, mime_type = nil, full_parse_mode: false) ⇒ Object

updates an attachment of the mkv file

Parameters:

  • file (String)

    path to the mkv file

  • selector (String)

    a selector to determine which attachment to replace. See MkvToolNix::PropEditSelector

  • name (String) (defaults to: nil)

    the new attachment name

  • description (String) (defaults to: nil)

    new attachments description

  • uid (String) (defaults to: nil)

    the new uid

  • mime_type (String) (defaults to: nil)

    the new files mime type

  • full_parse_mode (Boolean) (defaults to: false)

    sets full parse mod



205
206
207
208
209
210
211
212
213
214
215
216
217
# File 'lib/mkvtoolnix/modules/mkvpropedit.rb', line 205

def update_attachment(file, selector, name = nil, description = nil, uid = nil, mime_type = nil,
                      full_parse_mode: false)
  cmd = [@bin_path]
  add_default_options(cmd, full_parse_mode)
  cmd << file
  cmd << '--attachment-name' << name unless name.nil?
  cmd << '--attachment-description' << description unless description.nil?
  cmd << '--attachment-mime-type' << mime_type unless mime_type.nil?
  cmd << '--attachment-uid' << uid unless uid.nil?
  cmd << '--update-attachment' << selector

  call_cmd(cmd)
end

#versionObject

returns the mkvpropedit version

return [String] the version string



20
21
22
23
24
25
26
# File 'lib/mkvtoolnix/modules/mkvpropedit.rb', line 20

def version
  cmd = [@bin_path, '-V']

  result = call_cmd(cmd)

  result.stdout.strip
end