Adding Sonarr Delete Fix

This commit is contained in:
2018-11-20 18:43:18 -06:00
parent 97ebf34be0
commit 8257268df5
8 changed files with 178 additions and 18 deletions

View File

@ -1,6 +1,7 @@
package eraser
import (
"encoding/json"
"encoding/xml"
"fmt"
"io/ioutil"
@ -8,6 +9,7 @@ import (
"net/http"
"os"
"path/filepath"
"strings"
"git.linuxrocker.com/mattburchett/Housekeeper/pkg/config"
"git.linuxrocker.com/mattburchett/Housekeeper/pkg/model"
@ -92,6 +94,39 @@ func LookupTVFileLocation(config config.Config, ids []int) []string {
return results
}
func DeleteSeriesFromSonarr(config config.Config, ids []int) {
for _, i := range ids {
sonarrURL := fmt.Sprintf("%s%s%s%d%s%s", config.BaseURL, config.SonarrContext, "/api/series/", i, "/?deleteFiles=true&apikey=", config.SonarrAPIKey)
req, err := http.NewRequest(http.MethodDelete, sonarrURL, nil)
if err != nil {
log.Fatal(err)
}
httpClient := http.Client{}
req.Header.Set("User-Agent", "Housekeeper")
res, getErr := httpClient.Do(req)
if getErr != nil {
log.Fatal(getErr)
}
body, readErr := ioutil.ReadAll(res.Body)
if readErr != nil {
log.Fatal(readErr)
}
deleteModel := model.SonarrResponse{}
jsonErr := json.Unmarshal(body, &deleteModel)
if jsonErr != nil {
log.Fatal(jsonErr)
}
if strings.Contains("does not exist", deleteModel.Message) {
log.Printf("The following ID does not exist: %v", i)
}
}
}
// DeleteFiles will actually perform the deletion.
func DeleteFiles(delete bool, files []string) error {
var err error