switch from youtube username to channel ID
updates legacy code that really needs to be gone
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
module UsersHelper
|
|
||||||
require "open-uri"
|
require "open-uri"
|
||||||
|
require "rexml/document"
|
||||||
|
|
||||||
|
module UsersHelper
|
||||||
def mentions(content)
|
def mentions(content)
|
||||||
users = []
|
users = []
|
||||||
words = content.scan(/@[a-zA-Z0-9_]{1,16}/)
|
words = content.scan(/@[a-zA-Z0-9_]{1,16}/)
|
||||||
@@ -11,15 +12,16 @@ require "open-uri"
|
|||||||
users.uniq
|
users.uniq
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_youtube(yt_name)
|
def get_youtube(yt_channel)
|
||||||
yt = {channel: yt_name}
|
yt = {channel: yt_channel}
|
||||||
if yt_name.blank?
|
if yt_channel.blank?
|
||||||
yt[:channel] = nil
|
yt[:channel] = nil
|
||||||
yt[:channel_name] = nil
|
yt[:channel_name] = nil
|
||||||
yt[:is_correct?] = true
|
yt[:is_correct?] = true
|
||||||
else
|
else
|
||||||
begin
|
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
|
yt[:is_correct?] = true
|
||||||
rescue
|
rescue
|
||||||
yt[:is_correct?] = false
|
yt[:is_correct?] = false
|
||||||
|
|||||||
@@ -53,9 +53,9 @@
|
|||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>YouTube username</td>
|
<td>YouTube Channel ID</td>
|
||||||
<td>
|
<td>
|
||||||
<%= f.text_field :youtube, placeholder: "YouTube username", disabled: !can_edit? %>
|
<%= f.text_field :youtube, placeholder: "YouTube Channel ID", disabled: !can_edit? %>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
|
|||||||
@@ -60,7 +60,7 @@
|
|||||||
<% if !@user.youtube.blank? && !@user.youtube_channelname.blank? %>
|
<% if !@user.youtube.blank? && !@user.youtube_channelname.blank? %>
|
||||||
<tr>
|
<tr>
|
||||||
<td><b>YouTube</b></td>
|
<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>
|
</tr>
|
||||||
<% end %>
|
<% end %>
|
||||||
<% if !@user.twitter.blank? %>
|
<% if !@user.twitter.blank? %>
|
||||||
|
|||||||
Reference in New Issue
Block a user