Created
November 17, 2012 01:49
-
-
Save mendelgusmao/4092565 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
** Invoke library:build (first_time) | |
** Invoke environment (first_time) | |
** Execute environment | |
** Execute library:build | |
rake aborted! | |
undefined method `external_encoding' for #<String:0xa5e559c> | |
/usr/local/lib/ruby/1.9.1/psych.rb:203:in `parse' | |
/usr/local/lib/ruby/1.9.1/psych.rb:203:in `parse_stream' | |
/usr/local/lib/ruby/1.9.1/psych.rb:151:in `parse' | |
/usr/local/lib/ruby/1.9.1/psych.rb:127:in `load' | |
/usr/local/lib/ruby/gems/1.9.1/gems/railties-3.2.8/lib/rails/application/configuration.rb:115:in `database_configuration' | |
/usr/local/lib/ruby/gems/1.9.1/gems/activerecord-3.2.8/lib/active_record/railtie.rb:78:in `block (2 levels) in <class:Railtie>' | |
/usr/local/lib/ruby/gems/1.9.1/gems/activesupport-3.2.8/lib/active_support/lazy_load_hooks.rb:36:in `instance_eval' | |
/usr/local/lib/ruby/gems/1.9.1/gems/activesupport-3.2.8/lib/active_support/lazy_load_hooks.rb:36:in `execute_hook' | |
/usr/local/lib/ruby/gems/1.9.1/gems/activesupport-3.2.8/lib/active_support/lazy_load_hooks.rb:43:in `block in run_load_hooks' | |
/usr/local/lib/ruby/gems/1.9.1/gems/activesupport-3.2.8/lib/active_support/lazy_load_hooks.rb:42:in `each' | |
/usr/local/lib/ruby/gems/1.9.1/gems/activesupport-3.2.8/lib/active_support/lazy_load_hooks.rb:42:in `run_load_hooks' | |
/usr/local/lib/ruby/gems/1.9.1/gems/activerecord-3.2.8/lib/active_record/base.rb:721:in `<top (required)>' | |
/media/sf_Devs/projetos/soad/app/models/country.rb:1:in `<top (required)>' | |
/usr/local/lib/ruby/gems/1.9.1/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:469:in `load' | |
/usr/local/lib/ruby/gems/1.9.1/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:469:in `block in load_file' | |
/usr/local/lib/ruby/gems/1.9.1/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:639:in `new_constants_in' | |
/usr/local/lib/ruby/gems/1.9.1/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:468:in `load_file' | |
/usr/local/lib/ruby/gems/1.9.1/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:353:in `require_or_load' | |
/usr/local/lib/ruby/gems/1.9.1/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:502:in `load_missing_constant' | |
/usr/local/lib/ruby/gems/1.9.1/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:192:in `block in const_missing' | |
/usr/local/lib/ruby/gems/1.9.1/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:190:in `each' | |
/usr/local/lib/ruby/gems/1.9.1/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:190:in `const_missing' | |
/media/sf_Devs/projetos/soad/lib/tasks/library.rake:11:in `block (2 levels) in <top (required)>' | |
/usr/local/lib/ruby/gems/1.9.1/gems/rake-10.0.1/lib/rake/task.rb:227:in `call' | |
/usr/local/lib/ruby/gems/1.9.1/gems/rake-10.0.1/lib/rake/task.rb:227:in `block in execute' | |
/usr/local/lib/ruby/gems/1.9.1/gems/rake-10.0.1/lib/rake/task.rb:222:in `each' | |
/usr/local/lib/ruby/gems/1.9.1/gems/rake-10.0.1/lib/rake/task.rb:222:in `execute' | |
/usr/local/lib/ruby/gems/1.9.1/gems/rake-10.0.1/lib/rake/task.rb:166:in `block in invoke_with_call_chain' | |
/usr/local/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize' | |
/usr/local/lib/ruby/gems/1.9.1/gems/rake-10.0.1/lib/rake/task.rb:159:in `invoke_with_call_chain' | |
/usr/local/lib/ruby/gems/1.9.1/gems/rake-10.0.1/lib/rake/task.rb:152:in `invoke' | |
/usr/local/lib/ruby/gems/1.9.1/gems/rake-10.0.1/lib/rake/application.rb:141:in `invoke_task' | |
/usr/local/lib/ruby/gems/1.9.1/gems/rake-10.0.1/lib/rake/application.rb:99:in `block (2 levels) in top_level' | |
/usr/local/lib/ruby/gems/1.9.1/gems/rake-10.0.1/lib/rake/application.rb:99:in `each' | |
/usr/local/lib/ruby/gems/1.9.1/gems/rake-10.0.1/lib/rake/application.rb:99:in `block in top_level' | |
/usr/local/lib/ruby/gems/1.9.1/gems/rake-10.0.1/lib/rake/application.rb:108:in `run_with_threads' | |
/usr/local/lib/ruby/gems/1.9.1/gems/rake-10.0.1/lib/rake/application.rb:93:in `top_level' | |
/usr/local/lib/ruby/gems/1.9.1/gems/rake-10.0.1/lib/rake/application.rb:71:in `block in run' | |
/usr/local/lib/ruby/gems/1.9.1/gems/rake-10.0.1/lib/rake/application.rb:158:in `standard_exception_handling' | |
/usr/local/lib/ruby/gems/1.9.1/gems/rake-10.0.1/lib/rake/application.rb:68:in `run' | |
/usr/local/lib/ruby/gems/1.9.1/gems/rake-10.0.1/bin/rake:37:in `<top (required)>' | |
/usr/local/bin/rake:23:in `load' | |
/usr/local/bin/rake:23:in `<main>' | |
Tasks: TOP => library:build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace :mp3 do | |
task "build-library" => :environment do | |
music, albumart = read_collections_from_file | |
directories = {} | |
collections = {} | |
countries = {} | |
artists = {} | |
albums = {} | |
genres = {} | |
no_country = Country.create(:name => "...") | |
countries["..."] = no_country | |
Album.transaction do | |
music.each do |filename| | |
info = filename.split("\\") | |
next if info.size < 6 | |
# D:\MP3\Death Metal\Behemoth (Pol)\2004 - Demigod\01 - Sculpting The Throne Ov Seth.mp3 | |
base, collection_name, genre_name, artist_name, album_name, song_name = info | |
collection, genre, country, artist, album = nil | |
collection = collections[collection_name] ||= Collection.create(:name => collection_name, :path => base + "\\" + collection_name) | |
genre = genres[genre_name] ||= Genre.create(:name => genre_name) | |
artist_name, country_name = parse_artist_and_country(artist_name) | |
artist_uid = genre_name + "\\" + artist_name + "\\" + country_name | |
country = country_name.nil? ? no_country : (countries[country_name] ||= Country.create(:name => country_name)) | |
artist = artists[artist_uid] ||= Artist.create(:name => artist_name, :country => country, :genre => genre) | |
year, album_name = parse_year_and_album(album_name) | |
uid = [base, collection_name, genre_name, country_name, artist_name, year, album_name].join("\\") | |
if albums[uid].nil? | |
albums[uid] = \ | |
Album.create(:title => album_name, :year => year, | |
:collection => collection, | |
:artist => artist) | |
end | |
directories[uid] ||= [] | |
directories[uid] << song unless song.nil? | |
end | |
directories.each do |directory, songs| | |
next if songs.empty? | |
albums[directory].uid = Digest::SHA1.hexdigest(songs.inspect) | |
albums[directory].save | |
end | |
end | |
end | |
def parse_artist_and_country(input) | |
if input[-5].to_s + input[-1].to_s == "()" | |
[input[0..-7], input[-4..-2]] | |
else | |
[input, nil] | |
end | |
end | |
def parse_year_and_album(input) | |
if input[4..6].to_s == " - " and input[0..3][/\d{4}/] == input[0..3] | |
[input[0..3], input[7..-1]] | |
else | |
["0000", input] | |
end | |
end | |
def read_collections_from_glob | |
music_files = [] | |
albumart_files = [] | |
Collection.all.each do |c| | |
music_files += Dir.glob("#{c.path}\\**\\*.mp3") | |
albumart_files += Dir.glob("#{c.path}\\**\\folder.jpg") | |
end | |
[ music_files, albumart_files ] | |
end | |
def read_collections_from_file | |
def read(filename) | |
File.open(filename, "r:iso-8859-1") { |f| f.read.split("\n") } | |
end | |
[ | |
read("data/albuns.txt"), | |
read("data/folder.txt") | |
] | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment