or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

facebook-upload.mdindex.mdtelegram-bot.mdtiktok-api.mdvideo-processing.md

index.mddocs/

0

# TikTok Source

1

2

TikTok Source is a comprehensive Node.js application that provides functionality for downloading TikTok videos with or without watermarks and automatically uploading them to Facebook Reels. It includes optional Telegram bot integration for remote control, queue management for batch processing, and video format conversion capabilities.

3

4

## Package Information

5

6

- **Package Name**: tiktok-src

7

- **Package Type**: npm

8

- **Language**: JavaScript (ES modules)

9

- **Installation**: Clone repository and run `npm install`

10

- **License**: MIT

11

- **Main Dependencies**: puppeteer, axios, ffmpeg, chalk, telebot, better-queue

12

- **Node.js Version**: Requires Node.js with ES module support

13

14

## Core Imports

15

16

```javascript

17

import { TiktokDL } from './lib/ttapi.js';

18

import { ReelsUpload } from './lib/browserHandler.js';

19

```

20

21

## Basic Usage

22

23

```javascript

24

import { TiktokDL } from './lib/ttapi.js';

25

import { ReelsUpload } from './lib/browserHandler.js';

26

27

// Download TikTok video metadata

28

const result = await TiktokDL('https://tiktok.com/@user/video/123');

29

console.log(result.result.description);

30

31

// Upload to Facebook Reels (requires cookies.json)

32

const uploadResult = await ReelsUpload('videoId', 'My video caption');

33

console.log(uploadResult.status); // "success" or "error"

34

```

35

36

## Configuration Requirements

37

38

### Environment Variables

39

40

Create a `.env` file in the root directory:

41

42

```bash

43

# Telegram Bot Token (required for bot functionality)

44

BOT_TOKEN=your_telegram_bot_token_here

45

```

46

47

### Configuration Files

48

49

**config.json** - Bot configuration:

50

```json

51

{

52

"tokenBOT": "your_telegram_bot_token"

53

}

54

```

55

56

**cookies.json** - Facebook session cookies (required for Reels upload):

57

```json

58

[

59

{

60

"name": "cookie_name",

61

"value": "cookie_value",

62

"domain": ".facebook.com",

63

"path": "/",

64

"expires": 1234567890,

65

"httpOnly": true,

66

"secure": true

67

}

68

]

69

```

70

71

### Required Dependencies

72

73

```javascript { .api }

74

// Core dependencies and their purposes

75

interface Dependencies {

76

/** Browser automation for Facebook upload */

77

puppeteer: '^21.0.3';

78

/** HTTP requests and file downloads */

79

axios: '^1.4.0';

80

/** Video format conversion */

81

'fluent-ffmpeg': '^2.1.2';

82

/** Console output styling */

83

chalk: '^5.3.0';

84

/** Telegram bot framework */

85

telebot: '^1.4.1';

86

/** Queue management for batch processing */

87

'better-queue': '^3.8.10';

88

/** Download progress visualization */

89

progress: '^2.0.3';

90

/** Command line input handling */

91

'readline-sync': '^1.4.10';

92

/** Date/time formatting */

93

moment: '^2.29.4';

94

/** Async retry logic */

95

'async-retry': '^1.3.3';

96

/** File system utilities */

97

'fs-extra': '^11.1.1';

98

/** Process delays */

99

delay: '^6.0.0';

100

}

101

```

102

103

## Usage Patterns

104

105

This application can be used in three main ways:

106

107

1. **Command Line Interface**: Run `node index.js` for interactive download/upload

108

2. **Telegram Bot**: Run `node telebot.js` for remote control via Telegram

109

3. **Programmatic**: Import and use individual modules (`TiktokDL`, `ReelsUpload`) in custom scripts

110

111

## Architecture

112

113

TikTok Source is built around several key components:

114

115

- **TikTok API Module**: Fetches video metadata and download URLs from TikTok's API

116

- **Browser Automation**: Uses Puppeteer to upload videos to Facebook Reels

117

- **Queue System**: Manages concurrent downloads and uploads with better-queue

118

- **Telegram Bot**: Provides remote control interface with user rate limiting

119

- **Video Processing**: Handles format conversion using FFmpeg with support for WebM, AVI, MOV formats

120

- **File Management**: Organizes downloads, metadata, and converted files

121

122

## Capabilities

123

124

