Return to Snippet

Revision: 66569
at May 27, 2014 07:29 by astralis

Initial Code
<div><strong>Insert YouTube url:</strong></div>
<input type="text" id="ytlink" onkeyup="youtube_parser(this.value)">
    <div><strong>Output: YouTube video id:</strong></div>
    <input type="text" id="ytimagelink" value="">
        <div><strong>Output: Thumbnail</strong></div>
        <div id="ytimage"></div>

function youtube_parser(url) {
    var regExp = /.*(?\/|v\/|u\/\w\/|embed\/|watch\?v=)([^#\&\?]*).*/;
    var match = url.match(regExp);
    if (match && match[1].length == 11) {
        urllink = match[1];
        imagelink = "<img src=\"http:\/\/\/vi\/"+urllink+"\/hqdefault.jpg\">";
    } else {
        //urllink = "test"
    document.getElementById("ytimagelink").value = urllink;
    document.getElementById("ytimage").innerHTML = imagelink;       

Initial URL

Initial Description
This script will grab the YouTube video ID using regex so that many different types of YouTube urls. This will also output the id and thumbnail to view.

Initial Title
Grab YouTube video ID and thumbnail

Initial Tags

Initial Language