A tool for downloading TikTok videos with or without watermarks and automatically uploading them to Facebook Reels
—
File management, format conversion, metadata handling, and download queue management utilities. Provides comprehensive video processing capabilities including quality selection, batch processing, and automated workflows.
Interactive quality selection for TikTok videos with multiple resolution options.
/**
* Interactive video quality selection via command line
* @param videos - Array of available video quality options
* @returns Selected video quality object
*/
function chooseVideoQuality(videos: VideoQuality[]): VideoQuality;
interface VideoQuality {
/** Quality descriptor (e.g., "HD", "720p") */
quality?: string;
/** Video download URL */
url: string;
}Usage Examples:
These functions are part of the main application workflow when running node index.js. They are not exported for direct import but are used internally:
// When running the main application (node index.js)
// The user is presented with quality options automatically:
// Available video qualities:
// 1. HD
// 2. SD
// 3. Mobile
// Choose video quality (enter number): 1
// The function handles user input and returns selected quality
// Includes fallback for empty/invalid video arrays
if (!videos || videos.length === 0) {
console.log('No video qualities available. Using default.');
return videos[0];
}Save and manage video metadata in JSON format for archival and reference.
/**
* Save video metadata to JSON file
* @param metadata - Video metadata object to save
* @param filePath - Target file path for JSON output
*/
function saveMetadata(metadata: object, filePath: string): void;Usage Examples:
This function is used internally by the main application during the download process:
// During the downloadAndUpload workflow, metadata is automatically saved:
// Save metadata (happens automatically in main app)
const videoMetadata = result.result; // TikTok API result
saveMetadata(videoMetadata, path.resolve('download', `${namafile}_metadata.json`));
// Creates: ./download/video123_metadata.jsonConvert videos between different formats using FFmpeg integration.
/**
* Convert video to different format using FFmpeg
* @param inputPath - Source video file path
* @param outputPath - Target output file path
* @param format - Target video format (e.g., 'webm', 'avi', 'mov')
* @returns Promise resolving when conversion completes
*/
function convertVideo(inputPath: string, outputPath: string, format: string): Promise<void>;Usage Examples:
Video conversion happens automatically in the main application workflow:
// Conversion occurs automatically after download in the main app:
// Convert video (example to webm format) - from index.js
const webmPath = path.resolve('download', `${namafile}.webm`);
try {
await convertVideo(downloadPath, webmPath, 'webm');
console.log(`Video converted to WebM: ${webmPath}`);
} catch (error) {
console.log(`Error converting video: ${error.message}`);
}Integrated workflow combining download, processing, and upload operations.
/**
* Complete integrated workflow: download TikTok video, process, and upload to Facebook
* Includes quality selection, metadata saving, format conversion, and error handling
* @param url - TikTok video URL to process
* @param retries - Number of retry attempts on failure (default: 3)
* @returns Promise resolving when workflow completes successfully
* @throws Logs errors but doesn't throw, handles retries internally
*/
async function downloadAndUpload(url: string, retries?: number): Promise<void>;
/**
* Interactive command-line interface functions
* These functions handle user input and CLI workflow
*/
interface CLIFunctions {
/** Prompt user to choose between single URL or list processing */
promptForInputMode(): 'single' | 'list';
/** Get single TikTok URL from user input */
promptForSingleUrl(): string;
/** Get file path containing URL list from user input */
promptForListFilePath(): string;
}Usage Examples:
This function is the core workflow of the main application:
// Called internally by the queue system and main application
// When user provides URL via CLI or when processing queue items:
await downloadAndUpload(url, retries);
// The function automatically:
// 1. Downloads video metadata and file
// 2. Saves metadata to JSON
// 3. Converts video format
// 4. Uploads to Facebook Reels
// 5. Handles errors with retriesProcess multiple TikTok URLs from a text file with queue management.
/**
* Process multiple URLs from a text file
* @param filePath - Path to file containing URLs (one per line)
*/
function processUrlList(filePath: string): void;Usage Examples:
This function is used when the user chooses "list" mode in the main application:
// When user runs: node index.js
// And selects "list" option, then provides file path
// The function reads urls.txt containing:
// https://vm.tiktok.com/ZSFxxxxxx/
// https://vm.tiktok.com/ZSFyyyyyy/
// https://vm.tiktok.com/ZSFzzzzzz/
// processUrlList('./urls.txt') is called internally
// Automatically adds all URLs to download queueConcurrent download and upload processing with queue system.
/**
* Better-queue instance for managing concurrent downloads
*/
const downloadQueue: Queue;
interface QueueTask {
/** TikTok URL to process */
url: string;
}
/**
* Queue configuration options
*/
interface QueueConfig {
/** Number of concurrent workers */
concurrent: number;
}
// Queue events
downloadQueue.on('drain', () => void); // All tasks completedUsage Examples:
import Queue from 'better-queue';
// Queue is pre-configured with concurrent: 2
const downloadQueue = new Queue(async (task, cb) => {
await downloadAndUpload(task.url);
cb(null, task);
}, { concurrent: 2 });
// Add single URL to queue
downloadQueue.push({ url: 'https://vm.tiktok.com/ZSFxxxxxx/' });
// Monitor queue completion
downloadQueue.on('drain', () => {
console.log('All downloads completed!');
});
// Add multiple URLs
const urls = [
'https://vm.tiktok.com/ZSFxxxxxx/',
'https://vm.tiktok.com/ZSFyyyyyy/'
];
urls.forEach(url => downloadQueue.push({ url }));The video processing system organizes files in a structured manner:
project-root/
├── download/ # Main download directory
│ ├── {videoId}.mp4 # Downloaded video files
│ ├── {videoId}_metadata.json # Video metadata
│ └── {videoId}.webm # Converted video files
├── cookies.json # Facebook session cookies
└── config.json # Bot configuration// File naming patterns
const patterns = {
/** Original downloaded video */
video: `{videoId}.mp4`,
/** Video metadata */
metadata: `{videoId}_metadata.json`,
/** Converted video */
converted: `{videoId}.{format}`
};Visual progress indicators for download operations using the progress package:
// Progress bar configuration
const progressBarOptions = {
width: 40,
complete: '<',
incomplete: '•',
renderThrottle: 1,
format: `[ Downloading ] [:bar] :percent in :elapseds`
};Comprehensive error handling with automatic retry mechanisms:
Retry Configuration:
Common Error Scenarios:
Network Connectivity Issues:
Invalid TikTok URLs:
Missing Video Data:
Facebook Upload Failures:
File System Errors:
Video Processing Errors:
Queue System Errors:
Error Recovery:
// Automatic retry with decreasing attempts
if (retries > 0) {
console.log(`Error occurred. Retrying... (${retries} attempts left)`);
await downloadAndUpload(url, retries - 1);
} else {
console.log(`Failed to process URL after multiple attempts: ${url}`);
}Install with Tessl CLI
npx tessl i tessl/npm-tiktok-src