mirror of
https://github.com/pikami/tiktok-dl.git
synced 2026-01-06 02:56:57 +00:00
Added option to download metadata
This commit is contained in:
@@ -11,12 +11,14 @@ var Config struct {
|
||||
URL string
|
||||
OutputPath string
|
||||
Debug bool
|
||||
MetaData bool
|
||||
}
|
||||
|
||||
// GetConfig - Returns Config object
|
||||
func GetConfig() {
|
||||
outputPath := flag.String("output", "./downloads", "Output path")
|
||||
debug := flag.Bool("debug", false, "enables debug mode")
|
||||
debug := flag.Bool("debug", false, "Enables debug mode")
|
||||
metadata := flag.Bool("metadata", false, "Write video metadata to a .json file")
|
||||
flag.Parse()
|
||||
|
||||
args := flag.Args()
|
||||
@@ -28,4 +30,5 @@ func GetConfig() {
|
||||
Config.URL = flag.Args()[len(args)-1]
|
||||
Config.OutputPath = *outputPath
|
||||
Config.Debug = *debug
|
||||
Config.MetaData = *metadata
|
||||
}
|
||||
|
||||
@@ -2,13 +2,23 @@ package models
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// Upload - Upload object
|
||||
type Upload struct {
|
||||
ShareLink string `json:"shareLink"`
|
||||
URL string `json:"url"`
|
||||
ShareLink string `json:"shareLink"`
|
||||
Caption string `json:"caption"`
|
||||
Sound Sound `json:"sound"`
|
||||
}
|
||||
|
||||
// Sound - Sound object
|
||||
type Sound struct {
|
||||
Title string `json:"title"`
|
||||
Link string `json:"link"`
|
||||
}
|
||||
|
||||
// ParseUploads - Parses json uploads array
|
||||
@@ -30,3 +40,26 @@ func (u Upload) GetUploadID() string {
|
||||
parts := strings.Split(u.ShareLink, "/")
|
||||
return parts[len(parts)-1]
|
||||
}
|
||||
|
||||
// WriteToFile - Writes object to file
|
||||
func (u Upload) WriteToFile(outputPath string) {
|
||||
bytes, err := json.Marshal(u)
|
||||
if err != nil {
|
||||
fmt.Printf("Could not serialize json for video: %s", u.GetUploadID())
|
||||
fmt.Println()
|
||||
panic(err)
|
||||
}
|
||||
|
||||
// Create the file
|
||||
out, err := os.Create(outputPath)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
defer out.Close()
|
||||
|
||||
// Write to file
|
||||
_, err = out.Write(bytes)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user