2023-12-04 14:37:21 +01:00
|
|
|
package tails
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"log"
|
|
|
|
|
2024-03-30 01:59:29 +01:00
|
|
|
"git.hyperreal.coffee/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
|
|
|
|
}
|