beginning of adding Jellyfin support
This commit is contained in:
@@ -8,7 +8,15 @@ import (
|
||||
"github.com/pelletier/go-toml/v2"
|
||||
)
|
||||
|
||||
type ServerType string
|
||||
|
||||
const (
|
||||
ServerTypeSubsonic ServerType = "Subsonic"
|
||||
ServerTypeJellyfin ServerType = "Jellyfin"
|
||||
)
|
||||
|
||||
type ServerConnection struct {
|
||||
ServerType ServerType
|
||||
Hostname string
|
||||
AltHostname string
|
||||
Username string
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
package jellyfin
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"github.com/dweymouth/go-jellyfin"
|
||||
)
|
||||
|
||||
type jellyfinMediaProvider struct {
|
||||
client *jellyfin.Client
|
||||
prefetchCoverCB func(coverArtID string)
|
||||
}
|
||||
|
||||
func (j *jellyfinMediaProvider) SetPrefetchCoverCallback(cb func(coverArtID string)) {
|
||||
j.prefetchCoverCB = cb
|
||||
}
|
||||
|
||||
func (jellyfinMediaProvider) CreatePlaylist(name string, trackIDs []string) error {
|
||||
return errors.New("unimplemented")
|
||||
}
|
||||
|
||||
func (j *jellyfinMediaProvider) DeletePlaylist(id string) error {
|
||||
return j.client.DeletePlaylist(id)
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package mediaprovider
|
||||
|
||||
type Server interface {
|
||||
Ping() bool
|
||||
Login(username, password string) error
|
||||
MediaProvider() MediaProvider
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package subsonic
|
||||
|
||||
import (
|
||||
subsonicCli "github.com/dweymouth/go-subsonic/subsonic"
|
||||
"github.com/dweymouth/supersonic/backend/mediaprovider"
|
||||
)
|
||||
|
||||
type SubsonicServer struct {
|
||||
subsonicCli.Client
|
||||
}
|
||||
|
||||
func (s *SubsonicServer) Login(username, password string) error {
|
||||
s.User = username
|
||||
return s.Client.Authenticate(password)
|
||||
}
|
||||
|
||||
func (s *SubsonicServer) MediaProvider() mediaprovider.MediaProvider {
|
||||
return SubsonicMediaProvider(&s.Client)
|
||||
}
|
||||
+22
-16
@@ -43,7 +43,7 @@ func (s *ServerManager) ConnectToServer(conf *ServerConfig, password string) err
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
s.Server = subsonicMP.SubsonicMediaProvider(cli)
|
||||
s.Server = cli.MediaProvider()
|
||||
s.Server.SetPrefetchCoverCallback(s.prefetchCoverCB)
|
||||
s.LoggedInUser = conf.Username
|
||||
s.ServerID = conf.ID
|
||||
@@ -156,25 +156,31 @@ func (s *ServerManager) SetServerPassword(server *ServerConfig, password string)
|
||||
return keyring.Set(s.appName, server.ID.String(), password)
|
||||
}
|
||||
|
||||
func (s *ServerManager) connect(connection ServerConnection, password string) (*subsonic.Client, error) {
|
||||
cli := &subsonic.Client{
|
||||
Client: &http.Client{Timeout: 10 * time.Second},
|
||||
BaseUrl: connection.Hostname,
|
||||
User: connection.Username,
|
||||
PasswordAuth: connection.LegacyAuth,
|
||||
ClientName: "supersonic",
|
||||
func (s *ServerManager) connect(connection ServerConnection, password string) (mediaprovider.Server, error) {
|
||||
var cli, altCli mediaprovider.Server
|
||||
|
||||
cli = &subsonicMP.SubsonicServer{
|
||||
Client: subsonic.Client{
|
||||
Client: &http.Client{Timeout: 10 * time.Second},
|
||||
BaseUrl: connection.Hostname,
|
||||
User: connection.Username,
|
||||
PasswordAuth: connection.LegacyAuth,
|
||||
ClientName: "supersonic",
|
||||
},
|
||||
}
|
||||
altCli := &subsonic.Client{
|
||||
Client: &http.Client{Timeout: 10 * time.Second},
|
||||
BaseUrl: connection.AltHostname,
|
||||
User: connection.Username,
|
||||
PasswordAuth: connection.LegacyAuth,
|
||||
ClientName: "supersonic",
|
||||
altCli = &subsonicMP.SubsonicServer{
|
||||
Client: subsonic.Client{
|
||||
Client: &http.Client{Timeout: 10 * time.Second},
|
||||
BaseUrl: connection.AltHostname,
|
||||
User: connection.Username,
|
||||
PasswordAuth: connection.LegacyAuth,
|
||||
ClientName: "supersonic",
|
||||
},
|
||||
}
|
||||
pingChan := make(chan bool, 2) // false for primary hostname, true for alternate
|
||||
pingFunc := func(delay time.Duration, cli *subsonic.Client, val bool) {
|
||||
pingFunc := func(delay time.Duration, cli mediaprovider.Server, val bool) {
|
||||
<-time.After(delay)
|
||||
if err := cli.Authenticate(password); err == nil {
|
||||
if err := cli.Login(connection.Username, password); err == nil {
|
||||
pingChan <- val
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user