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