I wrote a ruby youtube url url parser. It is designed to enter the URL input of one of the following structures (currently I can find the youtube URL structures, maybe there are more?):
http://youtu.be/sGE4HMvDe-Q http://www.youtube.com/watch?v=Lp7E973zozc&feature=relmfu http://www.youtube.com/p/A0C3C1D163BE880A?hl=en_US&
The goal is to save only the ID of the clip or playlist so that it can be embedded, so if it is a clip: 'sGE4HMvDe-Q' , or if it is a playlist: 'p/A0C3C1D163BE880A'
The parser I wrote works fine for these URLs, but it seems a bit fragile and lanky, I'm just wondering if anyone can suggest a more convenient ruby approach to this problem?
def parse_youtube a = url.split('//').last.split('/') b = a.last.split('watch?v=').last.split('?').first.split('&').first if a[1] == 'p' url = "p/#{b}" else url = b end end
url ruby ruby-on-rails
Paul nelligan
source share