summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpdp8 <pdp8@pdp8.info>2022-08-20 11:58:59 +0200
committerpdp8 <pdp8@pdp8.info>2022-08-20 11:58:59 +0200
commit5cc948cbe8f1e36c61f4e224a5ad74a8a975dbfd (patch)
tree3ed89cef75f0f3c1815da0afc05c51eb473ac48d
initial import
-rwxr-xr-xmusic.rb41
1 files changed, 41 insertions, 0 deletions
diff --git a/music.rb b/music.rb
new file mode 100755
index 0000000..c07b693
--- /dev/null
+++ b/music.rb
@@ -0,0 +1,41 @@
+#!/usr/bin/env ruby
+require 'json'
+
+dir = ARGV[0]
+Dir.chdir dir
+input = JSON.load(File.read("config.json"))
+input["album"] = File.basename(dir).gsub("_", " ")
+input["artist"] ||= "pdp8@pdp8.info"
+input["year"] ||= `date +%Y`
+input["copyright"] ||= "Creative Commons Attribution-ShareAlike 4.0 International License (http://creativecommons.org/licenses/by-sa/4.0/)"
+dest = File.join(ENV["HOME"], "pub", "music", `date +%Y-%m-%d_`.strip + input["album"].gsub(" ", "_"))
+puts `mkdir -p '#{dest}'`
+cover = File.join(dest, "cover" + File.extname(input["cover"]))
+puts `cp -v '#{input["cover"]}' '#{cover}'`
+puts `exiv2 rm #{cover}`
+puts `exiv2 -M"set Xmp.dc.creator pdp8@pdp8.info" -M"set Xmp.dc.rights This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License (http://creativecommons.org/licenses/by-sa/4.0/)." -M"set Xmp.xmpRights.Marked True" #{cover}`
+n = 1
+input["tracks"].each do |t, s|
+ File.open(File.join(dest, "README"), "w+") { |f| f.puts input["text"] }
+ flac = File.join(dest, sprintf("%02d-%s.flac", n, t))
+ puts `cp -v '#{s}' '#{flac}'`
+ File.open("/tmp/meta", "w+") do |tmp|
+ tmp.puts "TITLE=#{t}"
+ tmp.puts "TRACK=#{n}"
+ [
+ "artist",
+ "year",
+ "album",
+ "genre",
+ "copyright"
+ ].each do |tag|
+ tmp.puts "#{tag.upcase}=#{input[tag]}"
+ end
+ end
+ puts `metaflac --remove-all --dont-use-padding #{flac}`
+ puts `metaflac --import-tags-from=/tmp/meta #{flac}`
+ puts `metaflac --import-picture-from=#{cover} #{flac}`
+ mp3 = flac.sub("flac", "mp3")
+ puts `ffmpeg -i #{flac} -c:v copy -ab 256k -f mp3 #{mp3}`
+ n += 1
+end