diff --git a/ruby/lib/jam_ruby/import/tency_stem_mapping.rb b/ruby/lib/jam_ruby/import/tency_stem_mapping.rb index e98436736..389b424d2 100644 --- a/ruby/lib/jam_ruby/import/tency_stem_mapping.rb +++ b/ruby/lib/jam_ruby/import/tency_stem_mapping.rb @@ -3,10 +3,140 @@ module JamRuby # this is probably a one-off class used to map Tency-named stems into JamKazam-named stems class TencyStemMapping - def init + @@log = Logging.logger[TencyStemMapping] + + def s3_manager + @s3_manager ||= S3Manager.new('jamkazam-tency', APP_CONFIG.aws_access_key_id, APP_CONFIG.aws_secret_access_key) + end + + def initialize + @originals_folder = "/Volumes/sethcall/Dropbox/seth@jamkazam.com/JamTracks - Tency Music - Original Folder for Normalization Map" + @mapping_folder = "/Volumes/sethcall/Dropbox/seth@jamkazam.com/JamTracks - Tency Music" + @originals_songs = {} + @mapping_songs = {} + end + + def create_map + tency_originals + end + + def md5(filepath) + Digest::MD5.file(filepath).hexdigest + end + + def tency_original_check + songs = Pathname.new(@originals_folder).children.select { |c| c.directory? } + songs.each do |song| + dirs = Pathname.new(song).children.select {|c| c.directory? } + + @@log.debug "SONG #{song}" + dirs.each do |dir| + @@log.debug "#{dir.basename.to_s}" + end + @@log.debug "" + end + end + def tency_originals + songs = Pathname.new(@originals_folder).children.select { |c| c.directory? } + songs.each do |filename| + id = parse_id(filename.basename.to_s ) + tracks = Pathname.new(filename).children.select {|c| c.file? } + + # also look into any 1st level folders we might find + + dirs = Pathname.new(filename).children.select {|c| c.directory? } + dirs.each do |dir| + more_tracks = Pathname.new(dir).children.select {|c| c.file? } + tracks = tracks + more_tracks + end + + puts "tracks #{tracks.inspect}" + break + end end + def tency_maps + songs = Pathname.new(@mapping_folder).children.select { |c| c.directory? } + songs.each do |filename| + id = parse_id_mapped(filename.basename.to_s ) + @@log.debug "processing song #{filename}" + tracks = Pathname.new(filename).children.select {|c| c.file? } + tracks.each do |track| + if track.include? "Stem" + md5 = md5(track.to_s) + + song = {md5:md5, filename:filename} + @mapping_songs[cache_id(id, md5)] = song + end + end + + break + end + end + + def cache_id(id, md5) + "#{id}-#{md5}" + end + + def parse_id(filename) + #amy-winehouse_you-know-i-m-no-good-feat-ghostface-killah_11767 + + index = filename.rindex('_') + if index + id = filename[(index + 1)..-1] + + if id.end_with?('/') + id = id[0...-1] + end + + id = id.to_i + + if id == 0 + raise "no valid ID in filename: #{filename}" + end + else + raise "no _ in filename: #{filename}" + end + id + end + + def parse_id_mapped(filename) + #Flyleaf - I'm So Sick - 15771 + + index = filename.rindex('-') + if index + id = filename[(index + 1)..-1] + + if id.end_with?('/') + id = id[0...-1] + end + + id.strip! + + id = id.to_i + + if id == 0 + raise "no valid ID in filename: #{filename}" + end + else + raise "no - in filename: #{filename}" + end + id + end + + + + def tency_originals2 + s3_manager.list_directories('mapper').each do |song_folder| + @@log.debug("searching through tency directory. song folder:'#{song_folder}'") + + id = parse_id(song_folder) + @@log.debug("ID #{id}") + + top_folder = s3_manager.list_directories(song_folder) + end + end end end \ No newline at end of file diff --git a/web/lib/tasks/jam_tracks.rake b/web/lib/tasks/jam_tracks.rake index 4d28e89a4..66c06aac2 100644 --- a/web/lib/tasks/jam_tracks.rake +++ b/web/lib/tasks/jam_tracks.rake @@ -91,4 +91,10 @@ namespace :jam_tracks do task download_masters: :environment do |task, arg| JamTrackImporter.download_masters end + + + task tency: :environment do |task, arg| + mapper = TencyStemMapping.new + mapper.create_map + end end