Add support for FreeBSD torrents

This commit is contained in:
Jeffrey Serio 2023-07-18 21:48:09 -05:00
parent 7818fe5ab8
commit 7bbf0d0c1c
2 changed files with 70 additions and 7 deletions

View File

@ -10,6 +10,7 @@ import (
"tildegit.org/hyperreal/go-torrent-helper/almalinux" "tildegit.org/hyperreal/go-torrent-helper/almalinux"
"tildegit.org/hyperreal/go-torrent-helper/debian" "tildegit.org/hyperreal/go-torrent-helper/debian"
"tildegit.org/hyperreal/go-torrent-helper/fedora" "tildegit.org/hyperreal/go-torrent-helper/fedora"
"tildegit.org/hyperreal/go-torrent-helper/freebsd"
"tildegit.org/hyperreal/go-torrent-helper/nixos" "tildegit.org/hyperreal/go-torrent-helper/nixos"
"tildegit.org/hyperreal/go-torrent-helper/parrot" "tildegit.org/hyperreal/go-torrent-helper/parrot"
"tildegit.org/hyperreal/go-torrent-helper/qubes" "tildegit.org/hyperreal/go-torrent-helper/qubes"
@ -123,13 +124,14 @@ func (r *RemoveCmd) Run(d Distro) error {
func (l *ListCmd) Run(d Distro) error { func (l *ListCmd) Run(d Distro) error {
supportedDistros := []string{ supportedDistros := []string{
"AlmaLinux", "almalinux",
"Debian", "debian",
"Fedora", "fedora",
"NixOS", "freebsd",
"Parrot OS", "nixos",
"Qubes OS", "parrot",
"Rocky Linux", "qubes",
"rocky",
} }
fmt.Println("Supported distributions:") fmt.Println("Supported distributions:")
@ -197,6 +199,10 @@ func Root(args []string) error {
f := &fedora.Fedora{NameSubstr: "Fedora", Relver: relver} f := &fedora.Fedora{NameSubstr: "Fedora", Relver: relver}
return cmd.Run(f) return cmd.Run(f)
case "freebsd":
fb := &freebsd.FreeBSD{NameSubstr: "FreeBSD", Relver: relver}
return cmd.Run(fb)
case "nixos": case "nixos":
n := &nixos.Nixos{NameSubstr: "nixos"} n := &nixos.Nixos{NameSubstr: "nixos"}
return cmd.Run(n) return cmd.Run(n)

57
freebsd/main.go Normal file
View File

@ -0,0 +1,57 @@
package freebsd
import (
"bufio"
"fmt"
"log"
"strings"
"github.com/hekmon/transmissionrpc"
"tildegit.org/hyperreal/go-torrent-helper/common"
)
type FreeBSD struct {
NameSubstr string
Relver string
URL string
}
func (fb FreeBSD) AddNewTorrents(transmissionbt *transmissionrpc.Client) error {
fb.URL = fmt.Sprintf("https://people.freebsd.org/~jmg/FreeBSD-%s-R-magnet.txt", fb.Relver)
respBody, err := common.GetResponse(fb.URL)
if err != nil {
return err
}
// Iterate throw lines of response body (FreeBSD-%s-R-magnet.txt)
fileScanner := bufio.NewScanner(respBody)
fileScanner.Split(bufio.ScanLines)
var torrentURLs []string
for fileScanner.Scan() {
if strings.Contains(fileScanner.Text(), "magnet:?") {
torrentURLs = append(torrentURLs, fileScanner.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 (fb FreeBSD) RemoveOldTorrents(transmissionbt *transmissionrpc.Client) error {
if err := common.RemoveTorrents(fb.NameSubstr, fb.Relver, transmissionbt); err != nil {
return err
}
return nil
}