Coder Social home page Coder Social logo

tobyg74 / tiktok-api-dl Goto Github PK

View Code? Open in Web Editor NEW
61.0 3.0 16.0 139 KB

Scrapper for download Video, Image, Music from Tiktok

License: Apache License 2.0

TypeScript 100.00%
tiktok tiktok-api tiktok-dl tiktok-downloader tiktok-scraper tiktok-wrap

tiktok-api-dl's Introduction

Tiktok Downloader & Stalk User



Table of Contents

Description

This project uses the Unofficial API from Tiktok.

  • Can be used to download videos, images / slides and music from Tiktok
  • Can be used to view someone's profile from Tiktok
  • No login or password are required
  • It is recommended to use your own cookies on Tiktok Stalker

How to get Tiktok Cookie

You can use cookies in the form of String or JSON

  • Method 1 (String) :

    Login to the Tiktok website -> Open the Inspect Element or you can press the shortcut CTRL + SHIFT + I -> Go to network -> Find the request that goes to tiktok then open the request and look for Cookie

Capture

  • Method 2 (JSON) :

    You can use the chrome extension EditThisCookies -> Login to the Tiktok website -> Then open the EditThisCookie extension -> Then click Export Cookie

Capture2

Build this project

  • Clone the repository
  • Install the dependencies
  • Run the build script
git clone https://github.com/TobyG74/tiktok-api-dl.git
cd tiktok-api-dl
npm install
npm run build

Install

  • This module requires Node.js v10+ to run.

From NPM

npm install @tobyg74/tiktok-api-dl

From YARN

yarn add @tobyg74/tiktok-api-dl

From Github

npm install github:TobyG74/tiktok-api-dl

Examples

Tiktok Downloader

  • V1 uses the API from TiktokAPI
  • V2 uses the API from SSSTik
  • V3 uses the API from MusicalDown

Options

  • version : The version of the downloader you want to use
    • v1 : TiktokAPI
    • v2 : SSSTik
    • v3 : MusicalDown
  • proxy : Proxy for request
const Tiktok = require("@tobyg74/tiktok-api-dl")

const tiktok_url = "https://vt.tiktok.com/ZS84BnrU9"

Tiktok.Downloader(tiktok_url, {
  version: "v1", //  version: "v1" | "v2" | "v3"
  proxy: "YOUR_PROXY" // Support Proxy Http, Https, Socks5
}).then((result) => {
  console.log(result)
})

Tiktok Search

Note : Cookies are required for searching users or live

Options

  • type : The type of search you want to use
    • user : Search User
    • live : Search Live
  • page : The page you want to search
  • cookie : Your Tiktok Cookie
  • proxy : Proxy for request

Search User | Live

const Tiktok = require("@tobyg74/tiktok-api-dl")

const username = "tobz2k19"

Tiktok.Search(username, {
  type: "user" || "live",
  page: 1,
  cookie: process.env.COOKIE || "Your Cookie",
  proxy: "YOUR_PROXY" // Support Proxy Http, Https, Socks5
}).then((result) => {
  console.log(result)
})

Tiktok Stalker

Options

  • cookie : Only needed if you want to get all user posts
  • postLimit : Limit the number of posts to display
  • proxy : Proxy for request
const Tiktok = require("@tobyg74/tiktok-api-dl")

const username = "tobz2k19"

Tiktok.StalkUser(username, {
  cookie: process.env.COOKIE || "Your Cookie"
  postLimit: 10, // Limit the number of posts to display
  proxy: "YOUR_PROXY" // Support Proxy Http, Https, Socks5
}).then((result) => {
  console.log(result)
})

Response


