Last active
May 25, 2025 23:18
-
-
Save Kaviaann/ac288a6f364dbf8725b5abb83fb29491 to your computer and use it in GitHub Desktop.
Youtube Downloader
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | |
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | |
return new (P || (P = Promise))(function (resolve, reject) { | |
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | |
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | |
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | |
step((generator = generator.apply(thisArg, _arguments || [])).next()); | |
}); | |
}; | |
import yts from "yt-search"; | |
import axios from "axios"; | |
/** | |
* Scraped By Kaviaann | |
* Protected By MIT LICENSE | |
* Whoever caught removing wm will be sued | |
* @description Any Request? Contact me : [email protected] | |
* @author Kaviaann 2024 | |
* @copyright https://whatsapp.com/channel/0029Vac0YNgAjPXNKPXCvE2e | |
*/ | |
export function youtube(data) { | |
return __awaiter(this, void 0, void 0, function* () { | |
return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () { | |
var _a; | |
try { | |
data = data.trim(); | |
!data && | |
(() => { | |
return reject("Enter either a youtube link for downloading, or query for searching"); | |
})(); | |
const yt = /youtu(\.)?be/gi.test(data); | |
if (!yt) { | |
const d = yield yts(data).then((v) => v.videos); | |
return resolve({ | |
type: "search", | |
query: data, | |
total: d.length || 0, | |
videos: d.map(({ videoId, views, url, title, description, image, thumbnail, seconds, timestamp, ago, author, }) => { | |
return { | |
title, | |
id: videoId, | |
url, | |
media: { | |
thumbnail: thumbnail || "", | |
image: image, | |
}, | |
description, | |
duration: { | |
seconds, | |
timestamp, | |
}, | |
published: ago, | |
views, | |
author, | |
}; | |
}), | |
}); | |
} | |
else { | |
const id = ((_a = /(?:youtu\.be\/|youtube\.com(?:\/(?:[^\/\n\s]+\/\S+\/|(?:v|e(?:mbed)?)\/|\S*?[?&]v=|shorts\/)|youtu\.be\/|embed\/|v\/|m\/|watch\?(?:[^=]+=[^&]+&)*?v=))([^"&?\/\s]{11})/gm.exec(data)) === null || _a === void 0 ? void 0 : _a[1]) || ""; | |
if (!id) | |
return reject("Enter valid youtube video link!"); | |
const { title, description, url, videoId, seconds, timestamp, views, genre, uploadDate, ago, image, thumbnail, author, } = yield yts({ | |
videoId: id, | |
}); | |
const headers = { | |
Accept: "*/*", | |
Origin: "https://id-y2mate.com", | |
Referer: "https://id-y2mate.com/", | |
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0.0.0 Safari/537.36", | |
"Sec-Ch-Ua-Platform-Version": '"15.0.0"', | |
"Sec-Ch-Ua-Bitness": "64", | |
"Sec-Ch-Ua-Model": "", | |
"Sec-Ch-Ua-Mobile": "?0", | |
"Sec-Ch-Ua-Arch": "x86", | |
"X-Requested-With": "XMLHttpRequest", | |
"Sec-Ch-Ua-Full-Version": "129.0.6668.90", | |
"Sec-Ch-Ua-Full-Version-List": '"Google Chrome";v="129.0.6668.90", "Not=A?Brand";v="8.0.0.0", "Chromium";v="129.0.6668.90"', | |
}; | |
const r = yield axios | |
.post("https://id-y2mate.com/mates/analyzeV2/ajax", new URLSearchParams({ | |
k_query: `https://youtube.com/watch?v=${id}`, | |
k_page: "home", | |
hl: "", | |
q_auto: "0", | |
}), { | |
headers, | |
}) | |
.then((v) => v.data); | |
if (!r) | |
return reject(new Error("Fail to get video & audio")); | |
const d = { | |
mp3: {}, | |
mp4: {}, | |
}; | |
yield new Promise((res) => { | |
for (let i of Object.values(r.links.mp4)) { | |
Object.assign(d.mp4, { | |
[i.q]: () => __awaiter(this, void 0, void 0, function* () { | |
return new Promise((res, rej) => __awaiter(this, void 0, void 0, function* () { | |
try { | |
const r = yield axios | |
.post("https://id-y2mate.com/mates/convertV2/index", new URLSearchParams({ | |
vid: id, | |
k: i.k, | |
}), { | |
headers: Object.assign(Object.assign({}, headers), { Referer: headers.Referer + id }), | |
}) | |
.then((v) => v.data); | |
if (!r || r.status !== "ok") | |
return rej(new Error("Fail to convert video")); | |
return res({ | |
size: i.size, | |
format: i.f, | |
url: r.dlink, | |
}); | |
} | |
catch (e) { | |
return rej(e); | |
} | |
})); | |
}), | |
}); | |
} | |
for (let i of Object.values(r.links.mp3)) { | |
Object.assign(d.mp3, { | |
[i.f]: () => __awaiter(this, void 0, void 0, function* () { | |
return new Promise((res, rej) => __awaiter(this, void 0, void 0, function* () { | |
try { | |
const r = yield axios | |
.post("https://id-y2mate.com/mates/convertV2/index", new URLSearchParams({ | |
vid: id, | |
k: i.k, | |
}), { | |
headers: Object.assign(Object.assign({}, headers), { Referer: headers.Referer + id }), | |
}) | |
.then((v) => v.data); | |
if (!r || r.status !== "ok") | |
return rej(new Error("Fail to convert video")); | |
return res({ | |
size: i.size, | |
format: i.f, | |
url: r.dlink, | |
}); | |
} | |
catch (e) { | |
return rej(e); | |
} | |
})); | |
}), | |
}); | |
} | |
res(); | |
}); | |
return resolve({ | |
type: "download", | |
download: { | |
title, | |
description, | |
url, | |
id: videoId, | |
duration: { | |
seconds, | |
timestamp, | |
}, | |
views, | |
genre, | |
releaseDate: uploadDate, | |
published: ago, | |
media: { | |
thumbnail, | |
image, | |
}, | |
author, | |
dl: yield d, | |
}, | |
}); | |
} | |
} | |
catch (e) { | |
return reject(e); | |
} | |
})); | |
}); | |
} |
Result :
Download Result
{
type: 'download',
download: {
title: 'Billie Eilish - Happier Than Ever (Official Music Video)',
description: 'Listen to the new album “Happier Than Ever”, out now: https://BillieEilish.lnk.to/HappierTh...\n' +
' \n' +
'Directed by Billie Eilish\n' +
' \n' +
'Follow Billie Eilish: \n' +
'Facebook: https://BillieEilish.lnk.to/Facebook\n' +
'Instagram: https://BillieEilish.lnk.to/Instagram\n' +
'Twitter: https://BillieEilish.lnk.to/Twitter\n' +
'TikTok: https://BillieEilish.lnk.to/TikTok\n' +
'YouTube: https://youtube.com/billieeilish\n' +
'Email: https://smarturl.it/BillieEilishEmail\n' +
'Store: https://smarturl.it/BillieEilishStore\n' +
'\n' +
'Lyrics:\n' +
"When I'm away from you, I'm happier than ever\n" +
'Wish I could explain it better\n' +
"I wish it wasn't true\n" +
'Give me a day or two to think of something clever\n' +
'To write myself a letter\n' +
'To tell me what to do, mm-mmm\n' +
'\n' +
'Do you read my interviews?\n' +
'Or do you skip my avenue? (My avenue)\n' +
'When you (when you) said you were passing through\n' +
'Was I even on your way?\n' +
'\n' +
'I knew when I asked you to (when I asked you to)\n' +
'Be cool about what I was telling you\n' +
"You'd do the opposite of what you said you'd do (what you said you'd do)\n" +
"And I'd end up more afraid\n" +
'\n' +
"Don't say it isn't fair\n" +
"You clearly weren't aware that you made me miserable\n" +
'So if you really wanna know\n' +
'\n' +
"When I'm away from you (when I'm away from you)\n" +
"I'm happier than ever (happier than ever)\n" +
'Wish I could explain it better (wish I could explain it better)\n' +
"I wish it wasn't true (wish it wasn't true), mmm-mmm\n" +
'\n' +
'You call me again, drunk in your Benz\n' +
'Driving home under the influence\n' +
"You scared me to death, but I'm wasting my breath\n" +
"'Cause you only listen to your fucking friends\n" +
'\n' +
"I don't relate to you\n" +
"I don't relate to you, no\n" +
"'Cause I'd never treat me this shitty\n" +
'You made me hate this city\n' +
'\n' +
"And I don't talk shit about you on the internet\n" +
'Never told anyone anything bad\n' +
"'Cause that shit's embarrassing, you were my everything\n" +
'And all that you did was make me fucking sad\n' +
"So don't waste the time I don't have\n" +
"And don't try to make me feel bad\n" +
'\n' +
'I could talk about every time that you showed up on time\n' +
"But I'd have an empty line 'cause you never did\n" +
'Never paid any mind to my mother or friends\n' +
"So I shut 'em all out for you 'cause I was a kid\n" +
'\n' +
'You ruined everything good\n' +
'Always said you were misunderstood\n' +
'Made all my moments your own\n' +
'Just fucking leave me alone',
url: 'https://youtube.com/watch?v=5GJWxDKyk3A',
id: '5GJWxDKyk3A',
duration: { seconds: 315, timestamp: '5:15' },
views: 390328886,
genre: 'music',
releaseDate: '2021-7-30',
published: '3 years ago',
media: {
thumbnail: 'https://i.ytimg.com/vi/5GJWxDKyk3A/hqdefault.jpg',
image: 'https://i.ytimg.com/vi/5GJWxDKyk3A/hqdefault.jpg'
},
author: {
name: 'Billie Eilish',
url: 'https://youtube.com/@BillieEilishVEVO'
},
dl: {
mp3: { m4a: [Function: m4a], mp3: [Function: mp3] },
mp4: {
'240p': [Function: 240p],
'360p': [Function: 360p],
'480p': [Function: 480p],
'1080p': [Function: 1080p],
'144p': [Function: 144p],
'720p': [Function: 720p],
auto: [Function: auto]
}
}}
}
Documentation :
export interface IYoutubeR {
size: string;
format: string;
url: string;
}
export interface IYoutubeDl {
mp4: {
[key: string]: () => Promise<IYoutubeR>;
};
mp3: {
[key: string]: () => Promise<IYoutubeR>;
};
}
export interface IYoutubeDownload {
title: string;
description: string;
url: string;
id: string;
duration: {
seconds: number;
timestamp: string;
};
views: number;
genre: string;
releaseDate: string;
published: string;
media: {
image: string;
thumbnail: string;
};
author: {
name: string;
url: string;
};
dl: IYoutubeDl;
}
export interface IYoutubeVideo {
title: string;
id: string;
url: string;
media: {
thumbnail: string;
image: string;
};
description: string;
duration: {
seconds: number;
timestamp: string;
};
published: string;
views: number;
author: {
name: string;
url: string;
};
}
export interface IYoutube {
type: "search" | "download";
download?: IYoutubeDownload;
query?: string;
total?: number;
videos?: IYoutubeVideo[];
}
/**
* Scraped By Kaviaann
* Protected By MIT LICENSE
* Whoever caught removing wm will be sued
* @description Any Request? Contact me : [email protected]
* @author Kaviaann 2024
* @copyright https://whatsapp.com/channel/0029Vac0YNgAjPXNKPXCvE2e
*/
export declare function youtube(data: string): Promise<IYoutube>;
Izin make,
makasihhhhhhhhh
thx om
ur welcomee
Bikin tutor pasang juga puh
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How to use :