Server changes/Sonarr
This commit is contained in:
@@ -27,9 +27,10 @@ type Client struct {
|
||||
|
||||
// Credentials identify one signed-in Emby user.
|
||||
type Credentials struct {
|
||||
UserID string
|
||||
Token string
|
||||
DeviceID string
|
||||
UserID string
|
||||
Token string
|
||||
DeviceID string
|
||||
DeviceName string
|
||||
}
|
||||
|
||||
type ItemsResult struct {
|
||||
@@ -82,13 +83,13 @@ func New(baseURL, publicURL, clientName string, timeout time.Duration) *Client {
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Client) Authenticate(ctx context.Context, username, password, deviceID string) (*AuthResult, error) {
|
||||
func (c *Client) Authenticate(ctx context.Context, username, password, deviceID, deviceName string) (*AuthResult, error) {
|
||||
body, err := json.Marshal(map[string]string{"Username": username, "Pw": password})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
req, err := c.newRequest(ctx, http.MethodPost, "/Users/AuthenticateByName", nil,
|
||||
Credentials{DeviceID: deviceID}, bytes.NewReader(body))
|
||||
Credentials{DeviceID: deviceID, DeviceName: deviceName}, bytes.NewReader(body))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -104,6 +105,16 @@ func (c *Client) Authenticate(ctx context.Context, username, password, deviceID
|
||||
return &out, nil
|
||||
}
|
||||
|
||||
// Logout retires a token created during authentication. The gateway uses this when a
|
||||
// device is refused by policy so Emby is not left holding an orphaned session.
|
||||
func (c *Client) Logout(ctx context.Context, cred Credentials) error {
|
||||
req, err := c.newRequest(ctx, http.MethodPost, "/Sessions/Logout", nil, cred, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return c.do(req, nil)
|
||||
}
|
||||
|
||||
func (c *Client) Items(ctx context.Context, cred Credentials, params url.Values) (*ItemsResult, error) {
|
||||
return c.items(ctx, cred, "/Users/"+url.PathEscape(cred.UserID)+"/Items", params)
|
||||
}
|
||||
@@ -285,10 +296,14 @@ func (c *Client) newRequest(ctx context.Context, method, path string, params url
|
||||
if deviceID == "" {
|
||||
deviceID = "memby-gateway"
|
||||
}
|
||||
deviceName := strings.TrimSpace(cred.DeviceName)
|
||||
if deviceName == "" {
|
||||
deviceName = "Memby TV"
|
||||
}
|
||||
req.Header.Set("Accept", "application/json")
|
||||
req.Header.Set("X-Emby-Authorization", fmt.Sprintf(
|
||||
`MediaBrowser Client="%s", Device="Memby Gateway", DeviceId="%s", Version="1.0"`,
|
||||
c.clientName, deviceID,
|
||||
`MediaBrowser Client="%s", Device="%s", DeviceId="%s", Version="1.0"`,
|
||||
c.clientName, strings.ReplaceAll(deviceName, `"`, ""), deviceID,
|
||||
))
|
||||
if cred.Token != "" {
|
||||
req.Header.Set("X-Emby-Token", cred.Token)
|
||||
|
||||
Reference in New Issue
Block a user