small fix for something
This commit is contained in:
parent
f458387d19
commit
83dbbc35a8
|
@ -32,37 +32,38 @@ class VideosController < ApplicationController
|
||||||
uri = URI('https://www.googleapis.com/youtube/v3/search?part=snippet&channelId=' + channel_id + '&key=AIzaSyCTFdyLgb7GJfrr1JOI3gvVslZFw7td2zQ')
|
uri = URI('https://www.googleapis.com/youtube/v3/search?part=snippet&channelId=' + channel_id + '&key=AIzaSyCTFdyLgb7GJfrr1JOI3gvVslZFw7td2zQ')
|
||||||
result = Net::HTTP.get(uri) # => String
|
result = Net::HTTP.get(uri) # => String
|
||||||
result = JSON.parse(result)
|
result = JSON.parse(result)
|
||||||
|
|
||||||
vc = []
|
vc = []
|
||||||
|
|
||||||
nextPageToken = result['nextPageToken'] rescue ""
|
nextPageToken = result['nextPageToken'] rescue ""
|
||||||
while !nextPageToken.nil?
|
while !nextPageToken.nil?
|
||||||
url = result['items'].first["id"]["videoId"].present? ? "https://www.youtube.com/embed/#{result['items'].first["id"]["videoId"]}" : "#"
|
if !result.nil? && !result['items'].nil?
|
||||||
vc << {
|
url = (result['items'].first["id"]["videoId"].present? ? "https://www.youtube.com/embed/#{result['items'].first["id"]["videoId"]}" : "#") rescue "#"
|
||||||
"title" => result['items'].first['snippet']['title'],
|
vc << {
|
||||||
"description" => result['items'].first['snippet']['description'] ,
|
"title" => (result['items'].first['snippet']['title'] rescue ""),
|
||||||
"publish_date" => result['items'].first['snippet']['publishedAt'],
|
"description" => (result['items'].first['snippet']['description'] rescue ""),
|
||||||
"img1_src" => result['items'].first['snippet']['thumbnails']['default']['url'],
|
"publish_date" => (result['items'].first['snippet']['publishedAt'] rescue ""),
|
||||||
"img2_src" => result['items'].first['snippet']['thumbnails']['medium']['url'],
|
"img1_src" => (result['items'].first['snippet']['thumbnails']['default']['url'] rescue ""),
|
||||||
"img3_src" => result['items'].first['snippet']['thumbnails']['high']['url'] ,
|
"img2_src" => (result['items'].first['snippet']['thumbnails']['medium']['url'] rescue ""),
|
||||||
"video_url" => url,
|
"img3_src" => (result['items'].first['snippet']['thumbnails']['high']['url'] rescue ""),
|
||||||
"channel_title" => result['items'].first['snippet']['channelTitle']
|
"video_url" => url,
|
||||||
}
|
"channel_title" => (result['items'].first['snippet']['channelTitle'] rescue "")
|
||||||
|
}
|
||||||
|
end
|
||||||
uri = URI('https://www.googleapis.com/youtube/v3/search?part=snippet&channelId=' + channel_id + '&key=AIzaSyCTFdyLgb7GJfrr1JOI3gvVslZFw7td2zQ&pageToken=' + nextPageToken)
|
uri = URI('https://www.googleapis.com/youtube/v3/search?part=snippet&channelId=' + channel_id + '&key=AIzaSyCTFdyLgb7GJfrr1JOI3gvVslZFw7td2zQ&pageToken=' + nextPageToken)
|
||||||
result = Net::HTTP.get(uri) # => String
|
result = Net::HTTP.get(uri) # => String
|
||||||
result = JSON.parse(result)
|
result = JSON.parse(result)
|
||||||
nextPageToken = result['nextPageToken'] rescue ""
|
nextPageToken = result['nextPageToken'] rescue ""
|
||||||
end
|
end
|
||||||
url = result['items'].first["id"]["videoId"].present? ? "https://www.youtube.com/embed/#{result['items'].first["id"]["videoId"]}" : "#"
|
url = (result['items'].first["id"]["videoId"].present? ? "https://www.youtube.com/embed/#{result['items'].first["id"]["videoId"]}" : "#") rescue "#"
|
||||||
vc << {
|
vc << {
|
||||||
"title" => result['items'].first['snippet']['title'],
|
"title" => (result['items'].first['snippet']['title'] rescue ""),
|
||||||
"description" => result['items'].first['snippet']['description'] ,
|
"description" => (result['items'].first['snippet']['description'] rescue ""),
|
||||||
"publish_date" => result['items'].first['snippet']['publishedAt'],
|
"publish_date" => (result['items'].first['snippet']['publishedAt'] rescue ""),
|
||||||
"img1_src" => result['items'].first['snippet']['thumbnails']['default']['url'],
|
"img1_src" => (result['items'].first['snippet']['thumbnails']['default']['url'] rescue ""),
|
||||||
"img2_src" => result['items'].first['snippet']['thumbnails']['medium']['url'],
|
"img2_src" => (result['items'].first['snippet']['thumbnails']['medium']['url'] rescue ""),
|
||||||
"img3_src" => result['items'].first['snippet']['thumbnails']['high']['url'] ,
|
"img3_src" => (result['items'].first['snippet']['thumbnails']['high']['url'] rescue ""),
|
||||||
"video_url" => url,
|
"video_url" => url,
|
||||||
"channel_title" => result['items'].first['snippet']['channelTitle']
|
"channel_title" => (result['items'].first['snippet']['channelTitle'] rescue "")
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue