New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@tobyg74/tiktok-api-dl

Package Overview
Dependencies
Maintainers
1
Versions
35
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@tobyg74/tiktok-api-dl - npm Package Compare versions

Comparing version 1.0.16 to 1.1.0

lib/constants/api.d.ts

22

lib/index.d.ts

@@ -1,2 +0,20 @@

export * from "./utils/downloader/tiktok_downloader";
export * from "./utils/stalker/tiktok_stalker";
import { MusicalDownResponse } from "./types/downloader/musicaldown";
import { SSSTikResponse } from "./types/downloader/ssstik";
import { TiktokAPIResponse } from "./types/downloader/tiktokApi";
import { TiktokUserSearchResponse } from "./types/search/userSearch";
import { StalkResult } from "./types/search/stalker";
type TiktokDownloaderResponse<T extends "v1" | "v2" | "v3"> = T extends "v1" ? TiktokAPIResponse : T extends "v2" ? SSSTikResponse : T extends "v3" ? MusicalDownResponse : TiktokAPIResponse;
type TiktokSearchResponse<T extends "user" | "video"> = T extends "user" ? TiktokUserSearchResponse : T extends "video" ? any : TiktokUserSearchResponse;
export declare const Tiktok: {
Downloader: <T extends "v1" | "v2" | "v3">(url: string, options?: {
version: T;
}) => Promise<TiktokDownloaderResponse<T>>;
Search: <T_1 extends "video" | "user">(query: string, options: {
type: T_1;
cookie: string;
}) => Promise<TiktokSearchResponse<T_1>>;
StalkUser: (username: string, options: {
cookie: string;
}) => Promise<StalkResult>;
};
export default Tiktok;

59

