* wip
This commit is contained in:
parent
7f32ccced4
commit
4288ebe0d0
|
|
@ -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 ('piccolo', 'Piccolo', 1);
|
||||||
INSERT INTO instruments (id, description, popularity) VALUES ('bagpipes', 'Bagpipes', 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 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 additional_info VARCHAR;
|
||||||
ALTER TABLE jam_tracks ADD COLUMN language VARCHAR NOT NULL DEFAULT 'eng';
|
ALTER TABLE jam_tracks ADD COLUMN language VARCHAR NOT NULL DEFAULT 'eng';
|
||||||
ALTER TABLE jam_tracks ADD COLUMN year INTEGER;
|
ALTER TABLE jam_tracks ADD COLUMN year INTEGER;
|
||||||
|
|
|
||||||
|
|
@ -71,6 +71,7 @@ module JamRuby
|
||||||
if master_found
|
if master_found
|
||||||
@@log.debug("master exists... skipping #{self.name} ")
|
@@log.debug("master exists... skipping #{self.name} ")
|
||||||
finish('success', nil)
|
finish('success', nil)
|
||||||
|
return
|
||||||
else
|
else
|
||||||
|
|
||||||
tracks = []
|
tracks = []
|
||||||
|
|
@ -248,6 +249,7 @@ module JamRuby
|
||||||
end
|
end
|
||||||
|
|
||||||
def determine_genres(metadata)
|
def determine_genres(metadata)
|
||||||
|
|
||||||
genres = []
|
genres = []
|
||||||
if metadata[:genres]
|
if metadata[:genres]
|
||||||
metadata[:genres].each do |genre|
|
metadata[:genres].each do |genre|
|
||||||
|
|
@ -285,7 +287,11 @@ module JamRuby
|
||||||
# swallow
|
# swallow
|
||||||
elsif genre == 'oriental'
|
elsif genre == 'oriental'
|
||||||
genres << genre.find('asian')
|
genres << genre.find('asian')
|
||||||
|
else
|
||||||
|
found = Genre.find_by_id(genre)
|
||||||
|
genres << found if found
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -807,9 +813,11 @@ module JamRuby
|
||||||
|
|
||||||
track = JamTrackTrack.new
|
track = JamTrackTrack.new
|
||||||
track.original_filename = wav_file
|
track.original_filename = wav_file
|
||||||
|
track.original_audio_s3_path = wav_file
|
||||||
|
|
||||||
file = JamTrackFile.new
|
file = JamTrackFile.new
|
||||||
file.original_filename = wav_file
|
file.original_filename = wav_file
|
||||||
|
file.original_audio_s3_path = wav_file
|
||||||
|
|
||||||
parsed_wav = parse_file(wav_file)
|
parsed_wav = parse_file(wav_file)
|
||||||
|
|
||||||
|
|
@ -836,11 +844,14 @@ module JamRuby
|
||||||
tracks << track
|
tracks << track
|
||||||
elsif parsed_wav[:type] == :clicktxt
|
elsif parsed_wav[:type] == :clicktxt
|
||||||
file.file_type = 'ClickTxt'
|
file.file_type = 'ClickTxt'
|
||||||
|
addt_files << file
|
||||||
elsif parsed_wav[:type] == :clickwav
|
elsif parsed_wav[:type] == :clickwav
|
||||||
file.file_type = 'ClickWav'
|
file.file_type = 'ClickWav'
|
||||||
|
addt_files << file
|
||||||
elsif parsed_wav[:type] == :precount
|
elsif parsed_wav[:type] == :precount
|
||||||
file.file_type = 'Precount'
|
file.file_type = 'Precount'
|
||||||
file.precount_num = parsed_wav[:precount_num]
|
file.precount_num = parsed_wav[:precount_num]
|
||||||
|
addt_files << file
|
||||||
else
|
else
|
||||||
finish("unknown_file_type", "unknown file type #{wave_file}")
|
finish("unknown_file_type", "unknown file type #{wave_file}")
|
||||||
return false
|
return false
|
||||||
|
|
@ -919,7 +930,7 @@ module JamRuby
|
||||||
wav_file = File.join(tmp_dir, basename)
|
wav_file = File.join(tmp_dir, basename)
|
||||||
|
|
||||||
# bring the original wav file down from S3 to local file system
|
# 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
|
sample_rate = `soxi -r "#{wav_file}"`.strip
|
||||||
|
|
||||||
|
|
@ -967,7 +978,10 @@ module JamRuby
|
||||||
if !preview_succeeded
|
if !preview_succeeded
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
elsif track.track_type == 'Track'
|
||||||
|
synchronize_track_preview(track, tmp_dir, ogg_44100)
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
track.save!
|
track.save!
|
||||||
|
|
@ -996,6 +1010,51 @@ module JamRuby
|
||||||
true
|
true
|
||||||
end
|
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)
|
def synchronize_master_preview(track, tmp_dir, ogg_44100, ogg_digest)
|
||||||
|
|
||||||
begin
|
begin
|
||||||
|
|
@ -1108,6 +1167,7 @@ module JamRuby
|
||||||
|
|
||||||
attr_accessor :storage_format
|
attr_accessor :storage_format
|
||||||
attr_accessor :tency_mapping
|
attr_accessor :tency_mapping
|
||||||
|
attr_accessor :tency_metadata
|
||||||
attr_accessor :summaries
|
attr_accessor :summaries
|
||||||
|
|
||||||
def report_summaries
|
def report_summaries
|
||||||
|
|
@ -1240,13 +1300,56 @@ module JamRuby
|
||||||
report_summaries
|
report_summaries
|
||||||
end
|
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
|
def create_masters
|
||||||
iterate_song_storage do |metadata, metalocation|
|
iterate_song_storage do |metadata, metalocation|
|
||||||
|
next if metadata.nil?
|
||||||
jam_track_importer = JamTrackImporter.new(@storage_format)
|
jam_track_importer = JamTrackImporter.new(@storage_format)
|
||||||
|
|
||||||
jam_track_importer.create_master(metadata, metalocation)
|
jam_track_importer.create_master(metadata, metalocation)
|
||||||
|
|
||||||
break
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -1457,23 +1560,23 @@ module JamRuby
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def onboarding_exceptions
|
||||||
|
JamTrack.all.each do |jam_track|
|
||||||
|
jam_track.onboarding_exceptions
|
||||||
|
end
|
||||||
|
end
|
||||||
def synchronize_all(options)
|
def synchronize_all(options)
|
||||||
importers = []
|
importers = []
|
||||||
|
|
||||||
s3_manager.list_directories('audio').each do |original_artist|
|
iterate_song_storage do |metadata, metalocation|
|
||||||
@@log.debug("searching through artist directory '#{original_artist}'")
|
|
||||||
|
|
||||||
songs = s3_manager.list_directories(original_artist)
|
next if metadata.nil? && is_tency_storage?
|
||||||
songs.each do |song|
|
|
||||||
@@log.debug("searching through song directory' #{song}'")
|
|
||||||
|
|
||||||
metalocation = "#{song}meta.yml"
|
importer = synchronize_from_meta(metalocation, options)
|
||||||
|
importers << importer
|
||||||
importer = synchronize_from_meta(metalocation, options)
|
|
||||||
importers << importer
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
@@log.info("SUMMARY")
|
@@log.info("SUMMARY")
|
||||||
@@log.info("-------")
|
@@log.info("-------")
|
||||||
importers.each do |importer|
|
importers.each do |importer|
|
||||||
|
|
@ -1557,12 +1660,34 @@ module JamRuby
|
||||||
@tency_metadata = {}
|
@tency_metadata = {}
|
||||||
# convert both to hashes
|
# convert both to hashes
|
||||||
mapping_csv.each do |line|
|
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
|
end
|
||||||
|
|
||||||
metadata_csv.each do |line|
|
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
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -1600,7 +1725,7 @@ module JamRuby
|
||||||
end
|
end
|
||||||
|
|
||||||
def sync_from_metadata(jam_track, meta, metalocation, options)
|
def sync_from_metadata(jam_track, meta, metalocation, options)
|
||||||
jam_track_importer = JamTrackImporter.new
|
jam_track_importer = JamTrackImporter.new(@storage_format)
|
||||||
|
|
||||||
JamTrack.transaction do
|
JamTrack.transaction do
|
||||||
#begin
|
#begin
|
||||||
|
|
|
||||||
|
|
@ -39,8 +39,8 @@ module JamRuby
|
||||||
validates :public_performance_royalty, inclusion: {in: [nil, true, false]}
|
validates :public_performance_royalty, inclusion: {in: [nil, true, false]}
|
||||||
validates :duration, numericality: {only_integer: true}, :allow_nil => true
|
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 :reproduction_royalty_amount, with: /^\d+\.*\d{0,4}$/, :allow_blank => true
|
||||||
validates_format_of :licensor_royalty_amount, with: /^\d+\.*\d{0,3}$/, :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'
|
belongs_to :licensor , class_name: 'JamRuby::JamTrackLicensor', foreign_key: 'licensor_id'
|
||||||
|
|
||||||
|
|
@ -82,42 +82,20 @@ module JamRuby
|
||||||
|
|
||||||
# reproduction royalty table based on duration
|
# reproduction royalty table based on duration
|
||||||
|
|
||||||
# 0:00-4:59 0.091 5 minutes
|
# The statutory mechanical royalty rate for permanent digital downloads is:
|
||||||
# 5:00-5:59 0.0875 6 minutes
|
# 9.10¢ per copy for songs 5 minutes or less, or
|
||||||
# 6:00-6:59 0.105 7 minutes
|
# 1.75¢ per minute or fraction thereof, per copy for songs over 5 minutes.
|
||||||
# 7:00-7:59 0.1225 8 minutes
|
# So the base rate is 9.1 cents for anything up to 5 minutes.
|
||||||
# 8:00-8:59 0.14 9 minutes
|
# 5.01 to 6 minutes should be 10.5 cents.
|
||||||
# 9:00-9:59 0.1575 10 minutes
|
# 6.01 to 7 minutes should be 12.25 cents.
|
||||||
# 10:00-10:59 0.175 11 minutes
|
# Etc.
|
||||||
# 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
|
royalty = nil
|
||||||
if self.duration
|
if self.duration
|
||||||
case self.duration
|
minutes = (self.duration - 1) / 60
|
||||||
when [0...min_5]
|
extra_minutes = minutes - 4
|
||||||
royalty = 0.091
|
extra_minutes = 0 if extra_minutes < 0
|
||||||
when [min_5...min_6]
|
royalty = 0.091 + (0.0175 * extra_minutes)
|
||||||
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
|
end
|
||||||
self.update_column(:reproduction_royalty_amount, royalty)
|
self.update_column(:reproduction_royalty_amount, royalty)
|
||||||
|
|
||||||
|
|
@ -126,7 +104,46 @@ module JamRuby
|
||||||
|
|
||||||
def onboarding_exceptions
|
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
|
end
|
||||||
|
|
||||||
def duplicate_positions?
|
def duplicate_positions?
|
||||||
|
|
@ -149,6 +166,17 @@ module JamRuby
|
||||||
duplicate
|
duplicate
|
||||||
end
|
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?
|
def missing_previews?
|
||||||
missing_preview = false
|
missing_preview = false
|
||||||
self.jam_track_tracks.each do |track|
|
self.jam_track_tracks.each do |track|
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ module JamRuby
|
||||||
|
|
||||||
before_destroy :delete_s3_files
|
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"
|
belongs_to :jam_track, class_name: "JamRuby::JamTrack"
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -131,81 +131,19 @@ module JamRuby
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def generate_preview
|
def generate_preview
|
||||||
|
|
||||||
begin
|
begin
|
||||||
Dir.mktmpdir do |tmp_dir|
|
Dir.mktmpdir do |tmp_dir|
|
||||||
|
|
||||||
input = File.join(tmp_dir, 'in.ogg')
|
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"]
|
raise 'no track' unless self["url_44"]
|
||||||
|
|
||||||
s3_manager.download(self.url_by_sample_rate(44), input)
|
s3_manager.download(self.url_by_sample_rate(44), input)
|
||||||
|
|
||||||
command = "sox \"#{input}\" \"#{output}\" trim #{sprintf("%.3f", start)} =#{sprintf("%.3f", stop)}"
|
process_preview(input, tmp_dir)
|
||||||
|
|
||||||
@@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
|
end
|
||||||
rescue Exception => e
|
rescue Exception => e
|
||||||
@@log.error("error in sox command #{e.to_s}")
|
@@log.error("error in sox command #{e.to_s}")
|
||||||
|
|
@ -214,6 +152,76 @@ module JamRuby
|
||||||
|
|
||||||
end
|
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
|
private
|
||||||
def normalize_position
|
def normalize_position
|
||||||
|
|
|
||||||
|
|
@ -22,79 +22,79 @@ describe JamTrack do
|
||||||
|
|
||||||
jam_track.duration = 0
|
jam_track.duration = 0
|
||||||
jam_track.save!
|
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.duration = 1
|
||||||
jam_track.save!
|
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.duration = 5 * 60 - 1 # just under 5 minutes
|
||||||
jam_track.save!
|
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.duration = 5 * 60
|
||||||
jam_track.save!
|
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.duration = 6 * 60 - 1 # just under 6 minutes
|
||||||
jam_track.save!
|
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.duration = 6 * 60
|
||||||
jam_track.save!
|
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.duration = 7 * 60 - 1
|
||||||
jam_track.save!
|
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.duration = 7 * 60
|
||||||
jam_track.save!
|
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.duration = 8 * 60 - 1
|
||||||
jam_track.save!
|
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.duration = 8 * 60
|
||||||
jam_track.save!
|
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.duration = 9 * 60 - 1
|
||||||
jam_track.save!
|
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.duration = 9 * 60
|
||||||
jam_track.save!
|
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.duration = 10 * 60 - 1
|
||||||
jam_track.save!
|
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.duration = 10 * 60
|
||||||
jam_track.save!
|
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.duration = 11 * 60 - 1
|
||||||
jam_track.save!
|
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.duration = 11 * 60
|
||||||
jam_track.save!
|
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.duration = 12 * 60 - 1
|
||||||
jam_track.save!
|
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.duration = 12 * 60
|
||||||
jam_track.save!
|
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.duration = 13 * 60
|
||||||
jam_track.save!
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -482,7 +482,7 @@ class ApiMusicSessionsController < ApiController
|
||||||
comment.save
|
comment.save
|
||||||
|
|
||||||
if comment.errors.any?
|
if comment.errors.any?
|
||||||
render :json => { :message => "Unexpected error occurred" }, :status => 500
|
render :json => { :errors => comment.errors }, :status => 422
|
||||||
return
|
return
|
||||||
else
|
else
|
||||||
render :json => {}, :status => 201
|
render :json => {}, :status => 201
|
||||||
|
|
@ -508,7 +508,7 @@ class ApiMusicSessionsController < ApiController
|
||||||
comment.save
|
comment.save
|
||||||
|
|
||||||
if comment.errors.any?
|
if comment.errors.any?
|
||||||
render :json => { :message => "Unexpected error occurred" }, :status => 500
|
render :json => { :errors => comment.errors }, :status => 422
|
||||||
return
|
return
|
||||||
else
|
else
|
||||||
music_session = MusicSession.find(params[:id])
|
music_session = MusicSession.find(params[:id])
|
||||||
|
|
|
||||||
|
|
@ -155,7 +155,7 @@ class ApiRecordingsController < ApiController
|
||||||
comment.save
|
comment.save
|
||||||
|
|
||||||
if comment.errors.any?
|
if comment.errors.any?
|
||||||
render :json => { :message => "Unexpected error occurred" }, :status => 500
|
render :json => { :errors => comment.errors }, :status => 422
|
||||||
return
|
return
|
||||||
else
|
else
|
||||||
render :json => {}, :status => 201
|
render :json => {}, :status => 201
|
||||||
|
|
@ -178,7 +178,7 @@ class ApiRecordingsController < ApiController
|
||||||
liker.save
|
liker.save
|
||||||
|
|
||||||
if liker.errors.any?
|
if liker.errors.any?
|
||||||
render :json => { :message => "Unexpected error occurred" }, :status => 500
|
render :json => { :errors => liker.errors }, :status => 422
|
||||||
return
|
return
|
||||||
else
|
else
|
||||||
render :json => {}, :status => 201
|
render :json => {}, :status => 201
|
||||||
|
|
|
||||||
|
|
@ -796,7 +796,7 @@ class ApiUsersController < ApiController
|
||||||
play.save
|
play.save
|
||||||
|
|
||||||
if play.errors.any?
|
if play.errors.any?
|
||||||
render :json => { :message => "Unexpected error occurred" }, :status => 500
|
render :json => { :errors => play.errors }, :status => 422
|
||||||
else
|
else
|
||||||
render :json => {}, :status => 201
|
render :json => {}, :status => 201
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,11 @@ namespace :jam_tracks do
|
||||||
JamTrackImporter.create_masters
|
JamTrackImporter.create_masters
|
||||||
end
|
end
|
||||||
|
|
||||||
|
task tency_delta: :environment do |task, args|
|
||||||
|
JamTrackImporter.storage_format = 'Tency'
|
||||||
|
JamTrackImporter.tency_delta
|
||||||
|
end
|
||||||
|
|
||||||
task sync: :environment do |task, args|
|
task sync: :environment do |task, args|
|
||||||
path = ENV['TRACK_PATH']
|
path = ENV['TRACK_PATH']
|
||||||
|
|
||||||
|
|
@ -41,6 +46,15 @@ namespace :jam_tracks do
|
||||||
JamTrackImporter.genre_dump
|
JamTrackImporter.genre_dump
|
||||||
end
|
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|
|
task sync_all: :environment do |task, args|
|
||||||
JamTrackImporter.synchronize_all(skip_audio_upload:false)
|
JamTrackImporter.synchronize_all(skip_audio_upload:false)
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue