Last active
October 16, 2020 10:14
-
-
Save oshikryu/5491584 to your computer and use it in GitHub Desktop.
youtube parsing
This file contains hidden or 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
function getYoutubeKey(linkText) { | |
// var linkText = $('#modal #vidEmbedKey').val(); | |
var reYoutubeKey = /^[a-zA-Z0-9\-]{11}$/; | |
if (reYoutubeKey.test(linkText)) { | |
return linkText; | |
} | |
var reYoutubeUrl = /http\:\/\/www\.youtube\.com\/watch\?v=([\w-]{11})/; | |
var httpsreYoutubeUrl = /https\:\/\/www\.youtube\.com\/watch\?v=([\w-]{11})/; | |
// made for shortened youtube share link | |
var shortreYoutubeUrl = /http\:\/\/youtu\.be\/([\w-]{11})/; | |
var httpsshortreYoutubeUrl = /https\:\/\/youtu\.be\/([\w-]{11})/; | |
// featured youtube | |
var featuredYoutubeUrl = /http\:\/\/www\.youtube\.com\/watch\?feature=player_embedded\&v=([\w-]{11})/; | |
var httpsfeaturedYoutubeUrl = /https\:\/\/www\.youtube\.com\/watch\?feature=player_embedded\&v=([\w-]{11})/; | |
// copied time | |
var copytimeYoutubeUrl = /http\:\/\/www\.youtube\.com\/watch\?feature=player_detailpage\&v=([\w-]{11})/; | |
var httpscopytimeYoutubeUrl = /http\:\/\/www\.youtube\.com\/watch\?feature=player_detailpage\&v=([\w-]{11})/; | |
var reMatch = linkText.match(reYoutubeUrl) || linkText.match(httpsreYoutubeUrl) || linkText.match(shortreYoutubeUrl) || linkText.match(httpsshortreYoutubeUrl) || linkText.match(featuredYoutubeUrl) || linkText.match(httpsfeaturedYoutubeUrl) || linkText.match(copytimeYoutubeUrl) || linkText.match(httpscopytimeYoutubeUrl); | |
return (reMatch) ? reMatch[1] : false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment