Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

tiktok-scraper-ts

Package Overview
Dependencies
Maintainers
1
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tiktok-scraper-ts - npm Package Compare versions

Comparing version 1.3.6 to 1.3.7

2

dist/main.d.ts

@@ -512,3 +512,3 @@ /**

declare class TTScraper {
_cookies: string;
_cookies?: string;
constructor(cookies?: string);

@@ -515,0 +515,0 @@ /**

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

var W=Object.create;var v=Object.defineProperty;var _=Object.getOwnPropertyDescriptor;var j=Object.getOwnPropertyNames;var D=Object.getPrototypeOf,q=Object.prototype.hasOwnProperty;var U=n=>v(n,"__esModule",{value:!0}),s=(n,r)=>v(n,"name",{value:r,configurable:!0});var P=(n,r)=>{for(var e in r)v(n,e,{get:r[e],enumerable:!0})},L=(n,r,e,t)=>{if(r&&typeof r=="object"||typeof r=="function")for(let o of j(r))!q.call(n,o)&&(e||o!=="default")&&v(n,o,{get:()=>r[o],enumerable:!(t=_(r,o))||t.enumerable});return n},p=(n,r)=>L(U(v(n!=null?W(D(n)):{},"default",!r&&n&&n.__esModule?{get:()=>n.default,enumerable:!0}:{value:n,enumerable:!0})),n),F=(n=>(r,e)=>n&&n.get(r)||(e=L(U({}),r,1),n&&n.set(r,e),e))(typeof WeakMap!="undefined"?new WeakMap:0);var B={};P(B,{Music:()=>w,TTScraper:()=>d,TikTokResult:()=>b,User:()=>I,Video:()=>g,fetchAllVideosFromUser:()=>G,fetchMusic:()=>z,fetchUser:()=>Y,fetchVideo:()=>J,fetchVideoNoWaterMark:()=>H,hashtag:()=>K});var S=p(require("cheerio")),x=p(require("miniget")),T=p(require("node-fetch")),m=require("fs"),E=p(require("puppeteer")),$=p(require("http")),N=p(require("https")),V=require("process");var I=class{constructor(r,e,t,o,i,u,c,h,l,f,M,k,y,A,C){this.id=r,this.uniqueId=e,this.nickname=t,this.avatar=o,this.signature=i,this.createdAt=u,this.verified=c,this.secretUID=h,this.bioLink=l,this.privateAccount=f,this.isUnderAge18=M,this.followers=k,this.following=y,this.hearts=A,this.videos=C}};s(I,"User");var b=class{constructor(r,e,t,o,i,u,c,h,l,f){this.author=r,this.video=e,this.audio=t,this.shareCount=o,this.likesCount=i,this.commentCount=u,this.playCount=c,this.createdAt=h,this.tiktokLink=l,this.thumbnail=f}};s(b,"TikTokResult");var g=class{constructor(r,e,t,o,i,u,c,h,l,f,M,k,y,A,C,R,O){this.id=r,this.description=e,this.createdAt=t,this.height=o,this.width=i,this.duration=u,this.resolution=c,this.shareCount=h,this.likesCount=l,this.commentCount=f,this.playCount=M,this.downloadURL=k,this.cover=y,this.dynamicCover=A,this.playURL=C,this.format=R,this.author=O}};s(g,"Video");var w=class{constructor(r,e,t,o,i,u,c,h,l){this.id=r,this.title=e,this.playURL=t,this.coverLarge=o,this.coverThumb=i,this.author=u,this.duration=c,this.original=h,this.album=l}};s(w,"Music");var d=class{constructor(r){this._cookies="";r=this._cookies}async requestWebsite(r,e){let t=new $.default.Agent({keepAlive:!0,maxSockets:20}),o=new N.default.Agent({keepAlive:!0,maxSockets:20}),i={agent:l=>l.protocol=="http:"?t:o,headers:{"User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.5060.134 Safari/537.36",Accept:"application/json, text/plain, */*","Accept-Encoding":"gzip, deflate, br","Cache-Control":"no-cache",Connection:"keep-alive",Cookie:`${this._cookies}`}},c=await(await(0,T.default)(`${r}`,e||i)).text();return S.load(c,{xmlMode:!0})}extractJSONObject(r){let e=r.split('<script id="SIGI_STATE" type="application/json">')[1].indexOf("<\/script>");return r.split('<script id="SIGI_STATE" type="application/json">')[1].slice(0,e)}checkJSONExisting(r){try{return!!JSON.parse(r)}catch{}}async requestWithPuppeteer(r){let e=await E.launch({headless:!0,args:["--no-sandbox","--disable-setuid-sandbox"]}),o=await(await e.newPage()).goto(r);if(o==null)throw new Error("Could not load the desired Page!");let i=await o.text();return await e.close(),this.extractJSONObject(i)}handleHTMLContent(r){let e=r,t=e.split("window['SIGI_STATE']=")[1].indexOf(";window['SIGI_RETRY']=");return JSON.parse(e.split("window['SIGI_STATE']=")[1].slice(0,t))}async TryFetch(r){let e=await this.requestWebsite(r);if(this.checkJSONExisting(e("#SIGI_STATE").text()))return JSON.parse(e("#SIGI_STATE").text());{let t=await this.requestWithPuppeteer(r);return JSON.parse(t)}}async video(r,e){if(!r)throw new Error("A video URL must be provided");let t=await this.TryFetch(r),o=t.ItemList.video.list[0];return new g(t.ItemModule[o].video.id,t.ItemModule[o].desc,new Date(Number(t.ItemModule[o].createTime)*1e3).toLocaleDateString(),Number(t.ItemModule[o].video.height),Number(t.ItemModule[o].video.width),Number(t.ItemModule[o].video.duration),t.ItemModule[o].video.ratio,t.ItemModule[o].stats.shareCount,t.ItemModule[o].stats.diggCount,t.ItemModule[o].stats.commentCount,t.ItemModule[o].stats.playCount,e?this.noWaterMark(t.ItemModule[o].video.id):t.ItemModule[o].video.downloadAddr.trim(),t.ItemModule[o].video.cover,t.ItemModule[o].video.dynamicCover,e?this.noWaterMark(t.ItemModule[o].video.id):t.ItemModule[o].video.playAddr.trim(),t.ItemModule[o].video.format,t.ItemModule[o].nickname)}async user(r){if(!r)throw new Error("Please enter a username");let e=await this.TryFetch(`https://www.tiktok.com/@${r}`),t=e.UserModule.users[r];return new I(t.id,t.uniqueId,t.nickname,t.avatarLarger,t.signature.trim(),new Date(t.createTime*1e3).toLocaleDateString(),t.verified,t.secUid,t?.bioLink?.link,t.privateAccount,t.isUnderAge18,e.UserModule.stats[r].followerCount,e.UserModule.stats[r].followingCount,e.UserModule.stats[r].heart,e.UserModule.stats[r].videoCount)}async getAllVideosFromUser(r){if(!r)throw new Error("You must provide a username!");let e=await this.TryFetch(`https://www.tiktok.com/@${r}`),t=[],{ItemList:o}=e;return o["user-post"].list.forEach(i=>{t.push(new g(e.ItemModule[i].video.id,e.ItemModule[i].desc,new Date(Number(e.ItemModule[i].createTime)*1e3).toLocaleDateString(),Number(e.ItemModule[i].video.height),Number(e.ItemModule[i].video.width),Number(e.ItemModule[i].video.duration),e.ItemModule[i].video.ratio,e.ItemModule[i].stats.shareCount,e.ItemModule[i].stats.diggCount,e.ItemModule[i].stats.commentCount,e.ItemModule[i].stats.playCount,e.ItemModule[i].video.downloadAddr.trim(),e.ItemModule[i].video.cover,e.ItemModule[i].video.dynamicCover,e.ItemModule[i].video.playAddr.trim(),e.ItemModule[i].video.format))}),t}async getMusic(r){if(!r)throw new Error("You must provide a link!");let e=await this.TryFetch(r),t=e.ItemList.video.list[0];return new w(e.ItemModule[t].music.id,e.ItemModule[t].music.title,e.ItemModule[t].music.playUrl,e.ItemModule[t].music.coverLarge,e.ItemModule[t].music.coverThumb,e.ItemModule[t].music.authorName,Number(e.ItemModule[t].music.duration),e.ItemModule[t].music.original,e.ItemModule[t].music.album)}async downloadAllVideosFromUser(r,e){if(!r)throw new Error("Please enter a username!");let t=await this.getAllVideosFromUser(r);if(!t)throw new Error("No Videos were found for this username. Either the videos are private or the user has not videos");if(!e.path){if(e.path=`${__dirname}/../${r}`,(0,m.existsSync)(e.path)){console.log("A folder with this username exists, that is unusual!");try{(0,m.unlinkSync)(e.path)}catch(o){console.log(`[ERROR] Could not remove ${e.path}
var W=Object.create;var v=Object.defineProperty;var _=Object.getOwnPropertyDescriptor;var j=Object.getOwnPropertyNames;var D=Object.getPrototypeOf,q=Object.prototype.hasOwnProperty;var U=n=>v(n,"__esModule",{value:!0}),s=(n,r)=>v(n,"name",{value:r,configurable:!0});var P=(n,r)=>{for(var e in r)v(n,e,{get:r[e],enumerable:!0})},L=(n,r,e,t)=>{if(r&&typeof r=="object"||typeof r=="function")for(let o of j(r))!q.call(n,o)&&(e||o!=="default")&&v(n,o,{get:()=>r[o],enumerable:!(t=_(r,o))||t.enumerable});return n},p=(n,r)=>L(U(v(n!=null?W(D(n)):{},"default",!r&&n&&n.__esModule?{get:()=>n.default,enumerable:!0}:{value:n,enumerable:!0})),n),F=(n=>(r,e)=>n&&n.get(r)||(e=L(U({}),r,1),n&&n.set(r,e),e))(typeof WeakMap!="undefined"?new WeakMap:0);var B={};P(B,{Music:()=>w,TTScraper:()=>d,TikTokResult:()=>b,User:()=>I,Video:()=>g,fetchAllVideosFromUser:()=>G,fetchMusic:()=>z,fetchUser:()=>Y,fetchVideo:()=>J,fetchVideoNoWaterMark:()=>H,hashtag:()=>K});var S=p(require("cheerio")),x=p(require("miniget")),T=p(require("node-fetch")),m=require("fs"),E=p(require("puppeteer")),$=p(require("http")),N=p(require("https")),V=require("process");var I=class{constructor(r,e,t,o,i,u,c,h,l,f,M,k,y,A,C){this.id=r,this.uniqueId=e,this.nickname=t,this.avatar=o,this.signature=i,this.createdAt=u,this.verified=c,this.secretUID=h,this.bioLink=l,this.privateAccount=f,this.isUnderAge18=M,this.followers=k,this.following=y,this.hearts=A,this.videos=C}};s(I,"User");var b=class{constructor(r,e,t,o,i,u,c,h,l,f){this.author=r,this.video=e,this.audio=t,this.shareCount=o,this.likesCount=i,this.commentCount=u,this.playCount=c,this.createdAt=h,this.tiktokLink=l,this.thumbnail=f}};s(b,"TikTokResult");var g=class{constructor(r,e,t,o,i,u,c,h,l,f,M,k,y,A,C,R,O){this.id=r,this.description=e,this.createdAt=t,this.height=o,this.width=i,this.duration=u,this.resolution=c,this.shareCount=h,this.likesCount=l,this.commentCount=f,this.playCount=M,this.downloadURL=k,this.cover=y,this.dynamicCover=A,this.playURL=C,this.format=R,this.author=O}};s(g,"Video");var w=class{constructor(r,e,t,o,i,u,c,h,l){this.id=r,this.title=e,this.playURL=t,this.coverLarge=o,this.coverThumb=i,this.author=u,this.duration=c,this.original=h,this.album=l}};s(w,"Music");var d=class{constructor(r){this._cookies="";this._cookies=r}async requestWebsite(r,e){let t=new $.default.Agent({keepAlive:!0,maxSockets:20}),o=new N.default.Agent({keepAlive:!0,maxSockets:20}),i={agent:l=>l.protocol=="http:"?t:o,headers:{"User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.5060.134 Safari/537.36",Accept:"application/json, text/plain, */*","Accept-Encoding":"gzip, deflate, br","Cache-Control":"no-cache",Connection:"keep-alive",Cookie:`${this._cookies}`}},c=await(await(0,T.default)(`${r}`,e||i)).text();return S.load(c,{xmlMode:!0})}extractJSONObject(r){let e=r.split('<script id="SIGI_STATE" type="application/json">')[1].indexOf("<\/script>");return r.split('<script id="SIGI_STATE" type="application/json">')[1].slice(0,e)}checkJSONExisting(r){try{return!!JSON.parse(r)}catch{}}async requestWithPuppeteer(r){let e=await E.launch({headless:!0,args:["--no-sandbox","--disable-setuid-sandbox"]}),o=await(await e.newPage()).goto(r);if(o==null)throw new Error("Could not load the desired Page!");let i=await o.text();return await e.close(),this.extractJSONObject(i)}handleHTMLContent(r){let e=r,t=e.split("window['SIGI_STATE']=")[1].indexOf(";window['SIGI_RETRY']=");return JSON.parse(e.split("window['SIGI_STATE']=")[1].slice(0,t))}async TryFetch(r){let e=await this.requestWebsite(r);if(this.checkJSONExisting(e("#SIGI_STATE").text()))return JSON.parse(e("#SIGI_STATE").text());{let t=await this.requestWithPuppeteer(r);return JSON.parse(t)}}async video(r,e){if(!r)throw new Error("A video URL must be provided");let t=await this.TryFetch(r),o=t.ItemList.video.list[0];return new g(t.ItemModule[o].video.id,t.ItemModule[o].desc,new Date(Number(t.ItemModule[o].createTime)*1e3).toLocaleDateString(),Number(t.ItemModule[o].video.height),Number(t.ItemModule[o].video.width),Number(t.ItemModule[o].video.duration),t.ItemModule[o].video.ratio,t.ItemModule[o].stats.shareCount,t.ItemModule[o].stats.diggCount,t.ItemModule[o].stats.commentCount,t.ItemModule[o].stats.playCount,e?this.noWaterMark(t.ItemModule[o].video.id):t.ItemModule[o].video.downloadAddr.trim(),t.ItemModule[o].video.cover,t.ItemModule[o].video.dynamicCover,e?this.noWaterMark(t.ItemModule[o].video.id):t.ItemModule[o].video.playAddr.trim(),t.ItemModule[o].video.format,t.ItemModule[o].nickname)}async user(r){if(!r)throw new Error("Please enter a username");let e=await this.TryFetch(`https://www.tiktok.com/@${r}`),t=e.UserModule.users[r];return new I(t.id,t.uniqueId,t.nickname,t.avatarLarger,t.signature.trim(),new Date(t.createTime*1e3).toLocaleDateString(),t.verified,t.secUid,t?.bioLink?.link,t.privateAccount,t.isUnderAge18,e.UserModule.stats[r].followerCount,e.UserModule.stats[r].followingCount,e.UserModule.stats[r].heart,e.UserModule.stats[r].videoCount)}async getAllVideosFromUser(r){if(!r)throw new Error("You must provide a username!");let e=await this.TryFetch(`https://www.tiktok.com/@${r}`),t=[],{ItemList:o}=e;return o["user-post"].list.forEach(i=>{t.push(new g(e.ItemModule[i].video.id,e.ItemModule[i].desc,new Date(Number(e.ItemModule[i].createTime)*1e3).toLocaleDateString(),Number(e.ItemModule[i].video.height),Number(e.ItemModule[i].video.width),Number(e.ItemModule[i].video.duration),e.ItemModule[i].video.ratio,e.ItemModule[i].stats.shareCount,e.ItemModule[i].stats.diggCount,e.ItemModule[i].stats.commentCount,e.ItemModule[i].stats.playCount,e.ItemModule[i].video.downloadAddr.trim(),e.ItemModule[i].video.cover,e.ItemModule[i].video.dynamicCover,e.ItemModule[i].video.playAddr.trim(),e.ItemModule[i].video.format))}),t}async getMusic(r){if(!r)throw new Error("You must provide a link!");let e=await this.TryFetch(r),t=e.ItemList.video.list[0];return new w(e.ItemModule[t].music.id,e.ItemModule[t].music.title,e.ItemModule[t].music.playUrl,e.ItemModule[t].music.coverLarge,e.ItemModule[t].music.coverThumb,e.ItemModule[t].music.authorName,Number(e.ItemModule[t].music.duration),e.ItemModule[t].music.original,e.ItemModule[t].music.album)}async downloadAllVideosFromUser(r,e){if(!r)throw new Error("Please enter a username!");let t=await this.getAllVideosFromUser(r);if(!t)throw new Error("No Videos were found for this username. Either the videos are private or the user has not videos");if(!e.path){if(e.path=`${__dirname}/../${r}`,(0,m.existsSync)(e.path)){console.log("A folder with this username exists, that is unusual!");try{(0,m.unlinkSync)(e.path)}catch(o){console.log(`[ERROR] Could not remove ${e.path}
Error Message: ${o.message}`),(0,V.exit)(1)}}(0,m.existsSync)(e.path)||(0,m.mkdirSync)(e.path)}if(!e.watermark){for(let[o,i]of t.entries()){console.log(`Downloading Video: ${i.description?i.description:i.id}, [${o+1}/${t.length}]`);let u=await this.noWaterMark(i.id);if(!u){console.log(`Could not fetch ${i.description?i.description:i.id} with no watermark`);continue}(0,x.default)(u).pipe((0,m.createWriteStream)(`${e.path}/${i.id}_${i.resolution}.${i.format}`))}return}for(let[o,i]of t.entries())console.log(`Downloading Video: ${i.description?i.description:i.id}, [${o+1}/${t.length}]`),(0,x.default)(i.downloadURL).pipe((0,m.createWriteStream)(`${e.path}/${i.id}_${i.resolution}.${i.format}`))}async noWaterMark(r){let e="";r.startsWith("https")?e=(await this.video(r)).id:e=r;let o=await(await(0,T.default)("https://api2.musical.ly/aweme/v1/aweme/detail/?aweme_id="+e)).json();if(!o)throw new Error("There was an Error retrieveing this video without watermark!");let i=o.aweme_detail.video.download_addr.uri;if(!i)throw new Error("There was an Error retrieveing this video without watermark!");return`https://api-h2.tiktokv.com/aweme/v1/play/?video_id=${i}`}async hashTag(r){if(!r)throw new Error("You must provide a tag name to complete the search!");let e=await this.TryFetch(`https://www.tiktok.com/tag/${r}`),{ItemList:t}=e,o=[];for(let i of t.challenge.list)o.push(new g(e.ItemModule[i].video.id,e.ItemModule[i].desc,new Date(Number(e.ItemModule[i].createTime)*1e3).toLocaleDateString(),Number(e.ItemModule[i].video.height),Number(e.ItemModule[i].video.width),Number(e.ItemModule[i].video.duration),e.ItemModule[i].video.ratio,e.ItemModule[i].stats.shareCount,e.ItemModule[i].stats.diggCount,e.ItemModule[i].stats.commentCount,e.ItemModule[i].stats.playCount,e.ItemModule[i].video.downloadAddr.trim(),e.ItemModule[i].video.cover,e.ItemModule[i].video.dynamicCover,e.ItemModule[i].video.playAddr.trim(),e.ItemModule[i].video.format,e.ItemModule[i].author));return o}};s(d,"TTScraper");async function J(n){if(!n)throw new Error("You must provide a Tiktok video url!");return await new d().video(n)}s(J,"fetchVideo");async function Y(n){if(!n)throw new Error("You must provide a username!");return await new d().user(n)}s(Y,"fetchUser");async function G(n){if(!n)throw new Error("You must provide a username!");return await new d().getAllVideosFromUser(n)}s(G,"fetchAllVideosFromUser");async function z(n){if(!n)throw new Error("You must provide a Tiktok video url!");return await new d().getMusic(n)}s(z,"fetchMusic");async function H(n){if(!n)throw new Error("You must provide a Tiktok video url!");return await new d().noWaterMark(n)}s(H,"fetchVideoNoWaterMark");async function K(n){if(!n)throw new Error("You must provide a tiktok hashtag");return await new d().hashTag(n)}s(K,"hashtag");module.exports=F(B);0&&(module.exports={Music,TTScraper,TikTokResult,User,Video,fetchAllVideosFromUser,fetchMusic,fetchUser,fetchVideo,fetchVideoNoWaterMark,hashtag});
{
"name": "tiktok-scraper-ts",
"version": "1.3.6",
"version": "1.3.7",
"description": "A scraper for tiktok videos, users and more",

@@ -42,2 +42,2 @@ "main": "dist/main.js",

}
}
}

Sorry, the diff of this file is not supported yet

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