#1019 YoutubeTitles::YOUTUBE_ID_REGEX supports data-anchor

This commit is contained in:
Arzumy MD 2011-05-04 23:54:25 +08:00
parent cdf94a0275
commit 5da6305b10
2 changed files with 5 additions and 6 deletions

View file

@ -212,11 +212,10 @@ module ApplicationHelper
end
def process_youtube(message, youtube_maps)
regex = /( |^)(https?:\/\/)?www\.youtube\.com\/watch[^ ]*v=([A-Za-z0-9_\-]+)(&[^ ]*)?(#[^ ]+)?/
processed_message = message.gsub(regex) do |matched_string|
match_data = matched_string.match(regex)
video_id = match_data[3]
anchor = match_data[5]
processed_message = message.gsub(YoutubeTitles::YOUTUBE_ID_REGEX) do |matched_string|
match_data = matched_string.match(YoutubeTitles::YOUTUBE_ID_REGEX)
video_id = match_data[1]
anchor = match_data[2]
anchor ||= ''
if youtube_maps && youtube_maps[video_id]
title = h(CGI::unescape(youtube_maps[video_id]))

View file

@ -20,5 +20,5 @@ module YoutubeTitles
end
end
YOUTUBE_ID_REGEX = /(?:youtu\.be\/|(?:[a-z]{2,3}\.)?youtube\.com\/watch(?:\?|#!|.+&|.+&)v=)([\w-]{11})/im unless defined? YOUTUBE_ID_REGEX
YOUTUBE_ID_REGEX = /(?:youtu\.be\/|(?:[a-z]{2,3}\.)?youtube\.com\/watch(?:\?|#!|.+&|.+&)v=)([\w-]{11})(?:\S*(#[^ ]+))?/im unless defined? YOUTUBE_ID_REGEX
end