Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 72 additions & 0 deletions lidarr/rename.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package lidarr

import (
"context"
"fmt"
"net/url"

"golift.io/starr"
)

const bpRename = APIver + "/rename"

// Rename is the /api/v1/rename endpoint.
type Rename struct {
ID int64 `json:"id"`
ArtistID int64 `json:"artistId"`
AlbumID int64 `json:"albumId"`
TrackNumbers []int64 `json:"trackNumbers"`
TrackFileID int64 `json:"trackFileId"`
ExistingPath string `json:"existingPath,omitempty"`
NewPath string `json:"newPath,omitempty"`
}

// GetRenames checks if the tracks by the specified artist (database ID) on the specified album (database ID)
// need to be renamed to follow the naming format. If albumID is set to -1, it will check all albums at once.
func (l *Lidarr) GetRenames(artistID int64, albumID int64) ([]*Rename, error) {
return l.GetRenamesContext(context.Background(), artistID, albumID)
}

// GetRenamesContext checks if the tracks by the specified artist (database ID) on the specified album (database ID)
// need to be renamed to follow the naming format. If albumID is set to -1, it will check all albums at once.
func (l *Lidarr) GetRenamesContext(ctx context.Context, artistID int64, albumID int64) ([]*Rename, error) {
params := make(url.Values)
params.Set("artistId", starr.Str(artistID))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Recommend running golangci-lint on this contribution.


if albumID != -1 {
params.Set("albumId", starr.Str(albumID))
}

var output []*Rename

req := starr.Request{URI: bpRename, Query: params}
if err := l.GetInto(ctx, req, &output); err != nil {
return nil, fmt.Errorf("api.Get(%s): %w", &req, err)
}

return output, nil
}

// GetArtistRenames checks if the tracks by the specified artist (database ID) need to be renamed to
// follow the naming format.
func (l *Lidarr) GetArtistRenames(artistID int64) ([]*Rename, error) {
return l.GetRenamesContext(context.Background(), artistID, -1)
}

// GetArtistRenamesContext checks if the tracks by the specified artist (database ID) need to be renamed to
// follow the naming format.
func (l *Lidarr) GetArtistRenamesContext(ctx context.Context, artistID int64) ([]*Rename, error) {
return l.GetRenamesContext(ctx, artistID, -1)
}

/* Doesn't exist yet
// GetAllRenames checks if any tracks need to be renamed to follow the naming format.
func (l *Lidarr) GetAllRenames() ([]*Rename, error) {
return l.GetRenamesContext(context.Background(), -1, -1)
} */

/* Doesn't exist yet
// GetAllRenamesContext checks if any tracks need to be renamed to follow the naming format.
func (l *Lidarr) GetAllRenamesContext(ctx context.Context) ([]*Rename, error) {
return l.GetRenamesContext(ctx, -1, -1)
} */
54 changes: 54 additions & 0 deletions radarr/rename.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package radarr

import (
"context"
"fmt"
"net/url"

"golift.io/starr"
)

const bpRename = APIver + "/rename"

// Rename is the /api/v3/rename endpoint.
type Rename struct {
ID int64 `json:"id"`
MovieID int64 `json:"movieId"`
MovieFileID int64 `json:"movieFileId"`
ExistingPath string `json:"existingPath,omitempty"`
NewPath string `json:"newPath,omitempty"`
}

// GetRenames checks if the movie with the specified movieID (database ID) needs to be renamed to
// follow the naming format.
func (r *Radarr) GetRenames(movieID int64) ([]*Rename, error) {
return r.GetRenamesContext(context.Background(), movieID)
}

// GetRenamesContext checks if the movie with the specified movieID (database ID) needs to be renamed to
// follow the naming format.
func (r *Radarr) GetRenamesContext(ctx context.Context, movieID int64) ([]*Rename, error) {
params := make(url.Values)
params.Set("movieId", starr.Str(movieID))

var output []*Rename

req := starr.Request{URI: bpRename, Query: params}
if err := r.GetInto(ctx, req, &output); err != nil {
return nil, fmt.Errorf("api.Get(%s): %w", &req, err)
}

return output, nil
}

/* Doesn't exist yet
// GetAllRenames checks if any movies need to be renamed to follow the naming format.
func (r *Radarr) GetAllRenames() ([]*Rename, error) {
return r.GetRenamesContext(context.Background(), -1)
} */

/* Doesn't exist yet
// GetAllRenamesContext checks if any movies need to be renamed to follow the naming format.
func (r *Radarr) GetAllRenamesContext(ctx context.Context) ([]*Rename, error) {
return r.GetRenamesContext(ctx, -1)
} */
71 changes: 71 additions & 0 deletions readarr/rename.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package readarr

import (
"context"
"fmt"
"net/url"

"golift.io/starr"
)

const bpRename = APIver + "/rename"

// Rename is the /api/v1/rename endpoint.
type Rename struct {
ID int64 `json:"id"`
AuthorID int64 `json:"authorId"`
BookID int64 `json:"bookId"`
BookFileID int64 `json:"bookFileId"`
ExistingPath string `json:"existingPath,omitempty"`
NewPath string `json:"newPath,omitempty"`
}

