From e2282af31c78a351a0ce3584d9d0a74939fdf6b2 Mon Sep 17 00:00:00 2001 From: Gregory Salaun Date: Mon, 25 Nov 2024 17:38:16 +0700 Subject: [PATCH] commit --- .gitignore | 3 ++ Makefile | 7 +++++ cmd/GoUploadAssistant/main.go | 20 ++++++++++++ go.mod | 9 ++++++ go.sum | 6 ++++ internal/release/release.go | 59 +++++++++++++++++++++++++++++++++++ internal/utils/utils.go | 19 +++++++++++ 7 files changed, 123 insertions(+) create mode 100644 Makefile create mode 100644 cmd/GoUploadAssistant/main.go create mode 100644 go.mod create mode 100644 go.sum create mode 100644 internal/release/release.go create mode 100644 internal/utils/utils.go diff --git a/.gitignore b/.gitignore index adf8f72..6b029c9 100644 --- a/.gitignore +++ b/.gitignore @@ -21,3 +21,6 @@ # Go workspace file go.work +*.log +.vscode +bin diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..b53a509 --- /dev/null +++ b/Makefile @@ -0,0 +1,7 @@ +BINARY_NAME=GoUploadAssistant + +build: + go build -o ./bin/${BINARY_NAME}.exe .\cmd\GoUploadAssistant\main.go + +run: + go run .\cmd\GoUploadAssistant\main.go -p "C:\\Perso\\Seafile\\Programmation\\Golang\\GoUploadAssistant\\Dune.Prophecy.S01E01.MULTi.1080p.AMZN.WEB.DDP5.1.H.265-TFA" \ No newline at end of file diff --git a/cmd/GoUploadAssistant/main.go b/cmd/GoUploadAssistant/main.go new file mode 100644 index 0000000..90fa2bb --- /dev/null +++ b/cmd/GoUploadAssistant/main.go @@ -0,0 +1,20 @@ +package main + +import ( + "flag" + "fmt" + + "git.rouggy.com/rouggy/GoUploadAssistant/internal/release" +) + +func main() { + var cfgPath, path string + flag.StringVar(&cfgPath, "cfg", "./config.yml", "path to a valid config file") + flag.StringVar(&path, "p", "", "Path to the release to upload") + + flag.Parse() + + r := release.Parse(path) + + fmt.Println(r) +} diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..0a6e833 --- /dev/null +++ b/go.mod @@ -0,0 +1,9 @@ +module git.rouggy.com/rouggy/GoUploadAssistant + +go 1.23.1 + +require ( + github.com/moistari/rls v0.5.12 // indirect + golang.org/x/sync v0.7.0 // indirect + golang.org/x/text v0.14.0 // indirect +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..5d6fe6a --- /dev/null +++ b/go.sum @@ -0,0 +1,6 @@ +github.com/moistari/rls v0.5.12 h1:PPtKMAkUT926vYiGCBmZWiU0iMMTcPmo08v28C2Sq9E= +github.com/moistari/rls v0.5.12/go.mod h1:+imnKzXNKNrbnDMppQH28S1y8ayitmniumqquzj229A= +golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M= +golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= +golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= +golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= diff --git a/internal/release/release.go b/internal/release/release.go new file mode 100644 index 0000000..f1c3994 --- /dev/null +++ b/internal/release/release.go @@ -0,0 +1,59 @@ +package release + +import ( + "path/filepath" + "strings" + + "git.rouggy.com/rouggy/GoUploadAssistant/internal/utils" + "github.com/moistari/rls" +) + +type Release struct { + TorrentName string + Title string + Season int + Episode int + Year int + Resolution string + Source string + HDR string + Audio string + AudioChannels string + Group string + Language string +} + +func Parse(path string) *Release { + var title string + + if utils.IsFolderRelease(path) { + title = filepath.Base(path) + } else { + title = strings.Replace(filepath.Base(path), ".mkv", "", 1) + } + + rel := rls.ParseString(title) + + r := Release{} + + r.TorrentName = title + r.Title = rel.Title + r.Season = rel.Series + r.Episode = rel.Episode + r.Source = rel.Source + r.Resolution = rel.Resolution + r.Year = rel.Year + if len(rel.HDR) > 0 { + r.HDR = rel.HDR[0] + } + + if len(rel.Audio) > 0 { + r.Audio = rel.Audio[0] + } + + r.AudioChannels = rel.Channels + r.Group = rel.Group + + return &r + +} diff --git a/internal/utils/utils.go b/internal/utils/utils.go new file mode 100644 index 0000000..bf5e780 --- /dev/null +++ b/internal/utils/utils.go @@ -0,0 +1,19 @@ +package utils + +import ( + "fmt" + "os" +) + +func IsFolderRelease(path string) bool { + info, err := os.Stat(path) + if err != nil { + fmt.Println(err) + } + + if info.IsDir() { + return true + } else { + return false + } +}