lots of stuff

This commit is contained in:
Ruling-Mac 2015-10-21 19:50:21 +08:00
parent b6c831714a
commit 097b781a27
9 changed files with 90 additions and 32 deletions

View File

@ -1,25 +0,0 @@
class VideoChannelsController < ApplicationController
def index
end
def show
@video_channel = VideoChannel.find(params[:id])
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)
nextPageToken = result['nextPageToken']
videos = {}
while !nextPageToken.nil?
result['items'].each do item
video = item['snippet']
end
end
end
end

View File

@ -0,0 +1,79 @@
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 = []
video_channels.each do |video_channel|
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)
nextPageToken = result['nextPageToken'] rescue ""
while !nextPageToken.nil?
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'] ,
"channel_title" => result['items'].first['snippet']['channelTitle']
}
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
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'] ,
"channel_title" => result['items'].first['snippet']['channelTitle']
}
end
{
"video_channels" => vc ,
"extras" => {
"th_title" => t('title'),
"th_description" => t('video.description'),
"th_publish_date" => t('video.publish_date')
}
}
end
end

View File

@ -7,4 +7,5 @@ Publish Date: <%= @r['items'].first['snippet']['publishedAt'] %><br>
img1: <img src="<%= @r['items'].first['snippet']['thumbnails']['default']['url'] %>"><br>
img2: <img src="<%= @r['items'].first['snippet']['thumbnails']['medium']['url'] %>"><br>
img3: <img src="<%= @r['items'].first['snippet']['thumbnails']['high']['url'] %>"><br>
Channel Title: <%= @r['items'].first['snippet']['channelTitle'] %><br>
Channel Title: <%= @r['items'].first['snippet']['channelTitle'] %><br>
<%= @r['nextPageToken'] %>

View File

@ -1,3 +0,0 @@
aaaaaa
<%= render_view %>

View File

@ -0,0 +1 @@
<%= render_view %>

View File

@ -1,4 +1,8 @@
en:
video:
video: Video
show_lang: Language
show_lang: Language
owner: Owner
channel_link: Channel Link
description: Description
publish_date: Publish Date

View File

@ -4,4 +4,5 @@ zh_tw:
show_lang: 呈現語系
owner: 頻道擁有者
channel_link: 頻道連結
description: 描述
description: 描述
publish_date: 發布日期

View File

@ -6,6 +6,6 @@ Rails.application.routes.draw do
resources :video_channels #backend
end
resources :video_channels #frontend
# resources :video_channels #frontend
end
end