Skip to content

Instantly share code, notes, and snippets.

@klumsy
Created June 11, 2013 02:44
Show Gist options
  • Save klumsy/5754171 to your computer and use it in GitHub Desktop.
Save klumsy/5754171 to your computer and use it in GitHub Desktop.
Code i wrote to that the dramatized audio bible (word of promise) i bought and downloaded as MP3 and rename the title to something that can be displayed as a whole on the Iphone , and also generate a CSV file of chapters and minutes for my curiousity.
require "rubygems"
require "mp3info"
require "csv"
chapterarray = []
#Dir.glob("/Users/klumsy/Downloads/bible/01_Genesis/*.mp3") do |f|
Dir.glob("/Users/klumsy/Downloads/bible/**/*.mp3") do |f|
Mp3Info.open(f) do |mp3info|
title = mp3info.tag.title
puts title
newtitle = title.sub("Chapter ","")
newtitle = newtitle.sub("(WOP-","")
newtitle = newtitle.sub(")","")
length = mp3info.length
bookofbible = title.scan(/[0-9]{2}(?=\))/)[0].to_i
puts bookofbible
#Dunno why this regex returns an array of arrays rather than just an
#array but oh well
book = newtitle.scan(/\s([a-zA-Z0-9_\s]+)(?=\s[0-9]{1,})/)[0][0].lstrip
chapter = newtitle.scan(/\s[0-9]{2,}/)[0].lstrip.to_i
# i know adding to an array like this is slow as it creates a new array
# but for a one once utility i don't care
chapterarray += [ [bookofbible,book,chapter,length ] ]
#show some info on screen
puts ":" + newtitle
#mp3info library actually updates the MP3s when you set properties
mp3info.tag.title = "B" + newtitle
album = "WOP" + String(bookofbible) + " "+ book
puts "!" + album
mp3info.tag.album = album
end
end
#create a CSV file
CSV.open("/Users/klumsy/Downloads/booksofbible.csv", "wb") do |csv|
#write a header row
csv << ["BookNum","Book","Chapter","Seconds"]
#Go through our array of arrays, and for each row write it to the CSV file
chapterarray.each { |item| csv << item }
end
@klumsy
Copy link
Author

klumsy commented Jun 11, 2013

i would have written it in powershell, but was on my mac at the time, plus mp3info library did the trick nicely

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment