Created
August 9, 2010 10:36
-
-
Save gunderwonder/515267 to your computer and use it in GitHub Desktop.
Normalize Youtube/Video videos to SWF paths
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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]}" . | |
"&server=vimeo.com&show_title=1&show_byline=1" . | |
"&show_portrait=0&color=&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&server=vimeo.com&show_title=1&show_byline=1&show_portrait=0&color=&fullscreen=1'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment