UNPKG

ditzzsenpai-api

Version:

Simple NPM api for your app

37 lines (31 loc) 986 B
const axios = require("axios"); const cheerio = require("cheerio"); const clean = (data) => { let regex = /(<([^>]+)>)/gi; data = data.replace(/(<br?\s?\/>)/gi, " \n"); return data.replace(regex, ""); }; async function shortener(url) { return url; } module.exports = async function (query) { let response = await axios("https://lovetik.com/api/ajax/search", { method: "POST", data: new URLSearchParams(Object.entries({ query })), }); result = {}; result.creator = "Ditzzy"; result.title = clean(response.data.desc); result.author = clean(response.data.author); result.nowm = await shortener( (response.data.links[0].a || "").replace("https", "http") ); result.watermark = await shortener( (response.data.links[1].a || "").replace("https", "http") ); result.audio = await shortener( (response.data.links[2].a || "").replace("https", "http") ); result.thumbnail = await shortener(response.data.cover); return result; }.bind();