From 44f1cfbd9df3d2725128bbedd47f0d9364b73bc4 Mon Sep 17 00:00:00 2001 From: nikk gitanes Date: Mon, 13 Sep 2021 00:37:56 +0300 Subject: [PATCH] change meta response --- server/dlna/dlna.go | 30 ----------------------------- server/dlna/list.go | 47 +++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 43 insertions(+), 34 deletions(-) diff --git a/server/dlna/dlna.go b/server/dlna/dlna.go index 6e43f45..a8763f8 100644 --- a/server/dlna/dlna.go +++ b/server/dlna/dlna.go @@ -10,10 +10,8 @@ import ( "time" "github.com/anacrolix/dms/dlna/dms" - "github.com/anacrolix/dms/upnpav" "server/log" - "server/torr" "server/web/pages/template" ) @@ -121,34 +119,6 @@ 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 962cf6b..4e1922f 100644 --- a/server/dlna/list.go +++ b/server/dlna/list.go @@ -114,6 +114,36 @@ 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 @@ -136,11 +166,15 @@ 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, ChildCount: 1} + meta := upnpav.Container{Object: obj} 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", @@ -149,13 +183,17 @@ 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, ChildCount: 1} + meta := upnpav.Container{Object: obj} 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, @@ -164,11 +202,12 @@ 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, ChildCount: 1} + meta := upnpav.Container{Object: obj} return meta } - + // for error response return nil }