This commit is contained in:
Gregory Salaun 2023-12-18 08:35:21 +07:00
parent f5d370e3e0
commit d545e76bfa
5 changed files with 67 additions and 13 deletions

3
.gitignore vendored
View File

@ -1 +1,2 @@
log.txt
log.txt
config.yml

View File

@ -8,6 +8,8 @@ import (
"path/filepath"
"slices"
"strings"
"gopkg.in/yaml.v2"
)
type GotifyMessage struct {
@ -25,15 +27,49 @@ type MediaFiles struct {
Arr string
}
func (m *MediaFiles) SendGotify(message string, arr string) {
type Config struct {
Gotify struct {
Enabled bool `yaml:"enabled"`
ServerURL string `yaml:"server_url"`
Token string `yaml:"token"`
} `yaml:"gotify"`
General struct {
RootFolders []string `yaml:"root_folders"`
} `yaml:"general"`
}
http.PostForm("https://gotify.rouggy.com/message?token=AKMj5SsZblmpAJ_",
func NewConfig(configPath string) (*Config, error) {
// Create config structure
config := &Config{}
// Open config file
file, err := os.Open(configPath)
if err != nil {
return nil, err
}
defer file.Close()
// Init new YAML decode
d := yaml.NewDecoder(file)
// Start YAML decoding from file
if err := d.Decode(&config); err != nil {
return nil, err
}
return config, nil
}
func (m *MediaFiles) SendGotify(message string, arr string, cfg *Config) {
http.PostForm(cfg.Gotify.ServerURL+"/message?token="+cfg.Gotify.Token,
url.Values{"message": {message}, "title": {"Deleting Media from " + arr}, "priority": {"10"}})
}
func (m *MediaFiles) IsInFolder() {
folderList := []string{"Movies", "4K-Movies", "Series", "4K-Series", "Kids", "Animes"}
func (m *MediaFiles) IsInFolder(cfg *Config) {
folderList := cfg.General.RootFolders
// []string{"Movies", "4K-Movies", "Series", "4K-Series", "Kids", "Animes"}
SplitFolder := strings.Split(m.SourcePath, "/")
LastFolder := SplitFolder[len(SplitFolder)-2]
@ -54,9 +90,9 @@ func (m *MediaFiles) IsInFolder() {
func main() {
// os.Setenv("radarr_moviefile_sourcepath", "/mnt/Multimedia/Download/PostProcess/Movies/Butchers.Crossing.2023.MULTi.1080p.WEB.x264-FW.mkv")
// os.Setenv("radarr_moviefile_sourcefolder", "/mnt/Multimedia/Download/PostProcess/Movies")
// os.Setenv("radarr_eventtype", "Download")
os.Setenv("radarr_moviefile_sourcepath", "/mnt/Multimedia/Download/PostProcess/Movies/Butchers.Crossing.2023.MULTi.1080p.WEB.x264-FW.mkv")
os.Setenv("radarr_moviefile_sourcefolder", "/mnt/Multimedia/Download/PostProcess/Movies")
os.Setenv("radarr_eventtype", "Download")
// os.Setenv("EventType", "Test")
if os.Getenv("radarr_eventtype") == "Test" || os.Getenv("sonarr_eventtype") == "Test" {
@ -70,6 +106,13 @@ func main() {
}
exPath := filepath.Dir(ex)
configPath := filepath.Join(exPath, "config.yml")
cfg, err := NewConfig(configPath)
if err != nil {
log.Fatal(err)
}
f, err := os.OpenFile(exPath+"/log.txt", os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
if err != nil {
log.Fatalf("error opening file: %v", err)
@ -102,7 +145,7 @@ func main() {
m.Arr = "Sonarr"
}
m.IsInFolder()
m.IsInFolder(cfg)
if m.InFolder {
@ -143,6 +186,6 @@ func main() {
log.Printf("Deleting the file %v", m.SourcePath)
}
m.SendGotify("Deleting Source Path"+m.SourcePath, m.Arr)
m.SendGotify("Deleting Source Path"+m.SourcePath, m.Arr, cfg)
}

View File

@ -1,6 +1,11 @@
gotify:
enabled: false
server_url: "https://gotify.url.com"
token: ""
server_url: https://gotify.rouggy.com
token:
general:
root_folders: ["Movies", "4K-Movies", "Series", "4K-Series", "Kids"]
root_folders:
- Movies
- 4K-Movies
- Series
- 4K-Series
- Kids

2
go.mod
View File

@ -1,3 +1,5 @@
module git.rouggy.com/DeleteArr
go 1.21.4
require gopkg.in/yaml.v2 v2.4.0 // indirect

3
go.sum Normal file
View File

@ -0,0 +1,3 @@
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=