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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user