From 4288ebe0d0e2c72ded850ea5788fd83bdbc85dc3 Mon Sep 17 00:00:00 2001 From: Seth Call Date: Fri, 7 Aug 2015 16:05:56 -0500 Subject: [PATCH] * wip --- db/up/jam_track_onboarding_enhancements.sql | 2 +- ruby/lib/jam_ruby/jam_track_importer.rb | 157 ++++++++++++++++-- ruby/lib/jam_ruby/models/jam_track.rb | 100 +++++++---- ruby/lib/jam_ruby/models/jam_track_file.rb | 2 +- ruby/lib/jam_ruby/models/jam_track_track.rb | 136 ++++++++------- ruby/spec/jam_ruby/models/jam_track_spec.rb | 38 ++--- .../api_music_sessions_controller.rb | 4 +- .../controllers/api_recordings_controller.rb | 4 +- web/app/controllers/api_users_controller.rb | 2 +- web/lib/tasks/jam_tracks.rake | 14 ++ 10 files changed, 317 insertions(+), 142 deletions(-) diff --git a/db/up/jam_track_onboarding_enhancements.sql b/db/up/jam_track_onboarding_enhancements.sql index 60d20eca9..1336ecdf4 100644 --- a/db/up/jam_track_onboarding_enhancements.sql +++ b/db/up/jam_track_onboarding_enhancements.sql @@ -14,7 +14,7 @@ INSERT INTO instruments (id, description, popularity) VALUES ('sitar', 'Sitar', INSERT INTO instruments (id, description, popularity) VALUES ('piccolo', 'Piccolo', 1); INSERT INTO instruments (id, description, popularity) VALUES ('bagpipes', 'Bagpipes', 1); ALTER TABLE jam_tracks ADD COLUMN onboarding_exceptions JSON; -ALTER TABLE jam_tracks ADD COLUMN original_filename VARCHAR; +ALTER TABLE jam_track_tracks ADD COLUMN original_filename VARCHAR; ALTER TABLE jam_tracks ADD COLUMN additional_info VARCHAR; ALTER TABLE jam_tracks ADD COLUMN language VARCHAR NOT NULL DEFAULT 'eng'; ALTER TABLE jam_tracks ADD COLUMN year INTEGER; diff --git a/ruby/lib/jam_ruby/jam_track_importer.rb b/ruby/lib/jam_ruby/jam_track_importer.rb index c08d970a8..0f119d0ac 100644 --- a/ruby/lib/jam_ruby/jam_track_importer.rb +++ b/ruby/lib/jam_ruby/jam_track_importer.rb @@ -71,6 +71,7 @@ module JamRuby if master_found @@log.debug("master exists... skipping #{self.name} ") finish('success', nil) + return else tracks = [] @@ -248,6 +249,7 @@ module JamRuby end def determine_genres(metadata) + genres = [] if metadata[:genres] metadata[:genres].each do |genre| @@ -285,7 +287,11 @@ module JamRuby # swallow elsif genre == 'oriental' genres << genre.find('asian') + else + found = Genre.find_by_id(genre) + genres << found if found end + end end @@ -807,9 +813,11 @@ module JamRuby track = JamTrackTrack.new track.original_filename = wav_file + track.original_audio_s3_path = wav_file file = JamTrackFile.new file.original_filename = wav_file + file.original_audio_s3_path = wav_file parsed_wav = parse_file(wav_file) @@ -836,11 +844,14 @@ module JamRuby tracks << track elsif parsed_wav[:type] == :clicktxt file.file_type = 'ClickTxt' + addt_files << file elsif parsed_wav[:type] == :clickwav file.file_type = 'ClickWav' + addt_files << file elsif parsed_wav[:type] == :precount file.file_type = 'Precount' file.precount_num = parsed_wav[:precount_num] + addt_files << file else finish("unknown_file_type", "unknown file type #{wave_file}") return false @@ -919,7 +930,7 @@ module JamRuby wav_file = File.join(tmp_dir, basename) # bring the original wav file down from S3 to local file system - JamTrackImporter::s3_manager.download(track.original_audio_s3_path, wav_file) + JamTrackImporter::song_storage_manager.download(track.original_audio_s3_path, wav_file) sample_rate = `soxi -r "#{wav_file}"`.strip @@ -967,7 +978,10 @@ module JamRuby if !preview_succeeded return false end + elsif track.track_type == 'Track' + synchronize_track_preview(track, tmp_dir, ogg_44100) end + end track.save! @@ -996,6 +1010,51 @@ module JamRuby true end + def synchronize_track_preview(track, tmp_dir, ogg_44100) + + out_wav = File.join(tmp_dir, 'stripped.wav') + command_strip_lead_silence = "sox \"#{ogg_44100}\" \"#{out_wav}\" silence 1 0.3 1%" + + @@log.debug("stripping silence: " + command_strip_lead_silence) + + output = `#{command_strip_lead_silence}` + + result_code = $?.to_i + + if result_code == 0 + + total_time_command = "soxi -D \"#{ogg_44100}\"" + stripped_time_command = "soxi -D \"#{out_wav}\"" + + total_time = `#{total_time_command}` + stripped_time = `#{stripped_time_command}` + + preview_start_time = total_time.to_f - stripped_time.to_f + + # this is in seconds; convert to integer milliseconds + preview_start_time = (preview_start_time * 1000).to_i + + preview_start_time = nil if preview_start_time < 0 + + track.preview_start_time = preview_start_time + + if track.preview_start_time + @@log.debug("determined track start time to be #{track.preview_start_time}") + else + @@log.debug("determined track start time to be #{track.preview_start_time}") + end + + track.process_preview(ogg_44100, tmp_dir) if track.preview_start_time + + if track.preview_generate_error + @@log.warn(track.preview_generate_error) + end + else + @@log.warn("unable to determine silence for jam_track #{track.original_filename}, #{output}") + end + + end + def synchronize_master_preview(track, tmp_dir, ogg_44100, ogg_digest) begin @@ -1108,6 +1167,7 @@ module JamRuby attr_accessor :storage_format attr_accessor :tency_mapping + attr_accessor :tency_metadata attr_accessor :summaries def report_summaries @@ -1240,13 +1300,56 @@ module JamRuby report_summaries end + # figure out which songs are in S3 that do not exist in the 2k spreadsheet (mapping.csv), and which songs are in the 2k spreadsheet that are not in S3 + def tency_delta + in_s3 = {} + in_mapping = {} + + load_tency_mappings + + JamTrackImporter.tency_metadata.each do |song_id, metadata| + in_mapping[song_id] = {artist: metadata[:original_artist], song: metadata[:name]} + end + + iterate_song_storage do |metadata, metalocation| + + importer = JamTrackImporter.new(@storage_format) + song_id = JamTrackImporter.extract_tency_song_id(metalocation) + parsed_metalocation = importer.parse_metalocation(metalocation) + + next if song_id.nil? + next if parsed_metalocation.nil? + + original_artist = parsed_metalocation[1] + meta_name = parsed_metalocation[2] + + in_s3[song_id] = {artist: original_artist, song: meta_name} + end + + in_s3_keys = Set.new(in_s3.keys) + in_mapping_keys = Set.new(in_mapping.keys) + only_in_mapping = in_mapping_keys - in_s3_keys + only_in_s3 = in_s3_keys - in_mapping_keys + + CSV.open("only_in_s3.csv", "wb") do |csv| + only_in_s3.each do |song_id| + csv << [ song_id, in_s3[song_id][:artist], in_s3[song_id][:song] ] + end + end + + CSV.open("only_in_2k_selection.csv", "wb") do |csv| + only_in_mapping.each do |song_id| + csv << [ song_id, in_mapping[song_id][:artist], in_mapping[song_id][:song] ] + end + end + + end def create_masters iterate_song_storage do |metadata, metalocation| + next if metadata.nil? jam_track_importer = JamTrackImporter.new(@storage_format) jam_track_importer.create_master(metadata, metalocation) - - break end end @@ -1457,23 +1560,23 @@ module JamRuby end end + def onboarding_exceptions + JamTrack.all.each do |jam_track| + jam_track.onboarding_exceptions + end + end def synchronize_all(options) importers = [] - s3_manager.list_directories('audio').each do |original_artist| - @@log.debug("searching through artist directory '#{original_artist}'") + iterate_song_storage do |metadata, metalocation| - songs = s3_manager.list_directories(original_artist) - songs.each do |song| - @@log.debug("searching through song directory' #{song}'") + next if metadata.nil? && is_tency_storage? - metalocation = "#{song}meta.yml" - - importer = synchronize_from_meta(metalocation, options) - importers << importer - end + importer = synchronize_from_meta(metalocation, options) + importers << importer end + @@log.info("SUMMARY") @@log.info("-------") importers.each do |importer| @@ -1557,12 +1660,34 @@ module JamRuby @tency_metadata = {} # convert both to hashes mapping_csv.each do |line| - @tency_mapping[line[0]] = {instrument: line[1], part: line[2], count: line[3], trust: line[4]} + @tency_mapping[line[0].strip] = {instrument: line[1], part: line[2], count: line[3], trust: line[4]} end metadata_csv.each do |line| - @tency_metadata[line[0]] = {id: line[0], original_artist: line[1], name: line[2], additional_info: line[3], year: line[4], language: line[5], isrc: line[10], genre1: line[11], genre2: line[12], genre3: line[13], genre4: line[14], genre5: line[15]} + @tency_metadata[line[0].strip] = {id: line[0].strip, original_artist: line[1], name: line[2], additional_info: line[3], year: line[4], language: line[5], isrc: line[10], genre1: line[11], genre2: line[12], genre3: line[13], genre4: line[14], genre5: line[15]} end + + + @tency_metadata.each do |id, value| + + genres = [] + + genre1 = value[:genre1] + genre2 = value[:genre2] + genre3 = value[:genre3] + genre4 = value[:genre4] + genre5 = value[:genre5] + + genres << genre1.downcase.strip if genre1 + genres << genre2.downcase.strip if genre2 + genres << genre3.downcase.strip if genre3 + genres << genre4.downcase.strip if genre4 + genres << genre5.downcase.strip if genre5 + + value[:genres] = genres + end + + end end @@ -1600,7 +1725,7 @@ module JamRuby end def sync_from_metadata(jam_track, meta, metalocation, options) - jam_track_importer = JamTrackImporter.new + jam_track_importer = JamTrackImporter.new(@storage_format) JamTrack.transaction do #begin diff --git a/ruby/lib/jam_ruby/models/jam_track.rb b/ruby/lib/jam_ruby/models/jam_track.rb index 3417dc407..db2a581fe 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}$/, :allow_blank => true - validates_format_of :licensor_royalty_amount, with: /^\d+\.*\d{0,3}$/, :allow_blank => true + validates_format_of :reproduction_royalty_amount, with: /^\d+\.*\d{0,4}$/, :allow_blank => true + validates_format_of :licensor_royalty_amount, with: /^\d+\.*\d{0,4}$/, :allow_blank => true belongs_to :licensor , class_name: 'JamRuby::JamTrackLicensor', foreign_key: 'licensor_id' @@ -82,42 +82,20 @@ module JamRuby # 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 + # The statutory mechanical royalty rate for permanent digital downloads is: + # 9.10¢ per copy for songs 5 minutes or less, or + # 1.75¢ per minute or fraction thereof, per copy for songs over 5 minutes. + # So the base rate is 9.1 cents for anything up to 5 minutes. + # 5.01 to 6 minutes should be 10.5 cents. + # 6.01 to 7 minutes should be 12.25 cents. + # Etc. 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 + minutes = (self.duration - 1) / 60 + extra_minutes = minutes - 4 + extra_minutes = 0 if extra_minutes < 0 + royalty = 0.091 + (0.0175 * extra_minutes) end self.update_column(:reproduction_royalty_amount, royalty) @@ -126,7 +104,46 @@ module JamRuby def onboarding_exceptions - return true + exceptions = {} + if self.duration.nil? + exceptions[:no_duration] = true + end + + if self.genres.count == 0 + exceptions[:no_genres] = true + end + + if self.year.nil? + exceptions[:no_year] = true + end + + if self.licensor.nil? + exceptions[:no_licensor] = true + end + + if self.missing_instrument_info? + exceptions[:unknown_instrument] = true + end + + if self.master_track.nil? + exceptions[:no_master] = true + end + + if missing_previews? + exceptions[:missing_previews] = true + end + + if duplicate_positions? + exceptions[:duplicate_positions] = true + end + + if exceptions.keys.length == 0 + self.update_column(:onboarding_exceptions, nil) + else + self.update_column(:onboarding_exceptions, exceptions.to_json) + end + + true end def duplicate_positions? @@ -149,6 +166,17 @@ module JamRuby duplicate end + def missing_instrument_info? + missing_instrument_info = false + self.jam_track_tracks.each do |track| + if track.instrument_id == 'other' && (track.part == nil || track.part.start_with?('Other')) + missing_instrument_info = true + break + end + end + missing_instrument_info + end + def missing_previews? missing_preview = false self.jam_track_tracks.each do |track| diff --git a/ruby/lib/jam_ruby/models/jam_track_file.rb b/ruby/lib/jam_ruby/models/jam_track_file.rb index 1f71e5300..e7c880165 100644 --- a/ruby/lib/jam_ruby/models/jam_track_file.rb +++ b/ruby/lib/jam_ruby/models/jam_track_file.rb @@ -18,7 +18,7 @@ module JamRuby before_destroy :delete_s3_files - validates :track_type, inclusion: {in: FILE_TYPE } + validates :file_type, inclusion: {in: FILE_TYPE } belongs_to :jam_track, class_name: "JamRuby::JamTrack" diff --git a/ruby/lib/jam_ruby/models/jam_track_track.rb b/ruby/lib/jam_ruby/models/jam_track_track.rb index e20469076..c99246876 100644 --- a/ruby/lib/jam_ruby/models/jam_track_track.rb +++ b/ruby/lib/jam_ruby/models/jam_track_track.rb @@ -131,81 +131,19 @@ module JamRuby end + def generate_preview begin Dir.mktmpdir do |tmp_dir| input = File.join(tmp_dir, 'in.ogg') - output = File.join(tmp_dir, 'out.ogg') - output_mp3 = File.join(tmp_dir, 'out.mp3') - - start = self.preview_start_time.to_f / 1000 - stop = start + 20 raise 'no track' unless self["url_44"] s3_manager.download(self.url_by_sample_rate(44), input) - command = "sox \"#{input}\" \"#{output}\" trim #{sprintf("%.3f", start)} =#{sprintf("%.3f", stop)}" - - @@log.debug("trimming using: " + command) - - sox_output = `#{command}` - - result_code = $?.to_i - - if result_code != 0 - @@log.debug("fail #{result_code}") - @preview_generate_error = "unable to execute cut command #{sox_output}" - else - # now create mp3 off of ogg preview - - convert_mp3_cmd = "#{APP_CONFIG.ffmpeg_path} -i \"#{output}\" -ab 192k \"#{output_mp3}\"" - - @@log.debug("converting to mp3 using: " + convert_mp3_cmd) - - convert_output = `#{convert_mp3_cmd}` - - result_code = $?.to_i - - if result_code != 0 - @@log.debug("fail #{result_code}") - @preview_generate_error = "unable to execute mp3 convert command #{convert_output}" - else - ogg_digest = ::Digest::MD5.file(output) - mp3_digest = ::Digest::MD5.file(output_mp3) - self["preview_md5"] = ogg_md5 = ogg_digest.hexdigest - self["preview_mp3_md5"] = mp3_md5 = mp3_digest.hexdigest - - @@log.debug("uploading ogg preview to #{self.preview_filename('ogg')}") - s3_public_manager.upload(self.preview_filename(ogg_md5, 'ogg'), output, content_type: 'audio/ogg', content_md5: ogg_digest.base64digest) - @@log.debug("uploading mp3 preview to #{self.preview_filename('mp3')}") - s3_public_manager.upload(self.preview_filename(mp3_md5, 'mp3'), output_mp3, content_type: 'audio/mpeg', content_md5: mp3_digest.base64digest) - - self.skip_uploader = true - - original_ogg_preview_url = self["preview_url"] - original_mp3_preview_url = self["preview_mp3_url"] - - # and finally update the JamTrackTrack with the new info - self["preview_url"] = self.preview_filename(ogg_md5, 'ogg') - self["preview_length"] = File.new(output).size - # and finally update the JamTrackTrack with the new info - self["preview_mp3_url"] = self.preview_filename(mp3_md5, 'mp3') - self["preview_mp3_length"] = File.new(output_mp3).size - self.save! - - # if all that worked, now delete old previews, if present - begin - s3_public_manager.delete(original_ogg_preview_url) if original_ogg_preview_url && original_ogg_preview_url != self["preview_url"] - s3_public_manager.delete(original_mp3_preview_url) if original_mp3_preview_url && original_mp3_preview_url != track["preview_mp3_url"] - rescue - puts "UNABLE TO CLEANUP OLD PREVIEW URL" - end - - end - end + process_preview(input, tmp_dir) end rescue Exception => e @@log.error("error in sox command #{e.to_s}") @@ -214,6 +152,76 @@ module JamRuby end + # input is the original ogg file for the track. tmp_dir is where this code can safely generate output stuff and have it cleaned up later + def process_preview(input, tmp_dir) + uuid = SecureRandom.uuid + output = File.join(tmp_dir, "#{uuid}.ogg") + output_mp3 = File.join(tmp_dir, "#{uuid}.mp3") + + start = self.preview_start_time.to_f / 1000 + stop = start + 20 + + command = "sox \"#{input}\" \"#{output}\" trim #{sprintf("%.3f", start)} =#{sprintf("%.3f", stop)}" + + @@log.debug("trimming using: " + command) + + sox_output = `#{command}` + + result_code = $?.to_i + + if result_code != 0 + @@log.debug("fail #{result_code}") + @preview_generate_error = "unable to execute cut command #{sox_output}" + else + # now create mp3 off of ogg preview + + convert_mp3_cmd = "#{APP_CONFIG.ffmpeg_path} -i \"#{output}\" -ab 192k \"#{output_mp3}\"" + + @@log.debug("converting to mp3 using: " + convert_mp3_cmd) + + convert_output = `#{convert_mp3_cmd}` + + result_code = $?.to_i + + if result_code != 0 + @@log.debug("fail #{result_code}") + @preview_generate_error = "unable to execute mp3 convert command #{convert_output}" + else + ogg_digest = ::Digest::MD5.file(output) + mp3_digest = ::Digest::MD5.file(output_mp3) + self["preview_md5"] = ogg_md5 = ogg_digest.hexdigest + self["preview_mp3_md5"] = mp3_md5 = mp3_digest.hexdigest + + @@log.debug("uploading ogg preview to #{self.preview_filename('ogg')}") + s3_public_manager.upload(self.preview_filename(ogg_md5, 'ogg'), output, content_type: 'audio/ogg', content_md5: ogg_digest.base64digest) + @@log.debug("uploading mp3 preview to #{self.preview_filename('mp3')}") + s3_public_manager.upload(self.preview_filename(mp3_md5, 'mp3'), output_mp3, content_type: 'audio/mpeg', content_md5: mp3_digest.base64digest) + + self.skip_uploader = true + + original_ogg_preview_url = self["preview_url"] + original_mp3_preview_url = self["preview_mp3_url"] + + # and finally update the JamTrackTrack with the new info + self["preview_url"] = self.preview_filename(ogg_md5, 'ogg') + self["preview_length"] = File.new(output).size + # and finally update the JamTrackTrack with the new info + self["preview_mp3_url"] = self.preview_filename(mp3_md5, 'mp3') + self["preview_mp3_length"] = File.new(output_mp3).size + self.save! + + # if all that worked, now delete old previews, if present + begin + s3_public_manager.delete(original_ogg_preview_url) if original_ogg_preview_url && original_ogg_preview_url != self["preview_url"] + s3_public_manager.delete(original_mp3_preview_url) if original_mp3_preview_url && original_mp3_preview_url != track["preview_mp3_url"] + rescue + puts "UNABLE TO CLEANUP OLD PREVIEW URL" + end + + end + end + end + private def normalize_position diff --git a/ruby/spec/jam_ruby/models/jam_track_spec.rb b/ruby/spec/jam_ruby/models/jam_track_spec.rb index b8a2cfa63..9cc16c444 100644 --- a/ruby/spec/jam_ruby/models/jam_track_spec.rb +++ b/ruby/spec/jam_ruby/models/jam_track_spec.rb @@ -22,79 +22,79 @@ describe JamTrack do jam_track.duration = 0 jam_track.save! - jam_track.reproduction_royalty_amount.should eq(BigDecimal('0.091')) + jam_track.reproduction_royalty_amount.to_f.should eq(0.091) jam_track.duration = 1 jam_track.save! - jam_track.reproduction_royalty_amount.should eq(0.091) + jam_track.reproduction_royalty_amount.to_f.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.reproduction_royalty_amount.to_f.should eq(0.091) jam_track.duration = 5 * 60 jam_track.save! - jam_track.reproduction_royalty_amount.should eq(0.0875) + jam_track.reproduction_royalty_amount.to_f.should eq(0.091) jam_track.duration = 6 * 60 - 1 # just under 6 minutes jam_track.save! - jam_track.reproduction_royalty_amount.should eq(0.0875) + jam_track.reproduction_royalty_amount.should eq(0.091 + 0.0175) jam_track.duration = 6 * 60 jam_track.save! - jam_track.reproduction_royalty_amount.should eq(0.105) + jam_track.reproduction_royalty_amount.should eq(0.091 + 0.0175) jam_track.duration = 7 * 60 - 1 jam_track.save! - jam_track.reproduction_royalty_amount.should eq(0.105) + jam_track.reproduction_royalty_amount.should eq(0.091 + 0.0175 * 2) jam_track.duration = 7 * 60 jam_track.save! - jam_track.reproduction_royalty_amount.should eq(0.1225) + jam_track.reproduction_royalty_amount.should eq(0.091 + 0.0175 * 2) jam_track.duration = 8 * 60 - 1 jam_track.save! - jam_track.reproduction_royalty_amount.should eq(0.1225) + jam_track.reproduction_royalty_amount.should eq(0.091 + 0.0175 * 3) jam_track.duration = 8 * 60 jam_track.save! - jam_track.reproduction_royalty_amount.should eq(0.14) + jam_track.reproduction_royalty_amount.should eq(0.091 + 0.0175 * 3) jam_track.duration = 9 * 60 - 1 jam_track.save! - jam_track.reproduction_royalty_amount.should eq(0.14) + jam_track.reproduction_royalty_amount.should eq(0.091 + 0.0175 * 4) jam_track.duration = 9 * 60 jam_track.save! - jam_track.reproduction_royalty_amount.should eq(0.1575) + jam_track.reproduction_royalty_amount.should eq(0.091 + 0.0175 * 4) jam_track.duration = 10 * 60 - 1 jam_track.save! - jam_track.reproduction_royalty_amount.should eq(0.1575) + jam_track.reproduction_royalty_amount.should eq(0.091 + 0.0175 * 5) jam_track.duration = 10 * 60 jam_track.save! - jam_track.reproduction_royalty_amount.should eq(0.175) + jam_track.reproduction_royalty_amount.should eq(0.091 + 0.0175 * 5) jam_track.duration = 11 * 60 - 1 jam_track.save! - jam_track.reproduction_royalty_amount.should eq(0.175) + jam_track.reproduction_royalty_amount.should eq(0.091 + 0.0175 * 6) jam_track.duration = 11 * 60 jam_track.save! - jam_track.reproduction_royalty_amount.should eq(0.1925) + jam_track.reproduction_royalty_amount.should eq(0.091 + 0.0175 * 6) jam_track.duration = 12 * 60 - 1 jam_track.save! - jam_track.reproduction_royalty_amount.should eq(0.1925) + jam_track.reproduction_royalty_amount.should eq(0.091 + 0.0175 * 7) jam_track.duration = 12 * 60 jam_track.save! - jam_track.reproduction_royalty_amount.should eq(0.1925) + jam_track.reproduction_royalty_amount.should eq(0.091 + 0.0175 * 7) jam_track.duration = 13 * 60 jam_track.save! - jam_track.reproduction_royalty_amount.should eq(0.1925) + jam_track.reproduction_royalty_amount.should eq(0.091 + 0.0175 * 8) end end diff --git a/web/app/controllers/api_music_sessions_controller.rb b/web/app/controllers/api_music_sessions_controller.rb index f1beaa5f9..c7433ea5a 100644 --- a/web/app/controllers/api_music_sessions_controller.rb +++ b/web/app/controllers/api_music_sessions_controller.rb @@ -482,7 +482,7 @@ class ApiMusicSessionsController < ApiController comment.save if comment.errors.any? - render :json => { :message => "Unexpected error occurred" }, :status => 500 + render :json => { :errors => comment.errors }, :status => 422 return else render :json => {}, :status => 201 @@ -508,7 +508,7 @@ class ApiMusicSessionsController < ApiController comment.save if comment.errors.any? - render :json => { :message => "Unexpected error occurred" }, :status => 500 + render :json => { :errors => comment.errors }, :status => 422 return else music_session = MusicSession.find(params[:id]) diff --git a/web/app/controllers/api_recordings_controller.rb b/web/app/controllers/api_recordings_controller.rb index b4012be5d..0767d9053 100644 --- a/web/app/controllers/api_recordings_controller.rb +++ b/web/app/controllers/api_recordings_controller.rb @@ -155,7 +155,7 @@ class ApiRecordingsController < ApiController comment.save if comment.errors.any? - render :json => { :message => "Unexpected error occurred" }, :status => 500 + render :json => { :errors => comment.errors }, :status => 422 return else render :json => {}, :status => 201 @@ -178,7 +178,7 @@ class ApiRecordingsController < ApiController liker.save if liker.errors.any? - render :json => { :message => "Unexpected error occurred" }, :status => 500 + render :json => { :errors => liker.errors }, :status => 422 return else render :json => {}, :status => 201 diff --git a/web/app/controllers/api_users_controller.rb b/web/app/controllers/api_users_controller.rb index 5c8f27377..18c2db8f8 100644 --- a/web/app/controllers/api_users_controller.rb +++ b/web/app/controllers/api_users_controller.rb @@ -796,7 +796,7 @@ class ApiUsersController < ApiController play.save if play.errors.any? - render :json => { :message => "Unexpected error occurred" }, :status => 500 + render :json => { :errors => play.errors }, :status => 422 else render :json => {}, :status => 201 end diff --git a/web/lib/tasks/jam_tracks.rake b/web/lib/tasks/jam_tracks.rake index 65ec0febb..edd589fb0 100644 --- a/web/lib/tasks/jam_tracks.rake +++ b/web/lib/tasks/jam_tracks.rake @@ -14,6 +14,11 @@ namespace :jam_tracks do JamTrackImporter.create_masters end + task tency_delta: :environment do |task, args| + JamTrackImporter.storage_format = 'Tency' + JamTrackImporter.tency_delta + end + task sync: :environment do |task, args| path = ENV['TRACK_PATH'] @@ -41,6 +46,15 @@ namespace :jam_tracks do JamTrackImporter.genre_dump end + task sync_tency: :environment do |task, args| + JamTrackImporter.storage_format = 'Tency' + JamTrackImporter.synchronize_all(skip_audio_upload:false) + end + + task onboarding_exceptions: :environment do |task, args| + JamTrackImporter.onboarding_exceptions + end + task sync_all: :environment do |task, args| JamTrackImporter.synchronize_all(skip_audio_upload:false) end