Tiktok Downloader V1
{
  status: "success" | "error"
  message?: string
  result?: {
    type: "video" | "image"
    id: string
    createTime: number
    description: string
    isADS: boolean
    hashtag: string[]
    author: {
      uid: string
      username: string
      nickname: string
      signature: string
      region: string
      avatarLarger: string
      avatarThumb: string
      avatarMedium: string
      url: string
    }
    statistics: {
      playCount: number
      downloadCount: number
      shareCount: number
      commentCount: number
      diggCount: number
      collectCount: number
      forwardCount: number
      whatsappShareCount: number
      loseCount: number
      loseCommentCount: number
      whatsappShareCount: number
      repostCount: number
    }
    video?: {
      ratio: string
      duration: number
      playAddr: string
      downloadAddr: string
      cover: string
      originCover: string
      dynamicCover: string
    }
    images?: string[]
    music: {
      id: number
      title: string
      author: string
      album: string
      playUrl: string[]
      coverLarge: string[]
      coverMedium: string[]
      coverThumb: string[]
      duration: number
      isCommerceMusic: boolean
      isOriginalSound: boolean
      isAuthorArtist: boolean
    }
  }
}
Tiktok Downloader V2
{
  status: "success" | "error"
  message?: string
  result?: {
    type: "video" | "image"
    description: string
    author: {
      nickname: string
      avatr: string
    }
    statistics: {
      likeCount: string
      commentCount: string
      shareCount: string
    }
    video?: string
    images?: string[]
    music: string
  }
}
Tiktok Downloader V3
{
  status: "success" | "error"
  message?: string
  result?: {
    type: "video" | "image"
    desc?: string
    author: {
      avatar?: string
      nickname: string
    }
    music?: string
    images?: string[]
    video1?: string
    video2?: string
    videoHD?: string
    videoWatermark?: string
  }
}
Tiktok Search "User"
{
  status: "success" | "error"
  message?: string
  result?: [{
    uid: string
    username: string
    nickname: string
    signature: string
    followerCount: number
    avatarThumb: string[]
    isVerified: boolean
    secUid: string
    url: string
  }]
}
Tiktok Search "Live"
{
  status: "success" | "error"
  message?: string
  result?: [{
    id: string
    title: string
    cover: string[]
    squareCover: string[]
    rectangleCover: string[]
    liveTypeThirdParty: boolean
    hashtag: string
    startTime: number
    stats: {
      totalUser: number
      viewerCount: number
      likeCount: number
    }
    owner: {
      id: string
      nickname: string
      username: string
      signature: string
      avatarThumb: string[]
      avatarMedium: string[]
      avatarLarge: string[]
      modifyTime: number
      stats: {
        followingCount: number
        followerCount: number
      }
      isVerified: boolean
    }
  }]
}
Tiktok Stalker
{
  status: "success" | "error"
  message?: string
  result?: {
    users: {
      username: string
      nickname: string
      avatar: string
      signature: string
      verified: boolean
      region: string
    }
    stats: {
      followerCount: number
      followingCount: number
      heartCount: number
      videoCount: number
      likeCount: number
    }
    posts: Posts[]
  }
}

Contributing

  • This repository is open source. We really appreciate it if you want to participate in developing this repository...
  • Please read our CONTRIBUTING.md and CODE_OF_CONDUCT.md before contributing.

License

  • This project is licensed under the Apache License - see the LICENSE file for details.

tiktok-api-dl's People

Contributors

3imad69 avatar nugraizy avatar tobyg74 avatar vasolix avatar zennn08 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

tiktok-api-dl's Issues

ERROR Request failed with status code 403

Hi Team,
I got error when using this lib in Nextjs production.

Tiktok.download .... response 403 error:
{ "status": "error", "message": "Request failed with status code 403" }

This error not happen in localhost. only run in server happen.
Please check and help

Result undefined for TiktokStalk

Hey

I'm getting undefined for result in:

TiktokStalk(username).then((result) => {
  console.log(result)
})

cookie or user-agent still valid?

Posts empty in Stalk User

I try get user profile and posts feed with Tiktok.StalkUser();

But why posts return empty array?

And after trying to hit or refresh several times, the posts data will appear.

Is there something wrong? And can you fix it?

And is it possible to add a function to get posts feed by username?

Thank you for this tool!

Error with TiktokStalk

i try this:

const { TiktokStalk } = require("@tobyg74/tiktok-api-dl")

const username = "tobz2k19"

TiktokStalk(username).then((result) => {
  console.log(result)
})

