diff --git a/dlna/dlnaserver.go b/dlna/dlnaserver.go index 299c19e86..feb78a207 100644 --- a/dlna/dlnaserver.go +++ b/dlna/dlnaserver.go @@ -14,6 +14,7 @@ import ( "strconv" "strings" "time" + "text/template" dms_dlna "github.com/anacrolix/dms/dlna" "github.com/anacrolix/dms/soap" @@ -91,7 +92,7 @@ func New(ds model.DataStore, broker events.Broker) *DLNAServer { r.Handle("/static/", http.StripPrefix("/static/", withHeader("Cache-Control", "public, max-age=86400", - http.FileServer(http.Dir("/tmp"))))) //TODO + http.FileServer(http.Dir("/tmp"))))) //TODO, is /static needed? s.ssdp.handler = r @@ -275,9 +276,12 @@ func (s *SSDPServer) resourceHandler(w http.ResponseWriter, r *http.Request) { //http.ServeContent(w, r, remotePath, time.Now(), in) } +// returns content for /rootDesc.xml func (s *SSDPServer) rootDescHandler(w http.ResponseWriter, r *http.Request) { + tmpl, _ := GetTemplate() buffer := new(bytes.Buffer) + _ = tmpl.Execute(buffer, s) w.Header().Set("content-type", `text/xml; charset="utf-8"`) w.Header().Set("cache-control", "private, max-age=60") @@ -392,3 +396,82 @@ func withHeader(name string, value string, next http.Handler) http.Handler { func serveError(what interface{}, w http.ResponseWriter, text string, err error) { http.Error(w, text+".", http.StatusInternalServerError) } + +func GetTemplate() (tpl *template.Template, err error) { + + templateBytes := ` + + + 1 + 0 + + + urn:schemas-upnp-org:device:MediaServer:1 + {{.FriendlyName}} + rclone (rclone.org) + https://rclone.org/ + rclone + rclone + {{.ModelNumber}} + https://rclone.org/ + 00000000 + {{.RootDeviceUUID}} + + DMS-1.50 + M-DMS-1.50 + smi,DCM10,getMediaInfo.sec,getCaptionInfo.sec + smi,DCM10,getMediaInfo.sec,getCaptionInfo.sec + + + image/png + 48 + 48 + 8 + /static/rclone-48x48.png + + + image/png + 120 + 120 + 8 + /static/rclone-120x120.png + + + + + urn:schemas-upnp-org:service:ContentDirectory:1 + urn:upnp-org:serviceId:ContentDirectory + /static/ContentDirectory.xml + /ctl + + + + urn:schemas-upnp-org:service:ConnectionManager:1 + urn:upnp-org:serviceId:ConnectionManager + /static/ConnectionManager.xml + /ctl + + + + urn:microsoft.com:service:X_MS_MediaReceiverRegistrar:1 + urn:microsoft.com:serviceId:X_MS_MediaReceiverRegistrar + /static/X_MS_MediaReceiverRegistrar.xml + /ctl + + + + / + +` + + var templateString = string(templateBytes) + + tpl, err = template.New("rootDesc").Parse(templateString) + if err != nil { + return nil, fmt.Errorf("get template parse: %w", err) + } + + return +} \ No newline at end of file