Skip to content

Instantly share code, notes, and snippets.

@jpablo
Created April 29, 2011 06:46
Show Gist options
  • Save jpablo/947955 to your computer and use it in GitHub Desktop.
Save jpablo/947955 to your computer and use it in GitHub Desktop.
transcode an ogg file into mp3
#!/usr/bin/env ruby
## depends on:
## oggdec, lame, mp3info
def procesa(file)
base = `basename "#{file}" .ogg`.chop
tags = `vorbiscomment "#{file}"`.split("\n")
tags.collect! {|t| t.split("=")}
d = {}
tags.each {|t| d[t.first.downcase] = t.last }
tags = d.to_a.collect {|t| "-t #{t.first}=\"#{t.last}\" "}.join
track = d["title"]
artist = d["artist"]
album = d["album"]
genero = d["genre"]
number = d["tracknumber"]
ruta = file.split("/")[0..-2]
ruta = ruta.join("/")
if ruta == "" then ruta = "." end
p ruta
nuevo = ruta + "/" + base + ".mp3"
p nuevo
#~ p "-t \"#{track}\" -n \"#{number}\" -a \"#{artist}\" -l \"#{album}\" \"#{nuevo}\""
#~ return
`oggdec -o "t-#{base}.wav" "#{file}"`
`lame -m s "t-#{base}.wav" "#{nuevo}"`
`rm -f "t-#{base}.wav"`
`mp3info -t "#{track}" -n "#{number}" -a "#{artist}" -l "#{album}" "#{nuevo}"`
end
#$ruta = `pwd`.chop.split("/")[-2..-1]
#$ruta = $ruta[0] + "/" + $ruta[1]
#p $ruta
ARGV.each {|f| procesa f}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment