tiktok-scraper-ts
Advanced tools
Comparing version 1.3.9 to 1.4.0
@@ -566,3 +566,3 @@ /** | ||
*/ | ||
video(uri: string, noWaterMark?: boolean): Promise<Video>; | ||
video(uri: string, noWaterMark?: boolean): Promise<Video | void>; | ||
/** | ||
@@ -580,4 +580,11 @@ * Scrapes the given user page and returns all available info | ||
*/ | ||
getAllVideosFromUser(username: string, noWaterMark?: boolean): Promise<IVideo[]>; | ||
getAllVideosFromUser(username: string): Promise<IVideo[]>; | ||
/** | ||
* Fetches Users Post directly from the API | ||
* @param userUID | ||
* @param cursor | ||
* @returns JSON Object from the API | ||
*/ | ||
fetchUserVideos(userUID: string, cursor: string): Promise<any>; | ||
/** | ||
* Scrapes the given Link and returns information about the Music of the Video | ||
@@ -617,3 +624,3 @@ * @param link tiktok video url | ||
*/ | ||
declare function fetchVideo(url: string, noWaterMark?: boolean): Promise<Video>; | ||
declare function fetchVideo(url: string, noWaterMark?: boolean): Promise<void | Video>; | ||
/** | ||
@@ -631,3 +638,3 @@ * Scrapes the given user page and returns all available info | ||
*/ | ||
declare function fetchAllVideosFromUser(username: string, noWaterMark?: boolean): Promise<IVideo[]>; | ||
declare function fetchAllVideosFromUser(username: string): Promise<IVideo[]>; | ||
/** | ||
@@ -634,0 +641,0 @@ * Scrapes the given Link and returns information about the Music of the Video |
@@ -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}),a=(n,r)=>v(n,"name",{value:r,configurable:!0});var P=(n,r)=>{for(var t in r)v(n,t,{get:r[t],enumerable:!0})},L=(n,r,t,e)=>{if(r&&typeof r=="object"||typeof r=="function")for(let o of j(r))!q.call(n,o)&&(t||o!=="default")&&v(n,o,{get:()=>r[o],enumerable:!(e=_(r,o))||e.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,t)=>n&&n.get(r)||(t=L(U({}),r,1),n&&n.set(r,t),t))(typeof WeakMap!="undefined"?new WeakMap:0);var B={};P(B,{Music:()=>w,TTScraper:()=>m,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")),c=require("fs"),E=p(require("puppeteer")),R=p(require("http")),N=p(require("https")),V=require("process");var I=class{constructor(r,t,e,o,i,s,d,h,l,f,M,k,y,C,A){this.id=r,this.uniqueId=t,this.nickname=e,this.avatar=o,this.signature=i,this.createdAt=s,this.verified=d,this.secretUID=h,this.bioLink=l,this.privateAccount=f,this.isUnderAge18=M,this.followers=k,this.following=y,this.hearts=C,this.videos=A}};a(I,"User");var b=class{constructor(r,t,e,o,i,s,d,h,l,f){this.author=r,this.video=t,this.audio=e,this.shareCount=o,this.likesCount=i,this.commentCount=s,this.playCount=d,this.createdAt=h,this.tiktokLink=l,this.thumbnail=f}};a(b,"TikTokResult");var g=class{constructor(r,t,e,o,i,s,d,h,l,f,M,k,y,C,A,$,O){this.id=r,this.description=t,this.createdAt=e,this.height=o,this.width=i,this.duration=s,this.resolution=d,this.shareCount=h,this.likesCount=l,this.commentCount=f,this.playCount=M,this.downloadURL=k,this.cover=y,this.dynamicCover=C,this.playURL=A,this.format=$,this.author=O}};a(g,"Video");var w=class{constructor(r,t,e,o,i,s,d,h,l){this.id=r,this.title=t,this.playURL=e,this.coverLarge=o,this.coverThumb=i,this.author=s,this.duration=d,this.original=h,this.album=l}};a(w,"Music");var m=class{constructor(r){this._cookies="";this._cookies=r}async requestWebsite(r,t){let e=new R.default.Agent({keepAlive:!0,maxSockets:20}),o=new N.default.Agent({keepAlive:!0,maxSockets:20}),i={agent:l=>l.protocol=="http:"?e: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}`}},d=await(await(0,T.default)(`${r}`,t||i)).text();return S.load(d,{xmlMode:!0})}extractJSONObject(r){let t=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,t)}checkJSONExisting(r){try{return!!JSON.parse(r)}catch{}}async requestWithPuppeteer(r){let t=await E.launch({headless:!0,args:["--no-sandbox","--disable-setuid-sandbox"]}),o=await(await t.newPage()).goto(r);if(o==null)throw new Error("Could not load the desired Page!");let i=await o.text();return await t.close(),this.extractJSONObject(i)}handleHTMLContent(r){let t=r,e=t.split("window['SIGI_STATE']=")[1].indexOf(";window['SIGI_RETRY']=");return JSON.parse(t.split("window['SIGI_STATE']=")[1].slice(0,e))}async TryFetch(r){let t=await this.requestWebsite(r);if(this.checkJSONExisting(t("#SIGI_STATE").text()))return JSON.parse(t("#SIGI_STATE").text());{let e=await this.requestWithPuppeteer(r);return JSON.parse(e)}}async video(r,t){if(!r)throw new Error("A video URL must be provided");let e=await this.TryFetch(r),o=e.ItemList.video.list[0],i=t?await this.noWaterMark(e.ItemModule[o].video.id):e.ItemModule[o].video.downloadAddr.trim();return new g(e.ItemModule[o].video.id,e.ItemModule[o].desc,new Date(Number(e.ItemModule[o].createTime)*1e3).toLocaleDateString(),Number(e.ItemModule[o].video.height),Number(e.ItemModule[o].video.width),Number(e.ItemModule[o].video.duration),e.ItemModule[o].video.ratio,e.ItemModule[o].stats.shareCount,e.ItemModule[o].stats.diggCount,e.ItemModule[o].stats.commentCount,e.ItemModule[o].stats.playCount,i,e.ItemModule[o].video.cover,e.ItemModule[o].video.dynamicCover,i,e.ItemModule[o].video.format,e.ItemModule[o].nickname)}async user(r){if(!r)throw new Error("Please enter a username");let t=await this.TryFetch(`https://www.tiktok.com/@${r}`),e=t.UserModule.users[r];return new I(e.id,e.uniqueId,e.nickname,e.avatarLarger,e.signature.trim(),new Date(e.createTime*1e3).toLocaleDateString(),e.verified,e.secUid,e?.bioLink?.link,e.privateAccount,e.isUnderAge18,t.UserModule.stats[r].followerCount,t.UserModule.stats[r].followingCount,t.UserModule.stats[r].heart,t.UserModule.stats[r].videoCount)}async getAllVideosFromUser(r,t){if(!r)throw new Error("You must provide a username!");let e=await this.TryFetch(`https://www.tiktok.com/@${r}`),o=[],{ItemList:i}=e;for(let s of i["user-post"].list){let d=t?await this.noWaterMark(e.ItemModule[s].video.id):e.ItemModule[s].video.downloadAddr.trim();o.push(new g(e.ItemModule[s].video.id,e.ItemModule[s].desc,new Date(Number(e.ItemModule[s].createTime)*1e3).toLocaleDateString(),Number(e.ItemModule[s].video.height),Number(e.ItemModule[s].video.width),Number(e.ItemModule[s].video.duration),e.ItemModule[s].video.ratio,e.ItemModule[s].stats.shareCount,e.ItemModule[s].stats.diggCount,e.ItemModule[s].stats.commentCount,e.ItemModule[s].stats.playCount,d,e.ItemModule[s].video.cover,e.ItemModule[s].video.dynamicCover,d,e.ItemModule[s].video.format,e.ItemModule[s].author))}return o}async getMusic(r){if(!r)throw new Error("You must provide a link!");let t=await this.TryFetch(r),e=t.ItemList.video.list[0];return new w(t.ItemModule[e].music.id,t.ItemModule[e].music.title,t.ItemModule[e].music.playUrl,t.ItemModule[e].music.coverLarge,t.ItemModule[e].music.coverThumb,t.ItemModule[e].music.authorName,Number(t.ItemModule[e].music.duration),t.ItemModule[e].music.original,t.ItemModule[e].music.album)}async downloadAllVideosFromUser(r,t){if(!r)throw new Error("Please enter a username!");let e=await this.getAllVideosFromUser(r);if(!e)throw new Error("No Videos were found for this username. Either the videos are private or the user has not videos");if(!t.path){if(t.path=`${__dirname}/../${r}`,(0,c.existsSync)(t.path)){console.log("A folder with this username exists, that is unusual!");try{(0,c.unlinkSync)(t.path)}catch(o){console.log(`[ERROR] Could not remove ${t.path} | ||
Error Message: ${o.message}`),(0,V.exit)(1)}}(0,c.existsSync)(t.path)||(0,c.mkdirSync)(t.path)}if(!t.watermark){for(let[o,i]of e.entries()){console.log(`Downloading Video: ${i.description?i.description:i.id}, [${o+1}/${e.length}]`);let s=await this.noWaterMark(i.id);if(!s){console.log(`Could not fetch ${i.description?i.description:i.id} with no watermark`);continue}(0,x.default)(s).pipe((0,c.createWriteStream)(`${t.path}/${i.id}_${i.resolution}.${i.format}`))}return}for(let[o,i]of e.entries())console.log(`Downloading Video: ${i.description?i.description:i.id}, [${o+1}/${e.length}]`),(0,x.default)(i.downloadURL).pipe((0,c.createWriteStream)(`${t.path}/${i.id}_${i.resolution}.${i.format}`))}async noWaterMark(r){let t="";r.startsWith("https")?t=(await this.video(r)).id:t=r;let o=await(await(0,T.default)("https://api2.musical.ly/aweme/v1/aweme/detail/?aweme_id="+t)).json();if(!o)throw new Error("There was an Error retrieveing this video without watermark!");let i=o.aweme_detail.video.play_addr;if(!i)throw new Error("There was an Error retrieveing this video without watermark!");return i.url_list[0]}async hashTag(r){if(!r)throw new Error("You must provide a tag name to complete the search!");let t=await this.TryFetch(`https://www.tiktok.com/tag/${r}`),{ItemList:e}=t,o=[];for(let i of e.challenge.list)o.push(new g(t.ItemModule[i].video.id,t.ItemModule[i].desc,new Date(Number(t.ItemModule[i].createTime)*1e3).toLocaleDateString(),Number(t.ItemModule[i].video.height),Number(t.ItemModule[i].video.width),Number(t.ItemModule[i].video.duration),t.ItemModule[i].video.ratio,t.ItemModule[i].stats.shareCount,t.ItemModule[i].stats.diggCount,t.ItemModule[i].stats.commentCount,t.ItemModule[i].stats.playCount,t.ItemModule[i].video.downloadAddr.trim(),t.ItemModule[i].video.cover,t.ItemModule[i].video.dynamicCover,t.ItemModule[i].video.playAddr.trim(),t.ItemModule[i].video.format,t.ItemModule[i].author));return o}};a(m,"TTScraper");async function J(n,r){if(!n)throw new Error("You must provide a Tiktok video url!");return await new m().video(n,r)}a(J,"fetchVideo");async function Y(n){if(!n)throw new Error("You must provide a username!");return await new m().user(n)}a(Y,"fetchUser");async function G(n,r){if(!n)throw new Error("You must provide a username!");return await new m().getAllVideosFromUser(n,r)}a(G,"fetchAllVideosFromUser");async function z(n){if(!n)throw new Error("You must provide a Tiktok video url!");return await new m().getMusic(n)}a(z,"fetchMusic");async function H(n){if(!n)throw new Error("You must provide a Tiktok video url!");return await new m().noWaterMark(n)}a(H,"fetchVideoNoWaterMark");async function K(n){if(!n)throw new Error("You must provide a tiktok hashtag");return await new m().hashTag(n)}a(K,"hashtag");module.exports=F(B);0&&(module.exports={Music,TTScraper,TikTokResult,User,Video,fetchAllVideosFromUser,fetchMusic,fetchUser,fetchVideo,fetchVideoNoWaterMark,hashtag}); | ||
var j=Object.create;var v=Object.defineProperty;var F=Object.getOwnPropertyDescriptor;var P=Object.getOwnPropertyNames;var W=Object.getPrototypeOf,$=Object.prototype.hasOwnProperty;var U=n=>v(n,"__esModule",{value:!0}),u=(n,r)=>v(n,"name",{value:r,configurable:!0});var q=(n,r)=>{for(var e in r)v(n,e,{get:r[e],enumerable:!0})},V=(n,r,e,t)=>{if(r&&typeof r=="object"||typeof r=="function")for(let o of P(r))!$.call(n,o)&&(e||o!=="default")&&v(n,o,{get:()=>r[o],enumerable:!(t=F(r,o))||t.enumerable});return n},p=(n,r)=>V(U(v(n!=null?j(W(n)):{},"default",!r&&n&&n.__esModule?{get:()=>n.default,enumerable:!0}:{value:n,enumerable:!0})),n),Y=(n=>(r,e)=>n&&n.get(r)||(e=V(U({}),r,1),n&&n.set(r,e),e))(typeof WeakMap!="undefined"?new WeakMap:0);var Z={};q(Z,{Music:()=>w,TTScraper:()=>m,TikTokResult:()=>I,User:()=>f,Video:()=>g,fetchAllVideosFromUser:()=>B,fetchMusic:()=>G,fetchUser:()=>Q,fetchVideo:()=>_,fetchVideoNoWaterMark:()=>J,hashtag:()=>H});var E=p(require("cheerio")),T=p(require("miniget")),k=p(require("node-fetch")),l=require("fs"),L=p(require("puppeteer")),S=p(require("http")),N=p(require("https")),R=require("process");var f=class{constructor(r,e,t,o,i,a,d,s,h,b,M,C,A,x,y){this.id=r,this.uniqueId=e,this.nickname=t,this.avatar=o,this.signature=i,this.createdAt=a,this.verified=d,this.secretUID=s,this.bioLink=h,this.privateAccount=b,this.isUnderAge18=M,this.followers=C,this.following=A,this.hearts=x,this.videos=y}};u(f,"User");var I=class{constructor(r,e,t,o,i,a,d,s,h,b){this.author=r,this.video=e,this.audio=t,this.shareCount=o,this.likesCount=i,this.commentCount=a,this.playCount=d,this.createdAt=s,this.tiktokLink=h,this.thumbnail=b}};u(I,"TikTokResult");var g=class{constructor(r,e,t,o,i,a,d,s,h,b,M,C,A,x,y,O,D){this.id=r,this.description=e,this.createdAt=t,this.height=o,this.width=i,this.duration=a,this.resolution=d,this.shareCount=s,this.likesCount=h,this.commentCount=b,this.playCount=M,this.downloadURL=C,this.cover=A,this.dynamicCover=x,this.playURL=y,this.format=O,this.author=D}};u(g,"Video");var w=class{constructor(r,e,t,o,i,a,d,s,h){this.id=r,this.title=e,this.playURL=t,this.coverLarge=o,this.coverThumb=i,this.author=a,this.duration=d,this.original=s,this.album=h}};u(w,"Music");var m=class{constructor(r){this._cookies="";this._cookies=r}async requestWebsite(r,e){let t=new S.default.Agent({keepAlive:!0,maxSockets:20}),o=new N.default.Agent({keepAlive:!0,maxSockets:20}),i={agent:h=>h.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}`}},d=await(await(0,k.default)(`${r}`,e||i)).text();return E.load(d,{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 L.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]??0;if(o==0)return console.log("Could not find the Video on Tiktok!");let i=e?await this.noWaterMark(t.ItemModule[o].video.id):t.ItemModule[o].video.downloadAddr.trim();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,i,t.ItemModule[o].video.cover,t.ItemModule[o].video.dynamicCover,i,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 f(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{secretUID:e}=await this.user(`${r}`);if(!e)throw new Error("Couuld not find user UID!");let t="",o=[],i=[],a=await this.fetchUserVideos(e,t);if(a?.itemList&&(i.push(a.itemList),t=a.cursor),a?.hasMore===!0)for(;;){let d=await this.fetchUserVideos(e,t);if(i.push(d.itemList),t=d.cursor,d.hasMore==!1)break}for(let d of i)for(let s of d)o.push(new g(s.id,s.desc,new Date(Number(s.createTime)*1e3).toLocaleDateString(),Number(s.video?.height),Number(s.video?.width),Number(s.video?.duration),s.video?.ratio,s?.stats?.shareCount,s?.stats?.diggCount,s?.stats?.commentCount,s?.stats?.playCount,s.video?.downloadAddr.trim(),s?.video?.cover,s?.video?.dynamicCover,s.video?.downloadAddr.trim(),s?.video?.format,s.author));return o}async fetchUserVideos(r,e){return await(await(0,k.default)(`https://m.tiktok.com/api/post/item_list/?aid=1988&count=35&secUid=${r}&cursor=${e}`,{headers:{"Accept-Encoding":"gzip, deflate, br",Connection:"keep-alive",Cookie:"_ttp=20giOKHgEqBuTmVEAZtfn1d2hY7; ttwid=1%7CTQIxz0XiWfp7pukZEMXLVKPHz-8yYy-hFtsuP9QH6qQ%7C1666445148%7Cb9a0888038642e8181e42a5fdaac6f198842f5be356d87316064ad3bf1f53e33; _abck=2C43FEAB6D7433C06BC6BA58A7ABDFFC~-1~YAAQPeUVAveE++WDAQAAMPXe/wjYc6xTVTh4Ke+kHGxxgJfxDRcT0ee3UkTu3sYlI0/69c8OLY/v+ofiwRwfxveidVDxaESN7yjCkBHSBV2dseB7rOBVUGyOtm1hGsf/hGHEVHVopulk0NAeiJoOWsARcJDql0k07Qhcv2pmP5lYQ17fhi75Lm6tFGCSwl+O9+idv5u8yCSf675M33/mdm5vuhXjPHCASZIjZVftaPqSdJdEDy6Z772SQ3VwQhMMOMpF51aj29e99OCtMRPM3bmbda16q4UAo2m8guw0c3HxhdCTYd/R7MmqDbr51KPRFFYiGmSJj49PstRweWQY4WjaAO+0Bx9ejfYha7dp1Cp/54sYHlI2oYIpTh9c9x2NbNRlFBEghhWK+d4=~-1~-1~-1; cookie-consent={%22ga%22:true%2C%22af%22:true%2C%22fbp%22:true%2C%22lip%22:true%2C%22bing%22:true%2C%22ttads%22:true%2C%22reddit%22:true%2C%22version%22:%22v8%22}; msToken=2ly4AKsEPS3tqqICLrucL3vfxEGgfhV8yzbp4ntCJRwbL0qBr1HGS-39CmfhhfoJgh9AjO-ZZw8yPTeh7VLiaRHPjEFNe-C4p0itrLBHjbjrrnc2vk19rUJNgefqanCQvlY5zg==; bm_sz=F7CD2096F100E2BBF898F75FB340B07E~YAAQPeUVAviE++WDAQAAMPXe/xGNyQyHT0csQ+5X+XBNhPNWpfB37e3Cc+Cy6ca1L3bb3+xVQCSUzwOAZt3AfYCmfis2wGK9oUPRr+6Osp3ZBR2QFOyQX7e3HU8optmJ0xHZV0D6MZc4YzD0xlxoFSkjOxb754ZanGbuFyLJgPCXD926sCOgNBQuGx6Zgk29NwARbeoupgQrRptG/t6eFoJcDA3vL+nHqMpm6XtIXV7i4O5kXn7+E+eCybbMVhkTt+qTnMfot7ULa1NNQSDaQgwZa1UIw8eKs71dyE0cikQFjc4=~4473158~3354937; tt_csrf_token=cBoP4X6a-FRM6sy440ir5_77ij4DfchzNfWQ","User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:106.0) Gecko/20100101 Firefox/106.0",Accept:"text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8"}})).json()}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,l.existsSync)(e.path)){console.log("A folder with this username exists, that is unusual!");try{(0,l.unlinkSync)(e.path)}catch(o){console.log(`[ERROR] Could not remove ${e.path} | ||
Error Message: ${o.message}`),(0,R.exit)(1)}}(0,l.existsSync)(e.path)||(0,l.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 a=await this.noWaterMark(i.id);if(!a){console.log(`Could not fetch ${i.description?i.description:i.id} with no watermark`);continue}(0,T.default)(a).pipe((0,l.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,T.default)(i.downloadURL).pipe((0,l.createWriteStream)(`${e.path}/${i.id}_${i.resolution}.${i.format}`))}async noWaterMark(r){let e="";if(r.startsWith("https")){let a=await this.video(r);if(!a?.id)return console.log("Could not extract the Video ID from Tiktok!");e=a.id}else e=r;let o=await(await(0,k.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.play_addr;if(!i)throw new Error("There was an Error retrieveing this video without watermark!");return i.url_list[0]}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}};u(m,"TTScraper");async function _(n,r){if(!n)throw new Error("You must provide a Tiktok video url!");return await new m().video(n,r)}u(_,"fetchVideo");async function Q(n){if(!n)throw new Error("You must provide a username!");return await new m().user(n)}u(Q,"fetchUser");async function B(n){if(!n)throw new Error("You must provide a username!");return await new m().getAllVideosFromUser(n)}u(B,"fetchAllVideosFromUser");async function G(n){if(!n)throw new Error("You must provide a Tiktok video url!");return await new m().getMusic(n)}u(G,"fetchMusic");async function J(n){if(!n)throw new Error("You must provide a Tiktok video url!");return await new m().noWaterMark(n)}u(J,"fetchVideoNoWaterMark");async function H(n){if(!n)throw new Error("You must provide a tiktok hashtag");return await new m().hashTag(n)}u(H,"hashtag");module.exports=Y(Z);0&&(module.exports={Music,TTScraper,TikTokResult,User,Video,fetchAllVideosFromUser,fetchMusic,fetchUser,fetchVideo,fetchVideoNoWaterMark,hashtag}); |
{ | ||
"name": "tiktok-scraper-ts", | ||
"version": "1.3.9", | ||
"version": "1.4.0", | ||
"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
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
49435
745
3