mirror of
https://github.com/Ernous/TorrServerJellyfin.git
synced 2025-12-19 13:36:09 +05:00
change meta response
This commit is contained in:
@@ -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")
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user