go-torrent-helper/tails/main.go

47 lines
1022 B
Go
Raw Normal View History

2023-12-04 14:37:21 +01:00
package tails
import (
"fmt"
"log"
2024-03-30 06:23:56 +01:00
"codeberg.org/hyperreal/go-torrent-helper/common"
2023-12-04 14:37:21 +01:00
"github.com/hekmon/transmissionrpc"
)
type Tails struct {
NameSubstr string
Relver string
URL string
}
func (t Tails) AddNewTorrents(transmissionbt *transmissionrpc.Client) error {
// Set torrentURLs for Tails mirror
t.URL = "https://tails.net/torrents/files/"
torrentURLs := []string{
fmt.Sprintf("%s/tails-amd64-%s.img.torrent", t.URL, t.Relver),
fmt.Sprintf("%s/tails-amd64-%s.iso.torrent", t.URL, t.Relver),
}
// Add torrents to Transmission instance
for _, torrentURL := range torrentURLs {
torrent, err := transmissionbt.TorrentAdd(&transmissionrpc.TorrentAddPayload{
Filename: &torrentURL,
})
if err != nil {
return err
}
log.Printf("%s added\n", *torrent.Name)
}
return nil
}
func (t Tails) RemoveOldTorrents(transmissionbt *transmissionrpc.Client) error {
if err := common.RemoveTorrents(t.NameSubstr, t.Relver, transmissionbt); err != nil {
return err
}
return nil
}