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')
|
||||
result = Net::HTTP.get(uri) # => String
|
||||
result = JSON.parse(result)
|
||||
|
||||
vc = []
|
||||
|
||||
nextPageToken = result['nextPageToken'] rescue ""
|
||||
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?
|
||||
url = (result['items'].first["id"]["videoId"].present? ? "https://www.youtube.com/embed/#{result['items'].first["id"]["videoId"]}" : "#") rescue "#"
|
||||
vc << {
|
||||
"title" => result['items'].first['snippet']['title'],
|
||||
"description" => result['items'].first['snippet']['description'] ,
|
||||
"publish_date" => result['items'].first['snippet']['publishedAt'],
|
||||
"img1_src" => result['items'].first['snippet']['thumbnails']['default']['url'],
|
||||
"img2_src" => result['items'].first['snippet']['thumbnails']['medium']['url'],
|
||||
"img3_src" => result['items'].first['snippet']['thumbnails']['high']['url'] ,
|
||||
"title" => (result['items'].first['snippet']['title'] rescue ""),
|
||||
"description" => (result['items'].first['snippet']['description'] rescue ""),
|
||||
"publish_date" => (result['items'].first['snippet']['publishedAt'] rescue ""),
|
||||
"img1_src" => (result['items'].first['snippet']['thumbnails']['default']['url'] rescue ""),
|
||||
"img2_src" => (result['items'].first['snippet']['thumbnails']['medium']['url'] rescue ""),
|
||||
"img3_src" => (result['items'].first['snippet']['thumbnails']['high']['url'] rescue ""),
|
||||
"video_url" => url,
|
||||
"channel_title" => result['items'].first['snippet']['channelTitle']
|
||||
"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)
|
||||
result = Net::HTTP.get(uri) # => String
|
||||
result = JSON.parse(result)
|
||||
nextPageToken = result['nextPageToken'] rescue ""
|
||||
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 << {
|
||||
"title" => result['items'].first['snippet']['title'],
|
||||
"description" => result['items'].first['snippet']['description'] ,
|
||||
"publish_date" => result['items'].first['snippet']['publishedAt'],
|
||||
"img1_src" => result['items'].first['snippet']['thumbnails']['default']['url'],
|
||||
"img2_src" => result['items'].first['snippet']['thumbnails']['medium']['url'],
|
||||
"img3_src" => result['items'].first['snippet']['thumbnails']['high']['url'] ,
|
||||
"title" => (result['items'].first['snippet']['title'] rescue ""),
|
||||
"description" => (result['items'].first['snippet']['description'] rescue ""),
|
||||
"publish_date" => (result['items'].first['snippet']['publishedAt'] rescue ""),
|
||||
"img1_src" => (result['items'].first['snippet']['thumbnails']['default']['url'] rescue ""),
|
||||
"img2_src" => (result['items'].first['snippet']['thumbnails']['medium']['url'] rescue ""),
|
||||
"img3_src" => (result['items'].first['snippet']['thumbnails']['high']['url'] rescue ""),
|
||||
"video_url" => url,
|
||||
"channel_title" => result['items'].first['snippet']['channelTitle']
|
||||
"channel_title" => (result['items'].first['snippet']['channelTitle'] rescue "")
|
||||
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue