Files
emby-mcp/internal/emby/library.go
T
gronod d40646211f
Build and publish / Test and build (darwin) (push) Failing after 1m42s
Build and publish / Test and build (linux) (push) Failing after 1m53s
Build and publish / Test and build (windows) (push) Failing after 2m50s
Build and publish / Build and publish Docker image (push) Skipped
Initial Go implementation of Emby.MCP
Go rewrite of the Python Emby.MCP server with tool parity (20 tools),
plus a streamable-HTTP transport with per-request Emby authentication
(Basic / Bearer token passthrough), a multi-arch Docker build, and a
Gitea CI workflow.
2026-09-20 22:52:46 +01:00

67 lines
1.9 KiB
Go

package emby
import (
"context"
"fmt"
)
// Library is the output shape for libraries (matches Python output keys).
type Library struct {
Name string `json:"name"`
Type string `json:"type"`
ID string `json:"id"`
}
// Authenticate logs in with username/password via POST /Users/AuthenticateByName
// and installs the resulting access token on the client.
func (c *Client) Authenticate(ctx context.Context, username, password string) (*AuthResult, error) {
var res AuthResult
err := c.Post(ctx, "/Users/AuthenticateByName", nil,
authRequest{Username: username, Pw: password}, &res)
if err != nil {
return nil, err
}
if res.AccessToken == "" || res.User == nil {
return nil, fmt.Errorf("authentication failed: empty token or user in response")
}
c.setToken(res.AccessToken, res.User.ID)
return &res, nil
}
// Logout revokes the access token via POST /Sessions/Logout.
func (c *Client) Logout(ctx context.Context) error {
return c.Post(ctx, "/Sessions/Logout", nil, nil, nil)
}
// GetLibraryList returns the server's collection-folder libraries.
func (c *Client) GetLibraryList(ctx context.Context) ([]Library, error) {
var res QueryResult[LibraryFolder]
if err := c.Get(ctx, "/Library/MediaFolders", nil, &res); err != nil {
return nil, err
}
libs := make([]Library, 0, len(res.Items))
for _, it := range res.Items {
if it.Type == "CollectionFolder" {
libs = append(libs, Library{Name: it.Name, Type: it.CollectionType, ID: it.ID})
}
}
return libs, nil
}
// GetGenreList returns genre names, optionally restricted to a library.
func (c *Client) GetGenreList(ctx context.Context, libraryID string) ([]string, error) {
q := qp("Recursive", "true")
if libraryID != "" {
q.Set("ParentId", libraryID)
}
var res QueryResult[GenreItem]
if err := c.Get(ctx, "/Genres", q, &res); err != nil {
return nil, err
}
genres := make([]string, 0, len(res.Items))
for _, g := range res.Items {
genres = append(genres, g.Name)
}
return genres, nil
}