Skip to content

Instantly share code, notes, and snippets.

@tejo
Created August 23, 2009 11:06
Show Gist options
  • Select an option

  • Save tejo/173241 to your computer and use it in GitHub Desktop.

Select an option

Save tejo/173241 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'mongomapper'
require 'freedb_reader'
MongoMapper.connection = XGen::Mongo::Driver::Mongo.new('localhost')
MongoMapper.database = 'cd'
class Cd
include MongoMapper::Document
key :disc_id, String
key :artist, String
key :title, String
key :genre, String
key :year, Integer
key :tracks, Array
end
freedb_path = 'freedb-complete-20090801.tar/'
dirs = Dir.entries(freedb_path).delete_if{|x| x.include?(".")}
dirs.each do |d|
Dir.entries(freedb_path+d).delete_if{|x| x.include?(".")}.each do |file|
entry = FreeDbReader.new(freedb_path+d+'/'+file)
begin
Cd.create({
:disc_id => entry.disc_id,
:artist => entry.artist,
:title => entry.title,
:genre => entry.genre,
:year => entry.year,
:tracks => entry.tracks
})
rescue
end
puts "insert #{entry}"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment