Skip to content

Instantly share code, notes, and snippets.

@gunderwonder
Created August 9, 2010 10:36
Show Gist options
  • Save gunderwonder/515267 to your computer and use it in GitHub Desktop.
Save gunderwonder/515267 to your computer and use it in GitHub Desktop.
Normalize Youtube/Video videos to SWF paths
<?php
function normalize_flash_video_url($url) {
$url = trim($url);
if (preg_match('{(^http://www\.)?youtube\.com}', $url)) {
if (preg_match('{watch\?v=([^&]+)}', $url, $matches)) {
if (isset($matches[1]))
return "http://www.youtube.com/v/{$matches[1]}";
} else if (preg_match('{/v/(\w+)}', $url, $matches))
return "http://www.youtube.com/v/{$matches[1]}";
} else if (preg_match('{(^http://www\.)?vimeo\.com/(\d+)}', $url, $matches)) {
if (isset($matches[2]))
return "http://vimeo.com/moogaloop.swf?clip_id={$matches[2]}" .
"&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1" .
"&amp;show_portrait=0&amp;color=&amp;fullscreen=1";
}
return false;
}
if ($_SERVER['PHP_SELF'] == __FILE__) {
assert(normalize_flash_video_url('http://www.youtube.com/v/Dq366VCmS2c') == 'http://www.youtube.com/v/Dq366VCmS2c');
assert(normalize_flash_video_url('http://www.youtube.com/watch?v=q6iAuPmFkuY&playnext=1&videos=6DSLYG1s0bY&feature=grec_index') == 'http://www.youtube.com/v/q6iAuPmFkuY');
assert(normalize_flash_video_url('http://vimeo.com/13354354') === 'http://vimeo.com/moogaloop.swf?clip_id=13354354&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=&amp;fullscreen=1');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment