@riqtu/tiktok-scraper
Version:
Modified TikTok Scraper with proxy support
38 lines (37 loc) • 1.57 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const fetcher_1 = __importDefault(require("./client/fetcher"));
const util_1 = require("./parser/util");
const socks_proxy_agent_1 = require("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 socks_proxy_agent_1.SocksProxyAgent(options.proxy)
: undefined;
const response = await (0, fetcher_1.default)(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 (0, util_1.isParsedOptions)(options)
? (0, util_1.parseAweme)(aweme, options.keys ? { keys: options.keys } : undefined)
: awemeList;
}
exports.default = Tiktok;