UNPKG

@riqtu/tiktok-scraper

Version:

Modified TikTok Scraper with proxy support

33 lines (32 loc) 1.31 kB
import fetchAwemeList from "./client/fetcher.js"; import { isParsedOptions, parseAweme } from "./parser/util.js"; import { SocksProxyAgent } from "socks-proxy-agent"; /** * Fetches a TikTok video or user profile based on the provided URL. * * @param url - The URL of the TikTok video or user profile. * @param options - Optional configuration options for the TikTok request. * @returns A Promise that resolves to an array of Aweme objects, a full IParsed object, or a Partial<IParsed> if keys are specified. * @throws An error if fetching fails or the aweme is not found. */ async function Tiktok(url, options) { const proxyAgent = options?.proxy ? new SocksProxyAgent(options.proxy) : undefined; const response = await fetchAwemeList(url, proxyAgent); if (!response) { throw new Error("Failed to fetch the response"); } const [awemeId, awemeList] = response; if (!awemeList) { throw new Error("Failed to fetch the aweme list"); } const aweme = awemeList.find((item) => item.aweme_id === awemeId); if (!aweme) { throw new Error("Failed to find the aweme"); } return isParsedOptions(options) ? parseAweme(aweme, options.keys ? { keys: options.keys } : undefined) : awemeList; } export default Tiktok;