Skip to content

Commit

Permalink
remove Grab type
Browse files Browse the repository at this point in the history
  • Loading branch information
davidnewhall committed Jul 8, 2024
1 parent 5e7b679 commit 6c955ad
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 70 deletions.
34 changes: 4 additions & 30 deletions radarr/release.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ type Release struct {
Seeders int `json:"seeders"`
Leechers int `json:"leechers"`
Protocol starr.Protocol `json:"protocol"`
IndexerFlags []string `json:"indexerFlags"`
IndexerFlags []string `json:"indexerFlags,omitempty"`
}

// SearchRelease searches for and returns a list releases available for download.
Expand All @@ -72,43 +72,17 @@ func (r *Radarr) SearchReleaseContext(ctx context.Context, movieID int64) ([]*Re
return output, nil
}

// Grab is the output from the Grab* methods.
type Grab struct {
GUID string `json:"guid"`
Quality *starr.Quality `json:"quality"`
CustomFormatScore int64 `json:"customFormatScore"`
QualityWeight int64 `json:"qualityWeight"`
Age int64 `json:"age"`
AgeHours int `json:"ageHours"`
AgeMinutes int `json:"ageMinutes"`
Size int64 `json:"size"`
IndexerID int64 `json:"indexerId"`
SceneSource bool `json:"sceneSource"`
Languages []*starr.Value `json:"languages"`
Approved bool `json:"approved"`
TemporarilyRejected bool `json:"temporarilyRejected"`
Rejected bool `json:"rejected"`
TmdbID int64 `json:"tmdbId"`
ImdbID int64 `json:"imdbId"`
PublishDate time.Time `json:"publishDate"`
DownloadAllowed bool `json:"downloadAllowed"`
ReleaseWeight int64 `json:"releaseWeight"`
Protocol string `json:"protocol"`
MovieID int64 `json:"movieId"`
ShouldOverride bool `json:"shouldOverride"`
}

