Skip to content

Commit

Permalink
Remove lidarr type file (#45)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidnewhall authored Mar 18, 2022
1 parent 3acbb1e commit 512e1e9
Show file tree
Hide file tree
Showing 11 changed files with 437 additions and 409 deletions.
84 changes: 84 additions & 0 deletions lidarr/album.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,94 @@ import (
"fmt"
"net/url"
"strconv"
"time"

"golift.io/starr"
)

// Album is the /api/v1/album endpoint.
type Album struct {
ID int64 `json:"id,omitempty"`
Title string `json:"title"`
Disambiguation string `json:"disambiguation"`
Overview string `json:"overview"`
ArtistID int64 `json:"artistId"`
ForeignAlbumID string `json:"foreignAlbumId"`
ProfileID int64 `json:"profileId"`
Duration int `json:"duration"`
AlbumType string `json:"albumType"`
SecondaryTypes []interface{} `json:"secondaryTypes"`
MediumCount int `json:"mediumCount"`
Ratings *starr.Ratings `json:"ratings"`
ReleaseDate time.Time `json:"releaseDate"`
Releases []*Release `json:"releases"`
Genres []interface{} `json:"genres"`
Media []*Media `json:"media"`
Artist *Artist `json:"artist"`
Links []*starr.Link `json:"links"`
Images []*starr.Image `json:"images"`
Statistics *Statistics `json:"statistics"`
RemoteCover string `json:"remoteCover,omitempty"`
AddOptions *AlbumAddOptions `json:"addOptions,omitempty"`
Monitored bool `json:"monitored"`
AnyReleaseOk bool `json:"anyReleaseOk"`
Grabbed bool `json:"grabbed"`
}

// Release is part of an Album.
type Release struct {
ID int64 `json:"id"`
AlbumID int64 `json:"albumId"`
ForeignReleaseID string `json:"foreignReleaseId"`
Title string `json:"title"`
Status string `json:"status"`
Duration int `json:"duration"`
TrackCount int `json:"trackCount"`
Media []*Media `json:"media"`
MediumCount int `json:"mediumCount"`
Disambiguation string `json:"disambiguation"`
Country []string `json:"country"`
Label []string `json:"label"`
Format string `json:"format"`
Monitored bool `json:"monitored"`
}

// Media is part of an Album.
type Media struct {
MediumNumber int64 `json:"mediumNumber"`
MediumName string `json:"mediumName"`
MediumFormat string `json:"mediumFormat"`
}

// ArtistAddOptions is part of an artist and an album.
type ArtistAddOptions struct {
Monitor string `json:"monitor,omitempty"`
Monitored bool `json:"monitored,omitempty"`
SearchForMissingAlbums bool `json:"searchForMissingAlbums,omitempty"`
}

// AddAlbumInput is currently unknown.
type AddAlbumInput struct {
ForeignAlbumID string `json:"foreignAlbumId"`
Monitored bool `json:"monitored"`
Releases []*AddAlbumInputRelease `json:"releases"`
AddOptions *AlbumAddOptions `json:"addOptions"`
Artist *Artist `json:"artist"`
}

// AddAlbumInputRelease is part of AddAlbumInput.
type AddAlbumInputRelease struct {
ForeignReleaseID string `json:"foreignReleaseId"`
Title string `json:"title"`
Media []*Media `json:"media"`
Monitored bool `json:"monitored"`
}

// AlbumAddOptions is part of an Album.
type AlbumAddOptions struct {
SearchForNewAlbum bool `json:"searchForNewAlbum,omitempty"`
}

// GetAlbum returns an album or all albums if mbID is "" (empty).
// mbID is the music brainz UUID for a "release-group".
func (l *Lidarr) GetAlbum(mbID string) ([]*Album, error) {
Expand Down
44 changes: 44 additions & 0 deletions lidarr/artist.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,54 @@ import (
"fmt"
"net/url"
"strconv"
"time"

"golift.io/starr"
)

// Artist represents the /api/v1/artist endpoint, and it's part of an Album.
type Artist struct {
ID int64 `json:"id"`
Status string `json:"status,omitempty"`
LastInfoSync time.Time `json:"lastInfoSync,omitempty"`
ArtistName string `json:"artistName,omitempty"`
ForeignArtistID string `json:"foreignArtistId,omitempty"`
TadbID int64 `json:"tadbId,omitempty"`
DiscogsID int64 `json:"discogsId,omitempty"`
QualityProfileID int64 `json:"qualityProfileId,omitempty"`
MetadataProfileID int64 `json:"metadataProfileId,omitempty"`
Overview string `json:"overview,omitempty"`
ArtistType string `json:"artistType,omitempty"`
Disambiguation string `json:"disambiguation,omitempty"`
RootFolderPath string `json:"rootFolderPath,omitempty"`
Path string `json:"path,omitempty"`
CleanName string `json:"cleanName,omitempty"`
SortName string `json:"sortName,omitempty"`
Links []*starr.Link `json:"links,omitempty"`
Images []*starr.Image `json:"images,omitempty"`
Genres []string `json:"genres,omitempty"`
Tags []int `json:"tags,omitempty"`
Added time.Time `json:"added,omitempty"`
Ratings *starr.Ratings `json:"ratings,omitempty"`
Statistics *Statistics `json:"statistics,omitempty"`
LastAlbum *Album `json:"lastAlbum,omitempty"`
NextAlbum *Album `json:"nextAlbum,omitempty"`
AddOptions *ArtistAddOptions `json:"addOptions,omitempty"`
AlbumFolder bool `json:"albumFolder,omitempty"`
Monitored bool `json:"monitored"`
Ended bool `json:"ended,omitempty"`
}

// Statistics is part of Artist and Album.
type Statistics struct {
AlbumCount int `json:"albumCount,omitempty"`
TrackFileCount int `json:"trackFileCount"`
TrackCount int `json:"trackCount"`
TotalTrackCount int `json:"totalTrackCount"`
SizeOnDisk int `json:"sizeOnDisk"`
PercentOfTracks float64 `json:"percentOfTracks"`
}

// GetArtist returns an artist or all artists.
func (l *Lidarr) GetArtist(mbID string) ([]*Artist, error) {
return l.GetArtistContext(context.Background(), mbID)
Expand Down
47 changes: 47 additions & 0 deletions lidarr/history.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,57 @@ import (
"context"
"fmt"
"strconv"
"time"

"golift.io/starr"
)

// History represents the /api/v1/history endpoint.
type History struct {
Page int `json:"page"`
PageSize int `json:"pageSize"`
SortKey string `json:"sortKey"`
SortDirection string `json:"sortDirection"`
TotalRecords int `json:"totalRecords"`
Records []*HistoryRecord `json:"records"`
}

// HistoryRecord is part of the history. Not all items have all Data members.
// Check EventType for events you need.
type HistoryRecord struct {
ID int64 `json:"id"`
AlbumID int64 `json:"albumId"`
ArtistID int64 `json:"artistId"`
TrackID int64 `json:"trackId"`
SourceTitle string `json:"sourceTitle"`
Quality *starr.Quality `json:"quality"`
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"`
AgeMinutes string `json:"ageMinutes"`
DownloadClient string `json:"downloadClient"`
DownloadForced string `json:"downloadForced"`
DownloadURL string `json:"downloadUrl"`
DroppedPath string `json:"droppedPath"`
GUID string `json:"guid"`
ImportedPath string `json:"importedPath"`
Indexer string `json:"indexer"`
Message string `json:"message"`
NzbInfoURL string `json:"nzbInfoUrl"`
Protocol string `json:"protocol"`
PublishedDate time.Time `json:"publishedDate"`
Reason string `json:"reason"`
ReleaseGroup string `json:"releaseGroup"`
Size string `json:"size"`
StatusMessages string `json:"statusMessages"`
TorrentInfoHash string `json:"torrentInfoHash"`
} `json:"data"`
}

// 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().
Expand Down
119 changes: 3 additions & 116 deletions lidarr/lidarr.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package lidarr

import (
"context"
"crypto/tls"
"fmt"
"net/http"

"golift.io/starr"
)

// APIver is the Lidarr API version supported by this library.
const APIver = "v1"

// Lidarr contains all the methods to interact with a Lidarr server.
type Lidarr struct {
starr.APIer
Expand Down Expand Up @@ -52,117 +53,3 @@ func New(config *starr.Config) *Lidarr {

return &Lidarr{APIer: config}
}

// 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.
// It grabs records in (paginated) batches of perPage, and concatenates
// them into one list. Passing zero for records will return all of them.
func (l *Lidarr) GetQueue(records, perPage int) (*Queue, error) {
return l.GetQueueContext(context.Background(), records, perPage)
}

// GetQueueContext returns a single page from the Lidarr Queue (processing, but not yet imported).
func (l *Lidarr) GetQueueContext(ctx context.Context, records, perPage int) (*Queue, error) {
queue := &Queue{Records: []*QueueRecord{}}
perPage = starr.SetPerPage(records, perPage)

for page := 1; ; page++ {
curr, err := l.GetQueuePageContext(ctx, &starr.Req{PageSize: perPage, Page: page})
if err != nil {
return nil, err
}

queue.Records = append(queue.Records, curr.Records...)

if len(queue.Records) >= curr.TotalRecords ||
(len(queue.Records) >= records && records != 0) ||
len(curr.Records) == 0 {
queue.PageSize = curr.TotalRecords
queue.TotalRecords = curr.TotalRecords
queue.SortDirection = curr.SortDirection
queue.SortKey = curr.SortKey

break
}

perPage = starr.AdjustPerPage(records, curr.TotalRecords, len(queue.Records), perPage)
}

return queue, nil
}

// GetQueuePage returns a single page from the Lidarr Queue.
// The page size and number is configurable with the input request parameters.
func (l *Lidarr) GetQueuePage(params *starr.Req) (*Queue, error) {
return l.GetQueuePageContext(context.Background(), params)
}

// GetQueuePageContext returns a single page from the Lidarr Queue.
// The page size and number is configurable with the input request parameters.
func (l *Lidarr) GetQueuePageContext(ctx context.Context, params *starr.Req) (*Queue, error) {
var queue Queue

params.CheckSet("sortKey", "timeleft")
params.CheckSet("includeUnknownArtistItems", "true")

_, err := l.GetInto(ctx, "v1/queue", params.Params(), &queue)
if err != nil {
return nil, fmt.Errorf("api.Get(queue): %w", err)
}

return &queue, nil
}

// GetQualityDefinition returns the Quality Definitions.
func (l *Lidarr) GetQualityDefinition() ([]*QualityDefinition, error) {
return l.GetQualityDefinitionContext(context.Background())
}

// GetQualityDefinitionContext returns the Quality Definitions.
func (l *Lidarr) GetQualityDefinitionContext(ctx context.Context) ([]*QualityDefinition, error) {
var definition []*QualityDefinition

_, err := l.GetInto(ctx, "v1/qualitydefinition", nil, &definition)
if err != nil {
return nil, fmt.Errorf("api.Get(qualitydefinition): %w", err)
}

return definition, nil
}

// GetRootFolders returns all configured root folders.
func (l *Lidarr) GetRootFolders() ([]*RootFolder, error) {
return l.GetRootFoldersContext(context.Background())
}

// GetRootFoldersContext returns all configured root folders.
func (l *Lidarr) GetRootFoldersContext(ctx context.Context) ([]*RootFolder, error) {
var folders []*RootFolder

_, err := l.GetInto(ctx, "v1/rootFolder", nil, &folders)
if err != nil {
return nil, fmt.Errorf("api.Get(rootFolder): %w", err)
}

return folders, nil
}

// GetMetadataProfiles returns the metadata profiles.
func (l *Lidarr) GetMetadataProfiles() ([]*MetadataProfile, error) {
return l.GetMetadataProfilesContext(context.Background())
}

// GetMetadataProfilesContext returns the metadata profiles.
func (l *Lidarr) GetMetadataProfilesContext(ctx context.Context) ([]*MetadataProfile, error) {
var profiles []*MetadataProfile

_, err := l.GetInto(ctx, "v1/metadataprofile", nil, &profiles)
if err != nil {
return nil, fmt.Errorf("api.Get(metadataprofile): %w", err)
}

return profiles, nil
}
46 changes: 46 additions & 0 deletions lidarr/metadataprofile.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package lidarr

import (
"context"
"fmt"

"golift.io/starr"
)

// MetadataProfile is the /api/v1/metadataprofile endpoint.
type MetadataProfile struct {
Name string `json:"name"`
ID int64 `json:"id"`
PrimaryAlbumTypes []*AlbumType `json:"primaryAlbumTypes"`
SecondaryAlbumTypes []*AlbumType `json:"secondaryAlbumTypes"`
ReleaseStatuses []*ReleaseStatus `json:"releaseStatuses"`
}

// AlbumType is part of MetadataProfile.
type AlbumType struct {
AlbumType *starr.Value `json:"albumType"`
Allowed bool `json:"allowed"`
}

// ReleaseStatus is part of MetadataProfile.
type ReleaseStatus struct {
ReleaseStatus *starr.Value `json:"releaseStatus"`
Allowed bool `json:"allowed"`
}

// GetMetadataProfiles returns the metadata profiles.
func (l *Lidarr) GetMetadataProfiles() ([]*MetadataProfile, error) {
return l.GetMetadataProfilesContext(context.Background())
}

// GetMetadataProfilesContext returns the metadata profiles.
func (l *Lidarr) GetMetadataProfilesContext(ctx context.Context) ([]*MetadataProfile, error) {
var profiles []*MetadataProfile

_, err := l.GetInto(ctx, "v1/metadataprofile", nil, &profiles)
if err != nil {
return nil, fmt.Errorf("api.Get(metadataprofile): %w", err)
}

return profiles, nil
}
Loading

0 comments on commit 512e1e9

Please sign in to comment.