Skip to content

Instantly share code, notes, and snippets.

@lihuelworks
Last active April 7, 2024 23:38
Show Gist options
  • Save lihuelworks/63c857ded1c13887093588e537070396 to your computer and use it in GitHub Desktop.
Save lihuelworks/63c857ded1c13887093588e537070396 to your computer and use it in GitHub Desktop.
Bookmarklet - recover private/deleted video video via Wayback Machine
javascript:(function() {
var ytUrl = window.location.href;
var useVideoId = false;
if (ytUrl.includes("youtube.com") || ytUrl.includes("youtu.be")) {
var useVideoIdInput = confirm("Do you want to use the video ID of the current YouTube video?");
if (useVideoIdInput) {
useVideoId = true;
}
}
var inputUrl;
if (useVideoId) {
inputUrl = "https://web.archive.org/web/20130720113437oe_/http://wayback-fakeurl.archive.org/yt/";
var videoId = getYouTubeVideoId(ytUrl);
if (videoId !== null) {
inputUrl += videoId;
} else {
alert("Failed to extract video ID.");
return;
}
} else {
var inputUrl = prompt("Please enter the URL:");
if (inputUrl === null || inputUrl.trim() === "") {
return;
}
if (inputUrl.includes("youtube.com") || inputUrl.includes("youtu.be")) {
var useVideoIdInput = confirm("Do you want to use the video ID of the provided YouTube video?");
if (useVideoIdInput) {
var videoId = getYouTubeVideoId(inputUrl);
if (videoId !== null) {
inputUrl = "https://web.archive.org/web/20130720113437oe_/http://wayback-fakeurl.archive.org/yt/" + videoId;
} else {
alert("Failed to extract video ID from the provided URL.");
return;
}
} else {
inputUrl = "https://web.archive.org/web/20130720113437oe_/http://wayback-fakeurl.archive.org/yt/" + inputUrl;
}
} else {
inputUrl = "https://web.archive.org/web/20130720113437oe_/http://wayback-fakeurl.archive.org/yt/" + inputUrl;
}
}
window.location.href = inputUrl;
function getYouTubeVideoId(url) {
var videoId = null;
if (url.includes("youtube.com")) {
var match = url.match(/[?&]v=([^?&]+)/);
if (match) {
videoId = match[1];
}
} else if (url.includes("youtu.be")) {
var match = url.match(/youtu\.be\/([^?]+)/);
if (match) {
videoId = match[1];
}
}
return videoId;
}
})();
@lihuelworks
Copy link
Author

NOTE: This tool is NOT foolproof, it depends exclusively if someone has made a snapshot into the Wayback Machine before. So, if you like a video a lot, be sure to put it in the Wayback Machine. Be kind, archive.
NOTE 2: If you're unlucky, you may get the video but not the audio. Happened to me for a single video of the many I've tried, but just keep that in mind.

This Bookmarklet (i.e bookmark that you click and does stuff) is made so it appends a youtub. While trying to backup my favorites playlist

  1. Copy the entire code block above.
  2. Create a new bookmark in your browser.
  3. Edit the bookmark's URL and paste the copied code as the URL.
  4. Now, whenever you're on a webpage, you can click the bookmarklet, and it will prompt you for a URL.
    • If you're on a YouTube video page, it will ask if you want to use the video ID. If you confirm, it will automatically append the video ID to the entered URL. Then it will navigate you to the Wayback Machine with the constructed URL.

Original idea goes to this specific reddit comment that shared it (Thanks colethedj, wherever you are)

If you want a less bookmark-y solution, also check from the this tool from the same thread (thanks TheHopeOfItAll_): https://www.waybackyt.download/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment