@prevter/tiktok-scraper
Version:
Library for downloading videos from TikTok (without watermark)
130 lines (129 loc) • 4.17 kB
TypeScript
/// <reference types="node" />
/**
* Loads a TikTok video page from short URL to get the full URL
* @param url Short TikTok video URL (e.g. https://vm.tiktok.com/...)
* @returns Promise containing the full TikTok video URL
*/
export declare const getFullURL: (url: string) => Promise<string>;
/**
* Get the video ID from a TikTok video URL (only full URL)
* @param url TikTok video URL
* @returns Video ID
*/
export declare const getVideoId: (url: string) => string;
/**
* Automatically deduce the video ID from a TikTok video URL
* @param url Any TikTok video URL (full or short)
* @returns Promise containing the video ID
*/
export declare const detectVideoId: (url: string) => Promise<string>;
/**
* Fetches a TikTok video data from a video ID or URL
* @param video TikTok video ID or URL
* @returns Promise containing the TikTok video data (see {@link TikTokVideo} interface for more details)
*/
export declare const fetchVideo: (video: string) => Promise<TikTokVideo>;
/**
* TikTok video source data containing all important information
* about the video: URL, size, like count, share count, etc.
*
* Contains a `download` method to download the video data to a buffer.
*/
export interface TikTokVideo {
/** Video ID */
readonly id: string;
/** Video URL */
readonly url: string;
/** Video description */
readonly description: string;
/** Video author name */
readonly author: string;
/** Video source with watermark */
readonly videoWatermark: TikTokVideoSource;
/** Video source without watermark */
readonly videoNoWatermark: TikTokVideoSource;
/** Video width */
readonly width: number;
/** Video height */
readonly height: number;
/** Number of likes */
readonly likes: number;
/** Number of shares */
readonly shares: number;
/** Number of plays */
readonly playCount: number;
/** Number of comments */
readonly comments: number;
/** Music data */
readonly music: TikTokMusic;
/** Preview image URL */
readonly previewImageUrl: string;
/**
* Downloads the video
* @param options Download options (see {@link DownloadOptions})
* @returns Promise containing the video data buffer
*/
readonly download: (options?: DownloadOptions) => Promise<Buffer>;
}
/**
* TikTok video source
*
* Contains information about the video source
* and provides a method to download the video
* @see {@link TikTokVideo}
*/
export interface TikTokVideoSource {
/** Video URI */
readonly uri: string;
/** Video download URL */
readonly url: string;
/** Video width */
readonly width: number;
/** Video height */
readonly height: number;
/** Video data size */
readonly dataSize: number;
/**
* Downloads the video
* @param progress Callback function to track the download progress
* @returns Promise containing the video data buffer
*/
readonly download: (progress?: (progress: DownloadProgress) => void) => Promise<Buffer>;
}
/**
* TikTok music
*
* Contains information about the music
* and provides a method to download the music
* @see {@link TikTokVideo}
*/
export interface TikTokMusic {
/** Music ID */
readonly id: string;
/** Music name */
readonly name: string;
/** Music author */
readonly author: string;
/** Music download URL */
readonly url: string;
/**
* Downloads the music
* @param progress Callback function to track the download progress
* @returns Promise containing the music data buffer
*/
readonly download: (progress?: (progress: DownloadProgress) => void) => Promise<Buffer>;
}
export interface DownloadProgress {
/** Total bytes to download */
readonly total: number;
/** Bytes downloaded */
readonly downloaded: number;
/** Download progress in percent */
readonly progress: number;
}
export interface DownloadOptions {
/** Whether to download the video with watermark or not */
readonly watermark?: boolean;
/** Callback function to track download progress */
progress?: (progress: DownloadProgress) => void;
}