Class: FlyAdmin::ConvertVideoJob
- Inherits:
-
ActiveJob::Base
- Object
- ActiveJob::Base
- FlyAdmin::ConvertVideoJob
- Includes:
- VideoModule
- Defined in:
- app/jobs/fly_admin/convert_video_job.rb
Instance Method Summary collapse
- #perform(options) ⇒ Object
-
#process_video(video) ⇒ Object
making thumbnail, moving file.
Instance Method Details
#perform(options) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'app/jobs/fly_admin/convert_video_job.rb', line 6 def perform() nodes = [:nodes] season_id = [:season_id] path = [:path] category_id = [:category_id] folders, files = nodes.partition { |n| n['li_attr']['type'] == 'folder' } files_for_convert = [] files.select {|file| video_file?(file["li_attr"]["url"]) }.each do |node| = { file_path: node["li_attr"]["url"], category_id: category_id, title: node["name"], season_id: season_id } files_for_convert << end folders.each do |node| node_path = node["li_attr"]["url"] files = Dir["#{path + node_path.shellescape}/**/*.{mp4,mp3,aaf,3gp,gif,asf,avchd,avi,cam,dat,dsh,flv,mpeg,mpeg-1,mpeg-2,fla,flr,sol,m4v,mkv,wrap,mng,mov,mpg,mpe,mxf,nsv,ogg,svi,smi,wmv}"] files.each do |file| file_path = file.split(path).last # remove root from path title = file_path.split("/").last = { file_path: file_path, category_id: category_id, title: title, season_id: season_id } files_for_convert << end end # Convert video stuff files_for_convert.uniq.each { |file| process_video(file) } end |
#process_video(video) ⇒ Object
making thumbnail, moving file
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'app/jobs/fly_admin/convert_video_job.rb', line 46 def process_video(video) title, file_path, season_id = video[:title], video[:file_path], video[:season_id] filename = file_path.split("/").last.gsub(/[^0-9A-Za-z.\-]/, '_') v = Video.create!(:title => title, :content => filename, :state => Video::BEFORE_SPAWNLING, :source_path => file_path, :uuid => SecureRandom.uuid) dir = File.dirname(v.content_path) FileUtils.mkdir_p(dir) v.set_duration v.delay.create_thumbnail season = Season.find(season_id) season.videos << v CONVERTATION_LOG.info "Convert Video id : #{v.id}" v.update_column(:state, Video::PENDING_STATE) # For debug only end |