1.0.1 ā¢ Published 8 months ago
@prevter/tiktok-scraper v1.0.1
TikTok Video Downloader
Simple library to download TikTok videos without watermark in TypeScript.
Installation
npm install @prevter/tiktok-scraper
Usage
// Typescript:
import { fetchVideo } from '@prevter/tiktok-scraper';
import { writeFileSync } from 'fs';
// Javascript:
// const { fetchVideo } = require('@prevter/tiktok-scraper');
// const { writeFileSync } = require('fs');
const url = 'https://www.tiktok.com/@username/video/1234567891234567891';
// Using promise
fetchVideo(url)
.then(async (video) => {
const buffer = await video.download();
writeFileSync('video.mp4', buffer);
})
.catch((err) => {
console.error(err);
});
// Using await
const video = await fetchVideo(url);
const buffer = await video.download();
writeFileSync('video.mp4', buffer);
Supports full URLs (www.tiktok.com) and short URLs (vm.tiktok.com).fetchVideo
parameter can be a URL or a video ID. It will automatically detect how to handle the parameter. If it fails to detect, it will throw an error, so you can handle it.
This method return a Promise<Buffer>
, so you can either save it to a file or just send it to anywhere you want.
You can also download video with watermark or even download music from the video:
const video = await fetchVideo(url);
// add `true` argument to download video with watermark
const watermarkBuffer = await video.download({ watermark: true });
const noWatermarkBuffer = await video.download();
const musicBuffer = await video.music.download();
You can add a progress
callback to track download progress:
const video = await fetchVideo(url);
const buffer = await video.download({
progress: (p) => {
console.log(`Downloaded ${p.progress}% (${p.downloaded}/${p.total} bytes)`);
},
});
In addition, you can get some information about the video:
const video = await fetchVideo(url);
console.log('Video description:', video.description);
console.log('š URL:', video.url);
console.log('š¤ Author:', video.author);
console.log('ā¤ļø Likes:', video.likes);
console.log('š¬ Comments:', video.comments);
console.log('š Shares:', video.shares);
console.log('ā¶ļø Plays:', video.playCount);
console.log('šµ Music:', video.music.name, '-', video.music.author);
console.log('š¼ļø Thumbnail URL:', video.previewImageUrl);
/*
Video description: This is a video description
š URL: https://www.tiktok.com/@username/video/1234567891234567891
š¤ Author: username
ā¤ļø Likes: 123456
š¬ Comments: 1234
š Shares: 1234
ā¶ļø Plays: 1234567
šµ Music: Music Name - Music Author
š¼ļø Thumbnail URL: https://p16-sign-sg.tiktokcdn.com/...
*/
Building and testing
Build typescript files:
npm run build
Build and run test script:
npm run build:test