Add VidHub endpoints
This commit is contained in:
@@ -13,26 +13,29 @@ import (
|
||||
"github.com/debridmediamanager/zurg/pkg/dav"
|
||||
)
|
||||
|
||||
// ServeRootDirectoryForDav serves the root directory for DAV
|
||||
// The first entry is the root directory e.g. /root/
|
||||
// Followed by the directories e.g. movies
|
||||
func ServeRootDirectoryForDav(torMgr *torrent.TorrentManager) ([]byte, error) {
|
||||
var buf bytes.Buffer
|
||||
buf.WriteString("<?xml version=\"1.0\" encoding=\"utf-8\"?><d:multistatus xmlns:d=\"DAV:\">")
|
||||
buf.WriteString(dav.BaseDirectory(addSlash(""), ""))
|
||||
buf.WriteString(dav.Directory(addSlash(""), ""))
|
||||
directories := torMgr.DirectoryMap.Keys()
|
||||
sort.Strings(directories)
|
||||
for _, directory := range directories {
|
||||
if strings.HasPrefix(directory, "int__") {
|
||||
continue
|
||||
}
|
||||
buf.WriteString(dav.Directory(directory, ""))
|
||||
buf.WriteString(dav.Directory(filepath.Base(directory), ""))
|
||||
}
|
||||
buf.WriteString(dav.Directory(config.DOWNLOADS, ""))
|
||||
buf.WriteString(dav.Directory(filepath.Base(config.DOWNLOADS), ""))
|
||||
_, size := version.GetFile()
|
||||
buf.WriteString(dav.File(version.FILE, size, ""))
|
||||
buf.WriteString("</d:multistatus>")
|
||||
return buf.Bytes(), nil
|
||||
}
|
||||
|
||||
func ServeTorrentsListForDav(directory string, torMgr *torrent.TorrentManager) ([]byte, error) {
|
||||
func ServeGroupDirectoryForDav(directory string, torMgr *torrent.TorrentManager) ([]byte, error) {
|
||||
torrents, ok := torMgr.DirectoryMap.Get(directory)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("cannot find directory %s", directory)
|
||||
@@ -40,7 +43,7 @@ func ServeTorrentsListForDav(directory string, torMgr *torrent.TorrentManager) (
|
||||
|
||||
var buf bytes.Buffer
|
||||
buf.WriteString("<?xml version=\"1.0\" encoding=\"utf-8\"?><d:multistatus xmlns:d=\"DAV:\">")
|
||||
buf.WriteString(dav.BaseDirectory(addSlash(directory), ""))
|
||||
buf.WriteString(dav.Directory(addSlash(directory), ""))
|
||||
torrentNames := torrents.Keys()
|
||||
sort.Strings(torrentNames)
|
||||
for _, torrentName := range torrentNames {
|
||||
@@ -48,13 +51,13 @@ func ServeTorrentsListForDav(directory string, torMgr *torrent.TorrentManager) (
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
buf.WriteString(dav.Directory(torMgr.GetKey(tor), tor.Added))
|
||||
buf.WriteString(dav.Directory(filepath.Base(torMgr.GetKey(tor)), tor.Added))
|
||||
}
|
||||
buf.WriteString("</d:multistatus>")
|
||||
return buf.Bytes(), nil
|
||||
}
|
||||
|
||||
func ServeFilesListForDav(directory, torrentName string, torMgr *torrent.TorrentManager, shouldHideBrokenTorrents bool) ([]byte, error) {
|
||||
func ServeTorrentFilesForDav(directory, torrentName string, torMgr *torrent.TorrentManager, shouldHideBrokenTorrents bool) ([]byte, error) {
|
||||
torrents, ok := torMgr.DirectoryMap.Get(directory)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("cannot find directory %s", directory)
|
||||
@@ -72,7 +75,7 @@ func ServeFilesListForDav(directory, torrentName string, torMgr *torrent.Torrent
|
||||
|
||||
var buf bytes.Buffer
|
||||
buf.WriteString("<?xml version=\"1.0\" encoding=\"utf-8\"?><d:multistatus xmlns:d=\"DAV:\">")
|
||||
buf.WriteString(dav.BaseDirectory(addSlash(filepath.Join(directory, torMgr.GetKey(tor))), tor.Added))
|
||||
buf.WriteString(dav.Directory(addSlash(filepath.Join(directory, torMgr.GetKey(tor))), tor.Added))
|
||||
filenames := tor.SelectedFiles.Keys()
|
||||
sort.Strings(filenames)
|
||||
for _, filename := range filenames {
|
||||
@@ -98,32 +101,10 @@ func ServeFilesListForDav(directory, torrentName string, torMgr *torrent.Torrent
|
||||
return buf.Bytes(), nil
|
||||
}
|
||||
|
||||
func HandleSingleFile(directory, torrentName, fileName string, torMgr *torrent.TorrentManager) ([]byte, error) {
|
||||
torrents, ok := torMgr.DirectoryMap.Get(directory)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("cannot find directory %s", directory)
|
||||
}
|
||||
tor, ok := torrents.Get(torrentName)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("cannot find torrent %s", torrentName)
|
||||
}
|
||||
file, ok := tor.SelectedFiles.Get(fileName)
|
||||
if !ok || file.State.Is("deleted_file") {
|
||||
return nil, fmt.Errorf("cannot find file %s", fileName)
|
||||
}
|
||||
|
||||
func ServeDownloadsForDav(torMgr *torrent.TorrentManager) ([]byte, error) {
|
||||
var buf bytes.Buffer
|
||||
buf.WriteString("<?xml version=\"1.0\" encoding=\"utf-8\"?><d:multistatus xmlns:d=\"DAV:\">")
|
||||
buf.WriteString(dav.BaseDirectory(addSlash(filepath.Join(directory, torMgr.GetKey(tor))), tor.Added))
|
||||
buf.WriteString(dav.File(fileName, file.Bytes, file.Ended))
|
||||
buf.WriteString("</d:multistatus>")
|
||||
return buf.Bytes(), nil
|
||||
}
|
||||
|
||||
func ServeDownloadsListForDav(torMgr *torrent.TorrentManager) ([]byte, error) {
|
||||
var buf bytes.Buffer
|
||||
buf.WriteString("<?xml version=\"1.0\" encoding=\"utf-8\"?><d:multistatus xmlns:d=\"DAV:\">")
|
||||
buf.WriteString(dav.BaseDirectory(config.DOWNLOADS, ""))
|
||||
buf.WriteString(dav.Directory(addSlash(config.DOWNLOADS), ""))
|
||||
filenames := torMgr.DownloadMap.Keys()
|
||||
sort.Strings(filenames)
|
||||
for _, filename := range filenames {
|
||||
@@ -136,3 +117,26 @@ func ServeDownloadsListForDav(torMgr *torrent.TorrentManager) ([]byte, error) {
|
||||
buf.WriteString("</d:multistatus>")
|
||||
return buf.Bytes(), nil
|
||||
}
|
||||
|
||||
// HandleSingleFile is for PROPFIND requests for a single file, shared by Infuse and VidHub
|
||||
func HandleSingleFile(directory, torrentName, filename string, torMgr *torrent.TorrentManager) ([]byte, error) {
|
||||
torrents, ok := torMgr.DirectoryMap.Get(directory)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("cannot find directory %s", directory)
|
||||
}
|
||||
tor, ok := torrents.Get(torrentName)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("cannot find torrent %s", torrentName)
|
||||
}
|
||||
file, ok := tor.SelectedFiles.Get(filename)
|
||||
if !ok || file.State.Is("deleted_file") {
|
||||
return nil, fmt.Errorf("cannot find file %s", filename)
|
||||
}
|
||||
|
||||
var buf bytes.Buffer
|
||||
buf.WriteString("<?xml version=\"1.0\" encoding=\"utf-8\"?><d:multistatus xmlns:d=\"DAV:\">")
|
||||
buf.WriteString(dav.Directory(addSlash(filepath.Join(directory, torMgr.GetKey(tor))), tor.Added))
|
||||
buf.WriteString(dav.File(filename, file.Bytes, file.Ended))
|
||||
buf.WriteString("</d:multistatus>")
|
||||
return buf.Bytes(), nil
|
||||
}
|
||||
|
||||
@@ -12,6 +12,9 @@ import (
|
||||
"github.com/debridmediamanager/zurg/pkg/dav"
|
||||
)
|
||||
|
||||
// ServeRootDirectoryForInfuse serves the root directory for Infuse
|
||||
// There is no root directory, just the directories e.g. movies
|
||||
// Actual path is based on configured base path and current directory
|
||||
func ServeRootDirectoryForInfuse(torMgr *torrent.TorrentManager) ([]byte, error) {
|
||||
var buf bytes.Buffer
|
||||
buf.WriteString("<?xml version=\"1.0\" encoding=\"utf-8\"?><d:multistatus xmlns:d=\"DAV:\">")
|
||||
@@ -23,10 +26,10 @@ func ServeRootDirectoryForInfuse(torMgr *torrent.TorrentManager) ([]byte, error)
|
||||
if strings.HasPrefix(directory, "int__") {
|
||||
continue
|
||||
}
|
||||
buf.WriteString(dav.BaseDirectory(directory, ""))
|
||||
buf.WriteString(dav.Directory(directory, ""))
|
||||
}
|
||||
|
||||
buf.WriteString(dav.BaseDirectory(config.DOWNLOADS, ""))
|
||||
buf.WriteString(dav.Directory(config.DOWNLOADS, ""))
|
||||
|
||||
_, size := version.GetFile()
|
||||
buf.WriteString(dav.File(version.FILE, size, ""))
|
||||
@@ -35,7 +38,7 @@ func ServeRootDirectoryForInfuse(torMgr *torrent.TorrentManager) ([]byte, error)
|
||||
return buf.Bytes(), nil
|
||||
}
|
||||
|
||||
func ServeTorrentsListForInfuse(directory string, torMgr *torrent.TorrentManager) ([]byte, error) {
|
||||
func ServeGroupDirectoryForInfuse(directory string, torMgr *torrent.TorrentManager) ([]byte, error) {
|
||||
torrents, ok := torMgr.DirectoryMap.Get(directory)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("cannot find directory %s", directory)
|
||||
@@ -52,14 +55,14 @@ func ServeTorrentsListForInfuse(directory string, torMgr *torrent.TorrentManager
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
buf.WriteString(dav.BaseDirectory(torMgr.GetKey(tor), tor.Added))
|
||||
buf.WriteString(dav.Directory(torMgr.GetKey(tor), tor.Added))
|
||||
}
|
||||
|
||||
buf.WriteString("</d:multistatus>")
|
||||
return buf.Bytes(), nil
|
||||
}
|
||||
|
||||
func ServeFilesListForInfuse(directory, torrentName string, torMgr *torrent.TorrentManager, shouldHideBrokenTorrents bool) ([]byte, error) {
|
||||
func ServeTorrentFilesForInfuse(directory, torrentName string, torMgr *torrent.TorrentManager, shouldHideBrokenTorrents bool) ([]byte, error) {
|
||||
torrents, ok := torMgr.DirectoryMap.Get(directory)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("cannot find directory %s", directory)
|
||||
@@ -107,7 +110,7 @@ func ServeFilesListForInfuse(directory, torrentName string, torMgr *torrent.Torr
|
||||
return buf.Bytes(), nil
|
||||
}
|
||||
|
||||
func ServeDownloadsListForInfuse(torMgr *torrent.TorrentManager) ([]byte, error) {
|
||||
func ServeDownloadsForInfuse(torMgr *torrent.TorrentManager) ([]byte, error) {
|
||||
var buf bytes.Buffer
|
||||
|
||||
buf.WriteString("<?xml version=\"1.0\" encoding=\"utf-8\"?><d:multistatus xmlns:d=\"DAV:\">")
|
||||
|
||||
14
internal/dav/util.go
Normal file
14
internal/dav/util.go
Normal file
@@ -0,0 +1,14 @@
|
||||
package dav
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func addSlash(input string) string {
|
||||
p := filepath.Join("/", input)
|
||||
if p == "/" || strings.HasSuffix(p, "/") {
|
||||
return p
|
||||
}
|
||||
return p + "/"
|
||||
}
|
||||
@@ -13,6 +13,9 @@ import (
|
||||
"github.com/debridmediamanager/zurg/pkg/dav"
|
||||
)
|
||||
|
||||
// ServeRootDirectoryForVidHub serves the root directory for VidHub
|
||||
// The first entry is the root directory e.g. /root/
|
||||
// Followed by the absolute path of directories e.g. /root/movies/
|
||||
func ServeRootDirectoryForVidHub(torMgr *torrent.TorrentManager) ([]byte, error) {
|
||||
var buf bytes.Buffer
|
||||
buf.WriteString("<?xml version=\"1.0\" encoding=\"utf-8\"?><d:multistatus xmlns:d=\"DAV:\">")
|
||||
@@ -33,7 +36,7 @@ func ServeRootDirectoryForVidHub(torMgr *torrent.TorrentManager) ([]byte, error)
|
||||
return buf.Bytes(), nil
|
||||
}
|
||||
|
||||
func ServeTorrentsListForVidHub(directory string, torMgr *torrent.TorrentManager) ([]byte, error) {
|
||||
func ServeGroupDirectoryForVidHub(directory string, torMgr *torrent.TorrentManager) ([]byte, error) {
|
||||
torrents, ok := torMgr.DirectoryMap.Get(directory)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("cannot find directory %s", directory)
|
||||
@@ -56,7 +59,7 @@ func ServeTorrentsListForVidHub(directory string, torMgr *torrent.TorrentManager
|
||||
return buf.Bytes(), nil
|
||||
}
|
||||
|
||||
func ServeFilesListForVidHub(directory, torrentName string, torMgr *torrent.TorrentManager, shouldHideBrokenTorrents bool) ([]byte, error) {
|
||||
func ServeTorrentFilesForVidHub(directory, torrentName string, torMgr *torrent.TorrentManager, shouldHideBrokenTorrents bool) ([]byte, error) {
|
||||
torrents, ok := torMgr.DirectoryMap.Get(directory)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("cannot find directory %s", directory)
|
||||
@@ -101,7 +104,7 @@ func ServeFilesListForVidHub(directory, torrentName string, torMgr *torrent.Torr
|
||||
return buf.Bytes(), nil
|
||||
}
|
||||
|
||||
func ServeDownloadsListForVidHub(torMgr *torrent.TorrentManager) ([]byte, error) {
|
||||
func ServeDownloadsForVidHub(torMgr *torrent.TorrentManager) ([]byte, error) {
|
||||
var buf bytes.Buffer
|
||||
buf.WriteString("<?xml version=\"1.0\" encoding=\"utf-8\"?><d:multistatus xmlns:d=\"DAV:\">")
|
||||
prefixPath := addSlash(config.DOWNLOADS)
|
||||
@@ -118,11 +121,3 @@ func ServeDownloadsListForVidHub(torMgr *torrent.TorrentManager) ([]byte, error)
|
||||
buf.WriteString("</d:multistatus>")
|
||||
return buf.Bytes(), nil
|
||||
}
|
||||
|
||||
func addSlash(input string) string {
|
||||
p := filepath.Join("/", input)
|
||||
if p == "/" || strings.HasSuffix(p, "/") {
|
||||
return p
|
||||
}
|
||||
return p + "/"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user