Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
yanosea committed Feb 28, 2025
1 parent 25f3ce3 commit 13922af
Show file tree
Hide file tree
Showing 9 changed files with 372 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ type GetAllTracksByAlbumIdUseCaseOutputDto struct {

// Run returns the get result of the artist.
func (uc *getAllTracksByAlbumIdUseCase) Run(id string) ([]*GetAllTracksByAlbumIdUseCaseOutputDto, error) {
album, err := uc.Client.GetAlbum(context.Background(), spotify.ID(id))
if err != nil {
return nil, err
}

var getAllTracksByAlbumIdUseCaseOutputDtos []*GetAllTracksByAlbumIdUseCaseOutputDto
allTracks, err := uc.Client.GetAlbumTracks(context.Background(), spotify.ID(id), nil)
if err != nil {
Expand All @@ -49,7 +54,7 @@ func (uc *getAllTracksByAlbumIdUseCase) Run(id string) ([]*GetAllTracksByAlbumId
Album: track.Album.Name,
Name: track.Name,
TrackNumber: strconv.Itoa(track.TrackNumber),
ReleaseDate: track.Album.ReleaseDateTime(),
ReleaseDate: album.ReleaseDateTime(),
}
getAllTracksByAlbumIdUseCaseOutputDtos = append(getAllTracksByAlbumIdUseCaseOutputDtos, getAllTracksByAlbumIdUseCaseOutputDto)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func (uc *getAllTracksByArtistIdUseCase) Run(id string) ([]*GetAllTracksByAlbumI
Album: album.Name,
Name: track.Name,
TrackNumber: strconv.Itoa(track.TrackNumber),
ReleaseDate: track.Album.ReleaseDateTime(),
ReleaseDate: album.ReleaseDateTime(),
}
getAllTracksByArtistIdUseCaseOutputDtos = append(getAllTracksByArtistIdUseCaseOutputDtos, getAllTracksByArtistIdUseCaseOutputDto)
}
Expand Down
9 changes: 8 additions & 1 deletion app/presentation/cli/spotlike/command/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

"github.com/yanosea/spotlike/app/presentation/cli/spotlike/command/spotlike"
"github.com/yanosea/spotlike/app/presentation/cli/spotlike/command/spotlike/completion"
"github.com/yanosea/spotlike/app/presentation/cli/spotlike/command/spotlike/get"
"github.com/yanosea/spotlike/app/presentation/cli/spotlike/command/spotlike/like"
"github.com/yanosea/spotlike/app/presentation/cli/spotlike/config"
"github.com/yanosea/spotlike/app/presentation/cli/spotlike/formatter"
Expand Down Expand Up @@ -60,6 +61,11 @@ func NewRootCommand(
cobra,
output,
),
get.NewGetCommand(
cobra,
conf,
output,
),
like.NewLikeCommand(
cobra,
conf,
Expand Down Expand Up @@ -123,7 +129,8 @@ Also, you can search for the ID of songs, albums, and artists in Spotify.
Available Commands:
auth, au, a 🔑 Authenticate your Spotify client.
like, lk, l 🤍 Like content on Spotify by ID.
get, ge, g ℹ️ Get the information of the content on Spotify by ID.
like, li, l 🤍 Like content on Spotify by ID.
search, se, s 🔍 Search for the ID of content in Spotify.
completion, comp, c 🔧 Generate the autocompletion script for the specified shell.
version, ver, v 🔖 Show the version of spotlike.
Expand Down
121 changes: 121 additions & 0 deletions app/presentation/cli/spotlike/command/spotlike/get/albums.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
package get

import (
c "github.com/spf13/cobra"

spotlikeApp "github.com/yanosea/spotlike/app/application/spotlike"
"github.com/yanosea/spotlike/app/presentation/cli/spotlike/command/spotlike"
"github.com/yanosea/spotlike/app/presentation/cli/spotlike/config"
"github.com/yanosea/spotlike/app/presentation/cli/spotlike/formatter"

"github.com/yanosea/spotlike/pkg/proxy"
)

type GetAlbumsOptions struct {
Format string
}

var (
GetAlbumsOps = GetAlbumsOptions{
Format: "table",
}
)

func NewAlbumCommand(
cobra proxy.Cobra,
conf *config.SpotlikeCliConfig,
output *string,
) proxy.Command {
cmd := cobra.NewCommand()
cmd.SetUse("albums")
cmd.SetAliases([]string{"als", "a"})
cmd.SetUsageTemplate(getAlbumsUsageTemplate)
cmd.SetHelpTemplate(getAlbumsHelpTemplate)
cmd.SetArgs(cobra.ExactArgs(1))
cmd.SetSilenceErrors(true)
cmd.Flags().StringVarP(
&GetAlbumsOps.Format,
"format",
"f",
"table",
"📝 format of the output (default \"table\", e.g: \"plain\")",
)

cmd.SetRunE(
func(_ *c.Command, args []string) error {
return runAlbum(output, args, conf)
},
)

return cmd
}

func runAlbum(output *string, args []string, conf *config.SpotlikeCliConfig) error {
client, err := spotlike.Auth(conf, output, false)
if err != nil {
return err
}

gctuc := spotlikeApp.NewGetContentTypeUseCase(client)
var albums []*spotlikeApp.GetContentTypeUseCaseOutputDto
gctucDto, err := gctuc.Run(args[0])
if err != nil {
return err
}

if gctucDto.Type != spotlikeApp.Artist {
o := formatter.Yellow("⚡ The id " + gctucDto.Name + " is not an artist. skipping...")
*output = o
return nil
}

gaauc := spotlikeApp.NewGetAllAlbumsByArtistIdUseCase(client)
allAlbums, err := gaauc.Run(args[0])
if err != nil {
return err
}

for _, album := range allAlbums {
album := &spotlikeApp.GetContentTypeUseCaseOutputDto{
ID: album.ID,
Type: spotlikeApp.Album,
Name: album.Name,
Artists: album.Artists,
ReleaseDate: album.ReleaseDate,
}
albums = append(albums, album)
}

f, err := formatter.NewFormatter(GetAlbumsOps.Format)
if err != nil {
o := formatter.Red("❌ Failed to create a formatter...")
*output = o
return err
}
o := "\n" + f.Format(albums)
*output = o

return nil
}

const (
getAlbumsHelpTemplate = `ℹ️💿 Get the information of the albums on Spotify by artist ID.
You can get the information of the albums on Spotify by artist ID.
Before using this command,
you need to get the ID of the artist you want to get by using the search command.
` + getAlbumsUsageTemplate
getAlbumsUsageTemplate = `Usage:
spotlike get albums [flags] [arguments]
spotlike get als [flags] [arguments]
spotlike get a [flags] [arguments]
Flags:
-f, --format 📝 format of the output (default "table", e.g: "plain")
Argument:
ID 🆔 ID of the artist (e.g. : "00DuPiLri3mNomvvM3nZvU")
`
)
86 changes: 86 additions & 0 deletions app/presentation/cli/spotlike/command/spotlike/get/get.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
package get

import (
c "github.com/spf13/cobra"

"github.com/yanosea/spotlike/app/presentation/cli/spotlike/config"
"github.com/yanosea/spotlike/app/presentation/cli/spotlike/formatter"

"github.com/yanosea/spotlike/pkg/proxy"
)

func NewGetCommand(
cobra proxy.Cobra,
conf *config.SpotlikeCliConfig,
output *string,
) proxy.Command {
cmd := cobra.NewCommand()
cmd.SetUse("get")
cmd.SetAliases([]string{"ge", "g"})
cmd.SetUsageTemplate(getUsageTemplate)
cmd.SetHelpTemplate(getHelpTemplate)
cmd.SetArgs(cobra.ExactArgs(0))
cmd.SetSilenceErrors(true)
cmd.AddCommand(
NewAlbumCommand(
cobra,
conf,
output,
),
NewTrackCommand(
cobra,
conf,
output,
),
)

cmd.SetRunE(
func(cmd *c.Command, args []string) error {
return runGet(output)
},
)

return cmd
}

func runGet(output *string) error {
o := formatter.Yellow(`⚡ Use sub command below...
- 💿 album
- 🎵 track
Use "spotlike get --help" for more information about spotlike get.
Use "spotlike get [command] --help" for more information about a command.
`)
*output = o

return nil
}

const (
getHelpTemplate = `ℹ️ Get the information of the content on Spotify by ID.
You can get the information of the content on Spotify by ID.
Before using this command,
you need to get the ID of the content you want to get by using the search command.
` + getUsageTemplate
getUsageTemplate = `Usage:
spotlike get [flags]
spotlike ge [flags]
spotlike g [flags]
spotlike get [command]
spotlike ge [command]
spotlike g [command]
Available Commands:
albums, als, a 💿 Get the information of the albums on Spotify by ID.
tracks, trs, t 🎵 Get the information of the tracks on Spotify by ID.
Flags:
-h, --help 🤝 help for like
Use "spotlike get [command] --help" for more information about a command.
`
)
Loading

0 comments on commit 13922af

Please sign in to comment.