tiktok-scraper-ts
Advanced tools
Comparing version 1.1.0 to 1.2.0
@@ -48,2 +48,6 @@ import { IVideo } from "../../Interfaces"; | ||
/** | ||
* a direct download url for the video | ||
*/ | ||
downloadURL: string; | ||
/** | ||
* a direct url to the video cover | ||
@@ -61,6 +65,2 @@ */ | ||
/** | ||
* a direct download url for the video | ||
*/ | ||
downloadURL?: string | undefined; | ||
/** | ||
* the format of the video | ||
@@ -88,4 +88,4 @@ */ | ||
*/ | ||
constructor(id: string, description: string, createdAt: string, height: number, width: number, duration: number, resolution: string, shareCount: number, likesCount: number, commentCount: number, playCount: number, cover?: string | undefined, dynamicCover?: string | undefined, playURL?: string | undefined, downloadURL?: string | undefined, format?: string | undefined); | ||
constructor(id: string, description: string, createdAt: string, height: number, width: number, duration: number, resolution: string, shareCount: number, likesCount: number, commentCount: number, playCount: number, downloadURL: string, cover?: string | undefined, dynamicCover?: string | undefined, playURL?: string | undefined, format?: string | undefined); | ||
} | ||
//# sourceMappingURL=Video.d.ts.map |
@@ -24,3 +24,3 @@ "use strict"; | ||
*/ | ||
constructor(id, description, createdAt, height, width, duration, resolution, shareCount, likesCount, commentCount, playCount, cover, dynamicCover, playURL, downloadURL, format) { | ||
constructor(id, description, createdAt, height, width, duration, resolution, shareCount, likesCount, commentCount, playCount, downloadURL, cover, dynamicCover, playURL, format) { | ||
this.id = id; | ||
@@ -27,0 +27,0 @@ this.description = description; |
@@ -51,3 +51,9 @@ import { IVideo } from "../../Interfaces/index"; | ||
getMusic(link: string): Promise<Music>; | ||
/** | ||
* Downloads all videos from a user page! | ||
* @param username tiktok username of the user | ||
* @param path the path where the videos should be downloaded. This is optional | ||
*/ | ||
downloadAllVideosFromUser(username: string, path?: string): Promise<void>; | ||
} | ||
//# sourceMappingURL=TikTokScraper.d.ts.map |
@@ -31,2 +31,5 @@ "use strict"; | ||
const Entities_1 = require("../Entities"); | ||
const node_fs_1 = require("node:fs"); | ||
const node_process_1 = require("node:process"); | ||
const miniget_1 = __importDefault(require("miniget")); | ||
class TTScraper { | ||
@@ -135,3 +138,3 @@ /** | ||
ItemList["user-post"].list.forEach((id) => { | ||
videos.push(new Entities_1.Video(userJsonObject.ItemModule[id].video.id, userJsonObject.ItemModule[id].desc, new Date(Number(userJsonObject.ItemModule[id].createTime) * 1000).toLocaleDateString(), Number(userJsonObject.ItemModule[id].video.height), Number(userJsonObject.ItemModule[id].video.width), Number(userJsonObject.ItemModule[id].video.duration), userJsonObject.ItemModule[id].video.ratio, userJsonObject.ItemModule[id].stats.shareCount, userJsonObject.ItemModule[id].stats.diggCount, userJsonObject.ItemModule[id].stats.commentCount, userJsonObject.ItemModule[id].stats.playCount, userJsonObject.ItemModule[id].video.cover, userJsonObject.ItemModule[id].video.dynamicCover, userJsonObject.ItemModule[id].video.playAddr.trim(), userJsonObject.ItemModule[id].video.downloadAddr.trim(), userJsonObject.ItemModule[id].video.format)); | ||
videos.push(new Entities_1.Video(userJsonObject.ItemModule[id].video.id, userJsonObject.ItemModule[id].desc, new Date(Number(userJsonObject.ItemModule[id].createTime) * 1000).toLocaleDateString(), Number(userJsonObject.ItemModule[id].video.height), Number(userJsonObject.ItemModule[id].video.width), Number(userJsonObject.ItemModule[id].video.duration), userJsonObject.ItemModule[id].video.ratio, userJsonObject.ItemModule[id].stats.shareCount, userJsonObject.ItemModule[id].stats.diggCount, userJsonObject.ItemModule[id].stats.commentCount, userJsonObject.ItemModule[id].stats.playCount, userJsonObject.ItemModule[id].video.downloadAddr.trim(), userJsonObject.ItemModule[id].video.cover, userJsonObject.ItemModule[id].video.dynamicCover, userJsonObject.ItemModule[id].video.playAddr.trim(), userJsonObject.ItemModule[id].video.format)); | ||
}); | ||
@@ -155,4 +158,36 @@ return videos; | ||
} | ||
/** | ||
* Downloads all videos from a user page! | ||
* @param username tiktok username of the user | ||
* @param path the path where the videos should be downloaded. This is optional | ||
*/ | ||
async downloadAllVideosFromUser(username, path) { | ||
if (!username) | ||
throw new Error("Please enter a username!"); | ||
const getAllvideos = await this.getAllVideosFromUser(username); | ||
if (!getAllvideos) | ||
throw new Error("No Videos were found for this username. Either the videos are private or the user has not videos"); | ||
if (!path) { | ||
path = __dirname + "/../../../" + username; | ||
if ((0, node_fs_1.existsSync)(path)) { | ||
console.log(`A folder with this username exists, that is unusual!`); | ||
try { | ||
(0, node_fs_1.unlinkSync)(path); | ||
} | ||
catch (error) { | ||
console.log(`[ERROR] Could not remove ${path}\n Error Message: ${error.message}`); | ||
(0, node_process_1.exit)(1); | ||
} | ||
} | ||
if (!(0, node_fs_1.existsSync)(path)) { | ||
(0, node_fs_1.mkdirSync)(path); | ||
} | ||
} | ||
getAllvideos.forEach((video, index) => { | ||
console.log(`Downloading Video: ${video.description ? video.description : video.id}, [${index + 1}/${getAllvideos.length}]`); | ||
(0, miniget_1.default)(video.downloadURL).pipe((0, node_fs_1.createWriteStream)(`${path}/${video.id}_${video.resolution}.${video.fomrat}`)); | ||
}); | ||
} | ||
} | ||
exports.TTScraper = TTScraper; | ||
//# sourceMappingURL=TikTokScraper.js.map |
@@ -50,2 +50,6 @@ /** | ||
/** | ||
* a direct download url for the video | ||
*/ | ||
downloadURL: string; | ||
/** | ||
* a direct url to the video cover | ||
@@ -63,6 +67,2 @@ */ | ||
/** | ||
* a direct download url for the video | ||
*/ | ||
downloadURL?: string; | ||
/** | ||
* the format of the video | ||
@@ -69,0 +69,0 @@ */ |
{ | ||
"name": "tiktok-scraper-ts", | ||
"version": "1.1.0", | ||
"version": "1.2.0", | ||
"description": "A scraper for tiktok videos", | ||
@@ -30,4 +30,5 @@ "main": "dist/main.js", | ||
"cheerio": "^1.0.0-rc.10", | ||
"miniget": "^4.2.2", | ||
"node-fetch": "^2.6.7" | ||
} | ||
} |
@@ -36,2 +36,3 @@ # tiktok-scraper | ||
.getMusic(url) Scrapes Music info from a video. Returns Promise<Music> | ||
.downloadAllVideosFromUser(username, path?: optional) Downloads all Videos of the given user. Returns Promise<void> | ||
``` | ||
@@ -38,0 +39,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
111376
975
307
3
+ Addedminiget@^4.2.2
+ Addedminiget@4.2.3(transitive)