golift.io/starr@v1.0.0/lidarr/track.go (about)

     1  package lidarr
     2  
     3  import (
     4  	"context"
     5  	"fmt"
     6  	"net/url"
     7  
     8  	"golift.io/starr"
     9  )
    10  
    11  const bpTrack = APIver + "/track"
    12  
    13  // Track is an album track.
    14  type Track struct {
    15  	ArtistID            int64          `json:"artistId"`
    16  	ForeignTrackID      string         `json:"foreignTrackId"`
    17  	ForeignRecordingID  string         `json:"foreignRecordingId"`
    18  	TrackFileID         int64          `json:"trackFileId"`
    19  	AlbumID             int64          `json:"albumId"`
    20  	Explicit            bool           `json:"explicit"`
    21  	AbsoluteTrackNumber int            `json:"absoluteTrackNumber"`
    22  	TrackNumber         string         `json:"trackNumber"`
    23  	Title               string         `json:"title"`
    24  	Duration            int            `json:"duration"`
    25  	MediumNumber        int            `json:"mediumNumber"`
    26  	HasFile             bool           `json:"hasFile"`
    27  	Ratings             *starr.Ratings `json:"ratings"`
    28  	Grabbed             bool           `json:"grabbed"`
    29  	ID                  int64          `json:"id"`
    30  	Artist              *Artist        `json:"artist"`    // probably empty.
    31  	TrackFile           *TrackFile     `json:"trackFile"` // probably empty.
    32  }
    33  
    34  // GetTracks by their IDs.
    35  func (l *Lidarr) GetTracks(trackID ...int64) ([]*Track, error) {
    36  	return l.GetTracksContext(context.Background(), trackID...)
    37  }
    38  
    39  // GetTracksContext gets track files by their IDs using a provided context.
    40  func (l *Lidarr) GetTracksContext(ctx context.Context, trackID ...int64) ([]*Track, error) {
    41  	req := starr.Request{URI: bpTrack, Query: make(url.Values)}
    42  	for _, id := range trackID {
    43  		req.Query.Add("trackIds", fmt.Sprint(id))
    44  	}
    45  
    46  	var output []*Track
    47  	if err := l.GetInto(ctx, req, &output); err != nil {
    48  		return nil, fmt.Errorf("api.Get(%s): %w", &req, err)
    49  	}
    50  
    51  	return output, nil
    52  }
    53  
    54  // GetTracksByAlbum gets track files using an album ID.
    55  func (l *Lidarr) GetTracksByAlbum(albumID int64) ([]*Track, error) {
    56  	return l.GetTracksByAlbumContext(context.Background(), albumID)
    57  }
    58  
    59  // GetTracksByAlbumContext gets track files using an album ID.
    60  func (l *Lidarr) GetTracksByAlbumContext(ctx context.Context, albumID int64) ([]*Track, error) {
    61  	req := starr.Request{URI: bpTrack, Query: make(url.Values)}
    62  	req.Query.Add("albumId", fmt.Sprint(albumID))
    63  
    64  	var output []*Track
    65  	if err := l.GetInto(ctx, req, &output); err != nil {
    66  		return nil, fmt.Errorf("api.Get(%s): %w", &req, err)
    67  	}
    68  
    69  	return output, nil
    70  }
    71  
    72  // GetTracksByArtist gets track files using an artist ID.
    73  func (l *Lidarr) GetTracksByArtist(artistID int64) ([]*Track, error) {
    74  	return l.GetTracksByArtistContext(context.Background(), artistID)
    75  }
    76  
    77  // GetTracksByAlbumRelease gets track files using an artist ID.
    78  func (l *Lidarr) GetTracksByArtistContext(ctx context.Context, artistID int64) ([]*Track, error) {
    79  	req := starr.Request{URI: bpTrack, Query: make(url.Values)}
    80  	req.Query.Add("artistId", fmt.Sprint(artistID))
    81  
    82  	var output []*Track
    83  	if err := l.GetInto(ctx, req, &output); err != nil {
    84  		return nil, fmt.Errorf("api.Get(%s): %w", &req, err)
    85  	}
    86  
    87  	return output, nil
    88  }
    89  
    90  // GetTracksByAlbumRelease gets track files using an album release ID.
    91  func (l *Lidarr) GetTracksByAlbumRelease(albumID int64) ([]*Track, error) {
    92  	return l.GetTracksByAlbumContext(context.Background(), albumID)
    93  }
    94  
    95  // GetTracksByAlbumReleaseContext gets track files using an album release ID.
    96  func (l *Lidarr) GetTracksByAlbumReleaseContext(ctx context.Context, albumReleaseID int64) ([]*Track, error) {
    97  	req := starr.Request{URI: bpTrack, Query: make(url.Values)}
    98  	req.Query.Add("albumReleaseId", fmt.Sprint(albumReleaseID))
    99  
   100  	var output []*Track
   101  	if err := l.GetInto(ctx, req, &output); err != nil {
   102  		return nil, fmt.Errorf("api.Get(%s): %w", &req, err)
   103  	}
   104  
   105  	return output, nil
   106  }