Sha256: 98b23af8c8a27a044550bc1c990f736c269160caf143047103cbf7aee63a4720

Contents?: true

Size: 1.29 KB

Versions: 11

Compression:

Stored size: 1.29 KB

Contents

module Pageflow
  class AudioFile < ApplicationRecord
    include UploadableFile
    include MediaEncodingStateMachine

    belongs_to :confirmed_by, class_name: 'User', optional: true

    has_attached_file(:peak_data,
                      Pageflow.config.paperclip_s3_default_options
                        .merge(styles: {
                                 original: {
                                   processors: [:pageflow_audio_waveform],
                                   format: 'json'
                                 }
                               }))

    do_not_validate_attachment_file_type :peak_data

    def attachment_s3_url
      "s3://#{File.join(attachment.bucket_name, attachment.path)}"
    end

    def m4a
      ZencoderAttachment.new(self, "audio.m4a")
    end

    def mp3
      ZencoderAttachment.new(self, "audio.mp3")
    end

    def ogg
      ZencoderAttachment.new(self, "audio.ogg")
    end

    def output_definition
      ZencoderAudioOutputDefinition.new(self)
    end

    def meta_data_attributes=(attributes)
      self.attributes = attributes.symbolize_keys.slice(:format, :duration_in_ms)
    end

    def post_process_encoded_files
      self.peak_data = URI.parse(ogg.url(default_protocol: 'https'))
    rescue OpenURI::HTTPError
      throw(:halt, :pending)
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
pageflow-17.0.4 app/models/pageflow/audio_file.rb
pageflow-17.0.3 app/models/pageflow/audio_file.rb
pageflow-17.0.2 app/models/pageflow/audio_file.rb
pageflow-17.0.1 app/models/pageflow/audio_file.rb
pageflow-17.0.0 app/models/pageflow/audio_file.rb
pageflow-16.2.0 app/models/pageflow/audio_file.rb
pageflow-16.1.0 app/models/pageflow/audio_file.rb
pageflow-16.0.0 app/models/pageflow/audio_file.rb
pageflow-15.8.0 app/models/pageflow/audio_file.rb
pageflow-15.7.1 app/models/pageflow/audio_file.rb
pageflow-15.7.0 app/models/pageflow/audio_file.rb