added view tiktok profile

This commit is contained in:
TobyG74 2023-04-03 21:16:11 +07:00
parent e683e6fc62
commit 1d29989363
6 changed files with 158 additions and 56 deletions

1
.gitignore vendored
View File

@ -1,4 +1,3 @@
.npmignore
node_modules
yarn-lock.json
package-lock.json

4
.npmignore Normal file
View File

@ -0,0 +1,4 @@
node_modules
yarn-lock.json
package-lock.json
.gitignore

View File

@ -21,6 +21,8 @@ yarn add @tobyg74/tiktok-api-dl
## Usage
### Tiktok Downloader
```
const { TiktokDL } = require("@tobyg74/tiktok-api-dl");
@ -32,7 +34,20 @@ TiktokDL(tiktok_url)
})
```
## Response
### Tiktok Profile
const { TiktokStalk } = require("@tobyg74/tiktok-api-dl");
const username = "tobz2k19"
```
TiktokStalk(username)
.then((result) => {
console.log(result);
})
```
## Tiktok Downloader Response
```
{
@ -57,3 +72,28 @@ TiktokDL(tiktok_url)
}
}
```
## Tiktok Profile Response
```
{
status: "success",
result: {
users: {
username: ...,
nickname: ...,
avatar: ...,
signature: ...,
verified: ...,
region: ...
},
stats: {
followerCount: ...,
followingCount: ...,
heartCount: ...,
videoCount: ...,
likeCount: ...
}
}
}
```

View File

@ -1,3 +1,3 @@
const { TiktokDL } = require("./utils");
const { TiktokDL, TiktokStalk } = require("./utils");
module.exports = { TiktokDL }
module.exports = { TiktokDL, TiktokStalk };

View File

@ -1,30 +1,30 @@
{
"name": "@tobyg74/tiktok-api-dl",
"version": "1.0.1-fix",
"description": "Scrapper for download Video, Image, Music from Tiktok",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git+https://github.com/TobyG74/tiktok-api-dl.git"
},
"keywords": [
"tiktok-api",
"tiktok-downloader",
"tiktok-dl",
"tiktok-nowatermark",
"tiktok"
],
"author": "Tobz",
"license": "ISC",
"bugs": {
"url": "https://github.com/TobyG74/tiktok-api-dl/issues"
},
"homepage": "https://github.com/TobyG74/tiktok-api-dl#readme",
"dependencies": {
"axios": "^1.3.4"
},
"devDependencies": {}
"name": "@tobyg74/tiktok-api-dl",
"version": "1.0.2",
"description": "Scrapper for download Video, Image, Music from Tiktok",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git+https://github.com/TobyG74/tiktok-api-dl.git"
},
"keywords": [
"tiktok-api",
"tiktok-downloader",
"tiktok-dl",
"tiktok-nowatermark",
"tiktok"
],
"author": "Tobz",
"license": "ISC",
"bugs": {
"url": "https://github.com/TobyG74/tiktok-api-dl/issues"
},
"homepage": "https://github.com/TobyG74/tiktok-api-dl#readme",
"dependencies": {
"axios": "^1.3.4",
"cheerio": "^1.0.0-rc.12"
}
}

View File

