Skip to content

Commit

Permalink
Don't return non-critical errors on startup
Browse files Browse the repository at this point in the history
  • Loading branch information
raitonoberu committed May 22, 2023
1 parent 565a129 commit 80d1bed
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 35 deletions.
6 changes: 1 addition & 5 deletions cmd/pipe.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,7 @@ var pipeCmd = &cobra.Command{
provider = spt
} else {
// create new client
client, err := spotify.New(conf.Cookie)
if err != nil {
return err
}
provider = client
provider, _ = spotify.New(conf.Cookie)
}
} else {
// use hosted provider
Expand Down
6 changes: 1 addition & 5 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,7 @@ var rootCmd = &cobra.Command{
provider = spt
} else {
// create new client
client, err := spotify.New(conf.Cookie)
if err != nil {
return err
}
provider = client
provider, _ = spotify.New(conf.Cookie)
}
} else {
// use hosted provider
Expand Down
7 changes: 2 additions & 5 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,14 +187,11 @@ func validateColor(color string) bool {
func GetPlayer(conf *Config) (player.Player, error) {
switch conf.Player {
case "spotify":
if conf.Cookie == "" {
return nil, spotify.ErrInvalidCookie
}
return spotify.New(conf.Cookie)
case "mpd":
return mpd.New(conf.Mpd.Address, conf.Mpd.Password)
return mpd.New(conf.Mpd.Address, conf.Mpd.Password), nil
case "mopidy":
return mopidy.New(conf.Mopidy.Address)
return mopidy.New(conf.Mopidy.Address), nil
case "mpris":
return mpris.New(conf.Mpris.Players)
}
Expand Down
7 changes: 2 additions & 5 deletions services/mopidy/mopidy.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,8 @@ import (
"sptlrx/player"
)

func New(address string) (*Client, error) {
c := &Client{
address: address,
}
return c, nil
func New(address string) *Client {
return &Client{address: address}
}

// Client implements player.Player
Expand Down
5 changes: 2 additions & 3 deletions services/mpd/mpd.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@ import (
"github.com/fhs/gompd/mpd"
)

func New(address, password string) (*Client, error) {
c := &Client{
func New(address, password string) *Client {
return &Client{
address: address,
password: password,
}
return c, c.connect()
}

// Client implements player.Player
Expand Down
18 changes: 9 additions & 9 deletions services/mpris/mpris_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,21 @@ import (
)

func New(players []string) (*Client, error) {
conn, err := dbus.SessionBus()
if err != nil {
return nil, err
}
return &Client{players, conn}, nil
return &Client{players}, nil
}

// Client implements player.Player
type Client struct {
players []string
conn *dbus.Conn
}

func (c *Client) getPlayer() (*mpris.Player, error) {
players, err := mpris.List(c.conn)
conn, err := dbus.SessionBus()
if err != nil {
return nil, err
}

players, err := mpris.List(conn)
if err != nil {
return nil, err
}
Expand All @@ -32,15 +32,15 @@ func (c *Client) getPlayer() (*mpris.Player, error) {
}

if len(c.players) == 0 {
return mpris.New(c.conn, players[0]), nil
return mpris.New(conn, players[0]), nil
}

// iterating over configured names
for _, p := range c.players {
for _, player := range players {
// trim "org.mpris.MediaPlayer2."
if player[23:] == p {
return mpris.New(c.conn, player), nil
return mpris.New(conn, player), nil
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions services/spotify/spotify.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ const stateUrl = "https://api.spotify.com/v1/me/player/currently-playing"
const searchUrl = "https://api.spotify.com/v1/search?"

func New(cookie string) (*Client, error) {
c := &Client{
cookie: cookie,
if cookie == "" {
return nil, ErrInvalidCookie
}
return c, c.checkToken()
return &Client{cookie: cookie}, nil
}

// Client implements both player.Player and lyrics.Provider
Expand Down

0 comments on commit 80d1bed

Please sign in to comment.