mirror of
https://codeberg.org/hyperreal/go-torrent-helper
synced 2024-11-01 16:53:09 +01:00
Add support for FreeBSD torrents
This commit is contained in:
parent
7818fe5ab8
commit
7bbf0d0c1c
@ -10,6 +10,7 @@ import (
|
||||
"tildegit.org/hyperreal/go-torrent-helper/almalinux"
|
||||
"tildegit.org/hyperreal/go-torrent-helper/debian"
|
||||
"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/parrot"
|
||||
"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 {
|
||||
supportedDistros := []string{
|
||||
"AlmaLinux",
|
||||
"Debian",
|
||||
"Fedora",
|
||||
"NixOS",
|
||||
"Parrot OS",
|
||||
"Qubes OS",
|
||||
"Rocky Linux",
|
||||
"almalinux",
|
||||
"debian",
|
||||
"fedora",
|
||||
"freebsd",
|
||||
"nixos",
|
||||
"parrot",
|
||||
"qubes",
|
||||
"rocky",
|
||||
}
|
||||
|
||||
fmt.Println("Supported distributions:")
|
||||
@ -197,6 +199,10 @@ func Root(args []string) error {
|
||||
f := &fedora.Fedora{NameSubstr: "Fedora", Relver: relver}
|
||||
return cmd.Run(f)
|
||||
|
||||
case "freebsd":
|
||||
fb := &freebsd.FreeBSD{NameSubstr: "FreeBSD", Relver: relver}
|
||||
return cmd.Run(fb)
|
||||
|
||||
case "nixos":
|
||||
n := &nixos.Nixos{NameSubstr: "nixos"}
|
||||
return cmd.Run(n)
|
||||
|
57
freebsd/main.go
Normal file
57
freebsd/main.go
Normal 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
|
||||
}
|
Loading…
Reference in New Issue
Block a user