YouTube URL Parser

Developer
Size
3,519 Kb
Views
8,096

How do I make an youtube url parser?

Extracts and returns the ID, start time, and show-related-at-end-of-video parameters from every type of YouTube URL.. What is a youtube url parser? How do you make a youtube url parser? This script and codes were developed by Adam on 07 January 2023, Saturday.

YouTube URL Parser Previews

YouTube URL Parser - Script Codes HTML Codes

<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>YouTube URL Parser</title> <style> /* NOTE: The styles were added inline because Prefixfree needs access to your styles and they must be inlined if they are on local disk! */ body { font-family: "Georgia"; background: #222; color: #888;
}
h1 { font-size: 32.5px;
}
h1 span { color: #e62117; font-weight: bold;
}
em { color: #e62117;
}
input { padding: 5px; background: #888; border: none; color: #fff; font-family: inherit; font-size: 24px;
}
input[type="text"] { width: 44%; height: 35px;
}
input[type="text"]:focus { outline-color: #e62117;
}
input[type="button"] { height: 45px; margin-left: 5px; background: #e62117; font-weight: bold; cursor: pointer;
}
input[type="button"]:hover { background: #0c0;
}
output { display: block; margin: 5px 0; color: #888;
}
figure { position: relative; padding-bottom: 56.25%; /* 16:9 */ height: 0; margin: 25px 0 0;
}
figure iframe,
figure object,
figure video,
figure embed,
figure div,
figure .BrightcoveExperience { position: absolute; top: 0; left: 0; width: 100% !important; /* Override inline styles from BrightCove */ height: 100% !important; /* Override inline styles from BrightCove */ border: none;
} </style> <script src="https://cdnjs.cloudflare.com/ajax/libs/prefixfree/1.0.7/prefixfree.min.js"></script>
</head>
<body> <h1><span>YouTube</span> URL Parser</h1>
<p>Extracts and returns the <em>ID</em>, <em>start time</em>, and show-<em>related</em>-at-end-of-video parameters from every type of YouTube URL.</p>
<input type="text" placeholder="URL, embed URL, playlist URL, partial URL, or ID"/>
<input type="button" value="Load Video"/>
<output></output>
<figure><!-- injected iframe here --></figure> <script src="js/index.js"></script>
</body>
</html>

YouTube URL Parser - Script Codes CSS Codes

body { font-family: "Georgia"; background: #222; color: #888;
}
h1 { font-size: 32.5px;
}
h1 span { color: #e62117; font-weight: bold;
}
em { color: #e62117;
}
input { padding: 5px; background: #888; border: none; color: #fff; font-family: inherit; font-size: 24px;
}
input[type="text"] { width: 44%; height: 35px;
}
input[type="text"]:focus { outline-color: #e62117;
}
input[type="button"] { height: 45px; margin-left: 5px; background: #e62117; font-weight: bold; cursor: pointer;
}
input[type="button"]:hover { background: #0c0;
}
output { display: block; margin: 5px 0; color: #888;
}
figure { position: relative; padding-bottom: 56.25%; /* 16:9 */ height: 0; margin: 25px 0 0;
}
figure iframe,
figure object,
figure video,
figure embed,
figure div,
figure .BrightcoveExperience { position: absolute; top: 0; left: 0; width: 100% !important; /* Override inline styles from BrightCove */ height: 100% !important; /* Override inline styles from BrightCove */ border: none;
}

YouTube URL Parser - Script Codes JS Codes

function youtubeUrlParser(url) { var timeToSec = function(str) { var sec = 0; if (/h/.test(str)) { sec += parseInt(str.match(/(\d+)h/,'$1')[0],10) * 60 * 60; } if (/m/.test(str)) { sec += parseInt(str.match(/(\d+)m/,'$1')[0],10) * 60; } if (/s/.test(str)) { sec += parseInt(str.match(/(\d+)s/,'$1')[0],10); } return sec; }; var videoId = /^https?\:\/\/(www\.)?youtu\.be/.test(url) ? url.replace(/^https?\:\/\/(www\.)?youtu\.be\/([\w-]{11}).*/,"$2") : url.replace(/.*\?v\=([\w-]{11}).*/,"$1"); var videoStartTime = /[^a-z]t\=/.test(url) ? url.replace(/^.+t\=([\dhms]+).*$/,'$1') : 0; var videoStartSeconds = videoStartTime ? timeToSec(videoStartTime) : 0; var videoShowRelated = ~~/rel\=1/.test(url); return { id: videoId, startString: videoStartTime, startSeconds: videoStartSeconds, showRelated: videoShowRelated };
}; // youtubeParser();
// Demo-only Stuff
var input = document.querySelector('input[type="text"]');
input.focus();
var button = document.querySelector('input[type="button"]');
var output = document.querySelector('output');
var figure = document.querySelector('figure');
var outputResult = function() { var video = youtubeUrlParser(input.value); figure.innerHTML = '<iframe src="https://www.youtube.com/embed/' + video.id + '?' + (video.startSeconds ? 'start=' + video.startSeconds + '&amp;' : '') + 'enablejsapi=1&amp;autohide=1&amp;color=white&amp;controls=1&amp;playsinline=1&amp;rel=' + video.showRelated + '&amp;autoplay=true&amp;showinfo=0&amp;theme=light&amp;wmode=transparent" width="1920" height="1080" allowfullscreen></iframe>'; output.textContent = 'ID: ' + video.id + (video.startString ? ' | Start @ ' + video.startString.replace(/t\=/,'').replace(/[a-z]/g,':').replace(/\:$/,'') : '');
};
button.addEventListener('click', outputResult);
document.addEventListener('keydown', function(e) { if (e.keyCode === 13) { outputResult(); }
});
YouTube URL Parser - Script Codes
YouTube URL Parser - Script Codes
Home Page Home
Developer Adam
Username depthdev
Uploaded January 07, 2023
Rating 3
Size 3,519 Kb
Views 8,096
Do you need developer help for YouTube URL Parser?

Find the perfect freelance services for your business! Fiverr's mission is to change how the world works together. Fiverr connects businesses with freelancers offering digital services in 500+ categories. Find Developer!

Adam (depthdev) Script Codes
Create amazing Facebook ads with AI!

Jasper is the AI Content Generator that helps you and your team break through creative blocks to create amazing, original content 10X faster. Discover all the ways the Jasper AI Content Platform can help streamline your creative workflows. Start For Free!