diff --git a/server/cmd/main.go b/server/cmd/main.go index 63260c9..01da235 100644 --- a/server/cmd/main.go +++ b/server/cmd/main.go @@ -3,6 +3,8 @@ package main import ( "context" "fmt" + "github.com/anacrolix/torrent" + "github.com/anacrolix/torrent/metainfo" "net" "os" "path/filepath" @@ -18,7 +20,6 @@ import ( "server/settings" "server/torr" "server/version" - "server/web/api/utils" ) type args struct { @@ -131,7 +132,7 @@ func watchTDir(dir string) { for _, file := range files { filename := filepath.Join(path, file.Name()) if strings.ToLower(filepath.Ext(file.Name())) == ".torrent" { - sp, err := utils.ParseLink("file://" + filename) + sp, err := openFile(filename) if err == nil { tor, err := torr.AddTorrent(sp, "", "", "") if err == nil { @@ -160,3 +161,23 @@ func watchTDir(dir string) { time.Sleep(time.Second * 5) } } + +func openFile(path string) (*torrent.TorrentSpec, error) { + minfo, err := metainfo.LoadFromFile(path) + if err != nil { + return nil, err + } + info, err := minfo.UnmarshalInfo() + if err != nil { + return nil, err + } + + mag := minfo.Magnet(info.Name, minfo.HashInfoBytes()) + // mag := minfo.Magnet(nil, &info) + return &torrent.TorrentSpec{ + InfoBytes: minfo.InfoBytes, + Trackers: [][]string{mag.Trackers}, + DisplayName: info.Name, + InfoHash: minfo.HashInfoBytes(), + }, nil +}