class MkvToolNix::Modules::MkvExtract

mkvtoolnix.download/doc/mkvpropedit.html#mkvpropedit.edit_selectors

Attributes

abort_at_warning[RW]

Public Class Methods

new(bin_path) click to toggle source
# File lib/mkvtoolnix/modules/mkvextract.rb, line 11
def initialize(bin_path)
  @bin_path = "#{bin_path}mkvextract"
  @abort_at_warning = false
end

Public Instance Methods

extract_attachments(file, attachments, full_parse_mode: false) click to toggle source

extracts the selected attachments

@param file [String] path to the mkv file @param attachments [Array] a list of Attachments, Strings or Hashes or a mix of them. @param full_parse_mode [Boolean] sets full parse mod

# File lib/mkvtoolnix/modules/mkvextract.rb, line 52
def extract_attachments(file, attachments, full_parse_mode: false)
  cmd = [@bin_path, file, 'attachments']
  add_default_options(cmd, full_parse_mode)

  add_id_file_list(cmd, attachments)

  call_cmd(cmd)
end
extract_chapters(file, out_file, simple: false, simple_language: nil, full_parse_mode: false) click to toggle source

extracts the chapter xml file

@param file [String] path to the mkv file @param out_file [String] path to the file to write the chapter xml file to @param full_parse_mode [Boolean] sets full parse mod

# File lib/mkvtoolnix/modules/mkvextract.rb, line 66
def extract_chapters(file, out_file, simple: false, simple_language: nil, full_parse_mode: false)
  cmd = [@bin_path, file, 'chapters']
  add_default_options(cmd, full_parse_mode)

  cmd << '--simple' if simple
  cmd << '--simple-language' << simple_language unless simple_language.nil?

  cmd << out_file

  call_cmd(cmd)
end
extract_cue_sheet(file, out_file, full_parse_mode: false) click to toggle source

extracts the cue sheet

@param file [String] path to the mkv file @param out_file [String] path to the file to write cue sheet file to @param full_parse_mode [Boolean] sets full parse mod

# File lib/mkvtoolnix/modules/mkvextract.rb, line 97
def extract_cue_sheet(file, out_file, full_parse_mode: false)
  cmd = [@bin_path, file, 'cuesheet']
  add_default_options(cmd, full_parse_mode)

  cmd << out_file

  call_cmd(cmd)
end
extract_cues(file, tracks, full_parse_mode: false) click to toggle source

extracts the cues of the selected tracks

@param file [String] path to the mkv file @param tracks [Array] a list of Tracks, Strings or Hashes or a mix of them. @param full_parse_mode [Boolean] sets full parse mod

# File lib/mkvtoolnix/modules/mkvextract.rb, line 125
def extract_cues(file, tracks, full_parse_mode: false)
  cmd = [@bin_path, file, 'cues']
  add_default_options(cmd, full_parse_mode)

  add_id_file_list(cmd, tracks)

  call_cmd(cmd)
end
extract_tags(file, out_file, full_parse_mode: false) click to toggle source

extracts the tags xml file

@param file [String] path to the mkv file @param out_file [String] path to the file to write the tags xml file to @param full_parse_mode [Boolean] sets full parse mod

# File lib/mkvtoolnix/modules/mkvextract.rb, line 83
def extract_tags(file, out_file, full_parse_mode: false)
  cmd = [@bin_path, file, 'tags']
  add_default_options(cmd, full_parse_mode)

  cmd << out_file

  call_cmd(cmd)
end
extract_timestamps(file, tracks, full_parse_mode: false) click to toggle source

extracts the timestamps of the selected tracks

@param file [String] path to the mkv file @param tracks [Array] a list of Tracks, Strings or Hashes or a mix of them. @param full_parse_mode [Boolean] sets full parse mod

# File lib/mkvtoolnix/modules/mkvextract.rb, line 111
def extract_timestamps(file, tracks, full_parse_mode: false)
  cmd = [@bin_path, file, 'timestamps_v2']
  add_default_options(cmd, full_parse_mode)

  add_id_file_list(cmd, tracks)

  call_cmd(cmd)
end
extract_tracks(file, tracks, extract_cuesheet: false, raw: false, full_raw: false, full_parse_mode: false) click to toggle source

extracts the selected tracks

@param file [String] path to the mkv file @param tracks [Array] a list of Tracks, Strings or Hashes or a mix of them. @param extract_cuesheet [Boolean] extracts the cuesheet to [filename].cue @param raw [Boolean] if true, extracts the raw file, does not contain the CodecPrivate element @param full_raw [Boolean] if true, extracts the raw file, does contain the CodecPrivate element @param full_parse_mode [Boolean] sets full parse mod

# File lib/mkvtoolnix/modules/mkvextract.rb, line 35
def extract_tracks(file, tracks, extract_cuesheet: false, raw: false, full_raw: false, full_parse_mode: false)
  cmd = [@bin_path, file, 'tracks']
  add_default_options(cmd, full_parse_mode)
  cmd << '--cuesheet' if extract_cuesheet
  cmd << '--raw' if raw
  cmd << '--fullraw' if full_raw

  add_id_file_list(cmd, tracks)

  call_cmd(cmd)
end
version() click to toggle source

returns the mkvextract version

return [String] the version string

# File lib/mkvtoolnix/modules/mkvextract.rb, line 19
def version
  cmd = [@bin_path, '-V']

  result = call_cmd(cmd)

  result.stdout.strip
end

Private Instance Methods

add_default_options(cmd, full_parse_mode) click to toggle source
# File lib/mkvtoolnix/modules/mkvextract.rb, line 144
def add_default_options(cmd, full_parse_mode)
  cmd << '--parse-fully' if full_parse_mode
  cmd << '--abort-on-warnings' if @abort_at_warning
end
add_id_file_list(cmd, id_file_list) click to toggle source
# File lib/mkvtoolnix/modules/mkvextract.rb, line 134
def add_id_file_list(cmd, id_file_list)
  id_file_list.each_with_index do |ele, index|
    cmd << "#{ele.track_id}:#{ele.output_file}" if ele.is_a?(Types::Extract::Track)
    cmd << "#{ele.attachment_id}:#{ele.output_file}" if ele.is_a?(Types::Extract::Attachment)
    cmd << "#{ele[:id]}:#{ele[:output_file]}" if ele.is_a?(Hash)
    cmd << "#{ele[0]}:#{ele[1]}" if ele.is_a?(Array)
    cmd << "#{index + 1}:#{ele}" if ele.is_a?(String)
  end
end