diff --git a/ruby/lib/jam_ruby/jam_track_importer.rb b/ruby/lib/jam_ruby/jam_track_importer.rb index c7c39d25e..c08d970a8 100644 --- a/ruby/lib/jam_ruby/jam_track_importer.rb +++ b/ruby/lib/jam_ruby/jam_track_importer.rb @@ -35,6 +35,7 @@ module JamRuby # this method was created due to Tency-sourced data having no master track + # it goes through all audio tracks, and creates a master mix from it. (mix + normalize) def create_master(metadata, metalocation) parsed_metalocation = parse_metalocation(metalocation) @@ -74,7 +75,6 @@ module JamRuby tracks = [] - # XXX REMOVE - so i don't have to re-downloading 500mb every time I try to test this code # tmp_dir = Dir.mktmpdir Dir.mktmpdir do |tmp_dir| @@log.debug("downloading all audio files in #{tmp_dir}") @@ -137,12 +137,15 @@ module JamRuby original_artist = parsed_metalocation[1] name = parsed_metalocation[2] + JamTrackImporter.summaries[:unique_artists] << original_artist + success = dry_run_metadata(metadata, original_artist, name) return unless success audio_path = metalocation[0...-"/meta.yml".length] + dry_run_audio(metadata, audio_path) finish("success", nil) @@ -335,10 +338,10 @@ module JamRuby jam_track.language = determine_language(metadata) jam_track.plan_code = metadata["plan_code"] || gen_plan_code(jam_track.original_artist, jam_track.name) jam_track.price = 1.99 - jam_track.reproduction_royalty_amount = 0 + jam_track.reproduction_royalty_amount = nil jam_track.reproduction_royalty = true jam_track.public_performance_royalty = true - jam_track.licensor_royalty_amount = 0 + jam_track.licensor_royalty_amount = 0.4 jam_track.sales_region = 'Worldwide' jam_track.recording_type = 'Cover' jam_track.description = "This is a JamTrack audio file for use exclusively with the JamKazam service. This JamTrack is a high quality cover of the #{jam_track.original_artist} song \"#{jam_track.name}\"." @@ -525,7 +528,7 @@ module JamRuby instrument = nil part = nil precount_num = nil - + no_precount_detail = nil if comparable_filename == "click" || comparable_filename.include?("clicktrack") if filename.end_with?('.txt') type = :clicktxt @@ -536,7 +539,16 @@ module JamRuby type = :precount index = comparable_filename.index('precount') precount = comparable_filename[(index + 'precount'.length)..-1].strip - precount_num = precount.to_i unless precount.to_i == 0 + if precount.start_with?('_') + precount = precount[1..-1] + end + if precount.to_i == 0 + no_precount_detail = comparable_filename + else + precount_num = precount.to_i + end + + elsif comparable_filename.include?("master mix") || comparable_filename.include?("mastered mix") master = true type = :master @@ -591,7 +603,7 @@ module JamRuby end - {filename: filename, master: master, instrument: instrument, part: part, type: type, precount_num: precount_num} + {filename: filename, master: master, instrument: instrument, part: part, type: type, precount_num: precount_num, no_precount_detail: no_precount_detail} end def dry_run_audio(metadata, s3_path) @@ -630,6 +642,10 @@ module JamRuby elsif parsed_wav[:type] == :clicktxt elsif parsed_wav[:type] == :precount + if parsed_wav[:precount_num].nil? + JamTrackImporter.summaries[:no_precount_num] += 1 + JamTrackImporter.summaries[:no_precount_detail] << parsed_wav[:no_precount_detail] + end else JamTrackImporter.summaries[:unknown_filetype] += 1 @@ -1101,6 +1117,14 @@ module JamRuby if k == :no_instrument_detail @@log.debug("#{k}: #{v}") + elsif k == :no_precount_detail + v.each do |precount_detail| + @@log.debug("precount: #{precount_detail}") + end + elsif k == :unique_artists + v.each do |artist| + @@log.debug("artist: #{artist}") + end else @@log.debug("#{k}: #{v}") end @@ -1116,7 +1140,7 @@ module JamRuby end def summaries - @summaries ||= {unknown_filetype: 0, no_instrument: 0, no_part: 0, total_tracks: 0, no_instrument_detail: {}} + @summaries ||= {unknown_filetype: 0, no_instrument: 0, no_part: 0, total_tracks: 0, no_instrument_detail: {}, no_precount_num: 0, no_precount_detail: [], unique_artists: SortedSet.new} end def tency_s3_manager diff --git a/ruby/lib/jam_ruby/models/jam_track.rb b/ruby/lib/jam_ruby/models/jam_track.rb index 71b7aabed..3417dc407 100644 --- a/ruby/lib/jam_ruby/models/jam_track.rb +++ b/ruby/lib/jam_ruby/models/jam_track.rb @@ -39,8 +39,8 @@ module JamRuby validates :public_performance_royalty, inclusion: {in: [nil, true, false]} validates :duration, numericality: {only_integer: true}, :allow_nil => true - validates_format_of :reproduction_royalty_amount, with: /^\d+\.*\d{0,3}$/ - validates_format_of :licensor_royalty_amount, with: /^\d+\.*\d{0,3}$/ + validates_format_of :reproduction_royalty_amount, with: /^\d+\.*\d{0,3}$/, :allow_blank => true + validates_format_of :licensor_royalty_amount, with: /^\d+\.*\d{0,3}$/, :allow_blank => true belongs_to :licensor , class_name: 'JamRuby::JamTrackLicensor', foreign_key: 'licensor_id' @@ -70,6 +70,65 @@ module JamRuby accepts_nested_attributes_for :jam_track_tracks, allow_destroy: true accepts_nested_attributes_for :jam_track_tap_ins, allow_destroy: true + + # we can make sure a few things stay in sync here. + # 1) the reproduction_royalty_amount has to stay in sync based on duration + # 2) the onboarding_exceptions JSON column + after_save :sync_reproduction_royalty + after_save :onboarding_exceptions + + + def sync_reproduction_royalty + + # reproduction royalty table based on duration + + # 0:00-4:59 0.091 5 minutes + # 5:00-5:59 0.0875 6 minutes + # 6:00-6:59 0.105 7 minutes + # 7:00-7:59 0.1225 8 minutes + # 8:00-8:59 0.14 9 minutes + # 9:00-9:59 0.1575 10 minutes + # 10:00-10:59 0.175 11 minutes + # 11:00-11:59 0.1925 12 minutes + min_5 = 60 * 5 + min_6 = 60 * 6 + min_7 = 60 * 7 + min_8 = 60 * 8 + min_9 = 60 * 9 + min_10 =60 * 10 + min_11 =60 * 11 + + royalty = nil + if self.duration + case self.duration + when [0...min_5] + royalty = 0.091 + when [min_5...min_6] + royalty = 0.0875 + when [min_6...min_7] + royalty = 0.105 + when [min_7...min_8] + royalty = 0.1225 + when [min_8...min_9] + royalty = 0.14 + when [min_9 * min_10] + royalty = 0.1575 + when [min_10 * min_11] + royalty = 0.175 + else + royalty = 0.1925 + end + end + self.update_column(:reproduction_royalty_amount, royalty) + + true + end + + def onboarding_exceptions + + return true + end + def duplicate_positions? counter = {} jam_track_tracks.each do |track| diff --git a/ruby/spec/jam_ruby/models/jam_track_spec.rb b/ruby/spec/jam_ruby/models/jam_track_spec.rb index 3c17c1315..b8a2cfa63 100644 --- a/ruby/spec/jam_ruby/models/jam_track_spec.rb +++ b/ruby/spec/jam_ruby/models/jam_track_spec.rb @@ -15,6 +15,89 @@ describe JamTrack do jam_track.genres.length.should eq(1) end + describe 'sync_reproduction_royalty' do + it "all possible conditions" do + jam_track = FactoryGirl.create(:jam_track) + jam_track.reproduction_royalty_amount.should be_nil + + jam_track.duration = 0 + jam_track.save! + jam_track.reproduction_royalty_amount.should eq(BigDecimal('0.091')) + + jam_track.duration = 1 + jam_track.save! + jam_track.reproduction_royalty_amount.should eq(0.091) + + jam_track.duration = 5 * 60 - 1 # just under 5 minutes + jam_track.save! + jam_track.reproduction_royalty_amount.should eq(0.091) + + jam_track.duration = 5 * 60 + jam_track.save! + jam_track.reproduction_royalty_amount.should eq(0.0875) + + jam_track.duration = 6 * 60 - 1 # just under 6 minutes + jam_track.save! + jam_track.reproduction_royalty_amount.should eq(0.0875) + + jam_track.duration = 6 * 60 + jam_track.save! + jam_track.reproduction_royalty_amount.should eq(0.105) + + jam_track.duration = 7 * 60 - 1 + jam_track.save! + jam_track.reproduction_royalty_amount.should eq(0.105) + + jam_track.duration = 7 * 60 + jam_track.save! + jam_track.reproduction_royalty_amount.should eq(0.1225) + + jam_track.duration = 8 * 60 - 1 + jam_track.save! + jam_track.reproduction_royalty_amount.should eq(0.1225) + + jam_track.duration = 8 * 60 + jam_track.save! + jam_track.reproduction_royalty_amount.should eq(0.14) + + jam_track.duration = 9 * 60 - 1 + jam_track.save! + jam_track.reproduction_royalty_amount.should eq(0.14) + + jam_track.duration = 9 * 60 + jam_track.save! + jam_track.reproduction_royalty_amount.should eq(0.1575) + + jam_track.duration = 10 * 60 - 1 + jam_track.save! + jam_track.reproduction_royalty_amount.should eq(0.1575) + + jam_track.duration = 10 * 60 + jam_track.save! + jam_track.reproduction_royalty_amount.should eq(0.175) + + jam_track.duration = 11 * 60 - 1 + jam_track.save! + jam_track.reproduction_royalty_amount.should eq(0.175) + + jam_track.duration = 11 * 60 + jam_track.save! + jam_track.reproduction_royalty_amount.should eq(0.1925) + + jam_track.duration = 12 * 60 - 1 + jam_track.save! + jam_track.reproduction_royalty_amount.should eq(0.1925) + + jam_track.duration = 12 * 60 + jam_track.save! + jam_track.reproduction_royalty_amount.should eq(0.1925) + + jam_track.duration = 13 * 60 + jam_track.save! + jam_track.reproduction_royalty_amount.should eq(0.1925) + end + end + describe 'plays' do it "creates played instance properly" do @jam_track = FactoryGirl.create(:jam_track) diff --git a/web/spec/features/jamtrack_shopping_spec.rb b/web/spec/features/jamtrack_shopping_spec.rb index 23da6a3f4..a3171a282 100644 --- a/web/spec/features/jamtrack_shopping_spec.rb +++ b/web/spec/features/jamtrack_shopping_spec.rb @@ -5,8 +5,8 @@ describe "JamTrack Shopping", :js => true, :type => :feature, :capybara_feature let(:user) { FactoryGirl.create(:user, has_redeemable_jamtrack: false) } let(:jt_us) { FactoryGirl.create(:jam_track, :name=>'jt_us', sales_region: 'Worldwide', make_track: true, original_artist: "foobar") } let(:jt_ww) { FactoryGirl.create(:jam_track, :name=>'jt_ww', sales_region: 'Worldwide', make_track: true, original_artist: "barfoo") } - let(:jt_rock) { FactoryGirl.create(:jam_track, :name=>'jt_rock', genre: JamRuby::Genre.find('rock'), make_track: true, original_artist: "badfood") } - let(:jt_blues) { FactoryGirl.create(:jam_track, :name=>'jt_blues', genre: JamRuby::Genre.find('blues'), make_track: true, original_artist: "foodbart") } + let(:jt_rock) { FactoryGirl.create(:jam_track, :name=>'jt_rock', genres: [JamRuby::Genre.find('rock')], make_track: true, original_artist: "badfood") } + let(:jt_blues) { FactoryGirl.create(:jam_track, :name=>'jt_blues', genres: [JamRuby::Genre.find('blues')], make_track: true, original_artist: "foodbart") } before(:all) do Capybara.javascript_driver = :poltergeist