genii / lib /yt1s.js
processed's picture
Update lib/yt1s.js
5467b75 verified
raw
history blame contribute delete
887 Bytes
const axios = require('axios');
const cheerio = require('cheerio');
const yt1s = {
dl: async (link) => {
try {
const { data } = await axios.post(
'https://yt1s.io/api/ajaxSearch',
new URLSearchParams({ p: 'home', q: link, w: '', lang: 'en' }),
{
headers: {
'User-Agent': 'Postify/1.0.0',
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
}
}
);
if (data.status !== 'ok') throw new Error('Kagak ada response dari Api nya 🥴');
const $ = cheerio.load(data.data);
return $('a.abutton.is-success.is-fullwidth.btn-premium')
.map((_, el) => ({
title: $(el).attr('title'),
url: $(el).attr('href'),
}))
.get();
} catch (error) {
console.error(error);
throw error;
}
}
};
module.exports = yt1s;