Fix bug.
This commit is contained in:
parent
c8b21416c1
commit
986cca8c5c
|
@ -151,8 +151,8 @@ class AdBannersController < ApplicationController
|
||||||
extra_before_html = ""
|
extra_before_html = ""
|
||||||
extra_after_html = ""
|
extra_after_html = ""
|
||||||
if has_jplayer
|
if has_jplayer
|
||||||
extra_before_html = ActionController::Base.helpers.stylesheet_link_tag("banner/jplayer.blue.monday.min.css")
|
extra_before_html = "\n" + ActionController::Base.helpers.stylesheet_link_tag("banner/jplayer.blue.monday.min.css") + "\n" +
|
||||||
extra_after_html = ActionController::Base.helpers.javascript_include_tag("banner/jquery.jplayer.min.js")
|
ActionController::Base.helpers.javascript_include_tag("banner/jquery.jplayer.min.js") + "\n"
|
||||||
end
|
end
|
||||||
base_image = adbanner.base_image.nil? ? 1 : adbanner.base_image
|
base_image = adbanner.base_image.nil? ? 1 : adbanner.base_image
|
||||||
adbanner_title_escape = adbanner.title.to_s.gsub('"','"')
|
adbanner_title_escape = adbanner.title.to_s.gsub('"','"')
|
||||||
|
|
|
@ -8,7 +8,7 @@ class AdImage
|
||||||
mount_uploader :video_snapshot, BannerImageUploader
|
mount_uploader :video_snapshot, BannerImageUploader
|
||||||
mount_uploader :video_file, BannerUploader
|
mount_uploader :video_file, BannerUploader
|
||||||
mount_uploader :video_file_webm, BannerUploader
|
mount_uploader :video_file_webm, BannerUploader
|
||||||
|
field :default_video_snapshot, type: Boolean, default: false
|
||||||
field :auto_convert_video, type: Boolean, default: false
|
field :auto_convert_video, type: Boolean, default: false
|
||||||
field :title, type: String, localize: true
|
field :title, type: String, localize: true
|
||||||
field :context, type: String, localize: true
|
field :context, type: String, localize: true
|
||||||
|
@ -33,13 +33,38 @@ class AdImage
|
||||||
scope :can_display, ->{self.and(AdImage.unscoped.or({:postdate.lte=>Time.now},{:postdate=>nil}).selector,AdImage.unscoped.or({:deadline.gte=>Time.now},{:deadline=>nil}).selector)}
|
scope :can_display, ->{self.and(AdImage.unscoped.or({:postdate.lte=>Time.now},{:postdate=>nil}).selector,AdImage.unscoped.or({:deadline.gte=>Time.now},{:deadline=>nil}).selector)}
|
||||||
scope :is_expired, ->{self.and(AdImage.unscoped.or({:deadline.lte=>Time.now}).selector)}
|
scope :is_expired, ->{self.and(AdImage.unscoped.or({:deadline.lte=>Time.now}).selector)}
|
||||||
scope :not_expired, ->{self.and(AdImage.unscoped.or({:deadline.gte=>Time.now},{:deadline=>nil}).selector)}
|
scope :not_expired, ->{self.and(AdImage.unscoped.or({:deadline.gte=>Time.now},{:deadline=>nil}).selector)}
|
||||||
|
before_save do
|
||||||
|
unless @skip_callback
|
||||||
|
if self.video_snapshot_changed?
|
||||||
|
self.default_video_snapshot = false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
after_save do
|
after_save do
|
||||||
|
unless @skip_callback
|
||||||
if (self.video_file_changed? || self.auto_convert_video_changed?) && self.auto_convert_video
|
if (self.video_file_changed? || self.auto_convert_video_changed?) && self.auto_convert_video
|
||||||
Thread.new do
|
Thread.new do
|
||||||
self.generate_webm
|
self.generate_webm
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
if self.video_file? && self.video_file_changed? && (!(self.video_snapshot?) || self.default_video_snapshot)
|
||||||
|
Thread.new do
|
||||||
|
self.generate_video_snapshot
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
def generate_video_snapshot
|
||||||
|
if self.video_file?
|
||||||
|
self.default_video_snapshot = true
|
||||||
|
self[:video_snapshot] = File.basename(self.video_file.file.path).split(/\.[^.]+$/)[0] + ".jpg"
|
||||||
|
FileUtils.mkdir_p(File.dirname(self.video_snapshot.file.path))
|
||||||
|
system("tmp/ffmpeg/ffmpeg -i #{self.video_file.file.path} -vframes 1 #{self.video_snapshot.file.path}")
|
||||||
|
@skip_callback = true
|
||||||
|
self.save
|
||||||
|
@skip_callback = false
|
||||||
|
true
|
||||||
|
end
|
||||||
end
|
end
|
||||||
def generate_webm
|
def generate_webm
|
||||||
video_path = self.video_file.path rescue nil
|
video_path = self.video_file.path rescue nil
|
||||||
|
@ -49,7 +74,10 @@ class AdImage
|
||||||
flag = system("tmp/ffmpeg/ffmpeg -i #{video_path} -c:v libvpx-vp9 -crf 35 -b:v 0 -b:a 96k -c:a libopus -filter:v fps=20 #{video_webm} -cpu-used #{core_num}")
|
flag = system("tmp/ffmpeg/ffmpeg -i #{video_path} -c:v libvpx-vp9 -crf 35 -b:v 0 -b:a 96k -c:a libopus -filter:v fps=20 #{video_webm} -cpu-used #{core_num}")
|
||||||
if flag
|
if flag
|
||||||
self.video_file_webm = File.open(video_webm)
|
self.video_file_webm = File.open(video_webm)
|
||||||
|
@skip_callback = true
|
||||||
self.save
|
self.save
|
||||||
|
@skip_callback = false
|
||||||
|
true
|
||||||
else
|
else
|
||||||
puts "generate webm failed"
|
puts "generate webm failed"
|
||||||
end
|
end
|
||||||
|
|
|
@ -66,7 +66,7 @@
|
||||||
<% end %>
|
<% end %>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<%= image.title rescue "" %>
|
<%= image.title.to_s.html_safe rescue "" %>
|
||||||
<% if can_edit_or_delete?(@banner) %>
|
<% if can_edit_or_delete?(@banner) %>
|
||||||
<div class="quick-edit">
|
<div class="quick-edit">
|
||||||
<ul class="nav nav-pills">
|
<ul class="nav nav-pills">
|
||||||
|
|
|
@ -209,6 +209,7 @@
|
||||||
})
|
})
|
||||||
if (typeof(default_video_data)=='undefined'){
|
if (typeof(default_video_data)=='undefined'){
|
||||||
var default_video_data = {
|
var default_video_data = {
|
||||||
|
cssSelectorAncestor: "#jp_container_<%= i %>",
|
||||||
ready: function () {
|
ready: function () {
|
||||||
$(this).jPlayer("setMedia", {
|
$(this).jPlayer("setMedia", {
|
||||||
title: "Big Buck Bunny Trailer",
|
title: "Big Buck Bunny Trailer",
|
||||||
|
@ -365,7 +366,8 @@
|
||||||
//jPlayer_<%= i %>_data["autoPlay"] = <%= @autoplay_video == true %>;
|
//jPlayer_<%= i %>_data["autoPlay"] = <%= @autoplay_video == true %>;
|
||||||
jPlayer_<%= i %>["ready"] = function () {
|
jPlayer_<%= i %>["ready"] = function () {
|
||||||
$(this).jPlayer("setMedia", jPlayer_<%= i %>_data);
|
$(this).jPlayer("setMedia", jPlayer_<%= i %>_data);
|
||||||
if ($(this).parents(".ba-banner-widget-youtube").eq(0).find(".w-ba-banner__slide").index($(this).parents(".w-ba-banner__slide").eq(0))==0){
|
var slides = $(this).parents('.cycle-slideshow').data('cycle.opts').slides;
|
||||||
|
if (slides && slides.index($(this).parents(".w-ba-banner__slide").eq(0))==0){
|
||||||
<% if @autoplay_video == true %>
|
<% if @autoplay_video == true %>
|
||||||
var $video_ele = $(this).find('video');
|
var $video_ele = $(this).find('video');
|
||||||
if ($video_ele.length>0){
|
if ($video_ele.length>0){
|
||||||
|
|
|
@ -3,12 +3,19 @@ require 'fileutils'
|
||||||
get 'ad_banners/widget'
|
get 'ad_banners/widget'
|
||||||
if ENV['worker_num']=='0' && File.basename($0) != 'rake' && !Rails.const_defined?('Console')
|
if ENV['worker_num']=='0' && File.basename($0) != 'rake' && !Rails.const_defined?('Console')
|
||||||
Thread.new do
|
Thread.new do
|
||||||
|
s = Site.first
|
||||||
|
update_flag = s.respond_to?(:tmp_flags)
|
||||||
|
need_update = !update_flag || !(s.tmp_flags.include?('adf1'))
|
||||||
|
if need_update
|
||||||
ad_images = AdImage.where(:video_file.ne=>nil,:video_snapshot=>nil).to_a
|
ad_images = AdImage.where(:video_file.ne=>nil,:video_snapshot=>nil).to_a
|
||||||
ad_images.each do |ad_image|
|
ad_images.each do |ad_image|
|
||||||
ad_image[:video_snapshot] = File.basename(ad_image.video_file.file.path).split(/\.[^.]+$/)[0] + ".jpg"
|
ad_image.generate_video_snapshot
|
||||||
FileUtils.mkdir_p(File.dirname(ad_image.video_snapshot.file.path))
|
end
|
||||||
system("tmp/ffmpeg/ffmpeg -i #{ad_image.video_file.file.path} -vframes 1 #{ad_image.video_snapshot.file.path}")
|
if update_flag
|
||||||
ad_image.save
|
s = OrbitHelper::SharedHash['current_site']['site'] rescue Site.first
|
||||||
|
s.tmp_flags << 'adf1'
|
||||||
|
s.save
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue