2020-02-07 23:51:17 +00:00
|
|
|
package config
|
2020-01-19 02:11:53 +00:00
|
|
|
|
|
|
|
import (
|
2020-02-24 23:01:10 +00:00
|
|
|
"flag"
|
|
|
|
"fmt"
|
|
|
|
"os"
|
2020-04-12 14:56:50 +01:00
|
|
|
"strconv"
|
|
|
|
|
|
|
|
res "github.com/pikami/tiktok-dl/resources"
|
2020-01-19 02:11:53 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// Config - Runtime configuration
|
|
|
|
var Config struct {
|
2020-08-16 16:56:30 +01:00
|
|
|
URL string
|
|
|
|
OutputPath string
|
|
|
|
BatchFilePath string
|
|
|
|
ScrapedDataFilePath string
|
|
|
|
ArchiveFilePath string
|
|
|
|
FailLogFilePath string
|
|
|
|
Debug bool
|
|
|
|
MetaData bool
|
|
|
|
Quiet bool
|
|
|
|
JSONOnly bool
|
|
|
|
Deadline int
|
|
|
|
Limit int
|
2020-01-19 02:11:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// GetConfig - Returns Config object
|
|
|
|
func GetConfig() {
|
2020-04-12 14:56:50 +01:00
|
|
|
outputPath := flag.String(res.OutputFlag, res.OutputDefault, res.OutputDescription)
|
|
|
|
batchFilePath := flag.String(res.BatchFlag, res.BatchDefault, res.BatchDescription)
|
2020-08-16 16:56:30 +01:00
|
|
|
scrapedDataFilePath := flag.String(res.ScrapedDataFlag, res.ScrapedDataDefault, res.ScrapedDataDescription)
|
2020-04-12 14:56:50 +01:00
|
|
|
archive := flag.String(res.ArchiveFlag, res.ArchiveDefault, res.ArchiveDescription)
|
|
|
|
failLogPath := flag.String(res.FailLogFlag, res.FailLogDefault, res.FailLogDescription)
|
|
|
|
debug := flag.Bool(res.DebugFlag, parseBool(res.DebugDefault), res.DebugDescription)
|
|
|
|
metadata := flag.Bool(res.MetadataFlag, parseBool(res.MetadataDefault), res.MetadataDescription)
|
|
|
|
quiet := flag.Bool(res.QuietFlag, parseBool(res.QuietDefault), res.QuietDescription)
|
|
|
|
jsonOnly := flag.Bool(res.JsonFlag, parseBool(res.JsonDefault), res.JsonDescription)
|
|
|
|
deadline := flag.Int(res.DeadlineFlag, parseInt(res.DeadlineDefault), res.DeadlineDescription)
|
|
|
|
limit := flag.Int(res.LimitFlag, parseInt(res.LimitDefault), res.LimitDescription)
|
2020-02-24 23:01:10 +00:00
|
|
|
flag.Parse()
|
2020-01-19 02:11:53 +00:00
|
|
|
|
2020-02-24 23:01:10 +00:00
|
|
|
args := flag.Args()
|
2020-08-16 16:56:30 +01:00
|
|
|
if len(args) < 1 && *batchFilePath == "" && *scrapedDataFilePath == "" {
|
2020-04-12 14:56:50 +01:00
|
|
|
fmt.Println(res.UsageLine)
|
2020-02-24 23:01:10 +00:00
|
|
|
os.Exit(2)
|
|
|
|
}
|
2020-01-19 02:11:53 +00:00
|
|
|
|
2020-02-24 23:01:10 +00:00
|
|
|
if len(args) > 0 {
|
|
|
|
Config.URL = flag.Args()[len(args)-1]
|
|
|
|
} else {
|
|
|
|
Config.URL = ""
|
|
|
|
}
|
|
|
|
Config.OutputPath = *outputPath
|
|
|
|
Config.BatchFilePath = *batchFilePath
|
2020-08-16 16:56:30 +01:00
|
|
|
Config.ScrapedDataFilePath = *scrapedDataFilePath
|
2020-03-22 00:10:24 +00:00
|
|
|
Config.ArchiveFilePath = *archive
|
2020-04-09 16:10:33 +01:00
|
|
|
Config.FailLogFilePath = *failLogPath
|
2020-02-24 23:01:10 +00:00
|
|
|
Config.Debug = *debug
|
|
|
|
Config.MetaData = *metadata
|
|
|
|
Config.Quiet = *quiet
|
|
|
|
if *jsonOnly {
|
|
|
|
Config.Quiet = true
|
|
|
|
}
|
2020-03-22 00:10:24 +00:00
|
|
|
Config.JSONOnly = *jsonOnly
|
2020-02-24 23:01:10 +00:00
|
|
|
Config.Deadline = *deadline
|
|
|
|
Config.Limit = *limit
|
2020-01-19 02:11:53 +00:00
|
|
|
}
|
2020-04-12 14:56:50 +01:00
|
|
|
|
|
|
|
func parseBool(str string) bool {
|
|
|
|
val, err := strconv.ParseBool(str)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
return val
|
|
|
|
}
|
|
|
|
|
|
|
|
func parseInt(str string) int {
|
|
|
|
val, err := strconv.Atoi(str)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
return val
|
|
|
|
}
|