This commit is contained in:
Gregory Salaun 2023-12-17 17:37:39 +07:00
parent 7e096922a3
commit 50f1a502a4

View File

@ -8,35 +8,28 @@ import (
"slices" "slices"
) )
type RadarrMovie struct { type MediaFiles struct {
EventType string EventType string
SourcePath string SourcePath string
SourceFolder string SourceFolder string
FileName string FileName string
InFolder bool InFolder bool
Arr string
} }
type SonarrSerie struct { func (m *MediaFiles) IsInFolder() {
SourcePath string
SourceFolder string
FileName string
InFolder bool
SeasonFolder bool
}
func (r *RadarrMovie) IsInFolder() {
folderList := []string{"Movies", "4K-Movies"} folderList := []string{"Movies", "4K-Movies"}
dir, f := path.Split(r.SourcePath) dir, f := path.Split(m.SourcePath)
r.FileName = f m.FileName = f
ContainsFolder := slices.Contains(folderList, dir) ContainsFolder := slices.Contains(folderList, dir)
if !ContainsFolder { if !ContainsFolder {
r.InFolder = true m.InFolder = true
log.Printf("Movie %v is in a Folder\n", r.SourceFolder) log.Printf("Movie %v is in a Folder\n", m.SourceFolder)
} else { } else {
r.InFolder = false m.InFolder = false
log.Printf("Movie %v is not in a Folder\n", r.SourceFolder) log.Printf("Movie %v is not in a Folder\n", m.SourceFolder)
} }
} }
@ -63,18 +56,30 @@ func main() {
RadarrEventType := os.Getenv("radarr_eventtype") RadarrEventType := os.Getenv("radarr_eventtype")
SonarrEventType := os.Getenv("sonarr_eventtype") SonarrEventType := os.Getenv("sonarr_eventtype")
m := &MediaFiles{}
if RadarrEventType != "" { if RadarrEventType != "" {
r := &RadarrMovie{} m.EventType = os.Getenv("rad")
r.EventType = os.Getenv("radarr_eventtype") m.SourcePath = os.Getenv("radarr_moviefile_sourcepath")
r.SourcePath = os.Getenv("radarr_moviefile_sourcepath") log.Println(m.SourcePath)
log.Println(r.SourcePath) m.SourceFolder = os.Getenv("radarr_moviefile_sourcefolder")
r.SourceFolder = os.Getenv("radarr_moviefile_sourcefolder") log.Println(m.SourceFolder)
log.Println(r.SourceFolder)
r.IsInFolder() }
if r.InFolder { if SonarrEventType != "" {
f, err := os.Open(r.SourceFolder) m.EventType = os.Getenv("sonarr_eventtype")
m.SourcePath = os.Getenv("sonarr_episodefile_sourcepath")
log.Println(m.SourcePath)
m.SourceFolder = os.Getenv("radarr_moviefile_sourcefolder")
log.Println(m.SourceFolder)
}
m.IsInFolder()
if m.InFolder {
f, err := os.Open(m.SourceFolder)
if err != nil { if err != nil {
log.Println(err) log.Println(err)
return return
@ -86,17 +91,8 @@ func main() {
} }
for _, v := range files { for _, v := range files {
log.Println(v.Name(), v.IsDir()) log.Println(v.Name())
} }
} }
}
if SonarrEventType != "" {
s := &SonarrSerie{}
s.SourcePath = os.Getenv("sonarr_episodefile_sourcepath")
log.Println(s.SourcePath)
s.SourceFolder = os.Getenv("radarr_moviefile_sourcefolder")
log.Println(s.SourceFolder)
}
} }