From 52f9bde0a3c172d687331be1a1949f98bd4487f6 Mon Sep 17 00:00:00 2001 From: Seth Call Date: Thu, 13 Feb 2014 14:19:08 +0000 Subject: [PATCH] * taking gon to 5.0.1 for now --- admin/Gemfile | 2 +- .../_claimed_recording_fields.html.haml | 11 ++++ .../admin/recordings/_mix_fields.html.haml | 18 +++++++ .../recordings/_recorded_track.html.haml | 4 -- db/up/recordings_via_admin_web.sql | 4 ++ .../jam_ruby/app/uploaders/mix_uploader.rb | 52 +++++++++++++++++++ .../app/uploaders/recorded_track_uploader.rb | 0 .../app/uploaders/uploader_configuration.rb | 0 8 files changed, 86 insertions(+), 5 deletions(-) create mode 100644 admin/app/views/admin/recordings/_claimed_recording_fields.html.haml create mode 100644 admin/app/views/admin/recordings/_mix_fields.html.haml delete mode 100644 admin/app/views/admin/recordings/_recorded_track.html.haml create mode 100644 db/up/recordings_via_admin_web.sql create mode 100644 ruby/lib/jam_ruby/app/uploaders/mix_uploader.rb create mode 100644 ruby/lib/jam_ruby/app/uploaders/recorded_track_uploader.rb create mode 100644 ruby/lib/jam_ruby/app/uploaders/uploader_configuration.rb diff --git a/admin/Gemfile b/admin/Gemfile index a7a1d1e2c..498c95427 100644 --- a/admin/Gemfile +++ b/admin/Gemfile @@ -51,7 +51,7 @@ gem 'aasm', '3.0.16' gem 'postgres-copy', '0.6.0' gem 'aws-sdk', '1.29.1' gem 'bugsnag' -gem 'gon' +gem 'gon', '5.0.1' # '5.0.3' has an issue with setting globals in an initializer gem 'cocoon' gem 'haml-rails' gem 'resque' diff --git a/admin/app/views/admin/recordings/_claimed_recording_fields.html.haml b/admin/app/views/admin/recordings/_claimed_recording_fields.html.haml new file mode 100644 index 000000000..2b5c974db --- /dev/null +++ b/admin/app/views/admin/recordings/_claimed_recording_fields.html.haml @@ -0,0 +1,11 @@ += f.inputs name: 'Claimed Recording' do + = link_to_remove_association "Delete Claimed Recording", f, class: 'button', style: 'margin-left:10px; position: relative; top: -37px; left: 50px;' + %ol.nested-fields + + + %div{style: 'display:none'} + = #f.input :should_retry, :as => :hidden, :input_html => {:value => '0' } + + + + diff --git a/admin/app/views/admin/recordings/_mix_fields.html.haml b/admin/app/views/admin/recordings/_mix_fields.html.haml new file mode 100644 index 000000000..fe6b7dc99 --- /dev/null +++ b/admin/app/views/admin/recordings/_mix_fields.html.haml @@ -0,0 +1,18 @@ += f.inputs name: 'Track' do + %ol.nested-fields + = puts "f.object #{f.object.url}" + = f.input :user, :as => :autocomplete, :url => autocomplete_user_email_admin_users_path, :input_html => { id: "jam_ruby_recorded_track_user_id", name: "", id_element: "#WILL_BE_OVERRIDDEN_BY_JS_IN_RECORDED_FORM" } + = f.input :user_id, :as => :hidden, :input_html => { class: "jam_ruby_recorded_track[user_id]" } + = f.input :instrument, collection: Instrument.all + = f.input :sound, :as => :select, collection: options_for_select(RecordedTrack::SOUND, 'stereo') + = f.input :url, :as => :file + - unless f.object.nil? && f.object.url.nil? + %a{href: f.object.sign_url} current file + + = f.input :client_id, as: :hidden + = f.input :track_id, as: :hidden + = f.input :client_track_id, as: :hidden + + = link_to_remove_association "remove track", f + + diff --git a/admin/app/views/admin/recordings/_recorded_track.html.haml b/admin/app/views/admin/recordings/_recorded_track.html.haml deleted file mode 100644 index 88c59eda8..000000000 --- a/admin/app/views/admin/recordings/_recorded_track.html.haml +++ /dev/null @@ -1,4 +0,0 @@ -.nested-fields - = f.inputs :name => "Track" do - = f.input :user, :as => :autocomplete, :url => autocomplete_user_email_admin_users_path - = f.input :instrument, :collection => Instrument.all \ No newline at end of file diff --git a/db/up/recordings_via_admin_web.sql b/db/up/recordings_via_admin_web.sql new file mode 100644 index 000000000..2b35d1c7e --- /dev/null +++ b/db/up/recordings_via_admin_web.sql @@ -0,0 +1,4 @@ +ALTER TABLE recorded_tracks ALTER COLUMN user_id SET NOT NULL; +ALTER TABLE recorded_tracks ALTER COLUMN instrument_id SET NOT NULL; + +ALTER TABLE recordings ADD COLUMN name varchar(1024); \ No newline at end of file diff --git a/ruby/lib/jam_ruby/app/uploaders/mix_uploader.rb b/ruby/lib/jam_ruby/app/uploaders/mix_uploader.rb new file mode 100644 index 000000000..441dcdfa3 --- /dev/null +++ b/ruby/lib/jam_ruby/app/uploaders/mix_uploader.rb @@ -0,0 +1,52 @@ +class RecordedTrackUploader < CarrierWave::Uploader::Base + # include CarrierWaveDirect::Uploader + include CarrierWave::MimeTypes + + process :set_content_type + process :add_metadata + + def initialize(*) + super + JamRuby::UploaderConfiguration.set_aws_private_configuration(self) + end + + def add_metadata + + # add this metadata to ogg file without disturbing audio + #JamRecordingId=af9f1598-2243-4c21-98c1-5e0c56da5b89 + #JamTrackId=5b1c3ef4-01d7-471e-8684-e2a5743ffd26 + #JamClientId=8331bcec-7810-42c1-9f39-a5c129406e85 + #JamType=LocalTrack + + # secret sauce is -codec copy, and a bunch of -metadata arguments. + # after done, stomp input file with new one + + input_file = current_path + output_file = current_path + '.new.ogg' + ffmpeg_cmd = "#{APP_CONFIG.ffmpeg_path} -i \"#{input_file}\" -codec copy -metadata JamRecordingId=#{model.recording_id} -metadata JamTrackId=#{model.client_track_id} -metadata JamClientId=#{model.client_id} -metadata JamType=LocalTrack \"#{output_file}\"" + system(ffmpeg_cmd) + + unless $? == 0 + raise "ffmpeg failed" + end + + FileUtils.mv output_file, input_file + end + + # Add a white list of extensions which are allowed to be uploaded. + def extension_white_list + %w(ogg) + end + + def store_dir + nil + end + + def md5 + @md5 ||= ::Digest::MD5.file(current_path).hexdigest + end + + def filename + model.filename if model.id + end +end diff --git a/ruby/lib/jam_ruby/app/uploaders/recorded_track_uploader.rb b/ruby/lib/jam_ruby/app/uploaders/recorded_track_uploader.rb new file mode 100644 index 000000000..e69de29bb diff --git a/ruby/lib/jam_ruby/app/uploaders/uploader_configuration.rb b/ruby/lib/jam_ruby/app/uploaders/uploader_configuration.rb new file mode 100644 index 000000000..e69de29bb