and got this error:

{
  status: 'error',
  message: 'Client network socket disconnected before secure TLS connection was established'
}

Failed to get the request form error on V3 version

Hello author, i was using this API this morning and it was working fine but now when i try to make an request to download music with the V3 version of the API, it gives me an error saying "failed to get the request form error" so is there any suggestions on what the problem could be? I would really appreciate if you resolve this issue, thanks.

My Code:
tt-error

Console Error:
image

Add TikTok "photo" to valid URL

The Tiktok slide URL is marked as an invalid link e.g: https://www.tiktok.com/@binance/photo/7364097008107326763

It might be better to add the "photo" slug to the regex pattern.

Options for TikTokStalk

First of all, thanks for the repo!

Can you give options for the TikTokStalk function so that you can choose how many posts you want to scrape from a user?

And is there a way to get more than 35 Posts?

Not Working on Vercel wIth Next.JS 403 Forbitten

I am trying to build my own downloader. I got error when I sent request on production it doesn't happens on localhost.

You can see my app here: https://tiked.vercel.app

bol(errored)]: null,
    [Symbol(kHighWaterMark)]: 16384,
    [Symbol(kRejectNonStandardBodyWrites)]: false,
    [Symbol(kUniqueHeaders)]: null
  },
  response: {
    status: 403,
    statusText: 'Forbidden',
    headers: Object [AxiosHeaders] {
      server: 'nginx',
      'content-length': '0',
      'x-tt-system-error': '3',
      'proxy-status': '0000201403061000',
      'x-tt-trace-host': '01e11b73288eb114e390b13e0c7561618a4a1dba3aca6ecb8cc2669793af26e8d40bdb891b3e290b2ebc614e9db09a694a251d8f0225f1b2425979878fb12ff181f96bf1d85c9333078276aa27df7569a4',
      'x-tt-logid': '202309121400226B84A888AE8572102683',
      expires: 'Tue, 12 Sep 2023 14:00:22 GMT',
      'cache-control': 'max-age=0, no-cache, no-store',
      pragma: 'no-cache',
      date: 'Tue, 12 Sep 2023 14:00:22 GMT',
      'x-cache': 'TCP_MISS from a23-202-158-7.deploy.akamaitechnologies.com (AkamaiGHost/11.2.4-50766152) (-)',
      connection: 'close',
      'x-tt-trace-tag': 'id=16;cdn-cache=miss;type=dyn',
      'server-timing': 'cdn-cache; desc=MISS, edge; dur=1, origin; dur=7',
      'x-origin-response-time': '7,23.202.158.7',
      'x-akamai-request-id': 'a33467cc'
    },
    config: {
      transitional: [Object],
      adapter: 'http',
      transformRequest: [Array],
      transformResponse: [Array],
      timeout: 0,
      xsrfCookieName: 'XSRF-TOKEN',
      xsrfHeaderName: 'X-XSRF-TOKEN',
      maxContentLength: -1,
      maxBodyLength: -1,
      env: [Object],
      validateStatus: [Function: validateStatus],
      headers: [Object [AxiosHeaders]],
      method: 'head',
      url: 'https://www.tiktok.com/@yunsdespise/video/7226365854097706282?q=image%20slideshow&t=1694233131390',
      data: undefined
    },
    request: <ref *1> ClientRequest {
      _events: [Object: null prototype],
      _eventsCount: 7,
      _maxListeners: undefined,
      outputData: [],
      outputSize: 0,
      writable: true,
      destroyed: false,
      _last: true,
      chunkedEncoding: false,
      shouldKeepAlive: false,
      maxRequestsOnConnectionReached: false,
      _defaultKeepAlive: true,
      useChunkedEncodingByDefault: false,
      sendDate: false,
      _removedConnection: false,
      _removedContLen: false,
      _removedTE: false,
      strictContentLength: false,
      _contentLength: 0,
      _hasBody: true,
      _trailer: '',
      finished: true,
      _headerSent: true,
      _closed: false,
      socket: [TLSSocket],
      _header: 'HEAD /@yunsdespise/video/7226365854097706282?q=image%20slideshow&t=1694233131390 HTTP/1.1\r\n' +
        'Accept: application/json, text/plain, */*\r\n' +
        'User-Agent: axios/1.5.0\r\n' +
        'Accept-Encoding: gzip, compress, deflate, br\r\n' +
        'x-vercel-id: sin1::ztbqx-1694527220519-699460779dbb\r\n' +
        'Host: www.tiktok.com\r\n' +
        'Connection: close\r\n' +
        '\r\n',
      _keepAliveTimeout: 0,
      _onPendingData: [Function: nop],
      agent: [Agent],
      socketPath: undefined,
      method: 'HEAD',
      maxHeaderSize: undefined,
      insecureHTTPParser: undefined,
      joinDuplicateHeaders: undefined,
      path: '/@yunsdespise/video/7226365854097706282?q=image%20slideshow&t=1694233131390',
      _ended: true,
      res: [IncomingMessage],
      aborted: false,
      timeoutCb: null,
      upgradeOrConnect: false,
      parser: null,
      maxHeadersCount: null,
      reusedSocket: false,
      host: 'www.tiktok.com',
      protocol: 'https:',
      _redirectable: [Writable],
      [Symbol(kCapture)]: false,
      [Symbol(kBytesWritten)]: 0,
      [Symbol(kNeedDrain)]: false,
      [Symbol(corked)]: 0,
      [Symbol(kOutHeaders)]: [Object: null prototype],
      [Symbol(errored)]: null,
      [Symbol(kHighWaterMark)]: 16384,
      [Symbol(kRejectNonStandardBodyWrites)]: false,
      [Symbol(kUniqueHeaders)]: null
    },
    data: ''
  }
}

