tiktok-scraper
A fast light-weight scraper for tiktok to fetch and download video posts, video music, user info and more.
Installation
npm i tiktok-scraper-ts
Importing
TypeScript
import * as tiktokscraper from "tiktok-scraper-ts";
import { TTScraper } from "tiktok-scraper-ts";
JavaScript
const tiktokscraper = require("tiktok-scraper-ts");
const { TTScraper } = require("tiktok-scraper-ts");
Class Methods
.video(url, noWaterMark) scrapes video info and download link. You can decide if the video should have a watermark or not. Returns Promise<Video>
.user(username) Scrapes user info. Returns Promise<User>
.getAllVideosFromUser(username) Scrapes all available videos for the given user. Returns Promise<IVideo[]>
.getMusic(url) Scrapes Music info from a video. Returns Promise<Music>
.downloadAllVideosFromUser(username, path?: optional) Downloads all Videos of the given user. Returns Promise<void>
.noWaterMark(link) Returns a direct download link for the video without TikTok Watermark.
.hashtag(tag) Scrapes a hashtag posts
Individual Functions
Since 1.2.6 you can also import functions directly
API
fetchVideo(url, true);
fetchUser(username);
fetchAllVideosFromUser(username);
fetchMusic(url);
fetchVideoNoWaterMark(url);
hashtag(tag);
Examples
Cookies Support
Since 1.3.5 you can use cookies. In some cases where the request is not successful, a second request using puppteer will be made. However the request could take 2x longer. To avoid this you can use cookies. This is optional though.
The recommended way to get cookies is by installing the cookies.txt
extension for the browser and then go to www.tiktok.com
and export the cookies for current site. Then save the cookies.txt file and give the path of the cookie file as a parameter to the TTScraper class.
This is the only supported way to use cookies for now.
import { TTScraper } from "tiktok-scraper-ts";
const TikTokScraper = new TTScraper("./cookies.txt");
Fetch info for a single video
import { TTScraper } from "tiktok-scraper-ts";
const TikTokScraper = new TTScraper();
(async () => {
const fetchVideo = await TikTokScraper.video("link", true);
console.log(fetchVideo);
})();
import { fetchVideo } from "tiktok-scraper-ts";
(async () => {
const video = await fetchVideo("link");
console.log(video);
})();
Video {
id: '7049800036758080773',
description: undefined,
createdAt: '05/01/2022',
height: 1024,
width: 576,
duration: 10,
resolution: '720p',
shareCount: 12400,
likesCount: 554500,
commentCount: 7535,
playCount: 5500000,
cover: '',
playURL: 'PLAY LINK',
downloadURL: 'Download Link',
fomrat: 'mp4'
}
Fetch user page
import { TTScraper } from "tiktok-scraper-ts";
const TikTokScraper = new TTScraper();
(async () => {
const fetchUser = await TikTokScraper.user("user");
console.log(fetchUser);
})();
import { fetchUser } from "tiktok-scraper-ts";
(async () => {
const user = await fetchUser("link");
console.log(user);
})();
User {
id: '',
uniqueId: 'user',
nickname: 'new user',
avatar: 'PP Link',
signature: '',
createdAt: '12/12/2021',
verified: false,
secretUID: 'MS4wLjABAAAAkLv5v2jUnsIzViWXSAQoj5U4o685FeSDFSDfsdfsdflrk-k75Znw',
bioLink: undefined,
privateAccount: false,
isUnderAge18: false,
followers: 1,
following: 2,
hearts: 0,
videos: 0
}
Common Types
IUser
export interface IUser {
id: string;
uniqueId: string;
nickname: string;
avatar: string;
signature: string;
createdAt: string;
verified: boolean;
secretUID: string;
bioLink: string;
privateAccount: boolean;
isUnderAge18: boolean;
followers: number;
following: number;
hearts: number;
videos: number;
}
IVideo
export interface IVideo {
id: string;
description: string;
createdAt: string;
height: number;
width: number;
duration: number;
resolution: string;
shareCount: number;
likesCount: number;
commentCount: number;
playCount: number;
cover?: string;
dynamicCover?: string;
playURL?: string;
downloadURL?: string;
fomrat?: string;
}
IMusic
export interface IMusic {
id: number;
title: string;
playURL: string;
coverLarge: string;
coverThumb: string;
author: string;
duration: number;
original?: boolean;
album?: string;
}
Contributions
Software contributions are welcome. If you are not a dev, testing and reproting bugs can also be very helpful!
Questions?
Please open an issue if you have questions, wish to request a feature, etc.