从 url 获取播放列表 ID
function playlist_id(url) {
var VID_REGEX = /^.*(youtu.be\/|v\/|u\/\w\/|embed\/|watch\?v=|\&v=)([^#\&\?]*).*/
var regPlaylist = /[?&]list=([^#\&\?]+)/;
var match = url.match(regPlaylist);
return match[1];
}
从播放列表 url 获取视频 ID
function video_id_from_playlist(url) {
var VID_REGEX = /^.*(youtu.be\/|v\/|u\/\w\/|embed\/|watch\?v=|\&v=)([^#\&\?]*).*/
var video_id = url.match(VID_REGEX)[2];
return video_id ;
}
或来自 url 的视频 ID
function get_video_id(url) {
url = url.split(/(vi\/|v=|\/v\/|youtu\.be\/|\/embed\/)/);
return (url[2] !== undefined) ? url[2].split(/[^0-9a-z_\-]/i)[0] : url[0];
}