CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-tiktok-src

A tool for downloading TikTok videos with or without watermarks and automatically uploading them to Facebook Reels

Pending
Overview
Eval results
Files

tiktok-api.mddocs/

TikTok API

Core functionality for extracting video metadata, download URLs, and content from TikTok URLs. Supports both video posts and image carousels with comprehensive metadata extraction including author information, music details, and hashtags.

Capabilities

TikTok Download Function

Main function for downloading TikTok video or image data from URLs.

/**
 * Download TikTok video or image data from a URL
 * @param url - TikTok video URL (supports vm.tiktok.com, vt.tiktok.com, www.tiktok.com)
 * @returns Promise resolving to TiktokResult with video/image data or error
 */
function TiktokDL(url: string): Promise<TiktokResult>;

interface TiktokResult {
  status: 'success' | 'error';
  message?: string;
  result?: VideoResult | ImageResult;
}

Usage Examples:

import { TiktokDL } from './lib/ttapi.js';

// Download video data
const videoResult = await TiktokDL('https://vm.tiktok.com/ZSFxxxxxx/');
if (videoResult.status === 'success') {
  console.log('Video ID:', videoResult.result.id);
  console.log('Description:', videoResult.result.description);
  console.log('Video URLs:', videoResult.result.video);
}

// Handle image posts
const imageResult = await TiktokDL('https://www.tiktok.com/@user/photo/123');
if (imageResult.status === 'success' && imageResult.result.type === 'image') {
  console.log('Images:', imageResult.result.images);
}

// Error handling
const errorResult = await TiktokDL('invalid-url');
if (errorResult.status === 'error') {
  console.log('Error:', errorResult.message);
}

Video Result Type

Data structure returned for TikTok video posts.

interface VideoResult {
  /** Content type identifier */
  type: 'video';
  /** Unique TikTok video ID */
  id: string;
  /** Video creation timestamp */
  createTime: number;
  /** Video description/caption */
  description: string;
  /** Array of hashtags used in the video */
  hashtag: string[];
  /** Video duration in MM:SS format */
  duration: string;
  /** Author/creator information */
  author: AuthorInfo;
  /** Array of video download URLs from TikTok's play_addr.url_list */
  video: string[];
  /** Array of video cover image URLs from cover.url_list */
  cover: string[];
  /** Array of dynamic cover image URLs from dynamic_cover.url_list */
  dynamicCover: string[];
  /** Array of original cover image URLs from origin_cover.url_list */
  originCover: string[];
  /** Background music information */
  music: MusicInfo;
}

Image Result Type

Data structure returned for TikTok image carousel posts.

interface ImageResult {
  /** Content type identifier */
  type: 'image';
  /** Unique TikTok post ID */
  id: string;
  /** Post creation timestamp */
  createTime: number;
  /** Post description/caption */
  description: string;
  /** Array of hashtags used in the post */
  hashtag: string[];
  /** Author/creator information */
  author: AuthorInfo;
  /** Array of image URLs */
  images: string[];
  /** Background music information */
  music: MusicInfo;
}

Author Information

Comprehensive author/creator profile data.

interface AuthorInfo {
  /** TikTok user ID */
  uid: string;
  /** Unique username handle */
  username: string;
  /** Display name */
  nickname: string;
  /** User bio/signature */
  signature: string;
  /** User region/location */
  region: string;
  /** Avatar thumbnail URLs */
  avatarThumb: string[];
  /** Avatar medium size URLs */
  avatarMedium: string[];
  /** TikTok profile URL */
  url: string;
}

Music Information

Background music and audio track details.

interface MusicInfo {
  /** Music track ID */
  id: string;
  /** Track title */
  title: string;
  /** Music artist/author */
  author: string;
  /** Album name */
  album: string;
  /** Audio playback URLs */
  playUrl: string[];
  /** Large cover image URLs */
  coverLarge: string[];
  /** Medium cover image URLs */
  coverMedium: string[];
  /** Thumbnail cover image URLs */
  coverThumb: string[];
  /** Track duration in seconds */
  duration: number;
}

Error Handling

The TiktokDL function includes robust error handling for various failure scenarios:

  • Invalid URLs: Returns error status with descriptive message
  • Network failures: Automatic retry mechanism with exponential backoff
  • API rate limiting: Built-in retry logic for temporary API issues
  • Missing content: Graceful handling when video data is unavailable

Common error messages:

  • "Failed to fetch tiktok url. Make sure your tiktok url is correct!"
  • "Failed to fetch tiktok data. Make sure your tiktok url is correct!"

Internal Helper Functions

Core helper functions used internally by the TikTok API module.

/**
 * Parse raw TikTok API response data into structured format
 * @param data - Raw API response from TikTok
 * @returns Parsed content with author and music information
 */
function parseTiktokData(data: any): { content: any; author: AuthorInfo; music: MusicInfo } | { content: null };

/**
 * Generate required parameters for TikTok API requests
 * @param args - Base parameters to extend
 * @returns Complete parameter object with device simulation
 */
function withParams(args: object): TikTokAPIParams;

/**
 * Generate random character string for device identifiers
 * @param char - Character set to choose from
 * @param range - Length of random string
 * @returns Random string of specified length
 */
function randomChar(char: string, range: number): string;

/**
 * Convert duration in seconds to MM:SS format
 * @param duration - Duration in seconds
 * @returns Formatted duration string
 */
function toMinute(duration: number): string;

/**
 * Fetch TikTok data by video ID with retry logic
 * @param ID - TikTok video ID
 * @returns Parsed TikTok content data
 */
async function fetchTiktokData(ID: string): Promise<ParsedTikTokData>;

/**
 * Generate TikTok API endpoint URL
 * @param Params - URL parameters string
 * @returns Complete API endpoint URL
 */
function _tiktokapi(Params: string): string;

interface TikTokAPIParams {
  version_name: string;
  version_code: string;
  build_number: string;
  manifest_version_code: string;
  update_version_code: string;
  openudid: string;
  uuid: string;
  _rticket: number;
  ts: number;
  device_brand: string;
  device_type: string;
  device_platform: string;
  resolution: string;
  dpi: number;
  os_version: string;
  os_api: string;
  carrier_region: string;
  sys_region: string;
  region: string;
  app_name: string;
  app_language: string;
  language: string;
  timezone_name: string;
  timezone_offset: string;
  channel: string;
  ac: string;
  mcc_mnc: string;
  is_my_cn: number;
  aid: number;
  ssmix: string;
  as: string;
  cp: string;
}

interface ParsedTikTokData {
  content: any;
  author: AuthorInfo;
  music: MusicInfo;
}

Internal Implementation Details:

The module uses TikTok's unofficial mobile API endpoint (https://api22-normal-c-useast2a.tiktokv.com/aweme/v1/feed/) and mimics Android app requests with proper headers and parameters. URL processing handles various TikTok URL formats (vm.tiktok.com, vt.tiktok.com, www.tiktok.com) and redirects to extract the video ID for API calls.

The withParams() function generates a complete Android device simulation including:

  • Device specifications (Pixel 4, Android 10)
  • Network information (carrier, region: US)
  • App metadata (trill app, version 1.1.9)
  • Random device identifiers for uniqueness

The fetchTiktokData() function implements infinite retry logic with async-retry for handling API rate limits and temporary failures.

Install with Tessl CLI

npx tessl i tessl/npm-tiktok-src

docs

facebook-upload.md

index.md

telegram-bot.md

tiktok-api.md

video-processing.md

tile.json