X-Git-Url: http://gitweb.michael.orlitzky.com/?p=dead%2Fwhatever-dl.git;a=blobdiff_plain;f=src%2Fwebsites%2Fyoutube.rb;h=b9d9aa6c5e7ec586bb69b4d851428d975a006156;hp=0d9bf398338538a3dfd8e128e851a98680ca46ae;hb=83e06f83d8274cb32a406739839d56e759664b09;hpb=2c835ed7a247ed5639277bc9674b848722ad998d diff --git a/src/websites/youtube.rb b/src/websites/youtube.rb index 0d9bf39..b9d9aa6 100644 --- a/src/websites/youtube.rb +++ b/src/websites/youtube.rb @@ -26,15 +26,15 @@ require 'uri' class Youtube < Website - VALID_YOUTUBE_URL_REGEX = /^(http:\/\/)?(www\.)?youtube\.com\/((watch\?v=)|(v\/))[[:alnum:]]+(\&.*)?\#?$/ + VALID_YOUTUBE_URL_REGEX = /^(http:\/\/)?(www\.)?youtube\.com\/((watch\?v=)|(v\/))[a-z0-9_\-]+(\&.*)?\#?$/i def self.owns_url?(url) return url =~ VALID_YOUTUBE_URL_REGEX end - def get_video_url(url) - video_id = self.parse_video_id(url) + def get_video_url() + video_id = self.parse_video_id() # The video's URL (the "page data" URL) may be different from the # URL that was passed to the program. We support the /v/video_id @@ -52,12 +52,17 @@ class Youtube < Website return video_url end + + def get_video_filename() + return (self.parse_video_id() + '.flv') + end + protected; # Get the video id from the URL. Should be relatively easy, # unless Youtube supports some URL formats of which I'm unaware. - def parse_video_id(url) + def parse_video_id() # Return nil if we get no matches below. video_id = nil @@ -65,14 +70,14 @@ class Youtube < Website # them one at a time. The only tricky situation is when # parameters like "&hl=en" are tacked on to the end. # We'll call /watch?v=video_id the "first form." - first_form_video_id_regex = /v=([[:alnum:]]+)$/ - first_form_matches = first_form_video_id_regex.match(url) + first_form_video_id_regex = /v=([0-9a-z_\-]+)/i + first_form_matches = first_form_video_id_regex.match(@url) return first_form_matches[1] if not (first_form_matches.nil? || first_form_matches.length < 2) # First form didn't work? Try the second. - second_form_video_id_regex = /\/v\/([[:alnum:]]+)/ - second_form_matches = second_form_video_id_regex.match(url) + second_form_video_id_regex = /\/v\/([0-9a-z_\-]+)/i + second_form_matches = second_form_video_id_regex.match(@url) video_id = second_form_matches[1] if not (second_form_matches.nil? || second_form_matches.length < 2)