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
14 changes: 4 additions & 10 deletions cmd/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -587,9 +587,9 @@ func providers() []providerSpec {
section: "mixcloud",
intro: []string{
"Browse and play Mixcloud shows through its public API and yt-dlp.",
"A username adds your public library, following stream, and creators.",
"A username adds your public library and followed creators.",
"An optional developer access token adds /me and Listen Later.",
"Choose browser cookies for subscriber-only or signed-in playback.",
"Choose browser cookies for Stream and signed-in playback.",
"Docs: cliamp.stream → docs/mixcloud.md",
},
picker: &pickerSpec{
Expand All @@ -616,15 +616,13 @@ func providers() []providerSpec {
onlyIf: func(v map[string]string) bool { return v[keyMixcloudBrowser] == "custom" }},
{key: "styles", label: "Music styles (optional)", help: "comma-separated; blank uses cliamp defaults"},
{key: "max_items", label: "Items per view", help: fmt.Sprintf("%d-%d", mixcloud.MinItems, mixcloud.MaxItemsLimit), defaultV: strconv.Itoa(mixcloud.DefaultMaxItems)},
{key: "stream_creators", label: "Creators in Stream", help: fmt.Sprintf("%d-%d", mixcloud.MinItems, mixcloud.MaxStreamCreators), defaultV: strconv.Itoa(mixcloud.DefaultStreamCreators)},
},
extraValidate: func(v map[string]string) error {
limits := []struct {
key, label string
max int
}{
{key: "max_items", label: "items per view", max: mixcloud.MaxItemsLimit},
{key: "stream_creators", label: "stream creators", max: mixcloud.MaxStreamCreators},
}
for _, field := range limits {
n, err := strconv.Atoi(strings.TrimSpace(v[field.key]))
Expand All @@ -637,7 +635,7 @@ func providers() []providerSpec {
}
return nil
},
owned: []string{"enabled", "username", "access_token", "cookies_from", "styles", "max_items", "stream_creators"},
owned: []string{"enabled", "username", "access_token", "cookies_from", "styles", "max_items"},
body: func(v map[string]string) []config.KeyValue {
kv := []config.KeyValue{rawKV("enabled", "true")}
if username := strings.TrimSpace(v["username"]); username != "" {
Expand All @@ -656,11 +654,7 @@ func providers() []providerSpec {
if maxItems == "" {
maxItems = strconv.Itoa(mixcloud.DefaultMaxItems)
}
streamCreators := strings.TrimSpace(v["stream_creators"])
if streamCreators == "" {
streamCreators = strconv.Itoa(mixcloud.DefaultStreamCreators)
}
return append(kv, rawKV("max_items", maxItems), rawKV("stream_creators", streamCreators))
return append(kv, rawKV("max_items", maxItems))
},
},
{
Expand Down
9 changes: 3 additions & 6 deletions cmd/setup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -854,20 +854,18 @@ func TestMixcloudSetupBody(t *testing.T) {
"access_token": "token",
"styles": "ambient, deep-house",
"max_items": " 75 ",
"stream_creators": "15",
}
if err := spec.extraValidate(values); err != nil {
t.Fatalf("extraValidate: %v", err)
}
checkBody(t, spec.body(values), map[string]string{
"enabled": "true", "username": `"alice"`, "access_token": `"token"`,
"cookies_from": `"firefox"`, "styles": `["ambient", "deep-house"]`,
"max_items": "75", "stream_creators": "15",
"max_items": "75",
})
publicOnly := spec.body(map[string]string{
keyMixcloudBrowser: "none",
"max_items": "100",
"stream_creators": "20",
})
if _, ok := bodyValues(publicOnly)["cookies_from"]; ok {
t.Fatalf("public-only session must not write cookies_from: %q", publicOnly)
Expand All @@ -876,16 +874,15 @@ func TestMixcloudSetupBody(t *testing.T) {
keyMixcloudBrowser: "custom",
"cookies_from": "chrome:Profile 1",
"max_items": "100",
"stream_creators": "20",
})
checkBody(t, custom, map[string]string{"cookies_from": `"chrome:Profile 1"`})
if spec.validate != nil {
t.Fatal("mixcloud setup should not claim a live validation probe")
}

err := spec.extraValidate(map[string]string{"max_items": "bad", "stream_creators": "also bad"})
err := spec.extraValidate(map[string]string{"max_items": "bad"})
if err == nil || !strings.Contains(err.Error(), "items per view") {
t.Fatalf("validation order error = %v, want items per view first", err)
t.Fatalf("validation error = %v, want items per view", err)
}
}

Expand Down
8 changes: 4 additions & 4 deletions config.toml.example
Original file line number Diff line number Diff line change
Expand Up @@ -263,19 +263,19 @@ eq = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
# Mixcloud (optional, opt-in)
# Public discovery, show search, the live genre catalogue, genre/tag search,
# creator jumps, and Latest/Popular charts work with enabled=true. Set username
# for your following stream, profile activity, uploads, read-only show favorites,
# for profile activity, uploads, read-only show favorites,
# listening history, collections, and followed-creator browsing. A developer
# OAuth access_token makes /me the account identity and adds Listen Later.
# cookies_from is used by yt-dlp for signed-in playback only. styles is the
# local genre-favorites list; toggle it with [f] in Mixcloud's Genres browser.
# cookies_from supplies browser cookies via yt-dlp for cliamp's New Shows GraphQL
# requests and signed-in playback. yt-dlp handles playback, not feed requests.
# styles is the local genre-favorites list; toggle it with [f] in Mixcloud's Genres browser.
# [mixcloud]
# enabled = true
# username = "yourname"
# access_token = "${MIXCLOUD_ACCESS_TOKEN}"
# cookies_from = "firefox" # chrome, brave, edge, chromium, opera, safari, vivaldi, whale…
# styles = ["ambient", "deep-house", "house", "jazz", "techno"]
# max_items = 100
# stream_creators = 20

# ---
# NetEase Cloud Music (optional, opt-in)
Expand Down
23 changes: 9 additions & 14 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -565,18 +565,17 @@ func (s *SoundCloudConfig) set(key, val string) {

// MixcloudConfig holds settings for the Mixcloud provider. Public discovery
// works with only enabled=true. Username adds public account views; an access
// token adds /me and Listen Later; browser cookies are used only by yt-dlp for
// playback that needs the listener's signed-in Mixcloud session.
// token adds /me and Listen Later; browser cookies enable Stream and signed-in
// playback.
// Enable rule: opt-in.
type MixcloudConfig struct {
Enabled bool
Username string
AccessToken string
CookiesFrom string
Styles []string
StylesSet bool // distinguishes omitted styles (defaults) from an explicit empty list
MaxItems int
StreamCreators int
Enabled bool
Username string
AccessToken string
CookiesFrom string
Styles []string
StylesSet bool // distinguishes omitted styles (defaults) from an explicit empty list
MaxItems int
}

// IsSet reports whether the Mixcloud provider should be shown.
Expand All @@ -602,10 +601,6 @@ func (m *MixcloudConfig) set(key, val string) {
if v, ok := parseInt(val); ok {
m.MaxItems = v
}
case "stream_creators":
if v, ok := parseInt(val); ok {
m.StreamCreators = v
}
}
}

Expand Down
31 changes: 14 additions & 17 deletions config/config_golden_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ access_token = mc#token
cookies_from = "brave"
styles = ["ambient", "deep-house"]
max_items = 50
stream_creators = 10

[netease]
enabled = true
Expand Down Expand Up @@ -271,14 +270,13 @@ func TestLoadGolden(t *testing.T) {
sectionsWant.Podcast = PodcastConfig{Country: "no"}
sectionsWant.SoundCloud = SoundCloudConfig{Enabled: true, User: "sc-user", CookiesFrom: "chrome"}
sectionsWant.Mixcloud = MixcloudConfig{
Enabled: true,
Username: "mc-user",
AccessToken: "mc#token",
CookiesFrom: "brave",
Styles: []string{"ambient", "deep-house"},
StylesSet: true,
MaxItems: 50,
StreamCreators: 10,
Enabled: true,
Username: "mc-user",
AccessToken: "mc#token",
CookiesFrom: "brave",
Styles: []string{"ambient", "deep-house"},
StylesSet: true,
MaxItems: 50,
}
sectionsWant.NetEase = NetEaseConfig{Enabled: true, CookiesFrom: "chrome:Profile 1", CookiesFile: "/home/user/cookies.txt", UserID: "42"}
sectionsWant.Yandex = YandexConfig{Enabled: true, Token: "y0_token"}
Expand Down Expand Up @@ -363,14 +361,13 @@ func TestLoadGolden(t *testing.T) {
}
allWant.SoundCloud = SoundCloudConfig{Enabled: true, User: "yourname", CookiesFrom: "firefox"}
allWant.Mixcloud = MixcloudConfig{
Enabled: true,
Username: "yourname",
AccessToken: "mc-env-token",
CookiesFrom: "firefox",
Styles: []string{"ambient", "deep-house", "house", "jazz", "techno"},
StylesSet: true,
MaxItems: 100,
StreamCreators: 20,
Enabled: true,
Username: "yourname",
AccessToken: "mc-env-token",
CookiesFrom: "firefox",
Styles: []string{"ambient", "deep-house", "house", "jazz", "techno"},
StylesSet: true,
MaxItems: 100,
}
allWant.NetEase = NetEaseConfig{
Enabled: true,
Expand Down
3 changes: 1 addition & 2 deletions config/mixcloud_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ access_token = "${CLIAMP_TEST_MIXCLOUD_TOKEN}"
cookies_from = "firefox"
styles = ["ambient", "deep-house"]
max_items = 75
stream_creators = 15
`)
if err := os.WriteFile(path, data, 0o600); err != nil {
t.Fatal(err)
Expand All @@ -35,7 +34,7 @@ stream_creators = 15
if !cfg.Mixcloud.IsSet() || cfg.Mixcloud.Username != "alice" || cfg.Mixcloud.AccessToken != "secret-token" || cfg.Mixcloud.CookiesFrom != "firefox" {
t.Fatalf("Mixcloud config = %+v", cfg.Mixcloud)
}
if !slices.Equal(cfg.Mixcloud.Styles, []string{"ambient", "deep-house"}) || cfg.Mixcloud.MaxItems != 75 || cfg.Mixcloud.StreamCreators != 15 {
if !slices.Equal(cfg.Mixcloud.Styles, []string{"ambient", "deep-house"}) || cfg.Mixcloud.MaxItems != 75 {
t.Fatalf("Mixcloud limits/styles = %+v", cfg.Mixcloud)
}
if !cfg.Mixcloud.StylesSet {
Expand Down
8 changes: 4 additions & 4 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -469,11 +469,12 @@ native show search, direct creator jumps, and playback need no account:
enabled = true
```

Add `username` for your following stream, activity, uploads, read-only show
Add `username` for activity, uploads, read-only show
favorites, listening history, collections, and followed-creator browsing. An
optional developer `access_token` sets `/me/` as the account identity and adds
Listen Later. `cookies_from` gives yt-dlp your signed-in browser session for
playback that requires it.
Listen Later. For Stream (New Shows), cliamp makes GraphQL requests using browser
cookies loaded through yt-dlp via `cookies_from`. Playback uses yt-dlp, with the
same browser session when required.

```toml
[mixcloud]
Expand All @@ -483,7 +484,6 @@ access_token = "${MIXCLOUD_ACCESS_TOKEN}"
cookies_from = "firefox"
styles = ["ambient", "deep-house", "jazz", "techno"]
max_items = 100
stream_creators = 20
```

The `styles` list is also the local genre-favorites list for the provider. In
Expand Down
31 changes: 14 additions & 17 deletions docs/mixcloud.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pipeline. Put `yt-dlp` and `ffmpeg` on `PATH`.
| Live category catalogue and Latest/Popular genre charts | Provider enabled | **Genres** in the provider pane or `N` browser |
| Genre/tag search and local genre favorites | Provider enabled and writable config file | `/`, `Enter`, and `f` in **Genres** |
| Public profile activity, uploads, show favorites, listening history, and collections | Public profile `username`, or an `access_token` | **Your Mixcloud** and **Collections** sections |
| Following stream and followed-creator browser | Public profile `username`, or an `access_token` | **Stream (Following Releases)** and **Creators** |
| Following stream and followed-creator browser | Public profile `username`, or an `access_token`; Stream also needs `cookies_from` | **Stream (New Shows)** and **Creators** |
| Open a highlighted show's creator Uploads/Favorites | Provider enabled; account not required | Press `N` on a Mixcloud show |
| Listen Later | Developer OAuth `access_token` | **Your Mixcloud** section |
| Signed-in or subscriber-gated playback | `cookies_from` for a supported browser with a Mixcloud session | Playback through yt-dlp |
Expand Down Expand Up @@ -65,7 +65,7 @@ Press `X` to select Mixcloud. The provider pane has these sections.

| Section | Entry | Behaviour |
|---|---|---|
| **Your Mixcloud** | **Stream (Following Releases)** | Merges recent uploads from followed creators. See [Limits and tuning](#limits-and-tuning). |
| **Your Mixcloud** | **Stream (New Shows)** | Appears only when `cookies_from` is set. Reads the signed-in browser account's feed. See [Limits and tuning](#limits-and-tuning). |
| **Your Mixcloud** | **Favorites** | Reads the configured public account or the token owner `/me/` connections |
| **Your Mixcloud** | **Creators** | Lists the configured account and followed creators. Separates each creator **Uploads** and **Favorites**. |
| **Your Mixcloud** | **Uploads**, **Profile Activity**, **Listening History** | Reads the configured public account or the token owner `/me/` connections |
Expand All @@ -76,8 +76,10 @@ Press `X` to select Mixcloud. The provider pane has these sections.
| **Discover** | **Recent Releases**, **Popular** | Global public discovery. No account required. |
| **Music Styles** | `<Style> — Latest`, `<Style> — Popular` | One pair for each entry in `[mixcloud].styles` |

With a configured account, **Your Mixcloud** is first. It lists **Stream**,
then **Favorites**, then **Creators**. Public-only and degraded-account views
With a configured account, **Your Mixcloud** is first. It lists **Stream**
when `cookies_from` is set, then **Favorites**, then **Creators**. Without browser
cookies, Stream is hidden; the other account views remain available.
Public-only and degraded-account views
start with **Browse** and omit **Creators**. The hierarchy rows are shortcuts.
When you back out of the top-level Shows, Creators, or Genres list, cliamp
returns to this provider pane.
Expand Down Expand Up @@ -202,15 +204,15 @@ configuration levels:
| `enabled = true` | Public discovery, shows, genres, genre/tag search, and show search |
| `username` | Public account connections: following, activity, uploads, show favorites, listening history, and collections |
| `access_token` | Resolves the authorized user through `/me/` and adds Listen Later |
| `cookies_from` | Gives yt-dlp a signed-in browser session for playback only |
| `cookies_from` | Enables Stream and signed-in playback using the browser session |

If both `username` and `access_token` are set, the access-token owner `/me/`
identity controls all account views. This prevents a stale or different public
identity controls REST account views. This prevents a stale or different public
username from mixing two accounts in one menu.

Browser cookies do not authenticate the JSON API, reveal private library data,
Browser cookies do not authenticate the public JSON API
or replace a developer token. cliamp has no generic "logged in" badge for
cookie playback. It reads cookies only when yt-dlp starts a show.
cookie playback. Stream uses the browser account; yt-dlp also uses its cookies.

## Access token and Listen Later

Expand Down Expand Up @@ -319,10 +321,9 @@ the player silent.
| `enabled` | `false` | Registers the Mixcloud provider |
| `username` | empty | Public profile URL username for account views when no token is set |
| `access_token` | empty | Developer OAuth token for `/me/` and Listen Later |
| `cookies_from` | empty | Browser/profile sent to yt-dlp for signed-in playback |
| `cookies_from` | empty | Browser/profile used for Stream and signed-in playback |
| `styles` | cliamp default style list | Local genre favorites. Each produces Latest and Popular provider rows and show sort modes. |
| `max_items` | `100` | Maximum shows, creators, or collections per view. Setup accepts 1 to 500. Manual values at or below zero use the default. Values above 500 use 500. |
| `stream_creators` | `20` | Maximum followed creators for the following stream. Setup accepts 1 to 100. Manual values at or below zero use the default. Values above 100 use 100. |

Use this complete example:

Expand All @@ -336,17 +337,13 @@ access_token = "${MIXCLOUD_ACCESS_TOKEN}"
cookies_from = "firefox"
styles = ["chillout", "deep-house", "drum-bass", "electronica", "house", "techno"]
max_items = 100
stream_creators = 20
```

## Limits and tuning

The API does not expose the exact personalized Mixcloud website home feed.
**Stream (Following Releases)** is an approximation. It gets the first
`stream_creators` followed accounts, merges their newest uploads, sorts by
publication time, removes duplicates, and returns at most `max_items` shows.
Lower these values if you encounter API rate limits. cliamp includes the
Mixcloud `Retry-After` value in the error it shows.
**Stream (New Shows)** reads the website's New Shows feed in order, using
`cookies_from`. `max_items` limits the total. Lower it if you encounter API rate limits.
cliamp includes the Mixcloud `Retry-After` value in the error it shows.

Mixcloud does not provide audio streams through its JSON API. The official
third-party playback method is the visible web widget. Terminal playback depends
Expand Down
5 changes: 5 additions & 0 deletions external/mixcloud/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"time"

"github.com/bjarneo/cliamp/internal/httpclient"
"github.com/bjarneo/cliamp/internal/ytdlcookies"
)

const (
Expand Down Expand Up @@ -49,13 +50,17 @@ type client struct {
baseURL string
accessToken string
httpClient *http.Client
feedURL string
loadCookies func(context.Context, string) (http.CookieJar, error)
}

func newClient(accessToken string) *client {
return &client{
baseURL: defaultAPIBase,
accessToken: strings.TrimSpace(accessToken),
httpClient: httpclient.NewAPI(30 * time.Second),
feedURL: "https://app.mixcloud.com/graphql",
loadCookies: ytdlcookies.FromBrowser,
}
}

Expand Down
14 changes: 8 additions & 6 deletions external/mixcloud/live_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,17 +75,19 @@ func TestLivePublicAccount(t *testing.T) {
}

p := NewFromConfig(Config{
Enabled: true,
Username: username,
StylesSet: true,
MaxItems: 3,
StreamCreators: 2,
Enabled: true,
Username: username,
StylesSet: true,
MaxItems: 3,
})
lists, err := p.Playlists()
if err != nil {
t.Fatalf("account playlists: %v", err)
}
wantLists := []string{streamID, activityID, uploadsID, favoritesID, listensID}
if slices.ContainsFunc(lists, func(item playlist.PlaylistInfo) bool { return item.ID == streamID }) {
t.Error("Stream must be hidden without cookies_from")
}
wantLists := []string{activityID, uploadsID, favoritesID, listensID}
for _, id := range wantLists {
if !slices.ContainsFunc(lists, func(item playlist.PlaylistInfo) bool { return item.ID == id }) {
t.Errorf("account playlists omit %q: %+v", id, lists)
Expand Down
Loading
Loading