Skip to content

Commit

Permalink
improve yt example
Browse files Browse the repository at this point in the history
* proxy thumbnail images
* activate for any URL that ytdl-core can recognize

Fixes  #257
  • Loading branch information
nfriedly committed Jun 10, 2024
1 parent 1f5bdf3 commit 24748bb
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions examples/youtube/youtube.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
"use strict";

// Important: to use this you must also install ytdl-core as a dependency

const ytdl = require("ytdl-core");

// handles youtube video pages and replaces them with a custom page that just streams the video
function processRequest(data) {
const { hostname, pathname } = new URL(data.url);
if (hostname === "www.youtube.com" && pathname === "/watch") {
if (ytdl.validateURL(data.url)) {
const res = data.clientResponse;
// if we write headers, unblocker will detect that and stop trying to process this request
res.writeHead(200, { "content-type": "text/html; charset=utf-8" });
Expand All @@ -27,7 +28,7 @@ function processRequest(data) {
</head>
<body>
<h1>${info.videoDetails.title}</h1>
<video controls poster="${thumb.url}" style="width: 100%">
<video controls poster="/proxy/${thumb.url}" style="width: 100%">
${formats
.map(
(format) =>
Expand Down

0 comments on commit 24748bb

Please sign in to comment.