From 1d299893632e613558fa264743c122926a9fbc64 Mon Sep 17 00:00:00 2001 From: TobyG74 Date: Mon, 3 Apr 2023 21:16:11 +0700 Subject: [PATCH] added view tiktok profile --- .gitignore | 1 - .npmignore | 4 ++ README.md | 42 ++++++++++++++++++- index.js | 4 +- package.json | 56 +++++++++++++------------- utils/index.js | 107 ++++++++++++++++++++++++++++++++++++++----------- 6 files changed, 158 insertions(+), 56 deletions(-) create mode 100644 .npmignore diff --git a/.gitignore b/.gitignore index 48d0340..f4947dc 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,3 @@ -.npmignore node_modules yarn-lock.json package-lock.json \ No newline at end of file diff --git a/.npmignore b/.npmignore new file mode 100644 index 0000000..aec30ce --- /dev/null +++ b/.npmignore @@ -0,0 +1,4 @@ +node_modules +yarn-lock.json +package-lock.json +.gitignore \ No newline at end of file diff --git a/README.md b/README.md index 3beadc0..8744e57 100644 --- a/README.md +++ b/README.md @@ -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: ... + } + } +} +``` diff --git a/index.js b/index.js index 4235c24..1c84e49 100644 --- a/index.js +++ b/index.js @@ -1,3 +1,3 @@ -const { TiktokDL } = require("./utils"); +const { TiktokDL, TiktokStalk } = require("./utils"); -module.exports = { TiktokDL } \ No newline at end of file +module.exports = { TiktokDL, TiktokStalk }; diff --git a/package.json b/package.json index 6538472..cd50510 100644 --- a/package.json +++ b/package.json @@ -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" + } } diff --git a/utils/index.js b/utils/index.js index 9d77915..aea6518 100644 --- a/utils/index.js +++ b/utils/index.js @@ -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 };