From 2f10472df37c189df3b173aad3ee97caa3d66db2 Mon Sep 17 00:00:00 2001 From: Dan Walters Date: Sun, 15 Sep 2019 12:33:45 -0500 Subject: [PATCH] dlna: count the number of children in the response to BrowseMetadata --- cmd/serve/dlna/cds.go | 11 +++++++++-- cmd/serve/dlna/dlna_test.go | 8 ++++++-- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/cmd/serve/dlna/cds.go b/cmd/serve/dlna/cds.go index 2e77162a3..9b7d1ad59 100644 --- a/cmd/serve/dlna/cds.go +++ b/cmd/serve/dlna/cds.go @@ -77,10 +77,17 @@ func (cds *contentDirectoryService) cdsObjectToUpnpavObject(cdsObject object, fi } if fileInfo.IsDir() { + children, err := cds.readContainer(cdsObject, host) + if err != nil { + return nil, err + } + obj.Class = "object.container.storageFolder" obj.Title = fileInfo.Name() - ret = upnpav.Container{Object: obj} - return + return upnpav.Container{ + Object: obj, + ChildCount: len(children), + }, nil } if !fileInfo.Mode().IsRegular() { diff --git a/cmd/serve/dlna/dlna_test.go b/cmd/serve/dlna/dlna_test.go index 7fb5ce395..c83ded016 100644 --- a/cmd/serve/dlna/dlna_test.go +++ b/cmd/serve/dlna/dlna_test.go @@ -3,6 +3,7 @@ package dlna import ( "context" "fmt" + "html" "io/ioutil" "net/http" "net/url" @@ -118,6 +119,9 @@ func TestContentDirectoryBrowseMetadata(t *testing.T) { assert.Equal(t, http.StatusOK, resp.StatusCode) body, err := ioutil.ReadAll(resp.Body) require.NoError(t, err) - require.Contains(t, string(body), "<container ") - require.NotContains(t, string(body), "<item ") + // expect a element + require.Contains(t, string(body), html.EscapeString("