-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
44 lines (37 loc) · 1.02 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package main
import (
"TikTok-DL/tiktok"
"fmt"
"io"
"os"
)
func main() {
// Validate that all arguments are given
if len(os.Args) != 3 {
fmt.Println("ERROR: Invalid arguments provided")
fmt.Println(" Usage: tiktokdl <tiktokurl> <output (no file extenchion)>")
os.Exit(1)
}
// Get the list of videos on the TikTok url
links, ttrequest := tiktok.GetVideos(os.Args[1])
if len(links) == 0 {
fmt.Println("ERROR: Found no media urls in the provided link")
os.Exit(1)
}
// Download the raw video data
rawData := tiktok.DownloadVideo(links[0], *ttrequest)
// Create the output file
file, err := os.Create(os.Args[2] + ".mp4")
if err != nil {
fmt.Println("ERROR: Failed to generate output file (permission?)")
os.Exit(1)
}
defer file.Close() // Make sure to close the stream
// Copy the bytes into the output file
_, err = io.Copy(file, rawData)
if err != nil {
fmt.Println("ERROR: Failed to write to output file (permission?)")
os.Exit(1)
}
fmt.Println("Saved output media as", os.Args[2]+".mp4")
}