mirror of
https://github.com/Ernous/TorrServerJellyfin.git
synced 2025-12-19 13:36:09 +05:00
update dlna
This commit is contained in:
@@ -90,6 +90,9 @@ func Stop() {
|
|||||||
|
|
||||||
func onBrowse(path, rootObjectPath, host, userAgent string) (ret []interface{}, err error) {
|
func onBrowse(path, rootObjectPath, host, userAgent string) (ret []interface{}, err error) {
|
||||||
if path == "/" {
|
if path == "/" {
|
||||||
|
ret = getRoot()
|
||||||
|
return
|
||||||
|
} else if path == "/Torrents" {
|
||||||
ret = getTorrents()
|
ret = getTorrents()
|
||||||
return
|
return
|
||||||
} else if isHashPath(path) {
|
} else if isHashPath(path) {
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"net/url"
|
"net/url"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"sort"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
@@ -17,14 +18,41 @@ import (
|
|||||||
"server/torr/state"
|
"server/torr/state"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func getRoot() (ret []interface{}) {
|
||||||
|
|
||||||
|
// Root Object
|
||||||
|
rootObj := upnpav.Object{
|
||||||
|
ID: "%2FTorrents",
|
||||||
|
ParentID: "0",
|
||||||
|
Title: "Torrents",
|
||||||
|
Class: "object.container.storageFolder",
|
||||||
|
Restricted: 1,
|
||||||
|
Date: upnpav.Timestamp{Time: time.Now()},
|
||||||
|
}
|
||||||
|
|
||||||
|
// add Root Object
|
||||||
|
len := len(torr.ListTorrent())
|
||||||
|
cnt := upnpav.Container{Object: rootObj, ChildCount: len}
|
||||||
|
ret = append(ret, cnt)
|
||||||
|
|
||||||
|
return
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
func getTorrents() (ret []interface{}) {
|
func getTorrents() (ret []interface{}) {
|
||||||
|
|
||||||
torrs := torr.ListTorrent()
|
torrs := torr.ListTorrent()
|
||||||
|
// sort by title as in cds SortCaps
|
||||||
|
sort.Slice(torrs, func(i, j int) bool {
|
||||||
|
return torrs[i].Title < torrs[j].Title
|
||||||
|
})
|
||||||
|
|
||||||
var vol = 0
|
var vol = 0
|
||||||
for _, t := range torrs {
|
for _, t := range torrs {
|
||||||
vol++
|
vol++
|
||||||
obj := upnpav.Object{
|
obj := upnpav.Object{
|
||||||
ID: "%2F" + t.TorrentSpec.InfoHash.HexString(),
|
ID: "%2F" + t.TorrentSpec.InfoHash.HexString(),
|
||||||
ParentID: "0",
|
ParentID: "%2FTorrents",
|
||||||
Title: t.Title,
|
Title: t.Title,
|
||||||
Class: "object.container.storageFolder",
|
Class: "object.container.storageFolder",
|
||||||
Restricted: 1,
|
Restricted: 1,
|
||||||
@@ -38,7 +66,7 @@ func getTorrents() (ret []interface{}) {
|
|||||||
if vol == 0 {
|
if vol == 0 {
|
||||||
obj := upnpav.Object{
|
obj := upnpav.Object{
|
||||||
ID: "%2FNo Torrents",
|
ID: "%2FNo Torrents",
|
||||||
ParentID: "0",
|
ParentID: "%2FTorrents",
|
||||||
Title: "No Torrents",
|
Title: "No Torrents",
|
||||||
Class: "object.container.storageFolder",
|
Class: "object.container.storageFolder",
|
||||||
Restricted: 1,
|
Restricted: 1,
|
||||||
@@ -46,6 +74,7 @@ func getTorrents() (ret []interface{}) {
|
|||||||
}
|
}
|
||||||
cnt := upnpav.Container{Object: obj, ChildCount: 1}
|
cnt := upnpav.Container{Object: obj, ChildCount: 1}
|
||||||
ret = append(ret, cnt)
|
ret = append(ret, cnt)
|
||||||
|
vol = 1
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -139,12 +168,17 @@ func getObjFromTorrent(path, parent, host string, torr *torr.Torrent, file *stat
|
|||||||
|
|
||||||
mime, err := MimeTypeByPath(file.Path)
|
mime, err := MimeTypeByPath(file.Path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.TLogln("Can't detect mime type", err)
|
if settings.BTsets.EnableDebug {
|
||||||
|
log.TLogln("Can't detect mime type", err)
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if !mime.IsMedia() {
|
if !mime.IsMedia() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if settings.BTsets.EnableDebug {
|
||||||
|
log.TLogln("mime type", mime.String(), file.Path)
|
||||||
|
}
|
||||||
|
|
||||||
obj := upnpav.Object{
|
obj := upnpav.Object{
|
||||||
ID: parent + "%2F" + file.Path,
|
ID: parent + "%2F" + file.Path,
|
||||||
@@ -163,6 +197,7 @@ func getObjFromTorrent(path, parent, host string, torr *torr.Torrent, file *stat
|
|||||||
item.Res = append(item.Res, upnpav.Resource{
|
item.Res = append(item.Res, upnpav.Resource{
|
||||||
URL: getLink(host, pathPlay),
|
URL: getLink(host, pathPlay),
|
||||||
ProtocolInfo: fmt.Sprintf("http-get:*:%s:%s", mime, dlna.ContentFeatures{
|
ProtocolInfo: fmt.Sprintf("http-get:*:%s:%s", mime, dlna.ContentFeatures{
|
||||||
|
SupportTimeSeek: true,
|
||||||
SupportRange: true,
|
SupportRange: true,
|
||||||
}.String()),
|
}.String()),
|
||||||
Size: uint64(file.Length),
|
Size: uint64(file.Length),
|
||||||
|
|||||||
@@ -19,29 +19,31 @@ func init() {
|
|||||||
mimeType string
|
mimeType string
|
||||||
extensions string
|
extensions string
|
||||||
}{
|
}{
|
||||||
{"audio/aac", ".aac"},
|
{"image/bmp", ".bmp"},
|
||||||
|
{"image/gif", ".gif"},
|
||||||
|
{"image/jpeg", ".jpg,.jpeg"},
|
||||||
|
{"image/png", ".png"},
|
||||||
|
{"image/tiff", ".tiff,.tif"},
|
||||||
|
{"audio/x-aac", ".aac"},
|
||||||
{"audio/flac", ".flac"},
|
{"audio/flac", ".flac"},
|
||||||
{"audio/mpeg", ".mpga,.mpega,.mp2,.mp3,.m4a"},
|
{"audio/mpeg", ".mpga,.mpega,.mp2,.mp3,.m4a"},
|
||||||
{"audio/ogg", ".oga,.ogg,.opus,.spx"},
|
{"audio/ogg", ".oga,.ogg,.opus,.spx"},
|
||||||
{"audio/opus", ".opus"},
|
{"audio/opus", ".opus"},
|
||||||
{"audio/weba", ".weba"},
|
{"audio/weba", ".weba"},
|
||||||
{"audio/x-wav", ".wav"},
|
{"audio/x-wav", ".wav"},
|
||||||
{"image/bmp", ".bmp"},
|
|
||||||
{"image/gif", ".gif"},
|
|
||||||
{"image/jpeg", ".jpg,.jpeg"},
|
|
||||||
{"image/png", ".png"},
|
|
||||||
{"image/tiff", ".tiff,.tif"},
|
|
||||||
{"video/dv", ".dif,.dv"},
|
{"video/dv", ".dif,.dv"},
|
||||||
{"video/fli", ".fli"},
|
{"video/fli", ".fli"},
|
||||||
{"video/mpeg", ".mpeg,.mpg,.mpe"},
|
|
||||||
{"video/mp2t", ".ts,.m2ts,.mts"},
|
|
||||||
{"video/mp4", ".mp4"},
|
{"video/mp4", ".mp4"},
|
||||||
{"video/quicktime", ".qt,.mov"},
|
{"video/mpeg", ".mpeg,.mpg,.mpe"},
|
||||||
|
{"video/x-matroska", ".mpv,.mkv"},
|
||||||
|
{"video/mp2t", ".ts,.m2ts,.mts"},
|
||||||
{"video/ogg", ".ogv"},
|
{"video/ogg", ".ogv"},
|
||||||
{"video/webm", ".webm"},
|
{"video/webm", ".webm"},
|
||||||
{"video/x-msvideo", ".avi"},
|
{"video/x-msvideo", ".avi"},
|
||||||
{"video/x-matroska", ".mpv,.mkv"},
|
{"video/x-quicktime", ".qt,.mov"},
|
||||||
{"text/srt", ".srt"},
|
{"text/srt", ".srt"},
|
||||||
|
{"text/smi", ".smi"},
|
||||||
|
{"text/ssa", ".ssa"},
|
||||||
} {
|
} {
|
||||||
for _, ext := range strings.Split(t.extensions, ",") {
|
for _, ext := range strings.Split(t.extensions, ",") {
|
||||||
err := mime.AddExtensionType(ext, t.mimeType)
|
err := mime.AddExtensionType(ext, t.mimeType)
|
||||||
@@ -78,6 +80,11 @@ func (mt mimeType) IsImage() bool {
|
|||||||
return strings.HasPrefix(string(mt), "image/")
|
return strings.HasPrefix(string(mt), "image/")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IsSub returns true for subtitles MIME-types
|
||||||
|
func (mt mimeType) IsSub() bool {
|
||||||
|
return strings.HasPrefix(string(mt), "text/srt") || strings.HasPrefix(string(mt), "text/smi") || strings.HasPrefix(string(mt), "text/ssa")
|
||||||
|
}
|
||||||
|
|
||||||
// Returns the group "type", the part before the '/'.
|
// Returns the group "type", the part before the '/'.
|
||||||
func (mt mimeType) Type() string {
|
func (mt mimeType) Type() string {
|
||||||
return strings.SplitN(string(mt), "/", 2)[0]
|
return strings.SplitN(string(mt), "/", 2)[0]
|
||||||
@@ -94,7 +101,13 @@ func MimeTypeByPath(filePath string) (ret mimeType, err error) {
|
|||||||
if ret == "" {
|
if ret == "" {
|
||||||
ret, err = mimeTypeByContent(filePath)
|
ret, err = mimeTypeByContent(filePath)
|
||||||
}
|
}
|
||||||
if ret == "video/x-msvideo" {
|
// Custom DLNA-compat mime mappings
|
||||||
|
// TODO: make this client headers / profile map
|
||||||
|
if ret == "video/mp2t" {
|
||||||
|
ret = "video/mpeg"
|
||||||
|
else if ret == "video/x-matroska" {
|
||||||
|
ret = "video/mpeg"
|
||||||
|
else if ret == "video/x-msvideo" {
|
||||||
ret = "video/avi"
|
ret = "video/avi"
|
||||||
} else if ret == "" {
|
} else if ret == "" {
|
||||||
ret = "application/octet-stream"
|
ret = "application/octet-stream"
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ module server
|
|||||||
go 1.17
|
go 1.17
|
||||||
|
|
||||||
replace (
|
replace (
|
||||||
github.com/anacrolix/dms v1.2.2 => github.com/tsynik/dms v0.0.0-20210902055723-0fcf49216c68
|
github.com/anacrolix/dms v1.2.2 => github.com/tsynik/dms v0.0.0-20210906003125-e00296ccb6ef
|
||||||
github.com/anacrolix/torrent v1.30.3 => github.com/tsynik/torrent v1.2.7-0.20210903201852-d16ba45e0bbd
|
github.com/anacrolix/torrent v1.30.3 => github.com/tsynik/torrent v1.2.7-0.20210903201852-d16ba45e0bbd
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user