2015-10-21 11:50:21 +00:00
|
|
|
class VideosController < ApplicationController
|
|
|
|
def index
|
|
|
|
video_channels = VideoChannel.all
|
|
|
|
|
|
|
|
vcs = video_channels.collect do |vc|
|
|
|
|
{
|
|
|
|
"link_to_show" => OrbitHelper.url_to_show(vc.to_param),
|
|
|
|
"title" => vc.title,
|
|
|
|
"owner" => vc.owner,
|
|
|
|
"channel_link" => vc.channel_link,
|
|
|
|
"description" => vc.description
|
|
|
|
}
|
|
|
|
end
|
|
|
|
{
|
|
|
|
"video_channels" => vcs,
|
|
|
|
"extras" => {
|
|
|
|
"th_title" => t('title'),
|
|
|
|
"th_owner" => t('video.owner'),
|
|
|
|
"th_description" => t('video.description')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
def show
|
|
|
|
params = OrbitHelper.params
|
|
|
|
video_channel = VideoChannel.find_by_param(params[:uid])
|
|
|
|
|
|
|
|
page = Page.where(:page_id => params[:page_id]).first rescue nil
|
|
|
|
url = page.nil? ? "#" : "/#{I18n.locale.to_s}#{page.url}"
|
|
|
|
channel_id = video_channel.channel_link.split("/")[-1]
|
|
|
|
|
|
|
|
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 = []
|
2015-10-21 13:02:28 +00:00
|
|
|
|
|
|
|
nextPageToken = result['nextPageToken'] rescue ""
|
|
|
|
while !nextPageToken.nil?
|
|
|
|
url = result['items'].first["id"]["videoId"].present? ? "https://www.youtube.com/embed/#{result['items'].first["id"]["videoId"]}" : "#"
|
2015-10-21 11:50:21 +00:00
|
|
|
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'] ,
|
2015-10-21 13:02:28 +00:00
|
|
|
"video_url" => url,
|
2015-10-21 11:50:21 +00:00
|
|
|
"channel_title" => result['items'].first['snippet']['channelTitle']
|
|
|
|
}
|
2015-10-21 13:02:28 +00:00
|
|
|
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 ""
|
2015-10-21 11:50:21 +00:00
|
|
|
end
|
2015-10-21 13:02:28 +00:00
|
|
|
url = result['items'].first["id"]["videoId"].present? ? "https://www.youtube.com/embed/#{result['items'].first["id"]["videoId"]}" : "#"
|
|
|
|
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'] ,
|
|
|
|
"video_url" => url,
|
|
|
|
"channel_title" => result['items'].first['snippet']['channelTitle']
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-10-21 11:50:21 +00:00
|
|
|
{
|
|
|
|
"video_channels" => vc ,
|
|
|
|
"extras" => {
|
|
|
|
"th_title" => t('title'),
|
|
|
|
"th_description" => t('video.description'),
|
|
|
|
"th_publish_date" => t('video.publish_date')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|