1.0.1 ā€¢ Published 8 months ago

@prevter/tiktok-scraper v1.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
8 months ago

TikTok Video Downloader

npm npm type definitions GitHub

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
1.0.1

8 months ago

1.0.0

11 months ago