Skip to content

Commit

Permalink
Add quality and release profiles (#65)
Browse files Browse the repository at this point in the history
* Add quality and release profiles
* add method for full profiles
* Add lidarr and readarr methods too
  • Loading branch information
davidnewhall authored May 18, 2021
1 parent 63e45ec commit e488f78
Show file tree
Hide file tree
Showing 8 changed files with 288 additions and 11 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ require (
golang.org/x/sys v0.0.0-20210403161142-5e06dd20ab57
golift.io/cnfg v0.0.8-0.20201101095209-9c9085f1bf93
golift.io/rotatorr v0.0.0-20210307012029-65b11a8ea8f9
golift.io/starr v0.9.10
golift.io/starr v0.9.11
golift.io/version v0.0.2
gopkg.in/toast.v1 v1.0.0-20180812000517-0a84660828b2
gopkg.in/yaml.v2 v2.4.0 // indirect
Expand Down
6 changes: 6 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,12 @@ golift.io/rotatorr v0.0.0-20210307012029-65b11a8ea8f9 h1:j/WeLF6Ew1lc/m8/bh5qleZ
golift.io/rotatorr v0.0.0-20210307012029-65b11a8ea8f9/go.mod h1:EZevRvIGRh8jDMwuYL0/tlPns0KynquPZzb0SerIC1s=
golift.io/starr v0.9.10 h1:1XJRImHcIrr8iTzoH0e439XTwnlhnYt5J/LwyAAH92U=
golift.io/starr v0.9.10/go.mod h1:oaAjRa9vIpsj0lTR79vDDRVqXuq6ID6RXbQIoFljhbM=
golift.io/starr v0.9.11-0.20210510043850-4cbc75e9fe8b h1:2pl5UTK5d7TjU27WAnz380zBj1GHf/nu0sRs59gYSy8=
golift.io/starr v0.9.11-0.20210510043850-4cbc75e9fe8b/go.mod h1:oaAjRa9vIpsj0lTR79vDDRVqXuq6ID6RXbQIoFljhbM=
golift.io/starr v0.9.11-0.20210518045857-8d48a30fe2f0 h1:Sq7m3x/WUmoGPRNOfsPw1MHAHKLEJzEAfaeNi8QUwas=
golift.io/starr v0.9.11-0.20210518045857-8d48a30fe2f0/go.mod h1:oaAjRa9vIpsj0lTR79vDDRVqXuq6ID6RXbQIoFljhbM=
golift.io/starr v0.9.11 h1:rtn5CnnXsYwZ7ZFQCs/FOyxEgUnubwevTH1R5DEu/pc=
golift.io/starr v0.9.11/go.mod h1:oaAjRa9vIpsj0lTR79vDDRVqXuq6ID6RXbQIoFljhbM=
golift.io/version v0.0.2 h1:i0gXRuSDHKs4O0sVDUg4+vNIuOxYoXhaxspftu2FRTE=
golift.io/version v0.0.2/go.mod h1:76aHNz8/Pm7CbuxIsDi97jABL5Zui3f2uZxDm4vB6hU=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
Expand Down
1 change: 1 addition & 0 deletions pkg/apps/apps.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ var (
ErrNoLidarr = fmt.Errorf("configured %s ID not found", Lidarr)
ErrNoReadarr = fmt.Errorf("configured %s ID not found", Readarr)
ErrNotFound = fmt.Errorf("the request returned an empty payload")
ErrNonZeroID = fmt.Errorf("provided ID must be non-zero")
)

// APIHandler is our custom handler function for APIs.
Expand Down
58 changes: 56 additions & 2 deletions pkg/apps/lidarr.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ func (a *Apps) lidarrHandlers() {
a.HandleAPIpath(Lidarr, "/get/{albumid:[0-9]+}", lidarrGetAlbum, "GET")
a.HandleAPIpath(Lidarr, "/metadataProfiles", lidarrMetadata, "GET")
a.HandleAPIpath(Lidarr, "/qualityDefinitions", lidarrQualityDefs, "GET")
a.HandleAPIpath(Lidarr, "/qualityProfiles", lidarrProfiles, "GET")
a.HandleAPIpath(Lidarr, "/qualityProfiles", lidarrQualityProfiles, "GET")
a.HandleAPIpath(Lidarr, "/qualityProfile", lidarrGetQualityProfile, "GET")
a.HandleAPIpath(Lidarr, "/qualityProfile", lidarrAddQualityProfile, "POST")
a.HandleAPIpath(Lidarr, "/qualityProfile/{profileID:[0-9]+}", lidarrUpdateQualityProfile, "PUT")
a.HandleAPIpath(Lidarr, "/rootFolder", lidarrRootFolders, "GET")
a.HandleAPIpath(Lidarr, "/search/{query}", lidarrSearchAlbum, "GET")
a.HandleAPIpath(Lidarr, "/tag", lidarrGetTags, "GET")
Expand Down Expand Up @@ -172,7 +175,7 @@ func lidarrQualityDefs(r *http.Request) (int, interface{}) {
return http.StatusOK, p
}

func lidarrProfiles(r *http.Request) (int, interface{}) {
func lidarrQualityProfiles(r *http.Request) (int, interface{}) {
// Get the profiles from lidarr.
profiles, err := getLidarr(r).GetQualityProfiles()
if err != nil {
Expand All @@ -188,6 +191,57 @@ func lidarrProfiles(r *http.Request) (int, interface{}) {
return http.StatusOK, p
}

func lidarrGetQualityProfile(r *http.Request) (int, interface{}) {
// Get the profiles from lidarr.
profiles, err := getLidarr(r).GetQualityProfiles()
if err != nil {
return http.StatusInternalServerError, fmt.Errorf("getting profiles: %w", err)
}

return http.StatusOK, profiles
}

func lidarrAddQualityProfile(r *http.Request) (int, interface{}) {
var profile lidarr.QualityProfile

// Extract payload and check for TMDB ID.
err := json.NewDecoder(r.Body).Decode(&profile)
if err != nil {
return http.StatusBadRequest, fmt.Errorf("decoding payload: %w", err)
}

// Get the profiles from radarr.
id, err := getLidarr(r).AddQualityProfile(&profile)
if err != nil {
return http.StatusInternalServerError, fmt.Errorf("adding profile: %w", err)
}

return http.StatusOK, id
}

func lidarrUpdateQualityProfile(r *http.Request) (int, interface{}) {
var profile lidarr.QualityProfile

// Extract payload and check for TMDB ID.
err := json.NewDecoder(r.Body).Decode(&profile)
if err != nil {
return http.StatusBadRequest, fmt.Errorf("decoding payload: %w", err)
}

profile.ID, _ = strconv.ParseInt(mux.Vars(r)["profileID"], 10, 64)
if profile.ID == 0 {
return http.StatusBadRequest, ErrNonZeroID
}

// Get the profiles from radarr.
err = getLidarr(r).UpdateQualityProfile(&profile)
if err != nil {
return http.StatusInternalServerError, fmt.Errorf("updating profile: %w", err)
}

return http.StatusOK, "OK"
}

func lidarrRootFolders(r *http.Request) (int, interface{}) {
// Get folder list from Lidarr.
folders, err := getLidarr(r).GetRootFolders()
Expand Down
58 changes: 56 additions & 2 deletions pkg/apps/radarr.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ func (a *Apps) radarrHandlers() {
a.HandleAPIpath(Radarr, "/check/{tmdbid:[0-9]+}", radarrCheckMovie, "GET")
a.HandleAPIpath(Radarr, "/get/{movieid:[0-9]+}", radarrGetMovie, "GET")
a.HandleAPIpath(Radarr, "/get", radarrGetAllMovies, "GET")
a.HandleAPIpath(Radarr, "/qualityProfiles", radarrProfiles, "GET")
a.HandleAPIpath(Radarr, "/qualityProfiles", radarrQualityProfiles, "GET")
a.HandleAPIpath(Radarr, "/qualityProfile", radarrQualityProfile, "GET")
a.HandleAPIpath(Radarr, "/qualityProfile", radarrAddQualityProfile, "POST")
a.HandleAPIpath(Radarr, "/qualityProfile/{profileID:[0-9]+}", radarrUpdateQualityProfile, "PUT")
a.HandleAPIpath(Radarr, "/rootFolder", radarrRootFolders, "GET")
a.HandleAPIpath(Radarr, "/search/{query}", radarrSearchMovie, "GET")
a.HandleAPIpath(Radarr, "/tag", radarrGetTags, "GET")
Expand Down Expand Up @@ -143,7 +146,17 @@ func radarrGetAllMovies(r *http.Request) (int, interface{}) {
return http.StatusOK, movies
}

func radarrProfiles(r *http.Request) (int, interface{}) {
func radarrQualityProfile(r *http.Request) (int, interface{}) {
// Get the profiles from radarr.
profiles, err := getRadarr(r).GetQualityProfiles()
if err != nil {
return http.StatusInternalServerError, fmt.Errorf("getting profiles: %w", err)
}

return http.StatusOK, profiles
}

func radarrQualityProfiles(r *http.Request) (int, interface{}) {
// Get the profiles from radarr.
profiles, err := getRadarr(r).GetQualityProfiles()
if err != nil {
Expand All @@ -159,6 +172,47 @@ func radarrProfiles(r *http.Request) (int, interface{}) {
return http.StatusOK, p
}

func radarrAddQualityProfile(r *http.Request) (int, interface{}) {
var profile radarr.QualityProfile

// Extract payload and check for TMDB ID.
err := json.NewDecoder(r.Body).Decode(&profile)
if err != nil {
return http.StatusBadRequest, fmt.Errorf("decoding payload: %w", err)
}

// Get the profiles from radarr.
id, err := getRadarr(r).AddQualityProfile(&profile)
if err != nil {
return http.StatusInternalServerError, fmt.Errorf("adding profile: %w", err)
}

return http.StatusOK, id
}

func radarrUpdateQualityProfile(r *http.Request) (int, interface{}) {
var profile radarr.QualityProfile

// Extract payload and check for TMDB ID.
err := json.NewDecoder(r.Body).Decode(&profile)
if err != nil {
return http.StatusBadRequest, fmt.Errorf("decoding payload: %w", err)
}

profile.ID, _ = strconv.ParseInt(mux.Vars(r)["profileID"], 10, 64)
if profile.ID == 0 {
return http.StatusBadRequest, ErrNonZeroID
}

// Get the profiles from radarr.
err = getRadarr(r).UpdateQualityProfile(&profile)
if err != nil {
return http.StatusInternalServerError, fmt.Errorf("updating profile: %w", err)
}

return http.StatusOK, "OK"
}

func radarrRootFolders(r *http.Request) (int, interface{}) {
// Get folder list from Radarr.
folders, err := getRadarr(r).GetRootFolders()
Expand Down
60 changes: 57 additions & 3 deletions pkg/apps/readarr.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ func (a *Apps) readarrHandlers() {
a.HandleAPIpath(Readarr, "/check/{grid:[0-9]+}", readarrCheckBook, "GET")
a.HandleAPIpath(Readarr, "/get/{bookid:[0-9]+}", readarrGetBook, "GET")
a.HandleAPIpath(Readarr, "/metadataProfiles", readarrMetaProfiles, "GET")
a.HandleAPIpath(Readarr, "/qualityProfiles", readarrProfiles, "GET")
a.HandleAPIpath(Readarr, "/qualityProfiles", readarrQualityProfiles, "GET")
a.HandleAPIpath(Readarr, "/qualityProfile", readarrGetQualityProfile, "GET")
a.HandleAPIpath(Readarr, "/qualityProfile", readarrAddQualityProfile, "POST")
a.HandleAPIpath(Readarr, "/qualityProfile/{profileID:[0-9]+}", readarrUpdateQualityProfile, "PUT")
a.HandleAPIpath(Readarr, "/rootFolder", readarrRootFolders, "GET")
a.HandleAPIpath(Readarr, "/search/{query}", readarrSearchBook, "GET")
a.HandleAPIpath(Readarr, "/update", readarrUpdateBook, "PUT")
Expand Down Expand Up @@ -157,8 +160,8 @@ func readarrMetaProfiles(r *http.Request) (int, interface{}) {
return http.StatusOK, p
}

// Get the profiles from readarr.
func readarrProfiles(r *http.Request) (int, interface{}) {
// Get the quality profiles from readarr.
func readarrQualityProfiles(r *http.Request) (int, interface{}) {
profiles, err := getReadarr(r).GetQualityProfiles()
if err != nil {
return http.StatusInternalServerError, fmt.Errorf("getting profiles: %w", err)
Expand All @@ -173,6 +176,57 @@ func readarrProfiles(r *http.Request) (int, interface{}) {
return http.StatusOK, p
}

// Get the all quality profiles data from readarr.
func readarrGetQualityProfile(r *http.Request) (int, interface{}) {
profiles, err := getReadarr(r).GetQualityProfiles()
if err != nil {
return http.StatusInternalServerError, fmt.Errorf("getting profiles: %w", err)
}

return http.StatusOK, profiles
}

func readarrAddQualityProfile(r *http.Request) (int, interface{}) {
var profile readarr.QualityProfile

// Extract payload and check for TMDB ID.
err := json.NewDecoder(r.Body).Decode(&profile)
if err != nil {
return http.StatusBadRequest, fmt.Errorf("decoding payload: %w", err)
}

// Get the profiles from radarr.
id, err := getReadarr(r).AddQualityProfile(&profile)
if err != nil {
return http.StatusInternalServerError, fmt.Errorf("adding profile: %w", err)
}

return http.StatusOK, id
}

func readarrUpdateQualityProfile(r *http.Request) (int, interface{}) {
var profile readarr.QualityProfile

// Extract payload and check for TMDB ID.
err := json.NewDecoder(r.Body).Decode(&profile)
if err != nil {
return http.StatusBadRequest, fmt.Errorf("decoding payload: %w", err)
}

profile.ID, _ = strconv.ParseInt(mux.Vars(r)["profileID"], 10, 64)
if profile.ID == 0 {
return http.StatusBadRequest, ErrNonZeroID
}

// Get the profiles from radarr.
err = getReadarr(r).UpdateQualityProfile(&profile)
if err != nil {
return http.StatusInternalServerError, fmt.Errorf("updating profile: %w", err)
}

return http.StatusOK, "OK"
}

// Get folder list from Readarr.
func readarrRootFolders(r *http.Request) (int, interface{}) {
folders, err := getReadarr(r).GetRootFolders()
Expand Down
Loading

0 comments on commit e488f78

Please sign in to comment.