Created
September 17, 2013 22:21
-
-
Save mediamichael/6601484 to your computer and use it in GitHub Desktop.
Confirm if string is a YouTube URL, strip the youtube ID, and convert the url to a specific format and security.
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
var youTubeID; | |
var videoURL = "http://youtube.com/v/youtubeid" | |
if ( isYoutubeFile( videoURL ) == true ) { | |
//do something | |
} | |
function isYoutubeFile(vidURL) { | |
//console.log( "javascript: isYoutubeFile: vidURL: " +vidURL ); | |
var videoURL; | |
if ( vidURL.toLowerCase().indexOf( "http://www.youtube.com/v/" ) == 0 ) { | |
youTubeID = vidURL.substr( 25, 11 ); | |
if ( "https:" == document.location.protocol ) { | |
videoURL = "https://www.youtube.com/v/" + youTubeID; | |
} else { | |
videoURL = "http://www.youtube.com/v/" + youTubeID; | |
} | |
return true; | |
} | |
if ( vidURL.toLowerCase().indexOf( "http://www.youtube.com/watch?v=" ) == 0 ) { | |
youTubeID = vidURL.substr( 31, 11 ); | |
if ( "https:" == document.location.protocol ) { | |
videoURL = "https://www.youtube.com/v/" + youTubeID; | |
} else { | |
videoURL = "http://www.youtube.com/v/" + youTubeID; | |
} | |
return true; | |
} | |
if ( vidURL.toLowerCase().indexOf( "https://www.youtube.com/v/" ) == 0 ) { | |
youTubeID = vidURL.substr( 26, 11 ); | |
if ( "https:" == document.location.protocol ) { | |
videoURL = "https://www.youtube.com/v/" + youTubeID; | |
} else { | |
videoURL = "http://www.youtube.com/v/" + youTubeID; | |
} | |
return true; | |
} | |
if ( vidURL.toLowerCase().indexOf( "https://www.youtube.com/watch?v=" ) == 0 ) { | |
youTubeID = vidURL.substr(32, 11); | |
if ( "https:" == document.location.protocol ) { | |
videoURL = "https://www.youtube.com/v/" + youTubeID; | |
} else { | |
videoURL = "http://www.youtube.com/v/" + youTubeID; | |
} | |
return true; | |
} | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment