dirty fix for dlna list

This commit is contained in:
nikk gitanes
2021-08-27 17:25:57 +03:00
parent 065dccbcd4
commit b1f9f9b4ac
2 changed files with 13 additions and 8 deletions

View File

@@ -16,6 +16,7 @@ import (
"server/settings" "server/settings"
"server/torr" "server/torr"
"server/torr/state" "server/torr/state"
"server/utils"
) )
func getTorrents() (ret []interface{}) { func getTorrents() (ret []interface{}) {
@@ -49,9 +50,9 @@ func getTorrent(path, host string) (ret []interface{}) {
if torr == nil { if torr == nil {
return 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 torrent not loaded, get button for load
if torr.Files() == nil { if torr.Files() == nil {
obj := upnpav.Object{ obj := upnpav.Object{
@@ -101,11 +102,13 @@ func loadTorrent(path, host string) (ret []interface{}) {
parent := "%2F" + tor.TorrentSpec.InfoHash.HexString() parent := "%2F" + tor.TorrentSpec.InfoHash.HexString()
files := tor.Status().FileStats files := tor.Status().FileStats
for _, f := range files { for _, f := range files {
if utils.GetMimeType(f.Path) != "*/*" {
obj := getObjFromTorrent(path, parent, host, tor, f) obj := getObjFromTorrent(path, parent, host, tor, f)
if obj != nil { if obj != nil {
ret = append(ret, obj) ret = append(ret, obj)
} }
} }
}
return 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{}) { func getObjFromTorrent(path, parent, host string, torr *torr.Torrent, file *state.TorrentFileStat) (ret interface{}) {
mime, err := dms.MimeTypeByPath(file.Path) mime, err := dms.MimeTypeByPath(file.Path)
if err != nil { if err != nil {
return //return // this always err
mime = "video/mpeg"
} }
//mime := utils.GetMimeType(file.Path)
obj := upnpav.Object{ obj := upnpav.Object{
ID: parent + "%2" + file.Path, ID: parent + "%2F" + file.Path,
Restricted: 1, Restricted: 1,
ParentID: parent, ParentID: parent,
Class: "object.item." + mime.Type() + "Item", Class: "object.item." + mime.Type() + "Item",

View File

@@ -101,7 +101,7 @@ func GetTorrent(hashHex string) *Torrent {
go func() { go func() {
lockApi.Lock() lockApi.Lock()
defer lockApi.Unlock() defer lockApi.Unlock()
log.TLogln("Add torrent") log.TLogln("New torrent", tor.Hash())
tr, _ := NewTorrent(tor.TorrentSpec, bts) tr, _ := NewTorrent(tor.TorrentSpec, bts)
if tr != nil { if tr != nil {
tr.Title = tor.Title tr.Title = tor.Title