ruby 为id3标记的音频文件列表创建cue表

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ruby 为id3标记的音频文件列表创建cue表相关的知识,希望对你有一定的参考价值。

#!/usr/bin/env ruby

if ARGV.empty? 
  # This is the only error handling
  # The rest is unfinished
  puts "No input files..."
else
  files = ARGV.map {|arg| Dir.glob(arg)}.flatten
  meta = files.map do |file|
    tags = %x(ffprobe "#{file}" 2>&1)
    tags = tags.split("Metadata:").last.lines[1..-3]
    tags = tags.map{|tag| tag[0..-2].sub(/ */,"").split(/ *: /,2)}.to_h
    [file, tags]
  end 

  # Bases the album info on the metadata from the first file
  # Not the best method
  cue = [%Q(REM GENRE #{meta.first.last['genre']}), 
  %Q(REM DATE #{meta.first.last['date'][/\d{4}/]}),
  %Q(PERFORMER "#{meta.first.last['artist']}"),
  %Q(TITLE "#{meta.first.last['album']}")]
  
  meta = meta.to_h
  
  for file in files do
    pos = 4 * (meta[file]['track'].to_i - 1) + 4
    cue[pos] = %Q(FILE "#{file}" WAVE)
    cue[pos + 1] = %Q(  TRACK #{"%02d" % meta[file]['track'].to_i} AUDIO)
    cue[pos + 2] = %Q(    TITLE "#{meta[file]['title']}")
    cue[pos + 3] = %Q(    INDEX 01 00:00:00)
  end
  
  puts cue.join("\n")
end

以上是关于ruby 为id3标记的音频文件列表创建cue表的主要内容,如果未能解决你的问题,请参考以下文章