@ -1,5 +1,7 @@
const Axios = require("axios");
const cheerio = require("cheerio");
const _tiktokurl = "https://www.tiktok.com";
const _tiktokapi = (id) =>
`https://api16-va.tiktokv.com/aweme/v1/feed/?aweme_id=${id}&version_name=1.1.9&version_code=119&build_number=1.1.9&manifest_version_code=119&update_version_code=119&openudid=dlcrw3zg28ajm4ml&uuid=3703699664470627&_rticket=1677813932976&ts=1677813932&device_brand=Realme&device_type=RMX1821&device_platform=android&resolution=720*1370&dpi=320&os_version=11&os_api=30&carrier_region=US&sys_region=US%C2%AEion=US&app_name=TK%20Downloader&app_language=en&language=en&timezone_name=Western%20Indonesia%20Time&timezone_offset=25200&channel=googleplay&ac=wifi&mcc_mnc=&is_my_cn=0&aid=1180&ssmix=a&as=a1qwert123`;
@ -11,36 +13,40 @@ const TiktokDL = (url) => {
})
.then(({ request }) => {
const { responseUrl } = request.res;
let ID = responseUrl.match(/\d{17,21}/g)
if (ID === null) return reject({
status: "error",
message: "Failed to fetch tiktok url. Make sure your tiktok url is correct!",
});
ID = ID[0]
let ID = responseUrl.match(/\d{17,21}/g);
if (ID === null)
return reject({
status: "error",
message:
"Failed to fetch tiktok url. Make sure your tiktok url is correct!",
});
ID = ID[0];
Axios(_tiktokapi(ID), {
method: "GET",
})
.then(({ data }) => {
const content = data.aweme_list.filter((v) => v.aweme_id === ID)[0];
if (!content) return resolve({
status: "error",
message: "Failed to find tiktok data. Make sure your tiktok url is correct!",
});
if (!content)
return resolve({
status: "error",
message:
"Failed to find tiktok data. Make sure your tiktok url is correct!",
});
const statistics = {
play_count: content.statistics.play_count,
download_count: content.statistics.download_count,
share_count: content.statistics.share_count,
comment_count: content.statistics.comment_count,
like_count: content.statistics.digg_count,
favourite_count: content.statistics.collect_count
}
favourite_count: content.statistics.collect_count,
};
const author = {
username: content.author.unique_id,
nickname: content.author.nickname,
signature: content.author.signature,
birthday: content.author.birthday,
region: content.author.region
}
region: content.author.region,
};
if (content.image_post_info) {
resolve({
status: "success",
@ -51,10 +57,12 @@ const TiktokDL = (url) => {
description: content.desc,
author,
statistics,
images: content.image_post_info.images.map((v) => v.display_image.url_list[0]),
music: content.music.play_url.url_list
}
})
images: content.image_post_info.images.map(
(v) => v.display_image.url_list[0]
),
music: content.music.play_url.url_list,
},
});
} else {
resolve({
status: "success",
@ -66,15 +74,66 @@ const TiktokDL = (url) => {
author,
statistics,
video: content.video.play_addr.url_list,
music: content.music.play_url.url_list
}
})
music: content.music.play_url.url_list,
},
});
}
})
.catch((e) => reject(e));
.catch(reject);
})
.catch((e) => reject(e));
.catch(reject);
});
};
module.exports = { TiktokDL };
const TiktokStalk = (username) => {
return new Promise(async (resolve, reject) => {
const { data: cookie } = await Axios.get("https://pastebin.com/raw/ELJjcbZT");
username = username.replace("@", "");
Axios(`${_tiktokurl}/@${username}`, {
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",
cookie: cookie,
},
})
.then(({ data }) => {
const $ = cheerio.load(data);
const result = JSON.parse($("script#SIGI_STATE").text());
if (!result.UserModule) {
return resolve({
status: "error",
message: "User not found!",
});
}
const user = result.UserModule;
const users = {
username: user.users[username].uniqueId,
nickname: user.users[username].nickname,
avatar: user.users[username].avatarLarger,
signature: user.users[username].signature,
verified: user.users[username].verified,
region: user.users[username].region,
};
const stats = {
followerCount: user.stats[username].followerCount,
followingCount: user.stats[username].followingCount,
heartCount: user.stats[username].heartCount,
videoCount: user.stats[username].videoCount,
likeCount: user.stats[username].diggCount,
};
resolve({
status: "success",
result: {
users,
stats,
},
});
})
.catch((e) => {
resolve({ status: "error", message: e.message });
});
});
};
module.exports = { TiktokDL, TiktokStalk };