Hopefully make youtube_titles a little less ridiculous
This commit is contained in:
parent
d0ff24fef7
commit
983d4e5598
2 changed files with 5 additions and 3 deletions
|
|
@ -21,7 +21,6 @@ class StatusMessage < Post
|
||||||
validate :message_or_photos_present?
|
validate :message_or_photos_present?
|
||||||
|
|
||||||
attr_accessible :text
|
attr_accessible :text
|
||||||
|
|
||||||
serialize :youtube_titles, Hash
|
serialize :youtube_titles, Hash
|
||||||
|
|
||||||
after_create :create_mentions
|
after_create :create_mentions
|
||||||
|
|
|
||||||
|
|
@ -19,13 +19,16 @@ module YoutubeTitles
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_youtube_title text
|
def get_youtube_title text
|
||||||
|
self.youtube_titles = {}
|
||||||
youtube_match = text.enum_for(:scan, YOUTUBE_ID_REGEX).map { Regexp.last_match }
|
youtube_match = text.enum_for(:scan, YOUTUBE_ID_REGEX).map { Regexp.last_match }
|
||||||
return if youtube_match.empty?
|
return if youtube_match.empty?
|
||||||
|
|
||||||
self.youtube_titles ||= {}
|
matches = {}
|
||||||
youtube_match.each do |match_data|
|
youtube_match.each do |match_data|
|
||||||
self.youtube_titles[match_data[1]] = CGI::escape(youtube_title_for(match_data[1]))
|
matches[match_data[1]] = CGI::escape(youtube_title_for(match_data[1]))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
self.youtube_titles = matches unless matches.empty?
|
||||||
end
|
end
|
||||||
|
|
||||||
YOUTUBE_ID_REGEX = /(?:https?:\/\/)(?:youtu\.be\/|(?:[a-z]{2,3}\.)?youtube\.com\/watch(?:\?|#!|.+&|.+&)v=)([\w-]{11})(?:\S*(#[^ ]+)|\S+)?/im unless defined? YOUTUBE_ID_REGEX
|
YOUTUBE_ID_REGEX = /(?:https?:\/\/)(?:youtu\.be\/|(?:[a-z]{2,3}\.)?youtube\.com\/watch(?:\?|#!|.+&|.+&)v=)([\w-]{11})(?:\S*(#[^ ]+)|\S+)?/im unless defined? YOUTUBE_ID_REGEX
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue