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.

21 lines
729 B

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