diff --git a/app/controllers/import_controller.rb b/app/controllers/import_controller.rb index e0c3b32..371cdda 100644 --- a/app/controllers/import_controller.rb +++ b/app/controllers/import_controller.rb @@ -44,9 +44,9 @@ class ImportController < ApplicationController releases_mb_data = releases_mb_xml.scan(/.*?([a-zA-Z]+?)<\/status>.*?([0-9-]+?)<\/date>.*?([A-Z]+?)<\/country>/m) releases_mb_data.each do |item| if item[2].length == 4 - item[2] += '-01-01' + item[2] += '-12-28' elsif item[2].length == 7 - item[2] += '-01' + item[2] += '-28' end end @@ -92,9 +92,11 @@ class ImportController < ApplicationController # Creating hashed array for matching mb_main_tracks_hashed = [] mb_tracks.each do |mb_track| - mb_main_tracks_hashed << mb_track[2].downcase.scan(/[a-z0-9]*/).join - mb_track << main_release[3] # Release country - mb_track << 0 # Bonus flag + unless mb_main_tracks_hashed.include? mb_track[2].downcase.scan(/[a-z0-9]*/).join + mb_main_tracks_hashed << mb_track[2].downcase.scan(/[a-z0-9]*/).join + mb_track << main_release[3] # Release country + mb_track << 0 # Bonus flag + end end # Searching for tracks in other releases @@ -115,16 +117,18 @@ class ImportController < ApplicationController # Saving tracks mb_tracks.each do |mb_track| - track = Track.new - track.name = mb_track[2] - track.album_id = album.id - track.position = mb_track[0] - track.length = mb_track[3] - track.country = mb_track[4] - track.bonus = mb_track[5] - track.live = mb_track[2].downcase.include? 'live' - track.acoustic = mb_track[2].downcase.include? 'acoustic' - track.save + unless mb_track[2] == '[silence]' or mb_track[2] == '[untitled]' + track = Track.new + track.name = mb_track[2] + track.album_id = album.id + track.position = mb_track[0] + track.length = mb_track[3] + track.country = mb_track[4] + track.bonus = mb_track[5] + track.live = mb_track[2].downcase.include? 'live' + track.acoustic = mb_track[2].downcase.include? 'acoustic' + track.save + end end end # unless mb_main_tracks.empty?