tiktok-stats
Advanced tools
Comparing version 1.7.3 to 1.7.4
{ | ||
"name": "tiktok-stats", | ||
"version": "1.7.3", | ||
"version": "1.7.4", | ||
"description": "This package gives you the statistics of which user tiktok !", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -48,5 +48,15 @@ # tiktok-stats | ||
or | ||
```json | ||
{ | ||
"code": 429, | ||
"error": "The page cannot load." | ||
} | ||
``` | ||
This error appears because tiktok blocks when they receive too many requests. | ||
## Last patch | ||
● **Patch error for any account.** | ||
● **Patch error for any account and account not found.** | ||
@@ -53,0 +63,0 @@ |
119
src/Base.js
const fetch = require('node-fetch'); | ||
const entities = require("entities"); | ||
let accounts = []; | ||
module.exports = class Greeting { | ||
constructor() { | ||
this.user = "pioupia_dev" | ||
this.user = "pioupia_dev"; | ||
} | ||
callNumber(data, object) { | ||
const res = this.getNumber(data.split(object)); | ||
return res; | ||
} | ||
getData(data) { | ||
const array = ["Abonnements", "Abonnés", " J'aime"]; | ||
array.forEach(res => { | ||
this.getStats(data, res); | ||
}); | ||
return true; | ||
} | ||
getStats(data, response) { | ||
const res = this.callNumber(data, `<strong title="${response}">`); | ||
object.stats[traductor[response]] = res; | ||
} | ||
getNumber(data) { | ||
if (!data || !data[1]) return 0; | ||
const res = data[1].split("<")[0]; | ||
return res; | ||
} | ||
entitiesDetect(data) { | ||
data = entities.decodeHTML(data); | ||
return data; | ||
} | ||
pushToArray(object){ | ||
object.date = new Date().getTime(); | ||
accounts.push(object); | ||
} | ||
getStats() { | ||
return new Promise(async resolve => { | ||
const d = new Date().getTime(); | ||
if(accounts.find(r => r.user.profilName == this.user && d - r.date <= 3600000)){ | ||
resolve(accounts.find(r => r.user.profilName == this.user)) | ||
}else if(accounts.find(r => r.user.profilName == this.user && d - r.date > 3600000)){ | ||
const page = accounts.findIndex(r => r.user.profilName == this.user && d - r.date > 3600000); | ||
accounts.splice(page, page >= 0 ? 1 : 0); | ||
} | ||
/* Import JSON data */ | ||
@@ -33,4 +79,13 @@ const object = { | ||
fetch(`https://www.tiktok.com/@${this.user}?lang=fr`).then(res => res.text()).then(data => { | ||
if (!data || data == " ") { | ||
const header = { | ||
headers: { | ||
'User-Agent': 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:86.0) Gecko/20100101 Firefox/86.0', | ||
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8', | ||
'Accept-Language': 'fr,fr-FR;q=0.8,en-US;q=0.5,en;q=0.3', | ||
'Accept-Encoding': 'gzip, deflate, br' | ||
} | ||
} | ||
fetch(`https://www.tiktok.com/@${this.user}?lang=fr`, header).then(res => res.text()).then(data => { | ||
if (!data || data == " " || data.includes("jsx-4111167561 title")) { | ||
resolve({ | ||
@@ -42,4 +97,15 @@ "code": 404, | ||
} | ||
if(data.includes(`<div class="app_icon"></div> | ||
<div class="verify-wrap"> | ||
<div id="verify-ele"></div> | ||
</div> | ||
`)){ | ||
resolve({ | ||
"code": 429, | ||
"error": "The page cannot load." | ||
}); | ||
return false; | ||
} | ||
getData(data); | ||
this.getData(data); | ||
@@ -50,8 +116,8 @@ let certified = data.indexOf(`<circle cx="24" cy="24" r="24" fill="#20D5EC"></circle>`); | ||
const description = callNumber(data, `<h2 class="share-desc mt10">`); | ||
if (description && description != 0) object.user.description = entitiesDetect(description); | ||
const description = this.callNumber(data, `<h2 class="share-desc mt10">`); | ||
if (description && description != 0) object.user.description = this.entitiesDetect(description); | ||
const userName = callNumber(data, `<h1 class="share-sub-title">`); | ||
if (userName && userName != 0) object.user.username = entitiesDetect(userName); | ||
const userName = this.callNumber(data, `<h1 class="share-sub-title">`); | ||
if (userName && userName != 0) object.user.username = this.entitiesDetect(userName); | ||
let avatar = data.split(`<span class="tiktok-avatar tiktok-avatar-circle avatar jsx-3659161049" style="cursor:unset;width:116px;height:116px">`); | ||
@@ -67,37 +133,10 @@ if (avatar) { | ||
} | ||
this.pushToArray(object); | ||
resolve(object); | ||
}); | ||
function callNumber(data, object) { | ||
const res = getNumber(data.split(object)); | ||
return res; | ||
} | ||
function getData(data) { | ||
const array = ["Abonnements", "Abonnés", " J'aime"]; | ||
array.forEach(res => { | ||
getStats(data, res); | ||
}); | ||
return object; | ||
} | ||
function getStats(data, response) { | ||
const res = callNumber(data, `<strong title="${response}">`); | ||
object.stats[traductor[response]] = res; | ||
} | ||
function getNumber(data) { | ||
if (!data || !data[1]) return 0; | ||
const res = data[1].split("<")[0]; | ||
return res; | ||
} | ||
function entitiesDetect(data) { | ||
data = entities.decodeHTML(data); | ||
return data; | ||
} | ||
}) | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
7371
121
73