commit 016eb90a792c10c3c988d4460a3f71d95d81c26c
parent 6ae9ebfc64066797097d99dda75ed26c448ea748
Author: David Eisinger <[email protected]>
Date: Sun, 29 Oct 2023 22:57:09 -0400
Add audio processing script
Diffstat:
| A | bin/audio | | | 47 | +++++++++++++++++++++++++++++++++++++++++++++++ |
1 file changed, 47 insertions(+), 0 deletions(-)
diff --git a/bin/audio b/bin/audio
@@ -0,0 +1,47 @@
+#!/usr/bin/env ruby
+
+require "optparse"
+
+ARTIST = "David Eisinger"
+
+Config = Struct.new(:file, :title, :directory, :artist)
+
+config = Config.new
+
+parser = OptionParser.new do |opts|
+ opts.banner = "Usage: bin/audio [options]"
+
+ opts.on("-f", "--file FILE", "input file") do |file|
+ config.file = file
+ end
+
+ opts.on("-t", "--title TITLE", "title of the track") do |title|
+ config.title = title
+ end
+
+ opts.on("-d", "--directory DIRECTORY", "directory to put the output file") do |directory|
+ config.directory = directory
+ end
+
+ opts.on("-a", "--artist ARTIST", "artist (default: #{ARTIST})") do |artist|
+ config.artist = artist
+ end
+end
+
+begin
+ parser.parse!(ARGV)
+ config.artist ||= ARTIST
+ missing = config.to_h.filter_map { |k, v| k if v.nil? }
+ raise OptionParser::MissingArgument.new(missing * ", ") unless missing.empty?
+rescue
+ puts $!.to_s
+ puts parser
+ exit
+end
+
+dest = [config.directory, "#{config.title}.mp3"].join("/").squeeze("/")
+
+`ffmpeg -i "#{config.file}" -af "pan=mono|FC=FL" -y "#{dest}"`
+`id3tag --artist="#{config.artist}" --song="#{config.title}" "#{dest}"`
+
+puts `id3info "#{dest}"`