Housekeeper/cmd/main.go

89 lines
2.4 KiB
Go
Raw Normal View History

2018-10-16 17:16:58 +00:00
package main
2018-10-16 20:06:46 +00:00
import (
"flag"
"log"
"sort"
"strconv"
"strings"
2018-11-14 03:51:03 +00:00
2018-11-15 05:34:24 +00:00
"git.linuxrocker.com/mattburchett/Housekeeper/pkg/communicator"
2018-11-14 03:51:03 +00:00
"git.linuxrocker.com/mattburchett/Housekeeper/pkg/config"
2018-11-15 05:34:24 +00:00
"git.linuxrocker.com/mattburchett/Housekeeper/pkg/eraser"
2018-11-14 03:51:03 +00:00
"git.linuxrocker.com/mattburchett/Housekeeper/pkg/locator"
2018-10-16 20:06:46 +00:00
)
2018-10-17 17:21:16 +00:00
func main() {
2018-11-14 03:51:03 +00:00
var c string
2018-10-17 17:21:16 +00:00
var days int
var sectionID string
2018-11-15 05:34:24 +00:00
var check bool
var text bool
2018-11-15 05:34:24 +00:00
var delete bool
2018-11-14 03:51:03 +00:00
flag.StringVar(&c, "config", "", "Configuration to load")
2018-11-15 05:39:41 +00:00
flag.IntVar(&days, "days", 0, "How many days of inactivity to look for on Plex.")
flag.StringVar(&sectionID, "sectionid", "", "Plex Section ID. Multiples can be specified (separated by a comma). Ex: 1,2")
2018-11-15 05:39:41 +00:00
flag.BoolVar(&check, "check", true, "Perform only a check. This will send the message out to Telegram with what can be removed. Does not delete.")
2020-09-23 15:17:34 +00:00
flag.BoolVar(&text, "text", false, "This will override the communication to Telegram and print to stdout.")
2018-11-15 05:34:24 +00:00
flag.BoolVar(&delete, "delete", false, "Perform the delete task.")
2018-10-17 17:21:16 +00:00
flag.Parse()
2018-11-15 05:54:59 +00:00
// Stop the app if they're missing required flags.
2018-11-14 03:51:03 +00:00
if c == "" {
log.Fatal("You need to specify a configuration file.")
}
if sectionID == "" {
2018-11-14 03:51:03 +00:00
log.Fatal("You need to specify a section ID for Plex.")
}
2018-10-17 17:21:16 +00:00
2018-11-14 03:51:03 +00:00
cfg, err := config.GetConfig(c)
2018-10-17 19:40:19 +00:00
if err != nil {
log.Fatal(err)
}
2018-11-15 05:34:24 +00:00
sectionIds := strings.Split(sectionID, ",")
titlesFullList := make([]string, 0)
for _, section := range sectionIds {
sectionIDConv, _ := strconv.Atoi(section)
libraryType := locator.GetLibraryType(cfg, sectionIDConv)
2018-11-15 05:34:24 +00:00
ids, titles := locator.GetTitles(cfg, sectionIDConv, days)
for _, title := range titles {
titlesFullList = append(titlesFullList, title)
}
if delete {
if libraryType == "movie" {
files := eraser.LookupMovieFileLocation(cfg, ids)
err = eraser.DeleteFiles(delete, files)
if err != nil {
log.Println(err)
}
} else if libraryType == "show" {
// files := eraser.LookupTVFileLocation(cfg, ids)
sonarrIDs := locator.GetSonarrIDs(cfg, titles)
eraser.DeleteSeriesFromSonarr(cfg, sonarrIDs)
// err = eraser.DeleteFiles(delete, files)
// if err != nil {
// log.Println(err)
// }
}
2018-11-15 05:34:24 +00:00
}
}
if check {
sort.Strings(titlesFullList)
if text {
communicator.StdoutPost(titlesFullList)
} else {
err = communicator.TelegramPost(cfg, titlesFullList)
2018-11-20 19:39:15 +00:00
if err != nil {
log.Fatal(err)
2018-11-20 19:39:15 +00:00
}
2018-11-15 05:34:24 +00:00
}
}
2018-10-16 17:16:58 +00:00
}