Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
tomjowitt committed Feb 17, 2024
1 parent be07a37 commit f9ffbdc
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 3 deletions.
74 changes: 72 additions & 2 deletions album.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package gotidal

import "strings"
import (
"strings"
"time"
)

// Album represents an individual release.
type Album struct {
Expand Down Expand Up @@ -40,6 +43,73 @@ func (a Album) ArtistsToString() string {
return strings.Join(artistNames, " / ")
}

// Duration returns the duration of the album in seconds.
func (a Album) Duration() int {
return a.Resource.Duration
}

// ReleaseDate returns the release date of the album as a time object.
func (a Album) ReleaseDate() *time.Time {
layout := "2006-01-02"

releaseDate, err := time.Parse(layout, a.Resource.ReleaseDate)
if err != nil {
return nil
}

return &releaseDate
}

// CoverImages returns a list of album images.
func (a Album) CoverImages() []Image {
return a.Resource.ImageCover
}

// VideoImages returns a list of video images.
func (a Album) VideoImages() []Image {
return a.Resource.VideoCover
}

// NumberOfVolumes returns the number of volumes in the album.
func (a Album) NumberOfVolumes() int {
return a.Resource.NumberOfVolumes
}

// NumberOfTracks returns the number of tracks on the album.
func (a Album) NumberOfTracks() int {
return a.Resource.NumberOfTracks
}

// NumberOfVideos returns the number of videos on the album.
func (a Album) NumberOfVideos() int {
return a.Resource.NumberOfVideos
}

// Type returns the type of the album.
func (a Album) Type() string {
return a.Resource.Type
}

// Copyright returns the compyright string for the album.
func (a Album) Copyright() string {
return a.Resource.Copyright
}

// Metadata returns the metadata for the album.
func (a Album) Metadata() MediaMetaData {
return a.Resource.MediaMetaData
}

// Properties returns a list of the properties for the album.
func (a Album) Properties() []string {
return a.Resource.Properties.Content
}

// URL returns the TIDAL URL for the album.
func (a Album) URL() string {
return a.Resource.TidalURL
}

type albumResource struct {
ID string `json:"id"`
BarcodeID string `json:"barcodeID"`
Expand All @@ -54,7 +124,7 @@ type albumResource struct {
NumberOfVideos int `json:"numberOfVideos"`
Type string `json:"type"`
Copyright string `json:"copyright"`
MediaMetadata MediaMetaData `json:"mediaMetadata"`
MediaMetaData MediaMetaData `json:"mediaMetadata"`
Properties AlbumProperties `json:"properties"`
TidalURL string `json:"tidalUrl"`
}
Expand Down
4 changes: 3 additions & 1 deletion doc.go
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
// Package gotidal provides a Go SDK for interacting with the TIDAL API.
// Package gotidal provides an unofficial Go SDK for interacting with the TIDAL API.
//
// https://developer.tidal.com/
package gotidal
1 change: 1 addition & 0 deletions examples/search/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ func main() {

for _, album := range results.Albums {
log.Printf("%s - %s", album.Title(), album.ArtistsToString())
log.Printf("%d - %s", album.Duration(), album.ReleaseDate())
}

for _, artist := range results.Artists {
Expand Down

0 comments on commit f9ffbdc

Please sign in to comment.