lib/index.js
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
Object.defineProperty(exports, "__esModule", { value: true });
exports.Tiktok = void 0;
const downloader_musicaldown_1 = require("./utils/downloader/downloader_musicaldown");
const downloader_ssstik_1 = require("./utils/downloader/downloader_ssstik");
const downloader_tiktokApi_1 = require("./utils/downloader/downloader_tiktokApi");
const tiktok_stalker_1 = require("./utils/search/tiktok_stalker");
const tiktok_user_search_1 = require("./utils/search/tiktok_user_search");
exports.Tiktok = {
Downloader: async (url, options) => {
switch (options?.version) {
case "v1": {
const response = await (0, downloader_tiktokApi_1.TiktokAPI)(url);
return response;
}
case "v2": {
const response = await (0, downloader_ssstik_1.SSSTik)(url);
return response;
}
case "v3": {
const response = await (0, downloader_musicaldown_1.MusicalDown)(url);
return response;
}
default: {
const response = await (0, downloader_tiktokApi_1.TiktokAPI)(url);
return response;
}
}
},
Search: async (query, options) => {
switch (options?.type) {
case "user": {
const response = await (0, tiktok_user_search_1.SearchUser)(query, options.cookie);
return response;
}
default: {
const response = await (0, tiktok_user_search_1.SearchUser)(query, options?.cookie);
return response;
}
}
},
StalkUser: async (username, options) => {
const response = await (0, tiktok_stalker_1.StalkUser)(username, options.cookie);
return response;
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
Object.defineProperty(exports, "__esModule", { value: true });
__exportStar(require("./utils/downloader/tiktok_downloader"), exports);
__exportStar(require("./utils/stalker/tiktok_stalker"), exports);
exports.default = exports.Tiktok;

@@ -1,2 +0,2 @@

import { MusicalDownResponse } from "../../types/musicaldown";
import { MusicalDownResponse } from "../../types/downloader/musicaldown";
export declare const MusicalDown: (url: string) => Promise<MusicalDownResponse>;

@@ -9,4 +9,11 @@ "use strict";

const cheerio_1 = require("cheerio");
const api_1 = require("../../api");
const api_1 = require("../../constants/api");
const TiktokURLregex = /(?:http[s]?:\/\/)?(?:www\.|m\.)?(?:tiktok\.com\/(?:@[\w.-]+\/video\/|@[\w.-]+\/video\/))?(\d+)/;
const getRequest = (url) => new Promise((resolve, reject) => {
if (!TiktokURLregex.test(url)) {
return resolve({
status: "error",
message: "Invalid Tiktok URL. Make sure your url is correct!"
});
}
axios_1.default.get(api_1._musicaldownurl, {

@@ -13,0 +20,0 @@ headers: {

@@ -1,2 +0,2 @@

import { SSSTikResponse } from "../../types/ssstik";
import { SSSTikResponse } from "../../types/downloader/ssstik";
export declare const SSSTik: (url: string) => Promise<SSSTikResponse>;

@@ -9,3 +9,4 @@ "use strict";

const cheerio_1 = require("cheerio");
const api_1 = require("../../api");
const api_1 = require("../../constants/api");
const TiktokURLregex = /(?:http[s]?:\/\/)?(?:www\.|m\.)?(?:tiktok\.com\/(?:@[\w.-]+\/video\/|@[\w.-]+\/video\/))?(\d+)/;
const fetchTT = () => new Promise(async (resolve, reject) => {

@@ -31,2 +32,8 @@ axios_1.default.get(api_1._ssstikurl, {

const SSSTik = (url) => new Promise(async (resolve, reject) => {
if (!TiktokURLregex.test(url)) {
return resolve({
status: "error",
message: "Invalid Tiktok URL. Make sure your url is correct!"
});
}
const tt = await fetchTT();

@@ -33,0 +40,0 @@ if (tt.status !== "success")

@@ -1,2 +0,2 @@

import { TiktokAPIResponse } from "../../types/tiktokApi";
import { TiktokAPIResponse } from "../../types/downloader/tiktokApi";
export declare const TiktokAPI: (url: string) => Promise<TiktokAPIResponse>;

@@ -8,8 +8,14 @@ "use strict";

const axios_1 = __importDefault(require("axios"));
const async_retry_1 = __importDefault(require("async-retry"));
const api_1 = require("../../api");
const api_1 = require("../../constants/api");
const params_1 = require("../../constants/params");
const TiktokURLregex = /(?:http[s]?:\/\/)?(?:www\.|m\.)?(?:tiktok\.com\/(?:@[\w.-]+\/video\/|@[\w.-]+\/video\/))?(\d+)/;
const TiktokAPI = (url) => new Promise((resolve, reject) => {
if (!TiktokURLregex.test(url)) {
return resolve({
status: "error",
message: "Invalid Tiktok URL. Make sure your url is correct!"
});
}
url = url.replace("https://vm", "https://vt");
axios_1.default
.head(url)
axios_1.default.head(url)
.then(async ({ request }) => {

@@ -25,3 +31,3 @@ const { responseUrl } = request.res;

let data2 = await fetchTiktokData(ID);
if (!data2.content) {
if (!data2?.content) {
return resolve({

@@ -42,2 +48,3 @@ status: "error",

hashtag: content.text_extra.filter((x) => x.hashtag_name !== undefined).map((v) => v.hashtag_name),
isADS: content.is_ads,
author,

@@ -51,2 +58,11 @@ statistics,

else {
const video = {
ratio: content.video.ratio,
duration: content.video.duration,
playAddr: content.video.play_addr.url_list,
downloadAddr: content.video.download_addr.url_list,
cover: content.video.cover.url_list,
dynamicCover: content.video.dynamic_cover.url_list,
originCover: content.video.origin_cover.url_list
};
resolve({

@@ -60,9 +76,6 @@ status: "success",

hashtag: content.text_extra.filter((x) => x.hashtag_name !== undefined).map((v) => v.hashtag_name),
duration: toMinute(content.duration),
isADS: content.is_ads,
author,
statistics,
video: content.video.play_addr.url_list,
cover: content.video.cover.url_list,
dynamicCover: content.video.dynamic_cover.url_list,
originCover: content.video.origin_cover.url_list,
video,
music

@@ -77,39 +90,35 @@ }

const fetchTiktokData = async (ID) => {
let data2;
await (0, async_retry_1.default)(async () => {
const res = await fetch((0, api_1._tiktokapi)(new URLSearchParams(withParams({
aweme_id: ID
})).toString()), {
method: "GET",
headers: {
"User-Agent": "com.ss.android.ugc.trill/494+Mozilla/5.0+(Linux;+Android+12;+2112123G+Build/SKQ1.211006.001;+wv)+AppleWebKit/537.36+(KHTML,+like+Gecko)+Version/4.0+Chrome/107.0.5304.105+Mobile+Safari/537.36"
}
});
if (res.headers.get("content-length") !== "0") {
const data = await res.json();
if (data) {
data2 = parseTiktokData(data);
return;
}
const res = await fetch((0, api_1._tiktokapi)(new URLSearchParams((0, params_1._tiktokApiParams)({
aweme_id: ID
})).toString()), {
method: "GET",
headers: {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.114 Safari/537.36"
}
throw new Error("Data is empty!");
}, { forever: true, minTimeout: 0, maxTimeout: 0 });
return data2;
});
if (res.headers.get("content-length") !== "0") {
const data = await res.json();
if (data) {
return parseTiktokData(ID, data);
}
}
return null;
};
const parseTiktokData = (data) => {
const parseTiktokData = (ID, data) => {
let content = data?.aweme_list;
if (!content)
return { content: null };
content = content[0];
content = content.find((v) => v.aweme_id === ID);
const statistics = {
commentCount: content.statistics.comment_count,
diggCount: content.statistics.digg_count,
downloadCount: content.statistics.download_count,
playCount: content.statistics.play_count,
downloadCount: content.statistics.download_count,
shareCount: content.statistics.share_count,
commentCount: content.statistics.comment_count,
likeCount: content.statistics.digg_count,
favoriteCount: content.statistics.collect_count,
forwardCount: content.statistics.forward_count,
loseCount: content.statistics.lose_count,
loseCommentCount: content.statistics.lose_comment_count,
whatsappShareCount: content.statistics.whatsapp_share_count,
loseCount: content.statistics.lose_count,
loseCommentCount: content.statistics.lose_comment_count
collectCount: content.statistics.collect_count,
repostCount: content.statistics.repost_count
};

@@ -135,57 +144,8 @@ const author = {

coverThumb: content.music.cover_thumb.url_list,
duration: content.music.duration
duration: content.music.duration,
isCommerceMusic: content.music.is_commerce_music,
isOriginalSound: content.music.is_original_sound,
isAuthorArtist: content.music.is_author_artist
};
return { content, statistics, author, music };
};
const withParams = (args) => {
return {
...args,
version_name: "1.1.9",
version_code: "2018111632",
build_number: "1.1.9",
manifest_version_code: "2018111632",
update_version_code: "2018111632",
openudid: randomChar("0123456789abcdef", 16),
uuid: randomChar("1234567890", 16),
_rticket: Date.now() * 1000,
ts: Date.now(),
device_brand: "Google",
device_type: "Pixel 4",
device_platform: "android",
resolution: "1080*1920",
dpi: 420,
os_version: "10",
os_api: "29",
carrier_region: "US",
sys_region: "US",
region: "US",
app_name: "trill",
app_language: "en",
language: "en",
timezone_name: "America/New_York",
timezone_offset: "-14400",
channel: "googleplay",
ac: "wifi",
mcc_mnc: "310260",
is_my_cn: 0,
aid: 1180,
ssmix: "a",
as: "a1qwert123",
cp: "cbfhckdckkde1"
};
};
const toMinute = (duration) => {
const mins = ~~((duration % 3600) / 60);
const secs = ~~duration % 60;
let ret = "";
ret += "" + mins + ":" + (secs < 10 ? "0" : "");
ret += "" + secs;
return ret;
};
const randomChar = (char, range) => {
let chars = "";
for (let i = 0; i < range; i++) {
chars += char[Math.floor(Math.random() * char.length)];
}
return chars;
};
{
"name": "@tobyg74/tiktok-api-dl",
"version": "1.0.16",
"version": "1.1.0",
"description": "Scraper for downloading media in the form of videos, images and audio from Tiktok. Also for stalking Tiktok Users",

@@ -36,6 +36,6 @@ "main": "lib/index.js",

"dependencies": {
"async-retry": "^1.3.3",
"axios": "^1.3.4",
"cheerio": "^1.0.0-rc.12",
"node-fetch": "^3.3.2"
"crypto-js": "^4.2.0",
"qs": "^6.12.0"
},

@@ -42,0 +42,0 @@ "devDependencies": {

@@ -28,2 +28,3 @@ <h1 align="center">

- [Tiktok Downloader](#tiktok-downloader)
- [Tiktok Search](#tiktok-search)
- [Tiktok Stalker](#tiktok-stalker)

@@ -82,7 +83,7 @@ - [Response](#response)

```js
const { TiktokDownloader } = require("@tobyg74/tiktok-api-dl")
const { default: Tiktok } = require("@tobyg74/tiktok-api-dl")
const tiktok_url = "https://vt.tiktok.com/ZS84BnrU9"
TiktokDownloader(tiktok_url, {
Tiktok.Downloader(tiktok_url, {
version: "v1" // version: "v1" | "v2" | "v3"

@@ -94,12 +95,17 @@ }).then((result) => {

## Tiktok Stalker
## Tiktok Search
- Using Default Cookies
### Search User
- Using Your Cookie
```js
const { TiktokStalk } = require("@tobyg74/tiktok-api-dl")
const { default: Tiktok } = require("@tobyg74/tiktok-api-dl")
const username = "tobz2k19"
TiktokStalk(username).then((result) => {
Tiktok.Search(username, {
type: "user",
cookie: process.env.COOKIE || "Your Cookie"
}).then((result) => {
console.log(result)

@@ -109,10 +115,12 @@ })

- Using Your Cookies
## Tiktok Stalker
- Using Your Cookie
```js
const { TiktokStalk } = require("@tobyg74/tiktok-api-dl")
const { default: Tiktok } = require("@tobyg74/tiktok-api-dl")
const username = "tobz2k19"
TiktokStalk(username, {
Tiktok.StalkUser(username, {
cookie: process.env.COOKIE || "Your Cookie"

@@ -140,3 +148,3 @@ }).then((result) => {

description: string
duration?: string
isADS: boolean
hashtag: string[]

@@ -159,3 +167,3 @@ author: {

commentCount: number
likeCount: number
diggCount: number
favoriteCount: number

@@ -166,7 +174,14 @@ forwardCount: number

loseCommentCount: number
whatsappShareCount: number
repostCount: number
}
video?: string[]
cover?: string[]
dynamicCover?: string[]
originCover: string[]
video?: {
ratio: string
duration: number
playAddr: string
downloadAddr: string
cover: string
originCover: string
dynamicCover: string
}
images?: string[]

@@ -183,2 +198,5 @@ music: {

duration: number
isCommerceMusic: boolean
isOriginalSound: boolean
isAuthorArtist: boolean
}

@@ -245,2 +263,25 @@ }

<details>
<summary><b>Tiktok Search "User"</b></summary>
<br>
```ts
[{
status: "success" | "error"
message?: string
result?: {
uid: string
username: string
nickname: string
signature: string
followerCount: number
avatarThumb: string[]
isVerified: boolean
secUid: string
url: string
}
}]
```
</details>
<details>
<summary><b>Tiktok Stalker</b></summary>

@@ -269,2 +310,3 @@ <br>

}
posts: Posts[]
}

@@ -271,0 +313,0 @@ }

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc