Skip to content

Commit 9c7597b

Browse files
committed
Pass around country code as pointer
1 parent 8092a32 commit 9c7597b

4 files changed

Lines changed: 7 additions & 8 deletions

File tree

cmd/daemon/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ func NewApp(cfg *Config) (app *App, err error) {
6868

6969
func (app *App) newSession(creds SessionCredentials) (*Session, error) {
7070
// connect new session
71-
sess := &Session{app: app}
71+
sess := &Session{app: app, countryCode: new(string)}
7272
if err := sess.Connect(creds); err != nil {
7373
return nil, err
7474
}

cmd/daemon/session.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ type Session struct {
3636

3737
// TODO: can this be factored better?
3838
prodInfo *ProductInfo
39-
countryCode string
39+
countryCode *string
4040

4141
// TODO: consider not locking this if we are modifying it always from the same routine
4242
state *State
@@ -61,7 +61,7 @@ func (s *Session) handleAccesspointPacket(pktType ap.PacketType, payload []byte)
6161
s.prodInfo = &prod
6262
return nil
6363
case ap.PacketTypeCountryCode:
64-
s.countryCode = string(payload)
64+
*s.countryCode = string(payload)
6565
return nil
6666
default:
6767
return nil

player/player.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const Channels = 2
1919
const MaxStateVolume = 65535
2020

2121
type Player struct {
22-
countryCode string
22+
countryCode *string
2323

2424
sp *spclient.Spclient
2525
audioKey *audio.KeyProvider
@@ -58,7 +58,7 @@ type playerCmdDataSet struct {
5858
paused bool
5959
}
6060

61-
func NewPlayer(sp *spclient.Spclient, audioKey *audio.KeyProvider, countryCode string, device string, volumeSteps uint32) (*Player, error) {
61+
func NewPlayer(sp *spclient.Spclient, audioKey *audio.KeyProvider, countryCode *string, device string, volumeSteps uint32) (*Player, error) {
6262
p := &Player{
6363
sp: sp,
6464
audioKey: audioKey,
@@ -215,7 +215,7 @@ func (p *Player) NewStream(tid librespot.TrackId, bitrate int, trackPosition int
215215
return nil, fmt.Errorf("failed getting track metadata: %w", err)
216216
}
217217

218-
if isTrackRestricted(trackMeta, p.countryCode) {
218+
if isTrackRestricted(trackMeta, *p.countryCode) {
219219
return nil, librespot.ErrTrackRestricted
220220
}
221221

player/restriction.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
package player
22

33
import (
4-
"fmt"
54
metadatapb "go-librespot/proto/spotify/metadata"
65
"strings"
76
)
87

98
func isTrackRestricted(track *metadatapb.Track, country string) bool {
109
if len(country) != 2 {
11-
panic(fmt.Sprintf("invalid country code: %s", country))
10+
return false
1211
}
1312

1413
contains := func(list string) bool {

0 commit comments

Comments
 (0)