This commit is contained in:
BoHung Chiu 2021-10-25 11:03:51 +08:00
parent 64e26d9e2e
commit 04da5dfc7e
1 changed files with 7 additions and 3 deletions

View File

@ -73,9 +73,13 @@ class AdImage
def youtube_thumb
uri = URI.parse(self.youtube) rescue nil
if !uri.nil? && uri.host == "www.youtube.com"
params = CGI.parse(uri.query)
v = params['v'].first
return "http://img.youtube.com/vi/#{v}/0.jpg"
params = CGI.parse(uri.query) rescue {}
if params.has_key?('v')
v = params['v'].first
return "http://img.youtube.com/vi/#{v}/0.jpg"
else
return ""
end
else
return ""
end