change youtube thumb source url to https.

This commit is contained in:
BoHung Chiu 2023-04-10 17:22:44 +08:00
parent 16b573bf1e
commit 9e9f2959bc
1 changed files with 9 additions and 2 deletions

View File

@ -71,8 +71,15 @@ class VideoImage
end end
if self.is_youtube if self.is_youtube
begin begin
youtube_img_url = "http:"+self.youtube_thumb youtube_img_url = "https:"+self.youtube_thumb
snapshot_content = Net::HTTP.get_response(URI.parse(youtube_img_url)).body rescue nil 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 if snapshot_content
self[:video_snapshot] = '0.jpg' self[:video_snapshot] = '0.jpg'
snapshot_file_path = self.video_snapshot.file.path snapshot_file_path = self.video_snapshot.file.path