Everything is in memory now without libs
This commit is contained in:
@@ -79,7 +79,7 @@ func extractIDFromFilename(filename string) (string, string) {
|
||||
}
|
||||
|
||||
// findLinkByFragment finds a link by a fragment, it might be wrong
|
||||
func findLinkByFragment(torrents []realdebrid.Torrent, fragment string) string {
|
||||
func findLinkByFragment(torrents []torrent.Torrent, fragment string) string {
|
||||
for _, torrent := range torrents {
|
||||
for _, link := range torrent.Links {
|
||||
if strings.HasPrefix(link, fmt.Sprintf("https://real-debrid.com/d/%s", fragment)) {
|
||||
|
||||
@@ -1,16 +1,14 @@
|
||||
package dav
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/debridmediamanager.com/zurg/internal/torrent"
|
||||
"github.com/debridmediamanager.com/zurg/pkg/dav"
|
||||
"github.com/debridmediamanager.com/zurg/pkg/realdebrid"
|
||||
)
|
||||
|
||||
// createMultiTorrentResponse creates a WebDAV response for a list of torrents
|
||||
func createMultiTorrentResponse(torrents []realdebrid.Torrent) (*dav.MultiStatus, error) {
|
||||
func createMultiTorrentResponse(torrents []torrent.Torrent) (*dav.MultiStatus, error) {
|
||||
var responses []dav.Response
|
||||
responses = append(responses, dav.Directory("/torrents"))
|
||||
|
||||
@@ -36,7 +34,7 @@ func createMultiTorrentResponse(torrents []realdebrid.Torrent) (*dav.MultiStatus
|
||||
}
|
||||
|
||||
// createTorrentResponse creates a WebDAV response for torrents with the same name
|
||||
func createCombinedTorrentResponse(torrents []realdebrid.Torrent, t *torrent.TorrentManager) (*dav.MultiStatus, error) {
|
||||
func createCombinedTorrentResponse(torrents []torrent.Torrent, t *torrent.TorrentManager) (*dav.MultiStatus, error) {
|
||||
var responses []dav.Response
|
||||
// initial response is the directory itself
|
||||
currentPath := filepath.Join("/torrents", torrents[0].Filename)
|
||||
@@ -51,57 +49,20 @@ func createCombinedTorrentResponse(torrents []realdebrid.Torrent, t *torrent.Tor
|
||||
if info == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
var selectedFiles []realdebrid.File
|
||||
for _, file := range info.Files {
|
||||
if file.Selected == 0 {
|
||||
for _, file := range info.SelectedFiles {
|
||||
filename := filepath.Base(file.Path)
|
||||
if _, exists := seen[filename]; exists {
|
||||
continue
|
||||
}
|
||||
selectedFiles = append(selectedFiles, file)
|
||||
}
|
||||
|
||||
if len(selectedFiles) != len(info.Links) {
|
||||
fmt.Println("Links and files do not match", info.Filename)
|
||||
// TODO: Add auto-healing for this
|
||||
// for _, link := range info.Links {
|
||||
// unrestrictFn := func() (*realdebrid.UnrestrictResponse, error) {
|
||||
// return realdebrid.UnrestrictCheck(os.Getenv("RD_TOKEN"), link)
|
||||
// }
|
||||
// resp := realdebrid.RetryUntilOk(unrestrictFn)
|
||||
// if resp == nil {
|
||||
// continue
|
||||
// } else {
|
||||
// if _, exists := seen[resp.Filename]; exists {
|
||||
// continue
|
||||
// }
|
||||
// seen[resp.Filename] = true
|
||||
// filePath := filepath.Join(currentPath, resp.Filename)
|
||||
// torrentResponses = append(torrentResponses,
|
||||
// dav.File(
|
||||
// filePath,
|
||||
// resp.Filesize,
|
||||
// info.Added,
|
||||
// resp.Link,
|
||||
// ),
|
||||
// )
|
||||
// }
|
||||
// }
|
||||
} else {
|
||||
for _, file := range selectedFiles {
|
||||
filename := filepath.Base(file.Path)
|
||||
if _, exists := seen[filename]; exists {
|
||||
continue
|
||||
}
|
||||
seen[filename] = true
|
||||
filePath := filepath.Join(currentPath, filename)
|
||||
torrentResponses = append(torrentResponses, dav.File(
|
||||
filePath,
|
||||
file.Bytes,
|
||||
convertDate(info.Added),
|
||||
info.Links[idx],
|
||||
))
|
||||
idx++
|
||||
}
|
||||
seen[filename] = true
|
||||
filePath := filepath.Join(currentPath, filename)
|
||||
torrentResponses = append(torrentResponses, dav.File(
|
||||
filePath,
|
||||
file.Bytes,
|
||||
convertDate(info.Added),
|
||||
info.Links[idx],
|
||||
))
|
||||
idx++
|
||||
}
|
||||
}
|
||||
responses = append(responses, torrentResponses...)
|
||||
|
||||
@@ -5,7 +5,6 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/debridmediamanager.com/zurg/internal/torrent"
|
||||
"github.com/debridmediamanager.com/zurg/pkg/realdebrid"
|
||||
)
|
||||
|
||||
// convertDate converts a date from RFC3339 to RFC1123
|
||||
@@ -19,8 +18,8 @@ func convertDate(input string) string {
|
||||
}
|
||||
|
||||
// findAllTorrentsWithName finds all torrents with a given name
|
||||
func findAllTorrentsWithName(t *torrent.TorrentManager, filename string) []realdebrid.Torrent {
|
||||
var matchingTorrents []realdebrid.Torrent
|
||||
func findAllTorrentsWithName(t *torrent.TorrentManager, filename string) []torrent.Torrent {
|
||||
var matchingTorrents []torrent.Torrent
|
||||
|
||||
torrents := t.GetAll()
|
||||
for _, torrent := range torrents {
|
||||
|
||||
Reference in New Issue
Block a user