Skip to content

Commit 24748bb

Browse files
committed
improve yt example
* proxy thumbnail images * activate for any URL that ytdl-core can recognize Fixes nfriedly#257
1 parent 1f5bdf3 commit 24748bb

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

examples/youtube/youtube.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
"use strict";
22

3+
// Important: to use this you must also install ytdl-core as a dependency
4+
35
const ytdl = require("ytdl-core");
46

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

0 commit comments

Comments
 (0)