diff --git a/app/controllers/video_channels_controller.rb b/app/controllers/video_channels_controller.rb deleted file mode 100644 index 7c1c71b..0000000 --- a/app/controllers/video_channels_controller.rb +++ /dev/null @@ -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 \ No newline at end of file diff --git a/app/controllers/videos_controller.rb b/app/controllers/videos_controller.rb new file mode 100644 index 0000000..105e070 --- /dev/null +++ b/app/controllers/videos_controller.rb @@ -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 \ No newline at end of file diff --git a/app/views/admin/video_channels/show.html.erb b/app/views/admin/video_channels/show.html.erb index 5403bd9..7c13ab7 100644 --- a/app/views/admin/video_channels/show.html.erb +++ b/app/views/admin/video_channels/show.html.erb @@ -7,4 +7,5 @@ Publish Date: <%= @r['items'].first['snippet']['publishedAt'] %>
img1:
img2:
img3:
-Channel Title: <%= @r['items'].first['snippet']['channelTitle'] %>
\ No newline at end of file +Channel Title: <%= @r['items'].first['snippet']['channelTitle'] %>
+<%= @r['nextPageToken'] %> \ No newline at end of file diff --git a/app/views/video_channels/index.html.erb b/app/views/video_channels/index.html.erb deleted file mode 100644 index 9fa5b9c..0000000 --- a/app/views/video_channels/index.html.erb +++ /dev/null @@ -1,3 +0,0 @@ -aaaaaa - -<%= render_view %> \ No newline at end of file diff --git a/app/views/video_channels/show.html.erb b/app/views/videos/index.html.erb similarity index 100% rename from app/views/video_channels/show.html.erb rename to app/views/videos/index.html.erb diff --git a/app/views/videos/show.html.erb b/app/views/videos/show.html.erb new file mode 100644 index 0000000..648b75c --- /dev/null +++ b/app/views/videos/show.html.erb @@ -0,0 +1 @@ +<%= render_view %> \ No newline at end of file diff --git a/config/locales/en.yml b/config/locales/en.yml index 2f2893c..323cb9d 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -1,4 +1,8 @@ en: video: video: Video - show_lang: Language \ No newline at end of file + show_lang: Language + owner: Owner + channel_link: Channel Link + description: Description + publish_date: Publish Date \ No newline at end of file diff --git a/config/locales/zh_tw.yml b/config/locales/zh_tw.yml index a2e11c1..c2df2b8 100644 --- a/config/locales/zh_tw.yml +++ b/config/locales/zh_tw.yml @@ -4,4 +4,5 @@ zh_tw: show_lang: 呈現語系 owner: 頻道擁有者 channel_link: 頻道連結 - description: 描述 \ No newline at end of file + description: 描述 + publish_date: 發布日期 \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 96acead..90699fd 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -6,6 +6,6 @@ Rails.application.routes.draw do resources :video_channels #backend end - resources :video_channels #frontend + # resources :video_channels #frontend end end \ No newline at end of file