// GrabRelease attempts to download a release for a movie from a search.
// Pass the release for the item from the SearchRelease output, and the movie ID you want the grab associated with.
// If the movieID is 0 then the MappedMovieID in the release is used, but that is not always set.
func (r *Radarr) GrabRelease(release *Release, movieID int64) (*Grab, error) {
func (r *Radarr) GrabRelease(release *Release, movieID int64) (*Release, error) {
return r.GrabReleaseContext(context.Background(), release, movieID)
}

// GrabReleaseContext attempts to download a release for a movie from a search.
// Pass the release for the item from the SearchRelease output, and the movie ID you want the grab associated with.
// If the movieID is 0 then the MappedMovieID in the release is used, but that is not always set.
func (r *Radarr) GrabReleaseContext(ctx context.Context, release *Release, movieID int64) (*Grab, error) {
func (r *Radarr) GrabReleaseContext(ctx context.Context, release *Release, movieID int64) (*Release, error) {
grab := struct { // These are the required fields on the Radarr POST /release endpoint.
G string `json:"guid"`
I int64 `json:"indexerId"`
Expand All @@ -126,7 +100,7 @@ func (r *Radarr) GrabReleaseContext(ctx context.Context, release *Release, movie
return nil, fmt.Errorf("json.Marshal(%s): %w", bpRelease, err)
}

var output Grab
var output Release

req := starr.Request{URI: bpRelease, Body: &body}
if err := r.PostInto(ctx, req, &output); err != nil {
Expand Down
49 changes: 9 additions & 40 deletions sonarr/release.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ type Release struct {
Quality starr.Quality `json:"quality"`
QualityWeight int64 `json:"qualityWeight"`
Age int64 `json:"age"`
AgeHours int `json:"ageHours"`
AgeMinutes int `json:"ageMinutes"`
AgeHours float64 `json:"ageHours"`
AgeMinutes float64 `json:"ageMinutes"`
Size int `json:"size"`
IndexerID int64 `json:"indexerId"`
Indexer string `json:"indexer"`
Expand All @@ -48,7 +48,7 @@ type Release struct {
TemporarilyRejected bool `json:"temporarilyRejected"`
Rejected bool `json:"rejected"`
TvdbID int64 `json:"tvdbId"`
TvRageID int `json:"tvRageId"`
TvRageID int64 `json:"tvRageId"`
Rejections []string `json:"rejections"`
PublishDate time.Time `json:"publishDate"`
CommentURL string `json:"commentUrl"`
Expand All @@ -65,7 +65,7 @@ type Release struct {
Seeders int `json:"seeders"`
Leechers int `json:"leechers"`
Protocol starr.Protocol `json:"protocol"`
IndexerFlags int64 `json:"indexerFlags"`
IndexerFlags int64 `json:"indexerFlags,omitempty"`
IsDaily bool `json:"isDaily"`
IsAbsoluteNumbering bool `json:"isAbsoluteNumbering"`
IsPossibleSpecialEpisode bool `json:"isPossibleSpecialEpisode"`
Expand Down Expand Up @@ -123,56 +123,25 @@ func (s *Sonarr) SearchReleaseContext(ctx context.Context, input *SearchRelease)
return output, nil
}

// Grab is the output from the Grab* methods.
type Grab struct {
Approved bool `json:"approved"`
DownloadAllowed bool `json:"downloadAllowed"`
EpisodeRequested bool `json:"episodeRequested"`
FullSeason bool `json:"fullSeason"`
Special bool `json:"special"`
TemporarilyRejected bool `json:"temporarilyRejected"`
IsAbsoluteNumbering bool `json:"isAbsoluteNumbering"`
IsDaily bool `json:"isDaily"`
IsPossibleSpecialEpisode bool `json:"isPossibleSpecialEpisode"`
Rejected bool `json:"rejected"`
SceneSource bool `json:"sceneSource"`
AgeHours int `json:"ageHours"`
AgeMinutes int `json:"ageMinutes"`
SeasonNumber int `json:"seasonNumber"`
Size int `json:"size"`
Age int64 `json:"age"`
CustomFormatScore int64 `json:"customFormatScore"`
IndexerFlags int64 `json:"indexerFlags"`
IndexerID int64 `json:"indexerId"`
LanguageWeight int64 `json:"languageWeight"`
QualityWeight int64 `json:"qualityWeight"`
ReleaseWeight int64 `json:"releaseWeight"`
TvRageID int64 `json:"tvRageId"`
TvdbID int64 `json:"tvdbId"`
PublishDate time.Time `json:"publishDate"`
GUID string `json:"guid"`
Protocol starr.Protocol `json:"protocol"`
}

// Grab adds a release and attempts to download it. Use this with Pr*wlarr search output.
func (s *Sonarr) Grab(guid string, indexerID int64) (*Grab, error) {
func (s *Sonarr) Grab(guid string, indexerID int64) (*Release, error) {
return s.GrabContext(context.Background(), guid, indexerID)
}

// GrabContext adds a release and attempts to download it. Use this with Pr*wlarr search output.
func (s *Sonarr) GrabContext(ctx context.Context, guid string, indexerID int64) (*Grab, error) {
func (s *Sonarr) GrabContext(ctx context.Context, guid string, indexerID int64) (*Release, error) {
return s.GrabReleaseContext(ctx, &Release{IndexerID: indexerID, GUID: guid})
}

// GrabRelease adds a release and attempts to download it.
// Pass the release for the item from the SearchRelease output.
func (s *Sonarr) GrabRelease(release *Release) (*Grab, error) {
func (s *Sonarr) GrabRelease(release *Release) (*Release, error) {
return s.GrabReleaseContext(context.Background(), release)
}

// GrabReleaseContext adds a release and attempts to download it.
// Pass the release for the item from the SearchRelease output.
func (s *Sonarr) GrabReleaseContext(ctx context.Context, release *Release) (*Grab, error) {
func (s *Sonarr) GrabReleaseContext(ctx context.Context, release *Release) (*Release, error) {
grab := struct { // We only use/need the guid and indexerID from the release.
G string `json:"guid"`
I int64 `json:"indexerId"`
Expand All @@ -183,7 +152,7 @@ func (s *Sonarr) GrabReleaseContext(ctx context.Context, release *Release) (*Gra
return nil, fmt.Errorf("json.Marshal(%s): %w", bpRelease, err)
}

var output Grab
var output Release

req := starr.Request{URI: bpRelease, Body: &body}
if err := s.PostInto(ctx, req, &output); err != nil {
Expand Down

0 comments on commit 6c955ad

Please sign in to comment.