YouTube URL Parser
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 - 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 + '&' : '') + 'enablejsapi=1&autohide=1&color=white&controls=1&playsinline=1&rel=' + video.showRelated + '&autoplay=true&showinfo=0&theme=light&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(); }
});
Developer | Adam |
Username | depthdev |
Uploaded | January 07, 2023 |
Rating | 3 |
Size | 3,519 Kb |
Views | 8,096 |
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!
Name | Size |
Pure JavaScript Draggable Ball | 2,599 Kb |
Responsive. Interactive. SVG. | 20,357 Kb |
Responsive SVG Line Graph with Animation | 3,954 Kb |
Canvas Arc | 2,389 Kb |
CSS Book with Scrolling Highlighter | 0 Kb |
Pure CSS Animated Photo Stack | 2,486 Kb |
Pure CSS Bulging Box | 2,224 Kb |
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!
Name | Username | Size |
Progressively reveal dots on a Bezier curve | GreenSock | 2,489 Kb |
Flexbox playground | Enxaneta | 5,418 Kb |
Pictos font library from CodePen | Jstam | 3,790 Kb |
Animated Slide Hamburger Mobile Menu | BJack | 2,247 Kb |
Automatic scroll | Skeurentjes | 4,042 Kb |
See Through | Larrygeams | 77,410 Kb |
JQuery AJAX reddit Exercise | Btholt | 1,777 Kb |
Speech bubbles | Something | 1,547 Kb |
Sass random color animation | Jotavejv | 4,827 Kb |
Slide like Mailbox | Hmps | 3,758 Kb |
Surf anonymously, prevent hackers from acquiring your IP address, send anonymous email, and encrypt your Internet connection. High speed, ultra secure, and easy to use. Instant setup. Hide Your IP Now!