#!/usr/bin/env ruby # Copyright (C) 2013-2020 all contributors # License: GPL-3.0+ # frozen_string_literal: true require 'yaml' require 'optparse' require 'dtas/splitfx' usage = "#$0 [-n|--dry-run][-j [JOBS]][-s|--silent] SPLITFX_FILE.yml [TARGET]" overrides = {} # FIXME: not tested default_target = "flac" opts = { jobs: 1 } OptionParser.new('', 24, ' ') do |op| op.banner = usage op.on('-n', '--dry-run') { opts[:dryrun] = true } op.on('-j', '--jobs [JOBS]', Integer) { |val| opts[:jobs] = val } # nil==inf op.on('-s', '--quiet', '--silent') { opts[:silent] = true } op.on('-D', '--no-dither') { opts[:no_dither] = true } op.on('-O', '--outdir OUTDIR') { |val| opts[:outdir] = val } op.on('-C', '--compression FACTOR') { |val| opts[:compression] = val } op.on('-r', '--rate RATE') do |val| mult = val.sub!(/k\z/, '') ? 1000 : 1 opts[:rate] = (val.to_f * mult).to_i end op.on('-b', '--bits RATE', Integer) { |val| opts[:bits] = val } op.on('-t', '--trim POSITION') { |val| opts[:trim] = val.tr(',', ' ') } op.on('-E', '--err-suffix SUFFIX') do |val| opts[:err_suffix] = val.start_with?('.') ? val.freeze : ".#{val}" end op.on('-p', '--sox-pipe') do opts[:sox_pipe] = true default_target = 'sox' end op.parse!(ARGV) end if opts[:sox_pipe] && opts[:err_suffix] abort '--err-suffix and --sox-pipe are mutually exclusive' end args = [] ARGV.each do |arg| case arg when %r{\A(\w+)=(.*)\z} key, val = $1, $2 # only one that makes sense is infile=another_file overrides[key] = YAML.load(val) when %r{\A(\w+)\.(\w+)=(.*)\z} # comments.ARTIST='blah' top, key, val = $1, $2, $3 hsh = overrides[top] ||= {} hsh[key] = val else args << arg end end trap(:INT) { exit 130 } file = args.shift or abort usage target = args.shift || default_target splitfx = DTAS::SplitFX.new splitfx.import(YAML.load(File.read(file)), overrides) splitfx.run(target, opts)