mirror of
https://github.com/pikami/tiktok-dl.git
synced 2026-01-08 03:55:30 +00:00
Download videos by hashtag; get json data without video downloading; limit option
This commit is contained in:
@@ -1,48 +1,57 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"os"
|
||||
"flag"
|
||||
"fmt"
|
||||
"os"
|
||||
)
|
||||
|
||||
// Config - Runtime configuration
|
||||
var Config struct {
|
||||
URL string
|
||||
OutputPath string
|
||||
BatchFilePath string
|
||||
Debug bool
|
||||
MetaData bool
|
||||
Quiet bool
|
||||
Deadline int
|
||||
URL string
|
||||
OutputPath string
|
||||
BatchFilePath string
|
||||
Debug bool
|
||||
MetaData bool
|
||||
Quiet bool
|
||||
Deadline int
|
||||
Limit int
|
||||
JSONOnly bool
|
||||
}
|
||||
|
||||
// GetConfig - Returns Config object
|
||||
func GetConfig() {
|
||||
outputPath := flag.String("output", "./downloads", "Output path")
|
||||
batchFilePath := flag.String("batch-file", "", "File containing URLs/Usernames to download, one value per line. Lines starting with '#', are considered as comments and ignored.")
|
||||
debug := flag.Bool("debug", false, "Enables debug mode")
|
||||
metadata := flag.Bool("metadata", false, "Write video metadata to a .json file")
|
||||
quiet := flag.Bool("quiet", false, "Supress output")
|
||||
deadline := flag.Int("deadline", 1500, "Sets the timout for scraper logic in seconds (used as a workaround for 'context deadline exceeded' error)")
|
||||
flag.Parse()
|
||||
outputPath := flag.String("output", "./downloads", "Output path")
|
||||
batchFilePath := flag.String("batch-file", "", "File containing URLs/Usernames to download, one value per line. Lines starting with '#', are considered as comments and ignored.")
|
||||
debug := flag.Bool("debug", false, "Enables debug mode")
|
||||
metadata := flag.Bool("metadata", false, "Write video metadata to a .json file")
|
||||
quiet := flag.Bool("quiet", false, "Supress output")
|
||||
deadline := flag.Int("deadline", 1500, "Sets the timout for scraper logic in seconds (used as a workaround for 'context deadline exceeded' error)")
|
||||
limit := flag.Int("limit", 0, "Sets the videos count limit (useful when there too many videos from the user or by hashtag)")
|
||||
jsonOnly := flag.Bool("json", false, "Just get JSON data from scraper (without video downloading)")
|
||||
flag.Parse()
|
||||
|
||||
args := flag.Args()
|
||||
if len(args) < 1 && *batchFilePath == "" {
|
||||
fmt.Println("Usage: tiktok-dl [OPTIONS] TIKTOK_USERNAME|TIKTOK_URL")
|
||||
fmt.Println(" or: tiktok-dl [OPTIONS] -batch-file path/to/users.txt")
|
||||
os.Exit(2)
|
||||
}
|
||||
args := flag.Args()
|
||||
if len(args) < 1 && *batchFilePath == "" {
|
||||
fmt.Println("Usage: tiktok-dl [OPTIONS] TIKTOK_USERNAME|TIKTOK_URL")
|
||||
fmt.Println(" or: tiktok-dl [OPTIONS] -batch-file path/to/users.txt")
|
||||
os.Exit(2)
|
||||
}
|
||||
|
||||
if len(args) > 0 {
|
||||
Config.URL = flag.Args()[len(args)-1]
|
||||
} else {
|
||||
Config.URL = ""
|
||||
}
|
||||
Config.OutputPath = *outputPath
|
||||
Config.BatchFilePath = *batchFilePath
|
||||
Config.Debug = *debug
|
||||
Config.MetaData = *metadata
|
||||
Config.Quiet = *quiet
|
||||
Config.Deadline = *deadline
|
||||
if len(args) > 0 {
|
||||
Config.URL = flag.Args()[len(args)-1]
|
||||
} else {
|
||||
Config.URL = ""
|
||||
}
|
||||
Config.OutputPath = *outputPath
|
||||
Config.BatchFilePath = *batchFilePath
|
||||
Config.Debug = *debug
|
||||
Config.MetaData = *metadata
|
||||
Config.Quiet = *quiet
|
||||
if *jsonOnly {
|
||||
Config.Quiet = true
|
||||
}
|
||||
Config.Deadline = *deadline
|
||||
Config.Limit = *limit
|
||||
Config.JSONOnly = *jsonOnly;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user