From b1f9f9b4ac282ed934a099418a7b714403e6733c Mon Sep 17 00:00:00 2001 From: nikk gitanes Date: Fri, 27 Aug 2021 17:25:57 +0300 Subject: [PATCH] dirty fix for dlna list --- server/dlna/list.go | 19 ++++++++++++------- server/torr/apihelper.go | 2 +- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/server/dlna/list.go b/server/dlna/list.go index aaf1020..46615fe 100644 --- a/server/dlna/list.go +++ b/server/dlna/list.go @@ -16,6 +16,7 @@ import ( "server/settings" "server/torr" "server/torr/state" + "server/utils" ) func getTorrents() (ret []interface{}) { @@ -49,9 +50,9 @@ func getTorrent(path, host string) (ret []interface{}) { if torr == nil { return nil } - parent := "%2F" + torr.TorrentSpec.InfoHash.HexString() - // get content from torrent + // get content from torrent + parent := "%2F" + torr.TorrentSpec.InfoHash.HexString() // if torrent not loaded, get button for load if torr.Files() == nil { obj := upnpav.Object{ @@ -101,9 +102,11 @@ func loadTorrent(path, host string) (ret []interface{}) { parent := "%2F" + tor.TorrentSpec.InfoHash.HexString() files := tor.Status().FileStats for _, f := range files { - obj := getObjFromTorrent(path, parent, host, tor, f) - if obj != nil { - ret = append(ret, obj) + if utils.GetMimeType(f.Path) != "*/*" { + obj := getObjFromTorrent(path, parent, host, tor, f) + if obj != nil { + ret = append(ret, obj) + } } } return @@ -123,11 +126,13 @@ func getLink(host, path string) string { func getObjFromTorrent(path, parent, host string, torr *torr.Torrent, file *state.TorrentFileStat) (ret interface{}) { mime, err := dms.MimeTypeByPath(file.Path) if err != nil { - return + //return // this always err + mime = "video/mpeg" } + //mime := utils.GetMimeType(file.Path) obj := upnpav.Object{ - ID: parent + "%2" + file.Path, + ID: parent + "%2F" + file.Path, Restricted: 1, ParentID: parent, Class: "object.item." + mime.Type() + "Item", diff --git a/server/torr/apihelper.go b/server/torr/apihelper.go index 1eb3782..773b609 100644 --- a/server/torr/apihelper.go +++ b/server/torr/apihelper.go @@ -101,7 +101,7 @@ func GetTorrent(hashHex string) *Torrent { go func() { lockApi.Lock() defer lockApi.Unlock() - log.TLogln("Add torrent") + log.TLogln("New torrent", tor.Hash()) tr, _ := NewTorrent(tor.TorrentSpec, bts) if tr != nil { tr.Title = tor.Title