diff --git a/app/controllers/video_pros_controller.rb b/app/controllers/video_pros_controller.rb index eb073a3..d5f0a1a 100644 --- a/app/controllers/video_pros_controller.rb +++ b/app/controllers/video_pros_controller.rb @@ -25,7 +25,7 @@ class VideoProsController < ApplicationController end @video_image.view_count += 1 @video_image.inc_count - render :layout=>false + render :layout=>false end def index params = OrbitHelper.params @@ -200,7 +200,7 @@ class VideoProsController < ApplicationController } } else - video_images = VideoImage.where(:title.nin => ["",nil]).can_display_and_sorted.filter_by_widget_categories.to_a + video_images = VideoImage.where(:title.nin => ["",nil]).can_display_and_sorted.filter_by_widget_categories.filter_by_tags(OrbitHelper.widget_tags).to_a custom_data_field = subpart.custom_data_field || {} @video_pro_setting = VideoProSetting.first videos = get_videos(video_images, OrbitHelper.widget_item_url(''), custom_data_field) diff --git a/app/models/video_image.rb b/app/models/video_image.rb index 46baead..7ccf4ad 100644 --- a/app/models/video_image.rb +++ b/app/models/video_image.rb @@ -72,34 +72,35 @@ class VideoImage self.youtube_id = v end end - if self.is_youtube - begin - youtube_img_url = "https:"+self.youtube_thumb - uri = URI.parse(youtube_img_url) - req = Net::HTTP::Get.new(uri.path) - res = Net::HTTP.start( uri.host, uri.port, - :use_ssl => (uri.scheme == 'https'), - :verify_mode => OpenSSL::SSL::VERIFY_NONE) do |https| - https.request(req) - end - snapshot_content = res.body rescue nil #Net::HTTP.get_response(URI.parse(youtube_img_url)).body rescue nil - if snapshot_content - self[:video_snapshot] = '0.jpg' - snapshot_file_path = self.video_snapshot.file.path - FileUtils.mkdir_p(File.dirname(snapshot_file_path)) - File.open(snapshot_file_path, 'wb'){|f| f.write(snapshot_content)} - image = MiniMagick::Image.open(snapshot_file_path) - self.scale = (1.0 * image[:height] / image[:width] * 100).round(2) - else - puts "cannot read #{youtube_img_url}" - end - rescue => e - puts e.to_s - self.scale = nil - end - else - self.scale = nil - end + # if self.is_youtube + # begin + # youtube_img_url = "https:"+self.youtube_thumb + # self.remote_file_url = youtube_img_url + # uri = URI.parse(youtube_img_url) + # req = Net::HTTP::Get.new(uri.path) + # res = Net::HTTP.start( uri.host, uri.port, + # :use_ssl => (uri.scheme == 'https'), + # :verify_mode => OpenSSL::SSL::VERIFY_NONE) do |https| + # https.request(req) + # end + # snapshot_content = res.body rescue nil #Net::HTTP.get_response(URI.parse(youtube_img_url)).body rescue nil + # if snapshot_content + # self[:video_snapshot] = '0.jpg' + # snapshot_file_path = self.video_snapshot.file.path + # FileUtils.mkdir_p(File.dirname(snapshot_file_path)) + # File.open(snapshot_file_path, 'wb'){|f| f.write(snapshot_content)} + # image = MiniMagick::Image.open(snapshot_file_path) + # self.scale = (1.0 * image[:height] / image[:width] * 100).round(2) + # else + # puts "cannot read #{youtube_img_url}" + # end + # rescue => e + # puts e.to_s + # self.scale = nil + # end + # else + # self.scale = nil + # end else self.youtube_id = nil image = MiniMagick::Image.open(self.video_snapshot.file.path) rescue nil @@ -128,6 +129,13 @@ class VideoImage self.generate_video_snapshot end end + if self.is_youtube + Thread.new do + youtube_img_url = "https:"+self.youtube_thumb + self.remote_file_url = youtube_img_url + self.save! + end + end end end def inc_count diff --git a/app/views/admin/video_pros/_form.html.erb b/app/views/admin/video_pros/_form.html.erb index de4d8bd..e145306 100644 --- a/app/views/admin/video_pros/_form.html.erb +++ b/app/views/admin/video_pros/_form.html.erb @@ -61,8 +61,19 @@ -