// GetRenames checks if the specified book (database ID) from the author (database ID) needs to be renamed to
// follow the naming format. If bookId is set to -1, it will check all books at once.
func (r *Readarr) GetRenames(authorID int64, bookID int64) ([]*Rename, error) {
return r.GetRenamesContext(context.Background(), authorID, bookID)
}

// GetRenamesContext checks if the specified book (database ID) from the author (database ID) needs to be renamed to
// follow the naming format. If bookId is set to -1, it will check all books at once.
func (r *Readarr) GetRenamesContext(ctx context.Context, authorID int64, bookID int64) ([]*Rename, error) {
params := make(url.Values)
params.Set("authorId", starr.Str(authorID))

if bookID != -1 {
params.Set("bookId", starr.Str(bookID))
}

var output []*Rename

req := starr.Request{URI: bpRename, Query: params}
if err := r.GetInto(ctx, req, &output); err != nil {
return nil, fmt.Errorf("api.Get(%s): %w", &req, err)
}

return output, nil
}

// GetAuthorRenames checks if the books from the specified author (database ID) need to be renamed to
// follow the naming format.
func (r *Readarr) GetAuthorRenames(authorID int64) ([]*Rename, error) {
return r.GetRenamesContext(context.Background(), authorID, -1)
}

// GetAuthorRenamesContext checks if the books from the specified author (database ID) need to be renamed to
// follow the naming format.
func (r *Readarr) GetAuthorRenamesContext(ctx context.Context, authorID int64) ([]*Rename, error) {
return r.GetRenamesContext(ctx, authorID, -1)
}

/* Doesn't exist yet
// GetAllRenames checks if any books need to be renamed to follow the naming format.
func (r *Readarr) GetAllRenames() ([]*Rename, error) {
return r.GetRenamesContext(context.Background(), -1, -1)
} */

/* Doesn't exist yet
// GetAllRenamesContext checks if any books need to be renamed to follow the naming format.
func (r *Readarr) GetAllRenamesContext(ctx context.Context) ([]*Rename, error) {
return r.GetRenamesContext(ctx, -1, -1)
} */
72 changes: 72 additions & 0 deletions sonarr/rename.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package sonarr

import (
"context"
"fmt"
"net/url"

"golift.io/starr"
)

const bpRename = APIver + "/rename"

// Rename is the /api/v3/rename endpoint.
type Rename struct {
ID int64 `json:"id"`
SeriesID int64 `json:"seriesId"`
SeasonNumber int64 `json:"seasonNumber"`
EpisodeNumbers []int64 `json:"episodeNumbers"`
EpisodeFileID int64 `json:"episodeFileId"`
ExistingPath string `json:"existingPath,omitempty"`
NewPath string `json:"newPath,omitempty"`
}

// GetRenames checks if the episodes in the specified series (database ID) and season need to be renamed to
// follow the naming format. If seasonNumber is set to -1, it will check all seasons at once.
func (s *Sonarr) GetRenames(seriesID int64, seasonNumber int64) ([]*Rename, error) {
return s.GetRenamesContext(context.Background(), seriesID, seasonNumber)
}

// GetRenamesContext checks if the episodes in the specified series (database ID) and season need to be renamed to
// follow the naming format. If seasonNumber is set to -1, it will check all seasons at once.
func (s *Sonarr) GetRenamesContext(ctx context.Context, seriesID int64, seasonNumber int64) ([]*Rename, error) {
params := make(url.Values)
params.Set("seriesId", starr.Str(seriesID))

if seasonNumber != -1 {
params.Set("seasonNumber", starr.Str(seasonNumber))
}

var output []*Rename

req := starr.Request{URI: bpRename, Query: params}
if err := s.GetInto(ctx, req, &output); err != nil {
return nil, fmt.Errorf("api.Get(%s): %w", &req, err)
}

return output, nil
}

// GetSeriesRenames checks if the episodes in the specified series (database ID) need to be renamed to
// follow the naming format.
func (s *Sonarr) GetSeriesRenames(seriesID int64) ([]*Rename, error) {
return s.GetRenamesContext(context.Background(), seriesID, -1)
}

// GetSeriesRenamesContext checks if the episodes in the specified series (database ID) need to be renamed to
// follow the naming format.
func (s *Sonarr) GetSeriesRenamesContext(ctx context.Context, seriesID int64) ([]*Rename, error) {
return s.GetRenamesContext(ctx, seriesID, -1)
}

/* Doesn't exist yet
// GetAllRenames checks if any episodes need to be renamed to follow the naming format.
func (s *Sonarr) GetAllRenames() ([]*Rename, error) {
return s.GetRenamesContext(context.Background(), -1, -1)
} */

/* Doesn't exist yet
// GetAllRenamesContext checks if any episodes need to be renamed to follow the naming format.
func (s *Sonarr) GetAllRenamesContext(ctx context.Context) ([]*Rename, error) {
return s.GetRenamesContext(ctx, -1, -1)
} */
Loading