fix: regex validate tiktok url

This commit is contained in:
TobyG74 2024-04-06 22:23:03 +07:00
parent 1b4d55be6a
commit f00fa49394
6 changed files with 34 additions and 15 deletions

View File

@ -19,6 +19,7 @@
- [Description](#description) - [Description](#description)
- [How to get Tiktok Cookie](#how-to-get-tiktok-cookie) - [How to get Tiktok Cookie](#how-to-get-tiktok-cookie)
- [Build this project](#build-this-project)
- [Install](#install) - [Install](#install)
- [From NPM](#from-npm) - [From NPM](#from-npm)
- [From Yarn](#from-yarn) - [From Yarn](#from-yarn)
@ -41,12 +42,32 @@ This project uses the Unofficial API from Tiktok.
# How to get Tiktok Cookie # How to get Tiktok Cookie
(If the Default Cookie Has Expired) You can use cookies in the form of String or JSON
- Login at [Tiktok](https://www.tiktok.com/) - Method 1 (String) :
- When you have finished logging in, you can press CTRL + SHIFT + I or Right Click and select Inspect
- Go to the Console section then type <b>document.cookie<b> Login to the [Tiktok website](https://tiktok/.com) -> Open the **Inspect Element** or you can press the shortcut **CTRL + SHIFT + I** -> Go to network -> Find the request that goes to tiktok then open the request and look for **Cookie**
- Then Copy Paste your Cookie and Use it for TiktokStalk
![Capture](https://github.com/TobyG74/tiktok-api-dl/assets/32604979/c516e5e8-7b8f-43cb-aa2e-2bbe92944dac)
- Method 2 (JSON) :
You can use the chrome extension [EditThisCookies](https://chromewebstore.google.com/detail/editthiscookie/fngmhnnpilhplaeedifhccceomclgfbg) -> Login to the [Tiktok website](https://tiktok/.com) -> Then open the **EditThisCookie** extension -> Then click **Export Cookie**
![Capture2](https://github.com/TobyG74/tiktok-api-dl/assets/32604979/fa0e4bc7-a646-4551-a974-160881a98198)
# Build this project
- Clone the repository
- Install the dependencies
- Run the build script
```bash
git clone https://github.com/TobyG74/tiktok-api-dl.git
cd tiktok-api-dl
npm install
npm run build
```
# Install # Install
@ -79,7 +100,7 @@ npm install github:TobyG74/tiktok-api-dl
- V3 uses the API from [MusicalDown](https://musicaldown.com/) - V3 uses the API from [MusicalDown](https://musicaldown.com/)
```js ```js
const { default: Tiktok } = require("@tobyg74/tiktok-api-dl") const Tiktok = require("@tobyg74/tiktok-api-dl")
const tiktok_url = "https://vt.tiktok.com/ZS84BnrU9" const tiktok_url = "https://vt.tiktok.com/ZS84BnrU9"
@ -97,7 +118,7 @@ Tiktok.Downloader(tiktok_url, {
- Using Your Cookie - Using Your Cookie
```js ```js
const { default: Tiktok } = require("@tobyg74/tiktok-api-dl") const Tiktok = require("@tobyg74/tiktok-api-dl")
const username = "tobz2k19" const username = "tobz2k19"
@ -115,7 +136,7 @@ Tiktok.Search(username, {
- Using Your Cookie - Using Your Cookie
```js ```js
const { default: Tiktok } = require("@tobyg74/tiktok-api-dl") const Tiktok = require("@tobyg74/tiktok-api-dl")
const username = "tobz2k19" const username = "tobz2k19"

View File

@ -1,6 +1,6 @@
{ {
"name": "@tobyg74/tiktok-api-dl", "name": "@tobyg74/tiktok-api-dl",
"version": "1.1.1", "version": "1.1.2",
"description": "Scraper for downloading media in the form of videos, images and audio from Tiktok. Also for stalking Tiktok Users", "description": "Scraper for downloading media in the form of videos, images and audio from Tiktok. Also for stalking Tiktok Users",
"main": "lib/index.js", "main": "lib/index.js",
"types": "lib/index.d.ts", "types": "lib/index.d.ts",

View File

@ -17,7 +17,7 @@ import { StalkResult } from "./types/search/stalker"
type TiktokDownloaderResponse<T extends "v1" | "v2" | "v3"> = T extends "v1" ? TiktokAPIResponse : T extends "v2" ? SSSTikResponse : T extends "v3" ? MusicalDownResponse : TiktokAPIResponse type TiktokDownloaderResponse<T extends "v1" | "v2" | "v3"> = T extends "v1" ? TiktokAPIResponse : T extends "v2" ? SSSTikResponse : T extends "v3" ? MusicalDownResponse : TiktokAPIResponse
type TiktokSearchResponse<T extends "user" | "video"> = T extends "user" ? TiktokUserSearchResponse : T extends "video" ? any : TiktokUserSearchResponse type TiktokSearchResponse<T extends "user" | "video"> = T extends "user" ? TiktokUserSearchResponse : T extends "video" ? any : TiktokUserSearchResponse
export const Tiktok = { export = {
Downloader: async <T extends "v1" | "v2" | "v3">(url: string, options?: { version: T }): Promise<TiktokDownloaderResponse<T>> => { Downloader: async <T extends "v1" | "v2" | "v3">(url: string, options?: { version: T }): Promise<TiktokDownloaderResponse<T>> => {
switch (options?.version) { switch (options?.version) {
case "v1": { case "v1": {
@ -59,5 +59,3 @@ export const Tiktok = {
return response return response
} }
} }
export default Tiktok

View File

@ -8,7 +8,7 @@ import { _musicaldownapi, _musicaldownmusicapi, _musicaldownurl } from "../../co
* BASE URL : https://ssstik.io * BASE URL : https://ssstik.io
*/ */
const TiktokURLregex = /(?:http[s]?:\/\/)?(?:www\.|m\.)?(?:tiktok\.com\/(?:@[\w.-]+\/video\/|@[\w.-]+\/video\/))?(\d+)/ const TiktokURLregex = /https:\/\/(?:m|www|vm|vt)?\.?tiktok\.com\/((?:.*\b(?:(?:usr|v|embed|user|video)\/|\?shareId=|\&item_id=)(\d+))|\w+)/
const getRequest = (url: string) => const getRequest = (url: string) =>
new Promise<getRequest>((resolve, reject) => { new Promise<getRequest>((resolve, reject) => {

View File

@ -8,7 +8,7 @@ import { _ssstikapi, _ssstikurl } from "../../constants/api"
* BASE URL : https://ssstik.io * BASE URL : https://ssstik.io
*/ */
const TiktokURLregex = /(?:http[s]?:\/\/)?(?:www\.|m\.)?(?:tiktok\.com\/(?:@[\w.-]+\/video\/|@[\w.-]+\/video\/))?(\d+)/ const TiktokURLregex = /https:\/\/(?:m|www|vm|vt)?\.?tiktok\.com\/((?:.*\b(?:(?:usr|v|embed|user|video)\/|\?shareId=|\&item_id=)(\d+))|\w+)/
const fetchTT = () => const fetchTT = () =>
new Promise<SSSTikFetchTT>(async (resolve, reject) => { new Promise<SSSTikFetchTT>(async (resolve, reject) => {

View File

@ -3,7 +3,7 @@ import { _tiktokapi, _tiktokurl } from "../../constants/api"
import { _tiktokApiParams } from "../../constants/params" import { _tiktokApiParams } from "../../constants/params"
import { Author, TiktokAPIResponse, Statistics, Music, responseParser, Video } from "../../types/downloader/tiktokApi" import { Author, TiktokAPIResponse, Statistics, Music, responseParser, Video } from "../../types/downloader/tiktokApi"
const TiktokURLregex = /(?:http[s]?:\/\/)?(?:www\.|m\.)?(?:tiktok\.com\/(?:@[\w.-]+\/video\/|@[\w.-]+\/video\/))?(\d+)/ const TiktokURLregex = /https:\/\/(?:m|www|vm|vt)?\.?tiktok\.com\/((?:.*\b(?:(?:usr|v|embed|user|video)\/|\?shareId=|\&item_id=)(\d+))|\w+)/
/** /**
* Tiktok API Downloader * Tiktok API Downloader