### TikTok Video Downloading

125

126

Core functionality for extracting video metadata, download URLs, and content from TikTok URLs. Supports both video posts and image carousels with full metadata extraction.

127

128

```javascript { .api }

129

function TiktokDL(url: string): Promise<TiktokResult>;

130

131

interface TiktokResult {

132

status: 'success' | 'error';

133

message?: string;

134

result?: VideoResult | ImageResult;

135

}

136

137

interface VideoResult {

138

type: 'video';

139

id: string;

140

createTime: number;

141

description: string;

142

hashtag: string[];

143

duration: string;

144

author: AuthorInfo;

145

video: string[];

146

cover: string[];

147

dynamicCover: string[];

148

originCover: string[];

149

music: MusicInfo;

150

}

151

152

interface ImageResult {

153

type: 'image';

154

id: string;

155

createTime: number;

156

description: string;

157

hashtag: string[];

158

author: AuthorInfo;

159

images: string[];

160

music: MusicInfo;

161

}

162

```

163

164

[TikTok API](./tiktok-api.md)

165

166

### Facebook Reels Upload

167

168

Browser automation system for uploading videos to Facebook Reels using Puppeteer. Handles session management, video upload workflow, and caption input.

169

170

```javascript { .api }

171

function ReelsUpload(namafile: string, caption: string): Promise<UploadResult>;

172

173

interface UploadResult {

174

status: 'success' | 'error';

175

message: string;

176

}

177

```

178

179

[Facebook Upload](./facebook-upload.md)

180

181

### Telegram Bot Interface

182

183

Complete bot implementation with user rate limiting, download statistics, and command handling for remote video processing.

184

185

```javascript { .api }

186

interface BotCommands {

187

'/start': () => void;

188

'/help': () => void;

189

'/stats': () => void;

190

}

191

192

function updateUserStats(userId: number): void;

193

function canUserDownload(userId: number): boolean;

194

```

195

196

[Telegram Bot](./telegram-bot.md)

197

198

### Video Processing Utilities

199

200

File management, format conversion, metadata handling, and download queue management utilities.

201

202

```javascript { .api }

203

function chooseVideoQuality(videos: VideoQuality[]): VideoQuality;

204

function saveMetadata(metadata: object, filePath: string): void;

205

function convertVideo(inputPath: string, outputPath: string, format: string): Promise<void>;

206

function downloadAndUpload(url: string, retries?: number): Promise<void>;

207

function processUrlList(filePath: string): void;

208

209

// Queue management

210

const downloadQueue: Queue<QueueTask>;

211

const MAX_DOWNLOADS_PER_DAY: number = 5;

212

```

213

214

[Video Processing](./video-processing.md)

215

216

## Types

217

218

```javascript { .api }

219

interface AuthorInfo {

220

uid: string;

221

username: string;

222

nickname: string;

223

signature: string;

224

region: string;

225

avatarThumb: string[];

226

avatarMedium: string[];

227

url: string;

228

}

229

230

interface MusicInfo {

231

id: string;

232

title: string;

233

author: string;

234

album: string;

235

playUrl: string[];

236

coverLarge: string[];

237

coverMedium: string[];

238

coverThumb: string[];

239

duration: number;

240

}

241

242

interface VideoQuality {

243

quality?: string;

244

url: string;

245

}

246

247

interface QueueTask {

248

/** TikTok URL to process */

249

url: string;

250

}

251

252

interface QueueConfig {

253

/** Number of concurrent workers (default: 2) */

254

concurrent: number;

255

}

256

257

interface TelegramBotConfig {

258

/** Bot token from environment or config */

259

token: string;

260

}

261

262

interface UserStats {

263

/** Date string from new Date().toDateString() */

264

date: string;

265

/** Download count for the date */

266

count: number;

267

}

268

269

interface BrowserConfig {

270

/** Chrome executable path */

271

executablePath: string;

272

/** Headless mode (false for debugging) */

273

headless: boolean;

274

/** Chrome launch arguments */

275

args: string[];

276

}

277

278

interface ProgressBarConfig {

279

/** Progress bar width */

280

width: number;

281

/** Complete character */

282

complete: string;

283

/** Incomplete character */

284

incomplete: string;

285

/** Render throttle in ms */

286

renderThrottle: number;

287

/** Total bytes for progress calculation */

288

total: number;

289

}

290

```