changed the logic of whole show page and module
This commit is contained in:
parent
83dbbc35a8
commit
c33b215704
|
@ -26,50 +26,48 @@ class VideosController < ApplicationController
|
||||||
video_channel = VideoChannel.find_by_param(params[:uid])
|
video_channel = VideoChannel.find_by_param(params[:uid])
|
||||||
|
|
||||||
page = Page.where(:page_id => params[:page_id]).first rescue nil
|
page = Page.where(:page_id => params[:page_id]).first rescue nil
|
||||||
url = page.nil? ? "#" : "/#{I18n.locale.to_s}#{page.url}"
|
page_url = page.nil? ? "#" : "/#{I18n.locale.to_s}#{page.url}"
|
||||||
channel_id = video_channel.channel_link.split("/")[-1]
|
channel_id = video_channel.channel_link.split("/")[-1]
|
||||||
|
|
||||||
uri = URI('https://www.googleapis.com/youtube/v3/search?part=snippet&channelId=' + channel_id + '&key=AIzaSyCTFdyLgb7GJfrr1JOI3gvVslZFw7td2zQ')
|
uri = URI("https://www.googleapis.com/youtube/v3/channels?id=#{channel_id}&key=AIzaSyCTFdyLgb7GJfrr1JOI3gvVslZFw7td2zQ&part=contentDetails")
|
||||||
result = Net::HTTP.get(uri) # => String
|
result = Net::HTTP.get(uri) # => String
|
||||||
result = JSON.parse(result)
|
result = JSON.parse(result)
|
||||||
vc = []
|
vc = []
|
||||||
|
if result["pageInfo"]["totalResults"] > 0
|
||||||
nextPageToken = result['nextPageToken'] rescue ""
|
if params["nppid"].present?
|
||||||
while !nextPageToken.nil?
|
u = "https://www.googleapis.com/youtube/v3/playlistItems?playlistId=#{result["items"].first["contentDetails"]["relatedPlaylists"]["uploads"]}&key=AIzaSyCTFdyLgb7GJfrr1JOI3gvVslZFw7td2zQ&part=snippet&maxResults=#{OrbitHelper.page_data_count}&pageToken=#{params["nppid"]}"
|
||||||
if !result.nil? && !result['items'].nil?
|
else
|
||||||
url = (result['items'].first["id"]["videoId"].present? ? "https://www.youtube.com/embed/#{result['items'].first["id"]["videoId"]}" : "#") rescue "#"
|
u = "https://www.googleapis.com/youtube/v3/playlistItems?playlistId=#{result["items"].first["contentDetails"]["relatedPlaylists"]["uploads"]}&key=AIzaSyCTFdyLgb7GJfrr1JOI3gvVslZFw7td2zQ&part=snippet&maxResults=#{OrbitHelper.page_data_count}"
|
||||||
vc << {
|
end
|
||||||
"title" => (result['items'].first['snippet']['title'] rescue ""),
|
url = URI(u)
|
||||||
"description" => (result['items'].first['snippet']['description'] rescue ""),
|
channel = Net::HTTP.get(url) # => String
|
||||||
"publish_date" => (result['items'].first['snippet']['publishedAt'] rescue ""),
|
channel = JSON.parse(channel)
|
||||||
"img1_src" => (result['items'].first['snippet']['thumbnails']['default']['url'] rescue ""),
|
if !channel["items"].blank?
|
||||||
"img2_src" => (result['items'].first['snippet']['thumbnails']['medium']['url'] rescue ""),
|
next_page_id = channel["nextPageToken"]
|
||||||
"img3_src" => (result['items'].first['snippet']['thumbnails']['high']['url'] rescue ""),
|
prev_page_id = channel["prevPageToken"]
|
||||||
"video_url" => url,
|
channel["items"].each do |item|
|
||||||
"channel_title" => (result['items'].first['snippet']['channelTitle'] rescue "")
|
video = item["snippet"]
|
||||||
}
|
if video["resourceId"].present? && video["resourceId"]["kind"] == "youtube#video"
|
||||||
|
videoid = (video["resourceId"]["videoId"].present? ? video["resourceId"]["videoId"] : "#") rescue "#"
|
||||||
|
vc << {
|
||||||
|
"title" => (item['snippet']['title'] rescue ""),
|
||||||
|
"description" => (video["description"] rescue ""),
|
||||||
|
"publish_date" => (DateTime.parse(video["publishedAt"]).strftime("%Y-%m-%d %H:%M") rescue ""),
|
||||||
|
"img1_src" => (video["thumbnails"]["default"]["url"] rescue ""),
|
||||||
|
"img2_src" => (video["thumbnails"]["medium"]["url"] rescue ""),
|
||||||
|
"img3_src" => (video["thumbnails"]["standard"]["url"] rescue ""),
|
||||||
|
# "video_url" => page_url + "?method=showvideo&id=#{videoid}"
|
||||||
|
"video_url" => "https://www.youtube.com/embed/#{videoid}"
|
||||||
|
}
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
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
|
end
|
||||||
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'] 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'] rescue "")
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
{
|
||||||
"video_channels" => vc ,
|
"video_channels" => vc ,
|
||||||
"extras" => {
|
"extras" => {
|
||||||
|
"next_page_id" => next_page_id,
|
||||||
|
"prev_page_id" => prev_page_id,
|
||||||
"th_title" => t('title'),
|
"th_title" => t('title'),
|
||||||
"th_description" => t('video.description'),
|
"th_description" => t('video.description'),
|
||||||
"th_publish_date" => t('video.publish_date')
|
"th_publish_date" => t('video.publish_date')
|
||||||
|
|
Loading…
Reference in New Issue