From d9b58bbade6eb370c2250b0c75c8561f00abd8fd Mon Sep 17 00:00:00 2001 From: Logan G Date: Tue, 31 Dec 2024 18:28:07 -0700 Subject: [PATCH] Added Makefile --- Makefile | 14 ++++++++++++++ config.toml | 4 ++-- ytva.go | 21 ++++++++++++++++++++- 3 files changed, 36 insertions(+), 3 deletions(-) create mode 100644 Makefile diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..1c69694 --- /dev/null +++ b/Makefile @@ -0,0 +1,14 @@ +.PHONY: default debug run + +GIT_COMMIT := $(shell git rev-parse HEAD) +BUILD_DATE := $(shell date -u +%Y%m%d.%H%M%S) +CGO_ENABLED=0 + +default: + CGO_ENABLED=$(CGO_ENABLED) go build -o out/ytva -trimpath -ldflags "-s -w -X main.gitCommit=$(GIT_COMMIT) -X main.buildDate=$(BUILD_DATE)" . + +debug: + go build -o out/ytva -ldflags "-X main.gitCommit=$(GIT_COMMIT) -X main.buildDate=$(BUILD_DATE)" . + +run: + go run . diff --git a/config.toml b/config.toml index b7aad7c..b7b3307 100644 --- a/config.toml +++ b/config.toml @@ -2,7 +2,7 @@ TempDir = "/tmp/" [Group.PCBuilders] URL = [ "https://www.youtube.com/@BudgetBuildsOfficial", "https://www.youtube.com/@RandomGaminginHD" ] -OutputDir = "out/%Channel%/%Playlist%/" +OutputDir = "videos/%Channel%/%Playlist%/" FileName = "%Timestamp% - %Title%.mkv" CFormat = "matroska" VideoFormat = "bestvideo[height<=720]" @@ -12,7 +12,7 @@ SizeLimit = 4294967296 [Group.Odysee] URL = [ "https://odysee.com/@AlphaNerd:8", "https://odysee.com/@rossmanngroup:a" ] -OutputDir = "out2/%Channel%/" +OutputDir = "videos2/%Channel%/" FileName = "%Timestamp% - %Title%.mkv" CFormat = "mp4" VideoFormat = "best[height<=720]" diff --git a/ytva.go b/ytva.go index ab1b226..aefdc15 100644 --- a/ytva.go +++ b/ytva.go @@ -3,7 +3,7 @@ package main import ( //"flag" "context" - //"fmt" + "fmt" "os" //"io" //"reflect" @@ -21,6 +21,7 @@ import ( type _flags struct { Quiet bool `arg:"-q,--quiet" help:"Output only warnings and errors."` Verbose bool `arg:"-v,--verbose" help:"Enables debug output."` + Version bool `arg:"--version" help:"Prints version of ytva and exits."` ConfigFile string `arg:"-c,--config,env:YTVA_CONFIG" help:"Specifies the path to a TOML formatted configuration file." default:"config.toml"` } @@ -50,6 +51,10 @@ type GroupConfig struct { var MainConfig _config +var gitCommit string +var buildDate string + + func main() { _ = arg.MustParse(&Flags) @@ -63,6 +68,20 @@ func main() { log.SetLevel(log.WarnLevel) } + if Flags.Version { + if gitCommit == "" { + gitCommit = "unknown" + } + + if buildDate == "" { + buildDate = "unknown" + } + + fmt.Printf("Commit %s built on %s\n", gitCommit, buildDate) + + os.Exit(0) + } + confFile, err := os.ReadFile(Flags.ConfigFile) if(err != nil) { log.Fatal(err)