mirror of
https://codeberg.org/hyperreal/go-torrent-helper
synced 2024-11-25 04:03:42 +01:00
Add NetBSD
This commit is contained in:
parent
e48e2e30e9
commit
841120a26b
@ -12,6 +12,7 @@ import (
|
||||
"codeberg.org/hyperreal/go-torrent-helper/fedora"
|
||||
"codeberg.org/hyperreal/go-torrent-helper/freebsd"
|
||||
"codeberg.org/hyperreal/go-torrent-helper/kali"
|
||||
"codeberg.org/hyperreal/go-torrent-helper/netbsd"
|
||||
"codeberg.org/hyperreal/go-torrent-helper/nixos"
|
||||
"codeberg.org/hyperreal/go-torrent-helper/parrot"
|
||||
"codeberg.org/hyperreal/go-torrent-helper/qubes"
|
||||
@ -133,6 +134,7 @@ func (l *ListCmd) Run(d Distro) error {
|
||||
"fedora",
|
||||
"freebsd",
|
||||
"kali",
|
||||
"netbsd",
|
||||
"nixos",
|
||||
"parrot",
|
||||
"qubes",
|
||||
@ -217,6 +219,10 @@ func Root(args []string) error {
|
||||
k := &kali.Kali{NameSubstr: "kali-linux", Relver: relver}
|
||||
return cmd.Run(k)
|
||||
|
||||
case "netbsd":
|
||||
nb := &netbsd.NetBSD{NameSubstr: "NetBSD", Relver: relver}
|
||||
return cmd.Run(nb)
|
||||
|
||||
case "nixos":
|
||||
n := &nixos.Nixos{NameSubstr: "nixos"}
|
||||
return cmd.Run(n)
|
||||
|
62
netbsd/main.go
Normal file
62
netbsd/main.go
Normal file
@ -0,0 +1,62 @@
|
||||
package netbsd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"strings"
|
||||
|
||||
"codeberg.org/hyperreal/go-torrent-helper/common"
|
||||
"github.com/PuerkitoBio/goquery"
|
||||
"github.com/hekmon/transmissionrpc"
|
||||
)
|
||||
|
||||
type NetBSD struct {
|
||||
NameSubstr string
|
||||
Relver string
|
||||
URL string
|
||||
}
|
||||
|
||||
func (nb NetBSD) AddNewTorrents(transmissionbt *transmissionrpc.Client) error {
|
||||
// Send HTTP GET request and receive response
|
||||
nb.URL = fmt.Sprintf("https://cdn.netbsd.org/pub/NetBSD/NetBSD-%s/images", nb.Relver)
|
||||
respBody, err := common.GetResponse(nb.URL)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Get a goquery doc from response body
|
||||
doc, err := goquery.NewDocumentFromReader(respBody)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Extract torrent URLs from web page source
|
||||
var torrentURLs []string
|
||||
doc.Find("a").Each(func(i int, s *goquery.Selection) {
|
||||
if strings.Contains(s.Text(), ".torrent") {
|
||||
torrentURLs = append(torrentURLs, fmt.Sprintf("%s/%s", nb.URL, s.Text()))
|
||||
}
|
||||
})
|
||||
|
||||
// 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 (nb NetBSD) RemoveOldTorrents(transmissionbt *transmissionrpc.Client) error {
|
||||
if err := common.RemoveTorrents(nb.NameSubstr, nb.Relver, transmissionbt); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
Loading…
Reference in New Issue
Block a user