From: Michael Orlitzky Date: Mon, 2 Mar 2009 00:14:09 +0000 (-0500) Subject: Updated the Youtube URL regex to allow any hostname.youtube.com pattern. X-Git-Url: https://gitweb.michael.orlitzky.com/?a=commitdiff_plain;h=4935683016a5378ca4cc67f12816178421c359cf;p=dead%2Fwhatever-dl.git Updated the Youtube URL regex to allow any hostname.youtube.com pattern. Added a test to ensure that uk.youtube.com URLs are handled properly. --- diff --git a/src/websites/youtube.rb b/src/websites/youtube.rb index 3388100..cbda4e2 100644 --- a/src/websites/youtube.rb +++ b/src/websites/youtube.rb @@ -26,7 +26,7 @@ require 'uri' class Youtube < Website - VALID_YOUTUBE_URL_REGEX = /^(http:\/\/)?(www\.)?(in\.)?youtube\.com\/((watch\?v=)|(v\/))[a-z0-9_\-]+(\&.*)?\#?$/i + VALID_YOUTUBE_URL_REGEX = /^(http:\/\/)?([a-z0-9]+\.)?youtube\.com\/((watch\?v=)|(v\/))[a-z0-9_\-]+(\&.*)?\#?$/i def self.owns_url?(url) return url =~ VALID_YOUTUBE_URL_REGEX diff --git a/test/youtube_test.rb b/test/youtube_test.rb index 507e43e..fa61cb2 100644 --- a/test/youtube_test.rb +++ b/test/youtube_test.rb @@ -34,6 +34,7 @@ class YoutubeTest < Test::Unit::TestCase assert(Youtube.owns_url?('http://www.youtube.com/watch?v=83-hlYMH1XE')) assert(Youtube.owns_url?('http://www.youtube.com/watch?v=83-hlYMH1XE&feature=dir')) assert(Youtube.owns_url?('http://in.youtube.com/watch?v=VcydqSpYN00&feature=channel_page')) + assert(Youtube.owns_url?('http://uk.youtube.com/watch?v=LN4Ov6ZLcrI')) end