Adding the ability for multiple section IDs, title sorting, completes #7
This commit is contained in:
parent
b1bbda788c
commit
f3424d83bc
42
cmd/main.go
42
cmd/main.go
@ -3,6 +3,9 @@ package main
|
|||||||
import (
|
import (
|
||||||
"flag"
|
"flag"
|
||||||
"log"
|
"log"
|
||||||
|
"sort"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"git.linuxrocker.com/mattburchett/Housekeeper/pkg/communicator"
|
"git.linuxrocker.com/mattburchett/Housekeeper/pkg/communicator"
|
||||||
"git.linuxrocker.com/mattburchett/Housekeeper/pkg/config"
|
"git.linuxrocker.com/mattburchett/Housekeeper/pkg/config"
|
||||||
@ -13,14 +16,14 @@ import (
|
|||||||
func main() {
|
func main() {
|
||||||
var c string
|
var c string
|
||||||
var days int
|
var days int
|
||||||
var sectionID int
|
var sectionID string
|
||||||
var check bool
|
var check bool
|
||||||
var text bool
|
var text bool
|
||||||
var delete bool
|
var delete bool
|
||||||
|
|
||||||
flag.StringVar(&c, "config", "", "Configuration to load")
|
flag.StringVar(&c, "config", "", "Configuration to load")
|
||||||
flag.IntVar(&days, "days", 0, "How many days of inactivity to look for on Plex.")
|
flag.IntVar(&days, "days", 0, "How many days of inactivity to look for on Plex.")
|
||||||
flag.IntVar(§ionID, "sectionid", 0, "Plex Section ID")
|
flag.StringVar(§ionID, "sectionid", "", "Plex Section ID. Multiples can be specified (separated by a comma). Ex: 1,2")
|
||||||
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.")
|
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.")
|
||||||
flag.BoolVar(&text, "text", false, "This will override the communication to Telegram and print to stdout.")
|
flag.BoolVar(&text, "text", false, "This will override the communication to Telegram and print to stdout.")
|
||||||
flag.BoolVar(&delete, "delete", false, "Perform the delete task.")
|
flag.BoolVar(&delete, "delete", false, "Perform the delete task.")
|
||||||
@ -30,7 +33,7 @@ func main() {
|
|||||||
if c == "" {
|
if c == "" {
|
||||||
log.Fatal("You need to specify a configuration file.")
|
log.Fatal("You need to specify a configuration file.")
|
||||||
}
|
}
|
||||||
if sectionID == 0 {
|
if sectionID == "" {
|
||||||
log.Fatal("You need to specify a section ID for Plex.")
|
log.Fatal("You need to specify a section ID for Plex.")
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -39,19 +42,17 @@ func main() {
|
|||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
libraryType := locator.GetLibraryType(cfg, sectionID)
|
sectionIds := strings.Split(sectionID, ",")
|
||||||
|
titlesFullList := make([]string, 0)
|
||||||
|
|
||||||
ids, titles := locator.GetTitles(cfg, sectionID, days)
|
for _, section := range sectionIds {
|
||||||
|
sectionIDConv, _ := strconv.Atoi(section)
|
||||||
|
libraryType := locator.GetLibraryType(cfg, sectionIDConv)
|
||||||
|
|
||||||
if check {
|
ids, titles := locator.GetTitles(cfg, sectionIDConv, days)
|
||||||
if text {
|
|
||||||
communicator.StdoutPost(titles)
|
for _, title := range titles {
|
||||||
} else {
|
titlesFullList = append(titlesFullList, title)
|
||||||
err = communicator.TelegramPost(cfg, titles)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if delete {
|
if delete {
|
||||||
@ -71,4 +72,17 @@ func main() {
|
|||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if check {
|
||||||
|
sort.Strings(titlesFullList)
|
||||||
|
if text {
|
||||||
|
communicator.StdoutPost(titlesFullList)
|
||||||
|
} else {
|
||||||
|
err = communicator.TelegramPost(cfg, titlesFullList)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user