github.com/artpar/rclone@v1.67.3/cmd/serve/dlna/upnpav/upnpav.go (about)

     1  // Package upnpav provides utilities for DLNA server.
     2  package upnpav
     3  
     4  import (
     5  	"encoding/xml"
     6  	"time"
     7  )
     8  
     9  const (
    10  	// NoSuchObjectErrorCode : The specified ObjectID is invalid.
    11  	NoSuchObjectErrorCode = 701
    12  )
    13  
    14  // Resource description
    15  type Resource struct {
    16  	XMLName      xml.Name `xml:"res"`
    17  	ProtocolInfo string   `xml:"protocolInfo,attr"`
    18  	URL          string   `xml:",chardata"`
    19  	Size         uint64   `xml:"size,attr,omitempty"`
    20  	Bitrate      uint     `xml:"bitrate,attr,omitempty"`
    21  	Duration     string   `xml:"duration,attr,omitempty"`
    22  	Resolution   string   `xml:"resolution,attr,omitempty"`
    23  }
    24  
    25  // Container description
    26  type Container struct {
    27  	Object
    28  	XMLName    xml.Name `xml:"container"`
    29  	ChildCount *int     `xml:"childCount,attr"`
    30  }
    31  
    32  // Item description
    33  type Item struct {
    34  	Object
    35  	XMLName  xml.Name `xml:"item"`
    36  	Res      []Resource
    37  	InnerXML string `xml:",innerxml"`
    38  }
    39  
    40  // Object description
    41  type Object struct {
    42  	ID          string    `xml:"id,attr"`
    43  	ParentID    string    `xml:"parentID,attr"`
    44  	Restricted  int       `xml:"restricted,attr"` // indicates whether the object is modifiable
    45  	Class       string    `xml:"upnp:class"`
    46  	Icon        string    `xml:"upnp:icon,omitempty"`
    47  	Title       string    `xml:"dc:title"`
    48  	Date        Timestamp `xml:"dc:date"`
    49  	Artist      string    `xml:"upnp:artist,omitempty"`
    50  	Album       string    `xml:"upnp:album,omitempty"`
    51  	Genre       string    `xml:"upnp:genre,omitempty"`
    52  	AlbumArtURI string    `xml:"upnp:albumArtURI,omitempty"`
    53  	Searchable  int       `xml:"searchable,attr"`
    54  }
    55  
    56  // Timestamp wraps time.Time for formatting purposes
    57  type Timestamp struct {
    58  	time.Time
    59  }
    60  
    61  // MarshalXML formats the Timestamp per DIDL-Lite spec
    62  func (t Timestamp) MarshalXML(e *xml.Encoder, start xml.StartElement) error {
    63  	return e.EncodeElement(t.Format("2006-01-02"), start)
    64  }