2018-10-16 17:16:58 +00:00
|
|
|
package main
|
|
|
|
|
2018-10-16 20:06:46 +00:00
|
|
|
import (
|
|
|
|
"flag"
|
|
|
|
"log"
|
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-11-14 03:51:03 +00:00
|
|
|
// func getFiles(location string, days int) ([]string, error) {
|
|
|
|
// var files []string
|
|
|
|
// err := filepath.Walk(location, func(path string, info os.FileInfo, err error) error {
|
|
|
|
// files = append(files, path)
|
|
|
|
// return nil
|
|
|
|
// })
|
|
|
|
// if err != nil {
|
|
|
|
// log.Fatal(err)
|
|
|
|
// }
|
2018-10-16 20:06:46 +00:00
|
|
|
|
2018-11-14 03:51:03 +00:00
|
|
|
// test := make([]string, 0)
|
2018-10-17 19:40:19 +00:00
|
|
|
|
2018-11-14 03:51:03 +00:00
|
|
|
// for _, file := range files {
|
|
|
|
// at, err := os.Stat(file)
|
|
|
|
// if err != nil {
|
|
|
|
// log.Fatal(err)
|
|
|
|
// }
|
|
|
|
// if isOlder(at.ModTime(), days) {
|
|
|
|
// test = append(test, file)
|
|
|
|
// }
|
2018-10-17 19:40:19 +00:00
|
|
|
|
2018-11-14 03:51:03 +00:00
|
|
|
// }
|
2018-10-16 17:16:58 +00:00
|
|
|
|
2018-11-14 03:51:03 +00:00
|
|
|
// return test, err
|
2018-10-17 17:21:16 +00:00
|
|
|
|
2018-11-14 03:51:03 +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
|
2018-11-14 03:51:03 +00:00
|
|
|
var sectionID int
|
2018-11-15 05:34:24 +00:00
|
|
|
var check bool
|
|
|
|
var delete bool
|
2018-11-14 03:51:03 +00:00
|
|
|
|
|
|
|
flag.StringVar(&c, "c", "", "Configuration to load")
|
2018-10-17 17:21:16 +00:00
|
|
|
flag.IntVar(&days, "days", 0, "days to poll")
|
2018-11-14 03:51:03 +00:00
|
|
|
flag.IntVar(§ionID, "sectionid", 0, "pick a section ID")
|
2018-11-15 05:34:24 +00:00
|
|
|
flag.BoolVar(&check, "check", true, "Perform only a check. Do not delete.")
|
|
|
|
flag.BoolVar(&delete, "delete", false, "Perform the delete task.")
|
2018-10-17 17:21:16 +00:00
|
|
|
flag.Parse()
|
2018-11-14 03:51:03 +00:00
|
|
|
if c == "" {
|
|
|
|
log.Fatal("You need to specify a configuration file.")
|
|
|
|
}
|
|
|
|
if sectionID == 0 {
|
|
|
|
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
|
|
|
|
|
|
|
ids, titles := locator.GetTitles(cfg, sectionID, days)
|
|
|
|
|
|
|
|
if check {
|
|
|
|
err = communicator.TelegramPost(cfg, titles)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if delete {
|
|
|
|
files := eraser.LookupFileLocation(cfg, ids)
|
|
|
|
err = eraser.DeleteMedia(delete, files)
|
|
|
|
if err != nil {
|
|
|
|
log.Println(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-16 17:16:58 +00:00
|
|
|
}
|