"Cannot read property 'responseUrl' of undefined"

I am attempting to create a TikTok video downloader using your library. The route.params.video_url is set to https://www.tiktok.com/@devslopes/video/7276699914241985835?is_from_webapp=1&sender_device=pc.

The issue I'm encountering only occurs when I execute the function in a React Native app. It does not occur when I run a script like node index.js. Below are the code examples for both scenarios:

Node.js Script:

const TiktokDL = require("@tobyg74/tiktok-api-dl");

TiktokDL("https://www.tiktok.com/@devslopes/video/7276699914241985835?is_from_webapp=1&sender_device=pc").then((result) => {
    console.log(result);
});

React Native Code:

import { Dimensions, View, Image } from 'react-native';
import { ActivityIndicator, Text } from 'react-native-paper';
import { useEffect, useState } from 'react';
import { DLResult } from '@tobyg74/tiktok-api-dl/lib/types';
import { TiktokDL } from '@tobyg74/tiktok-api-dl';

export default function ({ route, navigation }: any) {
    const [isLoading, setIsLoading] = useState<boolean>(true);
    const [data, setData] = useState<DLResult | null | void>(null);

    useEffect(() => {
        TiktokDL(route.params.video_url).then((result) => {
            setIsLoading(false);
            setData(result);
            console.log(result);
        });
    }, []);

    return (
        <View style={{
            height: Dimensions.get("window").height,
            backgroundColor: "#15131A"
        }}>
            <View style={{
                marginTop: 30,
                padding: 20
            }}>
                {isLoading ? <ActivityIndicator size={"large"} /> : null}
                {!isLoading && data && data.result != null ? (
                    <>
                        <View>
                            <View style={{
                                display: "flex",
                                flexDirection: "row",
                                justifyContent: "space-between",
                                alignItems: "center"
                            }}>
                                <View>
                                    <Image
                                        source={{
                                            uri: data.result.cover?.toString()
                                        }}
                                    />
                                </View>
                                <Text style={{ color: "#fff" }}>{data.result.description}</Text>
                            </View>
                        </View>
                    </>
                ) : null}
                {data?.status == "error" && (
                    <Text style={{ color: "red", fontSize: 16 }}>{data?.message}</Text>
                )}
            </View>
        </View>
    );
}

The issue I'm facing is titled "Cannot read property 'responseUrl' of undefined."

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.