Add VidHub endpoints

This commit is contained in:
Ben Adrian Sarmiento
2024-07-11 15:53:20 +02:00
parent f8f68e8225
commit 396a8781aa
10 changed files with 182 additions and 86 deletions

View File

@@ -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 + "/"
}