Skip to content

Commit

Permalink
Cleanup, couple new methods for lidarr and Readarr. (#123)
Browse files Browse the repository at this point in the history
* lidarr cleanup

* radarr cleanup

* sonarr cleanup

* fix author methods

* lint fix

* remove warnings

* delete book

* delete album
  • Loading branch information
davidnewhall authored Aug 15, 2023
1 parent 748fa85 commit 2470ad3
Show file tree
Hide file tree
Showing 24 changed files with 147 additions and 76 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@

**Go library to interact with APIs in all the Starr apps.**

- [Lidarr](http://lidarr.audio) ([over 70 methods](https://pkg.go.dev/golift.io/starr@main/lidarr))
- [Prowlarr](https://prowlarr.com) ([over 20 methods](https://pkg.go.dev/golift.io/starr@main/prowlarr))
- [Radarr](http://radarr.video) ([over 90 methods](https://pkg.go.dev/golift.io/starr@main/radarr))
- [Readarr](http://readarr.com) ([over 60 methods](https://pkg.go.dev/golift.io/starr@main/readarr))
- [Sonarr](http://sonarr.tv) ([over 100 methods](https://pkg.go.dev/golift.io/starr@main/sonarr))
- [Lidarr](http://lidarr.audio) ([over 80 methods](https://pkg.go.dev/golift.io/starr@main/lidarr))
- [Prowlarr](https://prowlarr.com) ([over 20 methods](https://pkg.go.dev/golift.io/starr@main/prowlarr))
- [Radarr](http://radarr.video) ([over 100 methods](https://pkg.go.dev/golift.io/starr@main/radarr))
- [Readarr](http://readarr.com) ([over 70 methods](https://pkg.go.dev/golift.io/starr@main/readarr))
- [Sonarr](http://sonarr.tv) ([over 100 methods](https://pkg.go.dev/golift.io/starr@main/sonarr))

[Custom Scripts support](https://wiki.servarr.com/radarr/custom-scripts) is also included.
[Custom Scripts support](https://wiki.servarr.com/radarr/custom-scripts) is also included.
[Check out the types and methods](https://pkg.go.dev/golift.io/starr@main/starrcmd) to get that data.

## One 🌟 To Rule Them All
Expand Down
20 changes: 20 additions & 0 deletions lidarr/album.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,3 +221,23 @@ func (l *Lidarr) LookupContext(ctx context.Context, term string) ([]*Album, erro

return output, nil
}

// DeleteAlbum removes an album from the database.
// Setting deleteFiles true will delete all content for the album.
func (l *Lidarr) DeleteAlbum(albumID int64, deleteFiles, addImportExclusion bool) error {
return l.DeleteAlbumContext(context.Background(), albumID, deleteFiles, addImportExclusion)
}

// DeleteAlbumContext removes an album from the database.
// Setting deleteFiles true will delete all content for the album.
func (l *Lidarr) DeleteAlbumContext(ctx context.Context, albumID int64, deleteFiles, addImportExclusion bool) error {
req := starr.Request{URI: path.Join(bpAlbum, fmt.Sprint(albumID)), Query: make(url.Values)}
req.Query.Set("deleteFiles", fmt.Sprint(deleteFiles))
req.Query.Set("addImportListExclusion", fmt.Sprint(addImportExclusion))

if err := l.DeleteAny(ctx, req); err != nil {
return fmt.Errorf("api.Delete(%s): %w", &req, err)
}

return nil
}
31 changes: 24 additions & 7 deletions lidarr/artist.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,8 @@ func (l *Lidarr) AddArtistContext(ctx context.Context, artist *Artist) (*Artist,
}

req := starr.Request{URI: bpArtist, Query: make(url.Values), Body: &body}
req.Query.Add("moveFiles", "true")

var output Artist

if err := l.PostInto(ctx, req, &output); err != nil {
return nil, fmt.Errorf("api.Post(%s): %w", &req, err)
}
Expand All @@ -120,25 +118,44 @@ func (l *Lidarr) AddArtistContext(ctx context.Context, artist *Artist) (*Artist,
}

// UpdateArtist updates an artist in place.
func (l *Lidarr) UpdateArtist(artist *Artist) (*Artist, error) {
return l.UpdateArtistContext(context.Background(), artist)
func (l *Lidarr) UpdateArtist(artist *Artist, moveFiles bool) (*Artist, error) {
return l.UpdateArtistContext(context.Background(), artist, moveFiles)
}

// UpdateArtistContext updates an artist in place.
func (l *Lidarr) UpdateArtistContext(ctx context.Context, artist *Artist) (*Artist, error) {
func (l *Lidarr) UpdateArtistContext(ctx context.Context, artist *Artist, moveFiles bool) (*Artist, error) {
var body bytes.Buffer
if err := json.NewEncoder(&body).Encode(artist); err != nil {
return nil, fmt.Errorf("json.Marshal(%s): %w", bpArtist, err)
}

req := starr.Request{URI: path.Join(bpArtist, fmt.Sprint(artist.ID)), Query: make(url.Values), Body: &body}
req.Query.Add("moveFiles", "true")
req.Query.Add("moveFiles", fmt.Sprint(moveFiles))

var output Artist

if err := l.PutInto(ctx, req, &output); err != nil {
return nil, fmt.Errorf("api.Put(%s): %w", &req, err)
}

return &output, nil
}

// DeleteArtist removes an artist from the database.
// Setting deleteFiles true will delete all content for the artist.
func (l *Lidarr) DeleteArtist(artistID int64, deleteFiles, addImportExclusion bool) error {
return l.DeleteArtistContext(context.Background(), artistID, deleteFiles, addImportExclusion)
}

// DeleteArtistContext removes an artist from the database.
// Setting deleteFiles true will delete all content for the artist.
func (l *Lidarr) DeleteArtistContext(ctx context.Context, artistID int64, deleteFiles, addImportExclusion bool) error {
req := starr.Request{URI: path.Join(bpArtist, fmt.Sprint(artistID)), Query: make(url.Values)}
req.Query.Set("deleteFiles", fmt.Sprint(deleteFiles))
req.Query.Set("addImportListExclusion", fmt.Sprint(addImportExclusion))

if err := l.DeleteAny(ctx, req); err != nil {
return fmt.Errorf("api.Delete(%s): %w", &req, err)
}

return nil
}
1 change: 0 additions & 1 deletion lidarr/history.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ type HistoryRecord struct {
}

// GetHistory returns the Lidarr History (grabs/failures/completed).
// WARNING: 12/30/2021 - this method changed.
// If you need control over the page, use lidarr.GetHistoryPage().
// This function simply returns the number of history records desired,
// up to the number of records present in the application.
Expand Down
1 change: 0 additions & 1 deletion lidarr/queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ type QueueRecord struct {
}

// GetQueue returns a single page from the Lidarr Queue (processing, but not yet imported).
// WARNING: 12/30/2021 - this method changed.
// If you need control over the page, use lidarr.GetQueuePage().
// This function simply returns the number of queue records desired,
// up to the number of records present in the application.
Expand Down
22 changes: 11 additions & 11 deletions radarr/blocklist.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,17 @@ type BlockList struct {

// BlockListRecord represents a single block list item.
type BlockListRecord struct {
Movie *Movie `json:"movie"`
Quality *starr.Quality `json:"quality"`
Languages []*starr.Value `json:"languages"`
CustomFormats []interface{} `json:"customFormats"`
MovieID int64 `json:"movieId"`
ID int64 `json:"id"`
Date time.Time `json:"date"`
SourceTitle string `json:"sourceTitle"`
Protocol string `json:"protocol"`
Indexer string `json:"indexer"`
Message string `json:"message"`
Movie *Movie `json:"movie"`
Quality *starr.Quality `json:"quality"`
Languages []*starr.Value `json:"languages"`
CustomFormats []*CustomFormatOutput `json:"customFormats"`
MovieID int64 `json:"movieId"`
ID int64 `json:"id"`
Date time.Time `json:"date"`
SourceTitle string `json:"sourceTitle"`
Protocol string `json:"protocol"`
Indexer string `json:"indexer"`
Message string `json:"message"`
}

// GetBlockList returns the count of block list items requested.
Expand Down
2 changes: 1 addition & 1 deletion radarr/downloadclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func (r *Radarr) TestDownloadClient(client *DownloadClientInput) error {

// TestDownloadClientContext tests a download client.
func (r *Radarr) TestDownloadClientContext(ctx context.Context, client *DownloadClientInput) error {
var output interface{}
var output interface{} // any ok

var body bytes.Buffer
if err := json.NewEncoder(&body).Encode(client); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion radarr/exclusions.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func (r *Radarr) AddExclusionsContext(ctx context.Context, exclusions []*Exclusi
return fmt.Errorf("json.Marshal(%s): %w", bpExclusions, err)
}

var output interface{}
var output interface{} // any ok

req := starr.Request{URI: path.Join(bpExclusions, "bulk"), Body: &body}
if err := r.PostInto(ctx, req, &output); err != nil {
Expand Down
26 changes: 12 additions & 14 deletions radarr/history.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,16 @@ type History struct {
// HistoryRecord is part of the History data.
// Not all items have all Data members. Check EventType for what you need.
type HistoryRecord struct {
ID int64 `json:"id"`
MovieID int64 `json:"movieId"`
SourceTitle string `json:"sourceTitle"`
Languages []*starr.Value `json:"languages"`
Quality *starr.Quality `json:"quality"`
CustomFormats []interface{} `json:"customFormats"`
QualityCutoffNotMet bool `json:"qualityCutoffNotMet"`
Date time.Time `json:"date"`
DownloadID string `json:"downloadId"`
EventType string `json:"eventType"`
ID int64 `json:"id"`
MovieID int64 `json:"movieId"`
SourceTitle string `json:"sourceTitle"`
Languages []*starr.Value `json:"languages"`
Quality *starr.Quality `json:"quality"`
CustomFormats []*CustomFormatOutput `json:"customFormats"`
QualityCutoffNotMet bool `json:"qualityCutoffNotMet"`
Date time.Time `json:"date"`
DownloadID string `json:"downloadId"`
EventType string `json:"eventType"`
Data struct {
Age string `json:"age"`
AgeHours string `json:"ageHours"`
Expand Down Expand Up @@ -61,13 +61,11 @@ type HistoryRecord struct {
}

// GetHistory returns the Radarr History (grabs/failures/completed).
// WARNING: 12/30/2021 - this method changed. The second argument no longer
// controls which page is returned, but instead adjusts the pagination size.
// If you need control over the page, use radarr.GetHistoryPage().
// This function simply returns the number of history records desired,
// up to the number of records present in the application.
// It grabs records in (paginated) batches of perPage, and concatenates
// them into one list. Passing zero for records will return all of them.
// them into one list. Passing zero for records will return all of them.
func (r *Radarr) GetHistory(records, perPage int) (*History, error) {
return r.GetHistoryContext(context.Background(), records, perPage)
}
Expand Down Expand Up @@ -131,7 +129,7 @@ func (r *Radarr) FailContext(ctx context.Context, historyID int64) error {
return fmt.Errorf("%w: invalid history ID: %d", starr.ErrRequestError, historyID)
}

var output interface{}
var output interface{} // any ok

// Strangely uses a POST without a payload.
req := starr.Request{URI: path.Join(bpHistory, "failed", fmt.Sprint(historyID))}
Expand Down
2 changes: 1 addition & 1 deletion radarr/importlist.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ func (r *Radarr) TestImportList(list *ImportListInput) error {

// TestImportListContextt tests an import list.
func (r *Radarr) TestImportListContextt(ctx context.Context, list *ImportListInput) error {
var output interface{}
var output interface{} // any ok

var body bytes.Buffer
if err := json.NewEncoder(&body).Encode(list); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion radarr/indexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func (r *Radarr) TestIndexer(indexer *IndexerInput) error {

// TestIndexerContext tests an indexer.
func (r *Radarr) TestIndexerContext(ctx context.Context, indexer *IndexerInput) error {
var output interface{}
var output interface{} // any ok

var body bytes.Buffer
if err := json.NewEncoder(&body).Encode(indexer); err != nil {
Expand Down
4 changes: 1 addition & 3 deletions radarr/queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ type QueueRecord struct {
MovieID int64 `json:"movieId"`
Languages []*starr.Value `json:"languages"`
Quality *starr.Quality `json:"quality"`
CustomFormats []interface{} `json:"customFormats"` // probably []int64
CustomFormats []*CustomFormatOutput `json:"customFormats"`
Size float64 `json:"size"`
Title string `json:"title"`
Sizeleft float64 `json:"sizeleft"`
Expand All @@ -46,8 +46,6 @@ type QueueRecord struct {
}

// GetQueue returns a single page from the Radarr Queue (processing, but not yet imported).
// WARNING: 12/30/2021 - this method changed. The second argument no longer
// controls which page is returned, but instead adjusts the pagination size.
// If you need control over the page, use radarr.GetQueuePage().
// This function simply returns the number of queue records desired,
// up to the number of records present in the application.
Expand Down
36 changes: 28 additions & 8 deletions readarr/author.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,28 +96,48 @@ func (r *Readarr) GetAuthorByIDContext(ctx context.Context, authorID int64) (*Au
}

// UpdateAuthor updates an author in place.
func (r *Readarr) UpdateAuthor(authorID int64, author *Author) error {
return r.UpdateAuthorContext(context.Background(), authorID, author)
func (r *Readarr) UpdateAuthor(author *Author, moveFiles bool) (*Author, error) {
return r.UpdateAuthorContext(context.Background(), author, moveFiles)
}

// UpdateAuthorContext updates an author in place.
func (r *Readarr) UpdateAuthorContext(ctx context.Context, authorID int64, author *Author) error {
func (r *Readarr) UpdateAuthorContext(ctx context.Context, author *Author, moveFiles bool) (*Author, error) {
var body bytes.Buffer
if err := json.NewEncoder(&body).Encode(author); err != nil {
return fmt.Errorf("json.Marshal(%s): %w", bpAuthor, err)
return nil, fmt.Errorf("json.Marshal(%s): %w", bpAuthor, err)
}

var output interface{} // not sure what this looks like.
var output Author

req := starr.Request{
URI: path.Join(bpAuthor, fmt.Sprint(authorID)),
URI: path.Join(bpAuthor, fmt.Sprint(author.ID)),
Query: make(url.Values),
Body: &body,
}
req.Query.Add("moveFiles", "true")
req.Query.Add("moveFiles", fmt.Sprint(moveFiles))

if err := r.PutInto(ctx, req, &output); err != nil {
return fmt.Errorf("api.Put(%s): %w", &req, err)
return nil, fmt.Errorf("api.Put(%s): %w", &req, err)
}

return &output, nil
}

// DeleteAuthor removes an Author from the database.
// Setting deleteFiles true will delete all content for the Author.
func (r *Readarr) DeleteAuthor(authorID int64, deleteFiles, addImportExclusion bool) error {
return r.DeleteAuthorContext(context.Background(), authorID, deleteFiles, addImportExclusion)
}

// DeleteAuthorContext removes na Author from the database.
// Setting deleteFiles true will delete all content for the Author.
func (r *Readarr) DeleteAuthorContext(ctx context.Context, authorID int64, deleteFiles, addImportExclusion bool) error {
req := starr.Request{URI: path.Join(bpAuthor, fmt.Sprint(authorID)), Query: make(url.Values)}
req.Query.Set("deleteFiles", fmt.Sprint(deleteFiles))
req.Query.Set("addImportListExclusion", fmt.Sprint(addImportExclusion))

if err := r.DeleteAny(ctx, req); err != nil {
return fmt.Errorf("api.Delete(%s): %w", &req, err)
}

return nil
Expand Down
20 changes: 20 additions & 0 deletions readarr/book.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,3 +222,23 @@ func (r *Readarr) LookupContext(ctx context.Context, term string) ([]*Book, erro

return output, nil
}

// DeleteBook removes a Book from the database.
// Setting deleteFiles true will delete all content for the Book.
func (r *Readarr) DeleteBook(bookID int64, deleteFiles, addImportExclusion bool) error {
return r.DeleteBookContext(context.Background(), bookID, deleteFiles, addImportExclusion)
}

// DeleteBookContext removes a Book from the database.
// Setting deleteFiles true will delete all content for the Book.
func (r *Readarr) DeleteBookContext(ctx context.Context, bookID int64, deleteFiles, addImportExclusion bool) error {
req := starr.Request{URI: path.Join(bpBook, fmt.Sprint(bookID)), Query: make(url.Values)}
req.Query.Set("deleteFiles", fmt.Sprint(deleteFiles))
req.Query.Set("addImportListExclusion", fmt.Sprint(addImportExclusion))

if err := r.DeleteAny(ctx, req); err != nil {
return fmt.Errorf("api.Delete(%s): %w", &req, err)
}

return nil
}
1 change: 0 additions & 1 deletion readarr/history.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ type HistoryRecord struct {
}

// GetHistory returns the Readarr History (grabs/failures/completed).
// WARNING: 12/30/2021 - this method changed.
// If you need control over the page, use readarr.GetHistoryPage().
// This function simply returns the number of history records desired,
// up to the number of records present in the application.
Expand Down
1 change: 0 additions & 1 deletion readarr/queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ type QueueRecord struct {
}

// GetQueue returns a single page from the Readarr Queue (processing, but not yet imported).
// WARNING: 12/30/2021 - this method changed.
// If you need control over the page, use readarr.GetQueuePage().
// This function simply returns the number of queue records desired,
// up to the number of records present in the application.
Expand Down
1 change: 1 addition & 0 deletions shared.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ type BackupFile struct {

// QueueDeleteOpts are the extra inputs when deleting an item from the Activity Queue.
// Set these appropriately for your expectations. All inputs are the same in all apps.
// Providing this input to the QueueDelete methods is optional; nil sets the defaults shown.
type QueueDeleteOpts struct {
// Default True, use starr.False() to change it.
RemoveFromClient *bool
Expand Down
24 changes: 12 additions & 12 deletions sonarr/blocklist.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,18 @@ type BlockList struct {

// BlockListRecord represents a single block list item.
type BlockListRecord struct {
Series *Series `json:"series"`
Quality *starr.Quality `json:"quality"`
Languages []*starr.Value `json:"languages"`
CustomFormats []interface{} `json:"customFormats"`
EpisodeIDs []int64 `json:"episodeIds"`
ID int64 `json:"id"`
SeriesID int64 `json:"seriesId"`
Date time.Time `json:"date"`
SourceTitle string `json:"sourceTitle"`
Protocol string `json:"protocol"`
Indexer string `json:"indexer"`
Message string `json:"message"`
Series *Series `json:"series"`
Quality *starr.Quality `json:"quality"`
Languages []*starr.Value `json:"languages"`
CustomFormats []*CustomFormatOutput `json:"customFormats"`
EpisodeIDs []int64 `json:"episodeIds"`
ID int64 `json:"id"`
SeriesID int64 `json:"seriesId"`
Date time.Time `json:"date"`
SourceTitle string `json:"sourceTitle"`
Protocol string `json:"protocol"`
Indexer string `json:"indexer"`
Message string `json:"message"`
}

// GetBlockList returns the count of block list items requested.
Expand Down
2 changes: 1 addition & 1 deletion sonarr/downloadclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func (s *Sonarr) TestDownloadClient(client *DownloadClientInput) error {

// TestDownloadClientContext tests a download client.
func (s *Sonarr) TestDownloadClientContext(ctx context.Context, client *DownloadClientInput) error {
var output interface{}
var output interface{} // any ok

var body bytes.Buffer
if err := json.NewEncoder(&body).Encode(client); err != nil {
Expand Down
Loading

0 comments on commit 2470ad3

Please sign in to comment.