diff --git a/server/dlna/dlna.go b/server/dlna/dlna.go index a8763f8..6e43f45 100644 --- a/server/dlna/dlna.go +++ b/server/dlna/dlna.go @@ -10,8 +10,10 @@ import ( "time" "github.com/anacrolix/dms/dlna/dms" + "github.com/anacrolix/dms/upnpav" "server/log" + "server/torr" "server/web/pages/template" ) @@ -119,6 +121,34 @@ func onBrowse(path, rootObjectPath, host, userAgent string) (ret []interface{}, } func onBrowseMeta(path string, rootObjectPath string, host, userAgent string) (ret interface{}, err error) { + if path == "/" { + rootObj := upnpav.Object{ + ID: "0", + ParentID: "-1", + Restricted: 1, + Searchable: 1, + Title: "TorrServer", + Date: upnpav.Timestamp{Time: time.Now()}, + Class: "object.container.storageFolder", + } + // add Root Object + ret = upnpav.Container{Object: rootObj, ChildCount: 1} + return + } else if path == "/TR" { + // TR Object Meta + trObj := upnpav.Object{ + ID: "%2FTR", + ParentID: "0", + Restricted: 1, + Searchable: 1, + Title: "Torrents", + Date: upnpav.Timestamp{Time: time.Now()}, + Class: "object.container.storageFolder", + } + vol := len(torr.ListTorrent()) + ret = upnpav.Container{Object: trObj, ChildCount: vol} + return + } ret = getTorrentMeta(path, host) if ret == nil { err = fmt.Errorf("meta not found") diff --git a/server/dlna/list.go b/server/dlna/list.go index 4e1922f..962cf6b 100644 --- a/server/dlna/list.go +++ b/server/dlna/list.go @@ -114,36 +114,6 @@ func getTorrent(path, host string) (ret []interface{}) { } func getTorrentMeta(path, host string) (ret interface{}) { - - if path=="/" { - rootObj := upnpav.Object{ - ID: "0", - ParentID: "-1", - Restricted: 1, - Searchable: 1, - Title: "TorrServer", - Date: upnpav.Timestamp{Time: time.Now()}, - Class: "object.container", - } - // add Root Object - meta := upnpav.Container{Object: rootObj} - return meta - } else if path == "/TR" { - // TR Object Meta - trObj := upnpav.Object{ - ID: "%2FTR", - ParentID: "0", - Restricted: 1, - Searchable: 1, - Title: "Torrents", - Date: upnpav.Timestamp{Time: time.Now()}, - Class: "object.container", - } - //vol := len(torr.ListTorrent()) - meta := upnpav.Container{Object: trObj} - return meta - } - // find torrent without load torrs := torr.ListTorrent() var torr *torr.Torrent @@ -166,15 +136,11 @@ func getTorrentMeta(path, host string) (ret interface{}) { Restricted: 1, Title: torr.Title, Date: upnpav.Timestamp{Time: time.Now()}, - Class: "object.container", } - meta := upnpav.Container{Object: obj} + meta := upnpav.Container{Object: obj, ChildCount: 1} return meta } else if filepath.Base(path) == "LD" { parent := url.PathEscape(filepath.Dir(path)) - if settings.BTsets.EnableDebug { - log.TLogln("getTorrentMeta parent for LD", parent) - } // LD object meta obj := upnpav.Object{ ID: parent + "%2FLD", @@ -183,17 +149,13 @@ func getTorrentMeta(path, host string) (ret interface{}) { Searchable: 1, Title: "Load Torrents", Date: upnpav.Timestamp{Time: time.Now()}, - Class: "object.container", } - meta := upnpav.Container{Object: obj} + meta := upnpav.Container{Object: obj, ChildCount: 1} return meta } else { file := filepath.Base(path) id := url.PathEscape(path) parent := url.PathEscape(filepath.Dir(path)) - if settings.BTsets.EnableDebug { - log.TLogln("getTorrentMeta id:", id, "parent:", parent) - } // file object meta obj := upnpav.Object{ ID: id, @@ -202,12 +164,11 @@ func getTorrentMeta(path, host string) (ret interface{}) { Searchable: 1, Title: file, Date: upnpav.Timestamp{Time: time.Now()}, - Class: "object.container", } - meta := upnpav.Container{Object: obj} + meta := upnpav.Container{Object: obj, ChildCount: 1} return meta } - // for error response + return nil }