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
4 changes: 2 additions & 2 deletions docs/plex.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,10 @@ provider = "plex"
cliamp calls the Plex HTTP API to list audio playlists (`/playlists`) and music library albums. When you select an entry, cliamp gets its track list from the playlist-items or album-children endpoint. It then creates authenticated streaming URLs in this form:

```
http://<server>:32400/library/parts/<partID>/<timestamp>/file.<ext>?X-Plex-Token=<token>
http://<server>:32400/library/parts/<partID>/<timestamp>/file.<ext>?download=1&X-Plex-Token=<token>
```

These URLs serve files directly. Plex serves the original file without transcoding. cliamp handles playback through its HTTP streaming pipeline. cliamp can play MP3, FLAC, AAC, OGG, OPUS, WAV, and other supported source formats.
These URLs serve files directly. Plex serves the original file without transcoding: cliamp asks for it with `download=1`, as Plexamp does, so Plex does not check the file against a client profile. Without it Plex refuses FLAC files it has analyzed with HTTP 500. cliamp handles playback through its HTTP streaming pipeline. cliamp can play MP3, FLAC, AAC, OGG, OPUS, WAV, and other supported source formats.

## Troubleshooting

Expand Down
7 changes: 6 additions & 1 deletion external/plex/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -377,8 +377,13 @@ func (c *Client) Search(query string) ([]Track, error) {
// StreamURL returns the authenticated HTTP URL for streaming a track part.
// partKey is the relative path from the Part element, e.g. "/library/parts/…/file.flac".
// The token is appended as a query parameter; Plex accepts it in either header or query form.
//
// download=1 asks for the original file, as Plexamp does. Without it Plex
// checks the part against the client's direct-play profile; cliamp has none,
// so Plex falls back to a generic profile without FLAC and answers 500 for
// every FLAC whose audio stream it has analyzed.
func (c *Client) StreamURL(partKey string) string {
return c.baseURL + partKey + "?X-Plex-Token=" + url.QueryEscape(c.token)
return c.baseURL + partKey + "?download=1&X-Plex-Token=" + url.QueryEscape(c.token)
}

// IsStreamURL reports whether the given URL looks like a Plex library part
Expand Down
32 changes: 31 additions & 1 deletion external/plex/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -622,7 +622,7 @@ func TestTracks_MissingMedia(t *testing.T) {
func TestStreamURL_Format(t *testing.T) {
c := NewClient("http://192.168.1.10:32400", "mytoken")
got := c.StreamURL("/library/parts/100/111/file.flac")
want := "http://192.168.1.10:32400/library/parts/100/111/file.flac?X-Plex-Token=mytoken"
want := "http://192.168.1.10:32400/library/parts/100/111/file.flac?download=1&X-Plex-Token=mytoken"
if got != want {
t.Errorf("StreamURL:\n got %q\n want %q", got, want)
}
Expand Down Expand Up @@ -720,3 +720,33 @@ func TestPingRejectsOversizedBody(t *testing.T) {
t.Fatalf("Ping() error = %v, want httpclient.ErrTooLarge", err)
}
}

// A part whose analyzed stream fails Plex's generic client profile answers
// 500 to a plain request; the original file request with download=1, as
// Plexamp sends it, plays.
func TestStreamURLPlaysAnalyzedFLAC(t *testing.T) {
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.URL.Query().Get("download") != "1" {
http.Error(w, "No direct play music profile exists for protocol http, with container flac", http.StatusInternalServerError)
return
}
if got := r.URL.Query().Get("X-Plex-Token"); got != "tok" {
t.Errorf("token = %q", got)
}
w.Header().Set("Content-Type", "audio/flac")
_, _ = w.Write([]byte("fLaC"))
}))
defer srv.Close()

resp, err := http.Get(NewClient(srv.URL, "tok").StreamURL("/library/parts/60716/1793101096/file.flac"))
if err != nil {
t.Fatalf("GET: %v", err)
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
t.Fatalf("status = %d, want 200", resp.StatusCode)
}
if !IsStreamURL(resp.Request.URL.String()) {
t.Fatal("stream URL no longer routes through the buffered pipeline")
}
}
Loading