Skip to content

Instantly share code, notes, and snippets.

@ixxra
Created February 17, 2014 03:39
Show Gist options
  • Select an option

  • Save ixxra/9044321 to your computer and use it in GitHub Desktop.

Select an option

Save ixxra/9044321 to your computer and use it in GitHub Desktop.
info2meta - Reads metadata information as downloaded by cd-info and writes it to flac files. See https://gist.github.com/ixxra/9044268 too
#!/usr/bin/env ruby
#
#
#info2meta
#
#Reads metadata information as downloaded by cd-info and writes it to flac files.
#I use this script together with https://gist.github.com/ixxra/9044268 to rip my
#cds into flac format.
#
require 'shellwords'
tracks = []
def new_track()
{
:TRACKNUMBER => 0,
:TITLE => '',
:ARTIST => '',
:ALBUM => '',
:GENRE => '',
:COMMENTS => '',
:FREEDB => ''
}
end
def fname_from_tracknumber(n)
sprintf "track%02d.flac", n
end
def shell_escape(s)
ShellWords.escape(s)
end
def metaflac_args(t)
t.map{|k, v| "--set-tag=#{k}=#{Shellwords.escape(v)}"}.join(' ')
end
GENRE = ''
ARTIST = ''
ALBUM = ''
FREEDB = ''
t = nil
File.open('disc.info', 'r') do |f|
f.each_line do |line|
if / Track/ =~ line
if not t.nil?
tracks.push t
end
t = new_track
t[:GENRE] = GENRE
t[:ARTIST] = ARTIST
t[:ALBUM] = ALBUM
t[:FREEDB] = FREEDB
elsif /Disc ID: (\w+)/ =~ line
FREEDB = $1
elsif /Music genre: '(.+)'/ =~ line
GENRE = $1
elsif /Artist: '(.+)'/ =~ line
ARTIST = $1
elsif /Title: '(.+)'/ =~ line
ALBUM = $1
end
if / number: (\d\d?)/ =~ line
t[:TRACKNUMBER] = $1
elsif / title: '(.*)'/ =~ line
t[:TITLE] = $1
elsif / artist: '(.*)'/ =~ line
t[:ARTIST] = $1
elsif / extended data: '(.*)'/ =~ line
if $1 != 'NULL'
t[:COMMENTS] = $1
end
end
end
end
tracks.push t
tracks.each do |t|
`metaflac #{metaflac_args t} #{fname_from_tracknumber t[:TRACKNUMBER]}`
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment