thumbnail fixes and tags

This commit is contained in:
rulingcom 2025-04-16 21:47:01 +08:00
parent 8940c3c63a
commit 43acff783e
3 changed files with 53 additions and 44 deletions

View File

@ -200,7 +200,7 @@ class VideoProsController < ApplicationController
} }
} }
else 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 || {} custom_data_field = subpart.custom_data_field || {}
@video_pro_setting = VideoProSetting.first @video_pro_setting = VideoProSetting.first
videos = get_videos(video_images, OrbitHelper.widget_item_url(''), custom_data_field) videos = get_videos(video_images, OrbitHelper.widget_item_url(''), custom_data_field)

View File

@ -72,34 +72,35 @@ class VideoImage
self.youtube_id = v self.youtube_id = v
end end
end end
if self.is_youtube # if self.is_youtube
begin # begin
youtube_img_url = "https:"+self.youtube_thumb # youtube_img_url = "https:"+self.youtube_thumb
uri = URI.parse(youtube_img_url) # self.remote_file_url = youtube_img_url
req = Net::HTTP::Get.new(uri.path) # uri = URI.parse(youtube_img_url)
res = Net::HTTP.start( uri.host, uri.port, # req = Net::HTTP::Get.new(uri.path)
:use_ssl => (uri.scheme == 'https'), # res = Net::HTTP.start( uri.host, uri.port,
:verify_mode => OpenSSL::SSL::VERIFY_NONE) do |https| # :use_ssl => (uri.scheme == 'https'),
https.request(req) # :verify_mode => OpenSSL::SSL::VERIFY_NONE) do |https|
end # https.request(req)
snapshot_content = res.body rescue nil #Net::HTTP.get_response(URI.parse(youtube_img_url)).body rescue nil # end
if snapshot_content # snapshot_content = res.body rescue nil #Net::HTTP.get_response(URI.parse(youtube_img_url)).body rescue nil
self[:video_snapshot] = '0.jpg' # if snapshot_content
snapshot_file_path = self.video_snapshot.file.path # self[:video_snapshot] = '0.jpg'
FileUtils.mkdir_p(File.dirname(snapshot_file_path)) # snapshot_file_path = self.video_snapshot.file.path
File.open(snapshot_file_path, 'wb'){|f| f.write(snapshot_content)} # FileUtils.mkdir_p(File.dirname(snapshot_file_path))
image = MiniMagick::Image.open(snapshot_file_path) # File.open(snapshot_file_path, 'wb'){|f| f.write(snapshot_content)}
self.scale = (1.0 * image[:height] / image[:width] * 100).round(2) # image = MiniMagick::Image.open(snapshot_file_path)
else # self.scale = (1.0 * image[:height] / image[:width] * 100).round(2)
puts "cannot read #{youtube_img_url}" # else
end # puts "cannot read #{youtube_img_url}"
rescue => e # end
puts e.to_s # rescue => e
self.scale = nil # puts e.to_s
end # self.scale = nil
else # end
self.scale = nil # else
end # self.scale = nil
# end
else else
self.youtube_id = nil self.youtube_id = nil
image = MiniMagick::Image.open(self.video_snapshot.file.path) rescue nil image = MiniMagick::Image.open(self.video_snapshot.file.path) rescue nil
@ -128,6 +129,13 @@ class VideoImage
self.generate_video_snapshot self.generate_video_snapshot
end end
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
end end
def inc_count def inc_count

View File

@ -61,7 +61,18 @@
</div> </div>
</div> </div>
<div id="exchange_item_3" style="display:none"> <div id="exchange_item_3" style="display:none;">
</div>
<div id="exchange_item_1" style="display:none">
<div class="control-group input-title">
<label class="control-label muted"><%= t("video_pro.youtube") %></label>
<div class="controls">
<div><%= 'ex. https://www.youtube.com/watch?v=UHF2e3lyPVU' %></div>
<%= f.text_field :youtube, placeholder: t("video_pro.youtube"), class: 'input-block-level' %>
</div>
</div>
<!-- Images Upload --> <!-- Images Upload -->
<div class="control-group"> <div class="control-group">
<label class="control-label muted"><%= t(:image) %></label> <label class="control-label muted"><%= t(:image) %></label>
@ -71,7 +82,7 @@
<% if @video_image.file.file %> <% if @video_image.file.file %>
<%= image_tag @video_image.file.url %> <%= image_tag @video_image.file.url %>
<% else %> <% else %>
<img src="https://via.placeholder.com/200x80/EFEFEF/AAAAAA" /> <img src="https://placehold.co/200X200" />
<% end %> <% end %>
</div> </div>
<div class="fileupload-preview fileupload-exists thumbnail pull-left"></div> <div class="fileupload-preview fileupload-exists thumbnail pull-left"></div>
@ -91,16 +102,6 @@
</div> </div>
</div> </div>
<div id="exchange_item_1" style="display:none">
<div class="control-group input-title">
<label class="control-label muted"><%= t("video_pro.youtube") %></label>
<div class="controls">
<div><%= 'ex. https://www.youtube.com/watch?v=UHF2e3lyPVU' %></div>
<%= f.text_field :youtube, placeholder: t("video_pro.youtube"), class: 'input-block-level' %>
</div>
</div>
</div>
<div id="exchange_item_2" style="display:none"> <div id="exchange_item_2" style="display:none">
<!-- Video Upload --> <!-- Video Upload -->
<div class="control-group"> <div class="control-group">
@ -133,7 +134,7 @@
<% if @video_image.video_snapshot.file %> <% if @video_image.video_snapshot.file %>
<%= image_tag @video_image.video_snapshot.url %> <%= image_tag @video_image.video_snapshot.url %>
<% else %> <% else %>
<img src="https://via.placeholder.com/200x80/EFEFEF/AAAAAA" /> <img src="https://placehold.co/200X200" />
<% end %> <% end %>
</div> </div>
<div class="fileupload-preview fileupload-exists thumbnail pull-left"></div> <div class="fileupload-preview fileupload-exists thumbnail pull-left"></div>