You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

23 lines
808 B

  1. # frozen_string_literal: true
  2. module Paperclip
  3. class AudioTranscoder < Paperclip::Processor
  4. def make
  5. max_aud_len = (ENV['MAX_AUDIO_LENGTH'] || 60.0).to_f
  6. meta = ::Av.cli.identify(@file.path)
  7. # {:length=>"0:00:02.14", :duration=>2.14, :audio_encode=>"mp3", :audio_bitrate=>"44100 Hz", :audio_channels=>"mono"}
  8. if meta[:duration] > max_aud_len
  9. raise Mastodon::ValidationError, "Audio uploads must be less than #{max_aud_len} seconds in length."
  10. end
  11. final_file = Paperclip::Transcoder.make(file, options, attachment)
  12. attachment.instance.file_file_name = 'media.mp4'
  13. attachment.instance.file_content_type = 'video/mp4'
  14. attachment.instance.type = MediaAttachment.types[:video]
  15. final_file
  16. end
  17. end
  18. end