tiktok-api-dl

repository·master·Indexed 42 days ago

https://github.com/tobyg74/tiktok-api-dl

A TikTok downloader and scraping tool (v1.3.8) for downloading videos, images, and audio. It provides a Node.js API and a `tiktokdl` CLI to retrieve user posts, likes, comments, followers, trending content, and music details. Features include support for proxies, collection and playlist retrieval, and user profile 'stalking'.

Tokens
27.4K
Snippets
90
Records
92
Agent score
54%

What's inside tiktok-api-dl

  1. Install @tobyg74/tiktok-api-dl

    master

    You can install the library using various package managers or an automated installation script.

    Using NPM

    npm install @tobyg74/tiktok-api-dl

    Using Yarn

    yarn add @tobyg74/tiktok-api-dl

    Using Github

    npm install github:TobyG74/tiktok-api-dl

    Automated Installation Script

    Run the following commands to verify Node.js and install the library automatically:

    curl -o install.sh https://raw.githubusercontent.com/TobyG74/tiktok-api-dl/master/install.sh
    chmod +x install.sh
    ./install.sh
  2. Install and use the tiktokdl CLI

    master

    The tiktokdl CLI tool allows you to interact with the API from your terminal.

    Global Installation

    npm install -g @tobyg74/tiktok-api-dl

    Direct Usage (without global install)

    If you have cloned the repository, you can run it using npx:

    npx ts-node src/cli/index.ts [command] [options]

    NPM Script

    npm run cli [command] [options]
  3. Get Music Details and Download Audio

    master

    Retrieve detailed information about a music track or download the audio file. This feature requires TikTok cookie authentication.

    1. Open TikTok in your browser and login.
    2. Open DevTools (F12).
    3. Go to Application/Storage > Cookies.
    4. Copy the entire cookie value.
    5. Set it in the CLI using: tiktokdl cookie set "YOUR_COOKIE".

    Node.js API

    Use Tiktok.GetMusicDetail(idOrUrl, options).

    Options:

    • cookie (string, required): Your TikTok cookie.
    • proxy (string, optional): Proxy URL.

    CLI Usage

    Note: You must set your cookie first using tiktokdl cookie set <value>.

    Get Music Details:

    # Get music detail by ID
    tiktokdl getmusicdetail 7562597337407785760
    
    # Get music detail by URL
    tiktokdl getmusicdetail "https://www.tiktok.com/music/QKThr-6771810675950880769"
    
    # Get music detail with proxy
    tiktokdl getmusicdetail 7562597337407785760 --proxy "http://your-proxy-url"
    
    # Get raw JSON response
    tiktokdl getmusicdetail 7562597337407785760 -r

    Download Music/Audio:

    # Download by music ID
    tiktokdl downloadmusic 7562597337407785760
    
    # Download by music URL
    tiktokdl downloadmusic "https://www.tiktok.com/music/QKThr-6771810675950880769"
    
    # Custom output directory
    tiktokdl downloadmusic 7562597337407785760 -o "./my-music"
    
    # With proxy
    tiktokdl downloadmusic 7562597337407785760 --proxy "http://your-proxy-url"
    const Tiktok = require("@tobyg74/tiktok-api-dl")
    
    // Using music ID
    const musicId = "7562597337407785760"
    Tiktok.GetMusicDetail(musicId, {
      cookie: "YOUR_COOKIE", // required
      proxy: "YOUR_PROXY" // optional
    }).then((result) => console.log(result))
    
    // Or using music URL
    const musicUrl = "https://www.tiktok.com/music/QKThr-6771810675950880769"
    Tiktok.GetMusicDetail(musicUrl, {
      cookie: "YOUR_COOKIE"
    }).then((result) => console.log(result))
  4. Manage Tiktok cookies via CLI

    master

    Use the cookie command to manage your session cookies for the CLI:

    # Set Tiktok Cookie
    tiktokdl cookie set "YOUR_COOKIE"
    
    # Get current Tiktok Cookie
    tiktokdl cookie get
    
    # Delete Tiktok Cookie
    tiktokdl cookie delete
    tiktokdl cookie set "YOUR_COOKIE"
  5. Use Tiktok.StalkUser() to view profiles

    master

    Retrieve detailed information about a Tiktok user's profile.

    Options:

    • proxy: (optional) Proxy URL

    CLI Usage:

    • tiktokdl stalk <username>
    const Tiktok = require("@tobyg74/tiktok-api-dl")
    
    const username = "Tobz2k19"
    Tiktok.StalkUser(username, {
      proxy: "YOUR_PROXY" // optional
    }).then((result) => console.log(result))
  6. Get Videos by Music ID or URL

    master

    Retrieve videos that use a specific music/audio track by providing the music ID or URL.

    Node.js API

    Use Tiktok.GetVideosByMusicId(idOrUrl, options).

    Options:

    • page (number, optional): Page number. Default is 1.
    • count (number, optional): Number of videos. Default is 30.
    • proxy (string, optional): Proxy URL.

    CLI Usage

    # Get videos by music ID
    tiktokdl getmusicvideos 7034143722082192134
    
    # Get videos by music URL
    tiktokdl getmusicvideos "https://www.tiktok.com/music/QKThr-6771810675950880769"
    
    # Get videos by music ID with page and count
    tiktokdl getmusicvideos 7034143722082192134 -p 1 -c 20
    
    # Get videos by music ID with proxy
    tiktokdl getmusicvideos 7034143722082192134 -p 1 -c 20 --proxy "http://your-proxy-url"
    
    # Get raw JSON response
    tiktokdl getmusicvideos 7034143722082192134 -r
    const Tiktok = require("@tobyg74/tiktok-api-dl")
    
    // Using music ID
    const musicId = "7034143722082192134"
    Tiktok.GetVideosByMusicId(musicId, {
      page: 1, // optional, default is 1
      count: 30, // optional, default is 30
      proxy: "YOUR_PROXY" // optional
    }).then((result) => console.log(result))
    
    // Or using music URL
    const musicUrl = "https://www.tiktok.com/music/QKThr-6771810675950880769"
    Tiktok.GetVideosByMusicId(musicUrl, {
      page: 1,
      count: 30
    }).then((result) => console.log(result))
  7. Get User Liked Videos

    master

    Retrieve a user's liked videos. Note: This feature requires valid TikTok cookies to access the user's private liked content.

    Node.js API

    Use Tiktok.GetUserLiked(username, options).

    Options:

    • postLimit (number, optional): Number of posts to retrieve. Default is 30.
    • cookie (string, required): Your TikTok cookie.
    • proxy (string, optional): Proxy URL.

    CLI Usage

    # Get User Liked Videos
    tiktokdl getuserliked <username>
    
    # Get User Liked Videos with limit of posts
    tiktokdl getuserliked <username> -l 10
    
    # Get User Liked Videos with proxy
    tiktokdl getuserliked <username> -l 10 -proxy "http://your-proxy-url"
    const Tiktok = require("@tobyg74/tiktok-api-dl")
    
    const username = "Tobz2k19"
    Tiktok.GetUserLiked(username, {
      postLimit: 10, // optional, default is 30
      cookie: "YOUR_COOKIE", // needed
      proxy: "YOUR_PROXY" // optional
    })
  8. Use Tiktok.GetUserPosts() and GetUserReposts()

    master

    Fetch a user's posts or reposts.

    Options for both:

    • postLimit: (optional) Number of items to fetch, default is 30
    • proxy: (optional) Proxy URL

    CLI Usage:

    • tiktokdl getuserposts <username>
    • tiktokdl getuserreposts <username>
    const Tiktok = require("@tobyg74/tiktok-api-dl")
    
    const username = "Tobz2k19"
    Tiktok.GetUserPosts(username, {
      postLimit: 10, // optional, default is 30
      proxy: "YOUR_PROXY" // optional
    }).then((result) => console.log(result))
  9. Get Trending Content and Creators

    master

    Retrieve trending content or trending creators from TikTok's discovery/explore page.

    Node.js API

    • Tiktok.Trending(options): Returns full trending content data.
    • Tiktok.TrendingCreators(options): Returns simplified trending creator data.

    Options:

    • proxy (string, optional): Proxy URL.

    CLI Usage

    # Get trending content
    tiktokdl trending
    
    # Get trending creators only
    tiktokdl trending-creators
    
    # With proxy
    tiktokdl trending -proxy "http://your-proxy-url"
    tiktokdl trending-creators -proxy "http://your-proxy-url"
    const Tiktok = require("@tobyg74/tiktok-api-dl")
    
    // Get all trending content (full data structure)
    Tiktok.Trending({
      proxy: "YOUR_PROXY" // optional
    }).then((result) => console.log(result))
    
    // Get trending creators only (simplified data)
    Tiktok.TrendingCreators({
      proxy: "YOUR_PROXY" // optional
    }).then((result) => console.log(result))
  10. Use Tiktok.Downloader() to download media

    master

    Download Tiktok videos, images/slides, or music using the Downloader method.

    Options:

    • version: "v1" | "v2" | "v3"
    • proxy: (optional) Proxy URL
    • showOriginalResponse: (optional, v1 only) boolean

    CLI Usage:

    • tiktokdl download <url>
    • tiktokdl download <url> -v <version>
    • tiktokdl download <url> -o <output_path>
    • tiktokdl download <url> -proxy <proxy_url>
    • tiktokdl download <collection_or_playlist_url> -c <count>
    const Tiktok = require("@tobyg74/tiktok-api-dl")
    
    const url = "https://vt.tiktok.com/xxxxxxxx"
    Tiktok.Downloader(url, {
      version: "v1", // "v1" | "v2" | "v3"
      proxy: "YOUR_PROXY", // optional
      showOriginalResponse: true // optional, v1 only
    }).then((result) => console.log(result))
  11. Use Tiktok.GetVideoComments() to fetch comments

    master

    Retrieve comments from a specific Tiktok video.

    Options:

    • commentLimit: (optional) Number of comments to fetch, default is 30
    • proxy: (optional) Proxy URL

    CLI Usage:

    • tiktokdl getvideocomments <url>
    • tiktokdl getvideocomments <url> -l <limit>
    const Tiktok = require("@tobyg74/tiktok-api-dl")
    
    const url = "https://vt.tiktok.com/xxxxxxxx"
    Tiktok.GetVideoComments(url, {
      commentLimit: 10, // optional, default is 30
      proxy: "YOUR_PROXY" // optional
    }).then((result) => console.log(result))