-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.ts
77 lines (67 loc) · 1.8 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import { serve } from "https://deno.land/[email protected]/http/server.ts";
import ytdl from "https://esm.sh/@distube/[email protected]";
const handler = async function(req: Request){
var url=new URL(req.url);
console.log(url.pathname)
if(url.pathname.indexOf("/vid") > -1) {
let id=url.searchParams.get("id");
if(ytdl.validateID(id)){
let yt =await ytdl.getInfo(id);
return new Response(`{"video":${JSON.stringify(yt.player_response.videoDetails)},"stream":${JSON.stringify(yt.player_response.streamingData)},"captions":${JSON.stringify(yt.player_response.captions) || "\"none\""}}`, {
status: 200,
headers: {
"content-type": "application/json; charset=utf-8",
"Access-Control-Allow-Origin":"*",
}
});
}else{
return new Response(`{"error":true}`, {
status: 404,
headers: {
"Content-Type": "application/json; charset=utf-8",
"Access-Control-Allow-Origin":"*",
}
});
}
}
else if(url.pathname.indexOf("audio") > -1 ){
let id=url.searchParams.get("id");
if(ytdl.validateID(id)){
let yt =await ytdl.getInfo(id);
let audioFormats = ytdl.filterFormats(yt.formats, 'audioonly');
return new Response(`{"audio":${JSON.stringify(audioFormats)}}`, {
status: 200,
headers: {
"content-type": "application/json; charset=utf-8",
"Access-Control-Allow-Origin":"*",
}
});
}else{
return new Response(`{"error":true}`, {
status: 404,
headers: {
"Content-Type": "application/json; charset=utf-8",
"Access-Control-Allow-Origin":"*",
}
});
}
}
else if(url.pathname=="/"){
let index=await Deno.readTextFile("./index.html");
const body = new TextEncoder().encode(index);
return new Response(body, {
status: 200,
headers: {
"content-type": "text/html; charset=utf-8",
}
});
}else{
return new Response(`<h1>404 NOT FOUND BRUH 🤣🤣🤣🤣`, {
status: 404,
headers: {
"content-type": "text/html; charset=utf-8",
}
});
}
};
serve(handler);