tiktok.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. import axios from 'axios';
  2. import cheerio from 'cheerio';
  3. const clean = (data) => {
  4. let regex = /(<([^>]+)>)/gi;
  5. data = data.replace(/(<br?\s?\/>)/gi, " \n");
  6. return data.replace(regex, "");
  7. };
  8. async function shortener(url) {
  9. return url;
  10. }
  11. export const Tiktok = async (query) => {
  12. let response = await axios("https://lovetik.com/api/ajax/search", {
  13. method: "POST",
  14. data: new URLSearchParams(Object.entries({ query })),
  15. });
  16. const result = {};
  17. result.creator = "YNTKTS";
  18. result.title = clean(response.data.desc);
  19. result.author = clean(response.data.author);
  20. result.nowm = await shortener(
  21. (response.data.links[0].a || "").replace("https", "http")
  22. );
  23. result.watermark = await shortener(
  24. (response.data.links[1].a || "").replace("https", "http")
  25. );
  26. result.audio = await shortener(
  27. (response.data.links[2].a || "").replace("https", "http")
  28. );
  29. result.thumbnail = await shortener(response.data.cover);
  30. return result;
  31. }
  32. async function ttimg(link) {
  33. try {
  34. let url = `https://dlpanda.com/es?url=${link}&token=G7eRpMaa`;
  35. let response = await axios.get(url);
  36. const html = response.data;
  37. const $ = cheerio.load(html);
  38. let imgSrc = [];
  39. $('div.col-md-12 > img').each((index, element) => {
  40. imgSrc.push($(element).attr('src'));
  41. });
  42. if (imgSrc.length === 0) {
  43. return { data: '*[❗] No se encontraron imágenes en el enlace proporcionado.*' };
  44. }
  45. return { data: imgSrc };
  46. } catch (error) {
  47. console.log(error);
  48. return { data: '*[❗] No se obtuvo respuesta de la página, intente más tarde.*' };
  49. }
  50. }
  51. export { ttimg };