Class: Wco::Video

Inherits:
Object
  • Object
show all
Includes:
Mongoid::Document, Mongoid::Paperclip, Mongoid::Paranoia, Mongoid::Timestamps, Utils
Defined in:
app/models/wco/video.rb

Constant Summary collapse

PAGE_PARAM_NAME =
'videos_page'

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Utils

#export, included

Class Method Details

.listObject



94
95
96
97
98
# File 'app/models/wco/video.rb', line 94

def self.list
  [['', nil]] + self.unscoped.order_by( :created_at => :desc ).map do |item|
    [ "#{item.created_at.strftime('%Y%m%d')} #{item.name}", item.id ]
  end
end

Instance Method Details

#export_fieldsObject



74
75
76
# File 'app/models/wco/video.rb', line 74

def export_fields
  %w| name descr |
end

#generate_thumbnailObject



100
101
102
103
104
105
106
107
108
109
# File 'app/models/wco/video.rb', line 100

def generate_thumbnail
  return unless video.queued_for_write[:original]

  input_path  = video.queued_for_write[:original].path
  output_path = Rails.root.join('tmp', "thumb_#{SecureRandom.hex}.jpg")
  movie = ::FFMPEG::Movie.new(input_path)
  movie.screenshot(output_path.to_s, seek_time: 1) ## at time 00:00:01 seconds
  self.thumb = File.open(output_path)
  File.delete(output_path) if File.exist?(output_path)
end

#publishedObject



23
24
25
# File 'app/models/wco/video.rb', line 23

def published
  where({ :is_public => true }).order_by({ :created_at => :desc })
end

#set_duration_msObject



79
80
81
82
83
84
# File 'app/models/wco/video.rb', line 79

def set_duration_ms
  return unless video.queued_for_write[:original]
  path = video.queued_for_write[:original].path
  movie = ::FFMPEG::Movie.new(path)
  self.duration_ms = (movie.duration * 1000).to_i if movie.duration
end

#set_titleObject



87
88
89
90
91
92
# File 'app/models/wco/video.rb', line 87

def set_title
  return unless video.present?
  filename = video_file_name # Paperclip metadata
  return unless filename
  self.name = File.basename(filename, ".*") if self.name.blank?
end

#subheadObject

still need it... 2023-03-24



20
# File 'app/models/wco/video.rb', line 20

field :subhead