class FLACsmith::Encoders::Track

A track encoder for encoding a file as a FLAC file.

Constants

DEFAULT_OPTIONS

Attributes

input_path[R]
logger[R]
output_dir[R]
picture[R]

Public Class Methods

new(input_path:, image_path: "", output_dir: "", logger: Logger.new(STDOUT)) click to toggle source

rubocop:disable Metrics/ParameterLists

# File lib/flacsmith/encoders/track.rb, line 15
def initialize input_path:, image_path: "", output_dir: "", logger: Logger.new(STDOUT)
  @input_path = Pathname String(input_path)
  @picture = Metadata::Image.new image_path
  @output_dir = Pathname String(output_dir)
  @logger = logger
end

Public Instance Methods

call() click to toggle source

rubocop:enable Metrics/ParameterLists

# File lib/flacsmith/encoders/track.rb, line 23
def call
  logger.debug { command_line }
  execute_command
  true
end

Private Instance Methods

command_line() click to toggle source
# File lib/flacsmith/encoders/track.rb, line 58
def command_line
  %(flac #{options.join " "} --output-name=#{escaped_output_path} #{escaped_input_path})
end
escaped_input_path(= Shellwords.escape input_path) click to toggle source
# File lib/flacsmith/encoders/track.rb, line 47
    def escaped_input_path = Shellwords.escape input_path

    def output_path
      return Pathname "" unless input_path.exist?

      file = Metadata::File.new input_path
      Pathname.new "#{output_dir}/#{file.name}.flac"
    end

    def escaped_output_path = Shellwords.escape output_path

    def command_line
      %(flac #{options.join " "} --output-name=#{escaped_output_path} #{escaped_input_path})
    end

    def execute_command
      stdout, stderr, status = Open3.capture3 command_line
      logger.info { stdout }
      fail Errors::Track, stderr unless status.success?
    end
  end
end
escaped_output_path(= Shellwords.escape output_path) click to toggle source
# File lib/flacsmith/encoders/track.rb, line 56
  def escaped_output_path = Shellwords.escape output_path

  def command_line
    %(flac #{options.join " "} --output-name=#{escaped_output_path} #{escaped_input_path})
  end

  def execute_command
    stdout, stderr, status = Open3.capture3 command_line
    logger.info { stdout }
    fail Errors::Track, stderr unless status.success?
  end
end
execute_command() click to toggle source
# File lib/flacsmith/encoders/track.rb, line 62
def execute_command
  stdout, stderr, status = Open3.capture3 command_line
  logger.info { stdout }
  fail Errors::Track, stderr unless status.success?
end
options(= substituted_options.compact + tags) click to toggle source
# File lib/flacsmith/encoders/track.rb, line 45
      def options = substituted_options.compact + tags

      def escaped_input_path = Shellwords.escape input_path

      def output_path
        return Pathname "" unless input_path.exist?

        file = Metadata::File.new input_path
        Pathname.new "#{output_dir}/#{file.name}.flac"
      end

      def escaped_output_path = Shellwords.escape output_path

      def command_line
        %(flac #{options.join " "} --output-name=#{escaped_output_path} #{escaped_input_path})
      end

      def execute_command
        stdout, stderr, status = Open3.capture3 command_line
        logger.info { stdout }
        fail Errors::Track, stderr unless status.success?
      end
    end
  end
end
output_path() click to toggle source
# File lib/flacsmith/encoders/track.rb, line 49
def output_path
  return Pathname "" unless input_path.exist?

  file = Metadata::File.new input_path
  Pathname.new "#{output_dir}/#{file.name}.flac"
end
substituted_options() click to toggle source
# File lib/flacsmith/encoders/track.rb, line 33
def substituted_options
  DEFAULT_OPTIONS.map do |option|
    case option
      when /<image_path>/
        option.sub "<image_path>", picture if picture.exist?
      else option
    end
  end
end
tags(= Metadata::File.new(input_path).tags.map { |tag| "--tag= click to toggle source
# File lib/flacsmith/encoders/track.rb, line 43
    def tags = Metadata::File.new(input_path).tags.map { |tag| "--tag=#{tag}" }

    def options = substituted_options.compact + tags

    def escaped_input_path = Shellwords.escape input_path

    def output_path
      return Pathname "" unless input_path.exist?

      file = Metadata::File.new input_path
      Pathname.new "#{output_dir}/#{file.name}.flac"
    end

    def escaped_output_path = Shellwords.escape output_path

    def command_line
      %(flac #{options.join " "} --output-name=#{escaped_output_path} #{escaped_input_path})
    end

    def execute_command
      stdout, stderr, status = Open3.capture3 command_line
      logger.info { stdout }
      fail Errors::Track, stderr unless status.success?
    end
  end
end