go-torrent-helper/debian/main.go

49 lines
1.2 KiB
Go
Raw Normal View History

2023-10-26 15:56:04 +02:00
package debian
2023-06-24 04:33:24 +02:00
import (
"fmt"
"log"
2023-10-26 02:45:21 +02:00
"git.sr.ht/~hyperreal/go-torrent-helper/common"
2023-10-26 15:56:04 +02:00
"github.com/hekmon/transmissionrpc"
2023-06-24 04:33:24 +02:00
)
type Debian struct {
NameSubstr string
Relver string
URL string
}
func (d Debian) AddNewTorrents(transmissionbt *transmissionrpc.Client) error {
// Set torrentURLs for Debian GNU/Linux mirror
d.URL = "https://cdimage.debian.org/debian-cd/current/"
torrentURLs := []string{
fmt.Sprintf("%s/amd64/bt-dvd/debian-%s-amd64-DVD-1.iso.torrent", d.URL, d.Relver),
fmt.Sprintf("%s/arm64/bt-dvd/debian-%s-arm64-DVD-1.iso.torrent", d.URL, d.Relver),
fmt.Sprintf("%s/ppc64el/bt-dvd/debian-%s-ppc64el-DVD-1.iso.torrent", d.URL, d.Relver),
fmt.Sprintf("%s/s390x/bt-dvd/debian-%s-s390x-DVD-1.iso.torrent", d.URL, d.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 (d Debian) RemoveOldTorrents(transmissionbt *transmissionrpc.Client) error {
2023-06-26 10:13:00 +02:00
if err := common.RemoveTorrents(d.NameSubstr, d.Relver, transmissionbt); err != nil {
2023-06-24 04:33:24 +02:00
return err
}
return nil
}