From 84170b443d76a79a938330aea745698c2f41377d Mon Sep 17 00:00:00 2001 From: bel Date: Tue, 30 Jul 2024 16:37:59 -0600 Subject: [PATCH] look for magenets in link too --- handlers/torrent/main.go | 8 ++++---- handlers/torrent/main_test.go | 4 ++++ 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/handlers/torrent/main.go b/handlers/torrent/main.go index 18b2073..20ce3e1 100755 --- a/handlers/torrent/main.go +++ b/handlers/torrent/main.go @@ -119,7 +119,7 @@ func pull(db storage.DB, vpntor, outdir, url string) error { if item.Author == nil { item.Author = &gofeed.Person{Name: "."} } - if err := handle(vpntor, path.Join(outdir, item.Author.Name), s); err != nil { + if err := handle(vpntor, path.Join(outdir, item.Author.Name), item.Link, s); err != nil { return err } if err := db.Set(item.Link, []byte{}); err != nil { @@ -166,9 +166,9 @@ func isDone(db storage.DB, url string) (bool, error) { return true, err } -func handle(vpntor, outdir, content string) error { - log.Printf("magnets: %v", findMagnets(content)) - for _, magnet := range findMagnets(content) { +func handle(vpntor, outdir, link, content string) error { + log.Printf("magnets: %v", append(findMagnets(content), findMagnets(link)...)) + for _, magnet := range append(findMagnets(content), findMagnets(link)...) { resp, err := submit(vpntor, outdir, magnet) if err != nil { return err diff --git a/handlers/torrent/main_test.go b/handlers/torrent/main_test.go index 9e1b959..9e4ea7d 100755 --- a/handlers/torrent/main_test.go +++ b/handlers/torrent/main_test.go @@ -244,6 +244,10 @@ func TestFindMagnets(t *testing.T) { s: `here is a link https://my.domain/a.b/c.torrent, and another `, l: 2, }, + { + s: `https://my.domain/a.b/c.torrent`, + l: 1, + }, } for i, c := range cases {