summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjomo <github@jomo.tv>2016-03-09 00:45:10 +0100
committerjomo <github@jomo.tv>2016-03-09 00:45:10 +0100
commitff84cee5527a9ce23506f6f4cfdfb5b203c49e35 (patch)
tree98373448ba5d5e45cafe1e13612004cc09ba3c65
parent78ddfadb342b715fdd4430495c5ba07152ace597 (diff)
switch from youtube username to channel ID
updates legacy code that really needs to be gone
-rw-r--r--app/helpers/users_helper.rb12
-rw-r--r--app/views/users/edit.html.erb4
-rw-r--r--app/views/users/show.html.erb2
3 files changed, 10 insertions, 8 deletions
diff --git a/app/helpers/users_helper.rb b/app/helpers/users_helper.rb
index 93067e8..2ce1765 100644
--- a/app/helpers/users_helper.rb
+++ b/app/helpers/users_helper.rb
@@ -1,6 +1,7 @@
-module UsersHelper
require "open-uri"
+require "rexml/document"
+module UsersHelper
def mentions(content)
users = []
words = content.scan(/@[a-zA-Z0-9_]{1,16}/)
@@ -11,15 +12,16 @@ require "open-uri"
users.uniq
end
- def get_youtube(yt_name)
- yt = {channel: yt_name}
- if yt_name.blank?
+ def get_youtube(yt_channel)
+ yt = {channel: yt_channel}
+ if yt_channel.blank?
yt[:channel] = nil
yt[:channel_name] = nil
yt[:is_correct?] = true
else
begin
- yt[:channel_name] = JSON.parse(open("https://gdata.youtube.com/feeds/api/users/#{CGI.escape(yt_name)}?alt=json", :read_timeout => 1).read)["entry"]["title"]["$t"]
+ # TODO: This whole thing needs to be gone badly
+ yt[:channel_name] = REXML::Document.new(open("https://www.youtube.com/feeds/videos.xml?channel_id=#{CGI.escape(yt_channel)}", :read_timeout => 1)).root.elements.find{ |n| n.name == "title" }.text
yt[:is_correct?] = true
rescue
yt[:is_correct?] = false
diff --git a/app/views/users/edit.html.erb b/app/views/users/edit.html.erb
index f07ea62..6a6fe4d 100644
--- a/app/views/users/edit.html.erb
+++ b/app/views/users/edit.html.erb
@@ -53,9 +53,9 @@
</td>
</tr>
<tr>
- <td>YouTube username</td>
+ <td>YouTube Channel ID</td>
<td>
- <%= f.text_field :youtube, placeholder: "YouTube username", disabled: !can_edit? %>
+ <%= f.text_field :youtube, placeholder: "YouTube Channel ID", disabled: !can_edit? %>
</td>
</tr>
<tr>
diff --git a/app/views/users/show.html.erb b/app/views/users/show.html.erb
index 5be791d..4eafb2c 100644
--- a/app/views/users/show.html.erb
+++ b/app/views/users/show.html.erb
@@ -60,7 +60,7 @@
<% if !@user.youtube.blank? && !@user.youtube_channelname.blank? %>
<tr>
<td><b>YouTube</b></td>
- <td><%= link_to @user.youtube_channelname, "https://youtube.com/user/#{CGI.escape(@user.youtube)}", :target => "_blank" %></td>
+ <td><%= link_to @user.youtube_channelname, "https://youtube.com/channel/#{CGI.escape(@user.youtube)}", :target => "_blank" %></td>
</tr>
<% end %>
<% if !@user.twitter.blank? %>