Created
June 28, 2024 18:50
-
-
Save ZTRdiamond/1c084b9fe82f57274333541f36908e02 to your computer and use it in GitHub Desktop.
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
| /* | |
| Author: https://github.com/ZTRdiamond | |
| Source: https://whatsapp.com/channel/0029VagFeoY9cDDa9ulpwM0T | |
| Pesan: lu gabisa pake cheerio dan skill issue saat pakenya? regex-kan saja | |
| */ | |
| const axios = require('axios'); | |
| async function ttdl(url) { | |
| try { | |
| if(!url) return { status: false, message: "undefined reading url!" }; | |
| return await new Promise(async(resolve, reject) => { | |
| axios.post("https://savetik.co/api/ajaxSearch", `q=${url}&lang=en`, { | |
| headers: { | |
| 'authority': 'savetik.co', | |
| 'content-type': 'application/x-www-form-urlencoded; charset=UTF-8', | |
| 'origin': 'https://savetik.co', | |
| 'referer': 'https://savetik.co/en/tiktok-photo-downloader', | |
| 'user-agent': 'Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Mobile Safari/537.36', | |
| 'x-requested-with': 'XMLHttpRequest' | |
| } | |
| }).then(raw => { | |
| const res = raw.data; | |
| if(!res.data) return reject("failed fetching data"); | |
| let images = Array.from(res?.data?.matchAll(/https:\/\/d\.tik-cdn\.com\/image([^"]*)/g), match => "https://d.tik-cdn.com/image" + match[1].replace("&", "&")); | |
| let videos = Array.from(res?.data?.matchAll(/<a\s+onclick="showAd\(\)"\s+href="https:\/\/d\.tik-cdn\.com\/dl\/([^"]*)"/g), match => "https://d.tik-cdn.com/dl/" + match[1].replace("&", "&")) | |
| if(!images || !videos) return reject("failed fetching data"); | |
| resolve({ | |
| status: true, | |
| ...((images.length > 0) ? { images } : { videos }) | |
| }) | |
| }) | |
| }); | |
| } catch (e) { | |
| return { status: false, message: e }; | |
| } | |
| } | |
| let v = "https://www.tiktok.com/@gawrgura/video/7213728634132073734"; | |
| let p = "https://www.tiktok.com/@itadoli.san/photo/7297422359831563525" | |
| ttdl(p) | |
| .then(console.log) | |
| .catch(console.log) | |
| module.export = ttdl; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment