tk4-downloader
Version:
Modern TikTok video downloader with FHD quality and no watermark
146 lines (115 loc) • 3.89 kB
Markdown
<div align="center">

**Advanced TikTok Video Downloader Library**
*Version 1.6.0*
</div>
- [Installation](
- [Quick Start](
- [Advanced Usage](
- [Configuration Options](
- [API Reference](
- [Events](
- [Statistics & Monitoring](
- [Error Handling](
- [Best Practices](
- [Examples](
- [Troubleshooting](
```bash
npm install tk4-downloader
yarn add tk4-downloader
```
```javascript
import TikTokDownloader from 'tk4-downloader';
// Initialize the downloader
const downloader = new TikTokDownloader();
// Basic usage
async function downloadVideo() {
try {
const result = await downloader.downloadVideo('https://www.tiktok.com/@user/video/1234567890');
console.log(`Video downloaded: ${result.url}`);
} catch (error) {
console.error('Download failed:', error.message);
}
}
```
```javascript
const downloader = new TikTokDownloader({
preferredQuality: 'high',
maxRetries: 5,
cacheResults: true,
debug: true,
parallelDownloads: 3
});
// Add event listeners
downloader.on('progress', ({status, message}) => {
console.log(`Progress: ${message}`);
});
downloader.on('success', (info) => {
console.log(`Downloaded from ${info.source} in ${info.duration}ms`);
});
// Download with monitoring
async function downloadWithMonitoring(url) {
const result = await downloader.downloadVideo(url);
const stats = downloader.getDetailedStats();
console.log(`Success rate: ${stats.successRate}%`);
}
```
| Option | Type | Default | Description |
|--------|------|---------|-------------|
| `preferredQuality` | string | 'high' | Video quality ('high', 'medium', 'low') |
| `maxRetries` | number | 3 | Maximum retry attempts |
| `timeout` | number | 10000 | Request timeout in milliseconds |
| `cacheResults` | boolean | true | Enable result caching |
| `maxCacheAge` | number | 3600000 | Cache duration in milliseconds |
| `parallelDownloads` | number | 3 | Number of concurrent downloads |
| `outputFormat` | string | 'mp4' | Output video format |
| `includeAudio` | boolean | true | Include audio in download |
| `debug` | boolean | false | Enable debug logging |
| `proxyUrl` | string | null | Proxy server URL |
| `customFileName` | string | null | Custom filename pattern |
| `downloadPath` | string | process.cwd() | Download directory path |
## API Reference
### Core Methods
#### `downloadVideo(url: string, options?: object): Promise<object>`
Downloads a TikTok video.
```javascript
const result = await downloader.downloadVideo(url);
// Returns: { url, author, description, quality, source }
```
Get detailed download statistics.
```javascript
const stats = downloader.getDetailedStats();
// Returns comprehensive statistics object
```
Reset all statistics counters.
```javascript
downloader.resetStats();
```
Fetch video metadata from multiple sources.
```javascript
const metadata = await downloader.getVideoMetadata(url);
```
Select best quality version from available sources.
```javascript
const bestQuality = downloader.selectBestQuality(results);
```
| Event | Description | Payload |
|-------|-------------|---------|
| `start` | Download started | `{ url, timestamp }` |
| `progress` | Download progress | `{ status, message }` |
| `success` | Download completed | `