Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Generate cue file for youtube comment setlist
# How to
# Meke audio file and comment file
# ex. ~/audio.wav and ~/audio.txt
# Run `ruby cue-for-youtube-setlist.rb artist_name audio.wav`
# Generated ~/audio.cue
def to_index(time)
t = time.split(":").map { |e| e.to_i }
s, m, h = t.reverse
m = h * 60 + m if h
m, s = sprintf("%02d", m), sprintf("%02d", s)
[m, s, "00"].join(":")
end
audio_file = File.expand_path(ARGV[1])
file_name = File.basename(audio_file, ".*")
comment_file = File.join(File.dirname(audio_file),file_name + ".txt")
cue_file = File.join(File.dirname(audio_file),file_name + ".cue")
comment_array = File.read(comment_file).split("\n")
artist = ARGV[0]
year = Time.now.year
genre = "Cover"
disc_name = file_name
# Delete youtube id
comment = file_name
if m = file_name.match(/(.*?)-[\d\w-]{11}$/)
disc_name = m[1]
end
# Match pattern
# ptt = /(^.*?\d{1,2}:\d{2})\s(.*?$)/ # 10:10 title
ptt = /(^.*?\d{1,2}:\d{2})\s(.*?)\/(.*$)/ # 10:10 title/songwriter
songs = comment_array.map { |e| e.match(ptt).to_a }.compact.reject(&:empty?)
cue_tracks = songs.map.with_index do |song, track_id|
track_id = sprintf("%02d", track_id.to_i + 1)
orgin, time, title, songwriter = song
index_time = to_index(time)
track = <<-"EOS"
TRACK #{track_id} AUDIO
TITLE "#{title}"
PERFORMER "#{artist}"
SONGWRITER "#{songwriter}"
INDEX 01 #{index_time}
EOS
end
cue_header = <<-"EOS"
REM GENRE #{genre}
REM DATE #{year}
REM COMMENT "#{comment}"
PERFORMER "#{artist}"
TITLE "#{disc_name}"
FILE "#{File.basename(audio_file)}" AUDIO
EOS
cue = cue_header + cue_tracks.join
File.write(cue_file, cue)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.