Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ A terminal-based music player for [SomaFM](https://somafm.com/) radio stations b
- Stations sorted by listener count
- Favorites management
- Persistent configuration (volume, favorites, last station)
- User-selectable preferred stream format (MP3 or AAC)
- Customizable color themes
- Automatic retry on stream failure

Expand Down Expand Up @@ -71,6 +72,7 @@ somafm --help # Show help and config file path
| `←` `→` or `+` `-` | Volume up / down |
| `Scroll` | Volume (on volume bar) |
| `m` | Mute / Unmute |
| `s` | Toggle preferred stream format |
| `f` | Toggle favorite |
| `?` | Show help |
| `a` | About |
Expand All @@ -84,6 +86,7 @@ Configuration is saved automatically to `~/.config/somafm/config.yml`.
volume: 70 # Volume level (0-100)
last_station: groovesalad # Last played station ID
autostart: false # Auto-play last station on launch (true/false)
preferred_format: mp3 # Preferred stream format: mp3 or aac
favorites: # List of favorite station IDs
- groovesalad
- dronezone
Expand All @@ -94,7 +97,7 @@ theme: # Color customization
highlight: "#ff9d65"
```

Settings are saved when you adjust volume, select a station, or toggle favorites.
Settings are saved when you adjust volume, select a station, toggle favorites, or switch the preferred stream format.

### Theme Options

Expand Down
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
module github.com/glebovdev/somafm-cli

go 1.25.0
go 1.25.6

require (
github.com/gdamore/tcell/v2 v2.13.8
github.com/go-resty/resty/v2 v2.17.1
github.com/gopxl/beep/v2 v2.1.1
github.com/rivo/tview v0.42.0
github.com/rs/zerolog v1.34.0
github.com/skrashevich/go-aac v0.1.0
gopkg.in/yaml.v3 v3.0.1
)

Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUc
github.com/rs/xid v1.6.0/go.mod h1:7XoLgs4eV+QndskICGsho+ADou8ySMSjJKDIan90Nz0=
github.com/rs/zerolog v1.34.0 h1:k43nTLIwcTVQAncfCw4KZ2VY6ukYoZaBPNOE8txlOeY=
github.com/rs/zerolog v1.34.0/go.mod h1:bJsvje4Z08ROH4Nhs5iH600c3IkWhwp44iRc54W6wYQ=
github.com/skrashevich/go-aac v0.1.0 h1:7oHNj1ADmgfjAHvi3wAIFbmbCpQBrcjZEVTLlRtAS1A=
github.com/skrashevich/go-aac v0.1.0/go.mod h1:Mj7r//4LDL4FC0ezORj+MnmQ+nDEkJhTOy2aMC8dzww=
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
Expand Down
34 changes: 25 additions & 9 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"os"
"path/filepath"
"strings"
"sync"

"github.com/gdamore/tcell/v2"
Expand All @@ -27,6 +28,9 @@ const (
DefaultVolume = 70
MinVolume = 0
MaxVolume = 100

AudioFormatMP3 = "mp3"
AudioFormatAAC = "aac"
)

// ClampVolume ensures volume is within the valid range [0, 100].
Expand All @@ -40,6 +44,15 @@ func ClampVolume(volume int) int {
return volume
}

func NormalizePreferredFormat(format string) string {
switch strings.ToLower(strings.TrimSpace(format)) {
case AudioFormatAAC:
return AudioFormatAAC
default:
return AudioFormatMP3
}
}

// AppVersion can be overridden at build time using ldflags:
// go build -ldflags "-X github.com/glebovdev/somafm-cli/internal/config.AppVersion=1.0.0"
var AppVersion = "dev"
Expand All @@ -61,11 +74,12 @@ type Theme struct {
}

type Config struct {
Volume int `yaml:"volume"`
LastStation string `yaml:"last_station"`
Autostart bool `yaml:"autostart"`
Favorites []string `yaml:"favorites"`
Theme Theme `yaml:"theme"`
Volume int `yaml:"volume"`
LastStation string `yaml:"last_station"`
Autostart bool `yaml:"autostart"`
PreferredFormat string `yaml:"preferred_format"`
Favorites []string `yaml:"favorites"`
Theme Theme `yaml:"theme"`

saveMu sync.Mutex `yaml:"-"`
}
Expand Down Expand Up @@ -101,6 +115,7 @@ func Load() (*Config, error) {
}

cfg.Volume = ClampVolume(cfg.Volume)
cfg.PreferredFormat = NormalizePreferredFormat(cfg.PreferredFormat)

return cfg, nil
}
Expand Down Expand Up @@ -156,10 +171,11 @@ func (c *Config) Save() error {

func DefaultConfig() *Config {
return &Config{
Volume: DefaultVolume,
LastStation: "",
Autostart: false,
Favorites: []string{},
Volume: DefaultVolume,
LastStation: "",
Autostart: false,
PreferredFormat: AudioFormatMP3,
Favorites: []string{},
Theme: Theme{
Background: "#1a1b25",
Foreground: "#a3aacb",
Expand Down
26 changes: 20 additions & 6 deletions internal/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,20 @@ func TestDefaultConfig(t *testing.T) {
if cfg.Autostart != false {
t.Errorf("DefaultConfig().Autostart = %v, want false", cfg.Autostart)
}

if cfg.PreferredFormat != AudioFormatMP3 {
t.Errorf("DefaultConfig().PreferredFormat = %q, want %q", cfg.PreferredFormat, AudioFormatMP3)
}
}

func TestConfigSaveAndLoad(t *testing.T) {
tmpDir := t.TempDir()
t.Setenv("HOME", tmpDir)

testCfg := &Config{
Volume: 85,
LastStation: "groovesalad",
Volume: 85,
LastStation: "groovesalad",
PreferredFormat: AudioFormatAAC,
}

err := testCfg.Save()
Expand All @@ -53,6 +58,10 @@ func TestConfigSaveAndLoad(t *testing.T) {
if loadedCfg.LastStation != testCfg.LastStation {
t.Errorf("Load().LastStation = %q, want %q", loadedCfg.LastStation, testCfg.LastStation)
}

if loadedCfg.PreferredFormat != testCfg.PreferredFormat {
t.Errorf("Load().PreferredFormat = %q, want %q", loadedCfg.PreferredFormat, testCfg.PreferredFormat)
}
}

func TestLoadNonExistentConfig(t *testing.T) {
Expand Down Expand Up @@ -93,8 +102,9 @@ func TestVolumeValidation(t *testing.T) {
t.Setenv("HOME", tmpDir)

testCfg := &Config{
Volume: tt.inputVolume,
LastStation: "groovesalad",
Volume: tt.inputVolume,
LastStation: "groovesalad",
PreferredFormat: AudioFormatAAC,
}

err := testCfg.Save()
Expand Down Expand Up @@ -145,8 +155,9 @@ func TestThemePersistence(t *testing.T) {
t.Setenv("HOME", tmpDir)

testCfg := &Config{
Volume: 70,
LastStation: "groovesalad",
Volume: 70,
LastStation: "groovesalad",
PreferredFormat: AudioFormatAAC,
Theme: Theme{
Background: "black",
Foreground: "yellow",
Expand Down Expand Up @@ -177,6 +188,9 @@ func TestThemePersistence(t *testing.T) {
if loadedCfg.Theme.Highlight != "red" {
t.Errorf("Theme.Highlight = %q, want %q", loadedCfg.Theme.Highlight, "red")
}
if loadedCfg.PreferredFormat != AudioFormatAAC {
t.Errorf("PreferredFormat = %q, want %q", loadedCfg.PreferredFormat, AudioFormatAAC)
}
}

func TestIsFavorite(t *testing.T) {
Expand Down
Loading