#coding=utf-8
namespace :video_transcode do
  desc "视频转码成h264"
  task :submit => :environment do
    i = []
    Video.where(transcoded: false).find_each do |v|
      if v.uuid.present? && v.file_url.present?
        code_info = AliyunVod::Service.get_meta_code_info(v.uuid)
        if v.file_url.include?('.mp4') && code_info[:codecnamne]&.include?("h264")
          v.update(transcoded: true)
        else
          puts("uuid: #{v.uuid}")
          i << "#{v.id}, #{v.file_url}, #{code_info[:codecnamne]}"
          AliyunVod::Service.submit_transcode_job(v.uuid, 'a0277c5c0c7458458e171b0cee6ebf5e') rescue nil
        end
      else
        v.update_column(:transcoded, true)
      end
    end
    puts "###########转码个数:#{i.size}"
    puts "###########id,file_url, codecnamne:#{i}"
    #Video.where(transcoded: false).update_all(transcoded: true)
  end
end