tiktok-stats
Advanced tools
Comparing version 1.7.5 to 1.7.6
const fetch = require('node-fetch'); | ||
const entities = require("entities"); | ||
module.exports.Stats = require('./src/stats'); | ||
module.exports.Stats = require('./src/Base'); |
{ | ||
"name": "tiktok-stats", | ||
"version": "1.7.5", | ||
"version": "1.7.6", | ||
"description": "This package gives you the statistics of which user tiktok !", | ||
@@ -9,6 +9,15 @@ "main": "index.js", | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/pioupia/tiktok-stats.git" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/pioupia/tiktok-stats/issues" | ||
}, | ||
"homepage": "https://github.com/pioupia/tiktok-stats", | ||
"keywords": [ | ||
"tiktok_stats", | ||
"tiktok", | ||
"stats" | ||
"stats", | ||
"scrapping" | ||
], | ||
@@ -15,0 +24,0 @@ "author": "Pioupia", |
128
src/Base.js
@@ -6,3 +6,4 @@ const fetch = require('node-fetch'); | ||
module.exports = class Greeting { | ||
constructor() { | ||
constructor(username) { | ||
this.user = username; | ||
this.traductor = { | ||
@@ -14,15 +15,15 @@ "Abonnements": "following", | ||
this.object = { | ||
"user": { | ||
"username": "No username was provided.", | ||
"profilName": this.user, | ||
"avatar": "No avatar was provided.", | ||
"description": "No description provided.", | ||
"certified": false | ||
}, | ||
"stats": { | ||
"following": 0, | ||
"follower": 0, | ||
"like": 0 | ||
} | ||
}; | ||
"user": { | ||
"username": "No username was provided.", | ||
"profilName": this.user, | ||
"avatar": "No avatar was provided.", | ||
"description": "No description provided.", | ||
"certified": false | ||
}, | ||
"stats": { | ||
"following": 0, | ||
"follower": 0, | ||
"like": 0 | ||
} | ||
}; | ||
@@ -38,4 +39,5 @@ } | ||
const array = ["Abonnements", "Abonnés", " J'aime"]; | ||
const _this = this; | ||
array.forEach(res => { | ||
this.getStats(data, res); | ||
_this.getStatsObject(data, res); | ||
}); | ||
@@ -46,5 +48,6 @@ | ||
getStats(data, response) { | ||
getStatsObject(data, response) { | ||
const res = this.callNumber(data, `<strong title="${response}">`); | ||
object.stats[this.traductor[response]] = res; | ||
this.object.stats[this.traductor[response]] = res; | ||
return true; | ||
} | ||
@@ -60,9 +63,7 @@ | ||
data = entities.decodeHTML(data); | ||
return data; | ||
} | ||
pushToArray(object){ | ||
pushToArray(object) { | ||
object.date = new Date().getTime(); | ||
accounts.push(object); | ||
@@ -72,10 +73,12 @@ } | ||
getStats() { | ||
const _this = this; | ||
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); | ||
if (accounts.find(r => r.user.profilName == _this.user && d - r.date <= 3600000)) { | ||
resolve(accounts.find(r => r.user.profilName == _this.user)) | ||
} | ||
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, 1); | ||
} | ||
@@ -91,52 +94,53 @@ const header = { | ||
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({ | ||
"code": 404, | ||
"error": "This account cannot be found." | ||
}); | ||
return false; | ||
} | ||
if(data.includes(`<div class="app_icon"></div> | ||
let data = await fetch(`https://www.tiktok.com/@${_this.user}?lang=fr`, header); | ||
data = await data.text(); | ||
if (!data || data == " " || data.includes("jsx-4111167561 title")) { | ||
resolve({ | ||
"code": 404, | ||
"error": "This account cannot be found." | ||
}); | ||
return false; | ||
} | ||
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; | ||
} | ||
`)) { | ||
resolve({ | ||
"code": 429, | ||
"error": "The page cannot load." | ||
}); | ||
return false; | ||
} | ||
this.getData(data); | ||
_this.getData(data); | ||
let certified = data.indexOf(`<circle cx="24" cy="24" r="24" fill="#20D5EC"></circle>`); | ||
certified > -1 ? certified = true : certified = false; | ||
if (certified && certified == true) this.object.user.certified = true; | ||
let certified = data.indexOf(`<circle cx="24" cy="24" r="24" fill="#20D5EC"></circle>`); | ||
certified > -1 ? certified = true : certified = false; | ||
if (certified && certified == true) _this.object.user.certified = true; | ||
const description = this.callNumber(data, `<h2 class="share-desc mt10">`); | ||
if (description && description != 0) this.object.user.description = this.entitiesDetect(description); | ||
const description = _this.callNumber(data, `<h2 class="share-desc mt10">`); | ||
if (description && description != 0) _this.object.user.description = _this.entitiesDetect(description); | ||
const userName = this.callNumber(data, `<h1 class="share-sub-title">`); | ||
if (userName && userName != 0) this.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">`); | ||
if (avatar) { | ||
if (certified && certified == true) { | ||
avatar = avatar[1].split(`<`)[1].replace(`img alt="${this.object.user.username} TikTok" src="`, "").replace(`"/>`, "").replace(/amp;/g, ""); | ||
} else { | ||
avatar = avatar[1].split(`<`)[1].replace(`img alt="" src="`, "").replace(`"/>`, "").replace(/amp;/g, ""); | ||
} | ||
const userName = _this.callNumber(data, `<h1 class="share-sub-title">`); | ||
if (userName && userName != 0) _this.object.user.username = _this.entitiesDetect(userName); | ||
this.object.user.avatar = avatar; | ||
let avatar = data.split(`<span class="tiktok-avatar tiktok-avatar-circle avatar jsx-3659161049" style="cursor:unset;width:116px;height:116px">`); | ||
if (avatar) { | ||
if (certified && certified == true) { | ||
avatar = avatar[1].split(`<`)[1].replace(`img alt="${_this.object.user.username} TikTok" src="`, "").replace(`"/>`, "").replace(/amp;/g, ""); | ||
} else { | ||
avatar = avatar[1].split(`<`)[1].replace(`img alt="" src="`, "").replace(`"/>`, "").replace(/amp;/g, ""); | ||
} | ||
this.pushToArray(this.object); | ||
_this.object.user.avatar = avatar; | ||
} | ||
resolve(this.object); | ||
}); | ||
}) | ||
_this.pushToArray(_this.object); | ||
resolve(_this.object); | ||
return true; | ||
}); | ||
} | ||
} |
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
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
No website
QualityPackage does not have a website.
Found 1 instance in 1 package
7390
0
1
0
4