serve dlna: fix invalid dc:date for containers

Containers (directories) never had their Date field set, producing
<dc:date>0001-01-01</dc:date> (Go's zero time) in DIDL-Lite metadata.
This invalid date can confuse strict DLNA clients.

Set the dc:date to the directory's modification time, and as a safety
net, omit the dc:date element entirely when the timestamp is zero.

See #9346
This commit is contained in:
Nick Craig-Wood
2026-04-24 16:27:09 +01:00
parent 49650db8af
commit 6d0bca0fc8
2 changed files with 6 additions and 1 deletions
+1
View File
@@ -44,6 +44,7 @@ func (cds *contentDirectoryService) cdsObjectToUpnpavObject(cdsObject object, fi
if fileInfo.IsDir() {
obj.Class = "object.container.storageFolder"
obj.Title = fileInfo.Name()
obj.Date = upnpav.Timestamp{Time: fileInfo.ModTime()}
childCount, err := cds.countChildren(cdsObject.Path)
if err != nil {
fs.Debugf(cds, "error counting children of %s: %v", cdsObject.Path, err)
+5 -1
View File
@@ -58,7 +58,11 @@ type Timestamp struct {
time.Time
}
// MarshalXML formats the Timestamp per DIDL-Lite spec
// MarshalXML formats the Timestamp per DIDL-Lite spec.
// Zero times are omitted to avoid producing invalid dates like "0001-01-01".
func (t Timestamp) MarshalXML(e *xml.Encoder, start xml.StartElement) error {
if t.IsZero() {
return nil
}
return e.EncodeElement(t.Format("2006-01-02"), start)
}