diff --git a/cmd/root.go b/cmd/root.go index 5980fea12..144ca4d5f 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -146,7 +146,7 @@ func startServer(ctx context.Context) func() error { func startDLNAServer(ctx context.Context) func() error { return func() error { a := CreateDLNAServer() - return a.Run(ctx, conf.Server.Address, conf.Server.Port, conf.Server.TLSCert, conf.Server.TLSKey) + return a.Run(ctx, conf.Server.Address, conf.Server.Port) } } diff --git a/dlna/contenddirectoryservice.go b/dlna/contenddirectoryservice.go index 8ffe7e225..ee2ae863e 100644 --- a/dlna/contenddirectoryservice.go +++ b/dlna/contenddirectoryservice.go @@ -33,7 +33,7 @@ func (cds *contentDirectoryService) updateIDString() string { // returned if the entry is not of interest. func (cds *contentDirectoryService) cdsObjectToUpnpavObject(cdsObject object, isContainer bool, host string) (ret interface{}, err error) { obj := upnpav.Object{ - ID: cdsObject.ID(), + ID: cdsObject.ID(), Restricted: 1, ParentID: cdsObject.ParentID(), Title: filepath.Base(cdsObject.Path), @@ -43,7 +43,7 @@ func (cds *contentDirectoryService) cdsObjectToUpnpavObject(cdsObject object, is defaultChildCount := 1 obj.Class = "object.container.storageFolder" return upnpav.Container{ - Object: obj, + Object: obj, ChildCount: &defaultChildCount, }, nil } @@ -56,7 +56,7 @@ func (cds *contentDirectoryService) cdsObjectToUpnpavObject(cdsObject object, is item := upnpav.Item{ Object: obj, - Res: make([]upnpav.Resource, 0, 1), + Res: make([]upnpav.Resource, 0, 1), } item.Res = append(item.Res, upnpav.Resource{ @@ -78,7 +78,8 @@ func (cds *contentDirectoryService) cdsObjectToUpnpavObject(cdsObject object, is // Returns all the upnpav objects in a directory. func (cds *contentDirectoryService) readContainer(o object, host string) (ret []interface{}, err error) { log.Printf("ReadContainer called with : %+v", o) - //TODO implement HTTP routing in a way that isn't awful + + //TODO implement HTTP routing rather than this switch o.Path { case "/": newObject := object{Path: "/Music"} @@ -91,7 +92,7 @@ func (cds *contentDirectoryService) readContainer(o object, host string) (ret [] ret = append(ret, thisObject) thisObject, _ = cds.cdsObjectToUpnpavObject(object{Path: "/Music/Albums"}, true, host) ret = append(ret, thisObject) - thisObject, _ = cds.cdsObjectToUpnpavObject(object{Path: "/Music/Genre"}, true, host) + thisObject, _ = cds.cdsObjectToUpnpavObject(object{Path: "/Music/Genres"}, true, host) ret = append(ret, thisObject) thisObject, _ = cds.cdsObjectToUpnpavObject(object{Path: "/Music/Recently Added"}, true, host) ret = append(ret, thisObject) @@ -107,11 +108,61 @@ func (cds *contentDirectoryService) readContainer(o object, host string) (ret [] ret = append(ret, convObj) } case "/Music/Artists": - + indexes,err := cds.ds.Artist(cds.ctx).GetIndex() + if err!= nil { + fmt.Printf("Error retrieving Indexes: %+v", err) + return nil, err + } + for indexItem := range indexes { + child := object{ + path.Join(o.Path, indexes[indexItem].Artists[0].Name), //TODO handle multiple artists here, fold it into some sort of unique list + } + convObj, _ := cds.cdsObjectToUpnpavObject(child, true, host) + ret = append(ret, convObj) + } case "/Music/Albums": - + indexes,err := cds.ds.Album(cds.ctx).GetAllWithoutGenres() + if err!= nil { + fmt.Printf("Error retrieving Indexes: %+v", err) + return nil, err + } + for indexItem := range indexes { + child := object{ + path.Join(o.Path, indexes[indexItem].Name), + } + convObj, _ := cds.cdsObjectToUpnpavObject(child, true, host) + ret = append(ret, convObj) + } + case "/Music/Genres": + indexes,err := cds.ds.Genre(cds.ctx).GetAll() + if err != nil { + fmt.Printf("Error retrieving Indexes: %+v", err) + return nil, err + } + for indexItem := range indexes { + child := object{ + path.Join(o.Path, indexes[indexItem].Name), + } + convObj, _ := cds.cdsObjectToUpnpavObject(child, true, host) + ret = append(ret, convObj) + } + case "/Music/Playlists": + indexes,err := cds.ds.Playlist(cds.ctx).GetAll() + if err != nil { + fmt.Printf("Error retrieving Indexes: %+v", err) + return nil, err + } + for indexItem := range indexes { + child := object{ + path.Join(o.Path, indexes[indexItem].Name), + } + convObj, _ := cds.cdsObjectToUpnpavObject(child, true, host) + ret = append(ret, convObj) + } } + + if strings.HasPrefix(o.Path, "/Music/Files/") { libraryPath,_ := strings.CutPrefix(o.Path, "/Music/Files") log.Printf("library path: %s", libraryPath) @@ -128,9 +179,9 @@ func (cds *contentDirectoryService) readContainer(o object, host string) (ret [] } type browse struct { - ObjectID string - BrowseFlag string - Filter string + ObjectID string + BrowseFlag string + Filter string StartingIndex int RequestedCount int } @@ -198,8 +249,8 @@ func (cds *contentDirectoryService) Handle(action string, argsXML []byte, r *htt return map[string]string{ "TotalMatches": fmt.Sprint(totalMatches), "NumberReturned": fmt.Sprint(len(objs)), - "Result": didlLite(string(result)), - "UpdateID": cds.updateIDString(), + "Result": didlLite(string(result)), + "UpdateID": cds.updateIDString(), }, nil case "BrowseMetadata": //TODO diff --git a/dlna/dlnaserver.go b/dlna/dlnaserver.go index 80746e77a..5c271e359 100644 --- a/dlna/dlnaserver.go +++ b/dlna/dlnaserver.go @@ -41,6 +41,7 @@ type DLNAServer struct { ds model.DataStore broker events.Broker ssdp SSDPServer + ctx context.Context } type SSDPServer struct { @@ -104,9 +105,9 @@ func New(ds model.DataStore, broker events.Broker) *DLNAServer { return s } -// Run starts the server with the given address, and if specified, with TLS enabled. -func (s *DLNAServer) Run(ctx context.Context, addr string, port int, tlsCert string, tlsKey string) (err error) { - +// Run starts the DLNA server (both SSDP and HTTP) with the given address +func (s *DLNAServer) Run(ctx context.Context, addr string, port int) (err error) { + s.ctx = ctx if s.ssdp.HTTPConn == nil { network := "tcp4" if strings.Count(s.ssdp.httpListenAddr, ":") > 1 {