notmebotz-tools
Version:
Sebuah Tools yang berfungsi untuk mendownload Video atau Foto dari media sosial, serta sebagai tools yang berguna untuk aplikasi kamu seperti untuk BOT
93 lines (83 loc) • 2.69 kB
JavaScript
const axios = require('axios');
const cheerio = require('cheerio');
const bing = {
search: async (query) => {
try {
const response = await axios.get(`https://www.bing.com/search?q=${query}`);
const html = response.data;
const $ = cheerio.load(html);
const results = [];
$('.b_algo').each((index, element) => {
const title = $(element).find('h2').text();
const link = $(element).find('a').attr('href');
const snippet = $(element).find('.b_caption p').text();
const image = $(element).find('.cico .rms_iac').attr('data-src');
results.push({
author: "Herza",
status: 200,
data: {
title,
link,
snippet,
image: image ? `https:${image}` : undefined
}
});
});
return results;
} catch (error) {
console.error('Error fetching data:', error);
}
},
images: async (query) => {
try {
const response = await axios.get(`https://www.bing.com/images/search?q=${query}`);
const html = response.data;
const $ = cheerio.load(html);
const url = [];
$(".imgpt > a").each((i, el) => {
url[i] = $(el).attr("href");
});
const result = [];
for (let i = 0; i < url.length; i++) {
result[i] = {
photo: 'https://www.bing.com/' + url[i]
};
}
return result;
} catch (error) {
console.error('Error fetching image data:', error);
}
},
videos: async (query) => {
try {
const url = `https://www.bing.com/videos/search?q=${query}`;
const { data } = await axios.get(url);
const $ = cheerio.load(data);
const videoDetails = [];
$('.mc_vtvc').each((index, element) => {
const title = $(element).find('.mc_vtvc_title strong').text();
const duration = $(element).find('.mc_bc_rc.items').first().text();
const views = $(element).find('.meta_vc_content').first().text();
const uploadDate = $(element).find('.meta_pd_content').first().text();
const channel = $(element).find('.mc_vtvc_meta_row_channel').text();
const link = $(element).find('a').attr('href');
videoDetails.push({
author: "Herza",
status: 200,
data: {
title,
duration,
views,
uploadDate,
channel,
link: 'https://bing.com/videos/search?q=' + `${link}`
}
});
});
return videoDetails;
} catch (error) {
console.error('Error fetching video details:', error);
}
}
};
module.exports = { bing }