Fix torrent URL extraction

This commit is contained in:
Jeffrey Serio 2023-07-16 21:28:25 -05:00
parent eedd50a88f
commit 9822eaedc4
3 changed files with 70 additions and 29 deletions

View File

@ -3,9 +3,11 @@ package parrot
import (
"fmt"
"log"
"regexp"
"strings"
"tildegit.org/hyperreal/go-torrent-helper/common"
"github.com/hekmon/transmissionrpc"
"tildegit.org/hyperreal/go-torrent-helper/common"
)
type Parrot struct {
@ -16,17 +18,22 @@ type Parrot struct {
func (p Parrot) AddNewTorrents(transmissionbt *transmissionrpc.Client) error {
// Set torrentURLs for Parrot Security
p.URL = "https://deb.parrot.sh/parrot/"
torrentURLs := []string{
fmt.Sprintf("%s/iso/%s/Parrot-security-%s_amd64.iso.torrent", p.URL, p.Relver, p.Relver),
fmt.Sprintf("%s/iso/%s/Parrot-security-%s_amd64.ova.torrent", p.URL, p.Relver, p.Relver),
fmt.Sprintf("%s/iso/%s/Parrot-security-%s_arm64.utm.torrent", p.URL, p.Relver, p.Relver),
fmt.Sprintf("%s/iso/%s/Parrot-home-%s_amd64.iso.torrent", p.URL, p.Relver, p.Relver),
fmt.Sprintf("%s/iso/%s/Parrot-home-%s_amd64.ova.torrent", p.URL, p.Relver, p.Relver),
fmt.Sprintf("%s/iso/%s/Parrot-home-%s_arm64.utm.torrent", p.URL, p.Relver, p.Relver),
fmt.Sprintf("%s/iso/%s/Parrot-htb-%s_amd64.iso.torrent", p.URL, p.Relver, p.Relver),
fmt.Sprintf("%s/iso/%s/Parrot-architect-%s_arm64.iso.torrent", p.URL, p.Relver, p.Relver),
fmt.Sprintf("%s/iso/%s/Parrot-architect-%s_amd64.iso.torrent", p.URL, p.Relver, p.Relver),
p.URL = fmt.Sprintf("https://deb.parrot.sh/parrot/iso/%s/", p.Relver)
dataInBytes, err := common.GetResponse(p.URL)
if err != nil {
return err
}
bodyText := string(dataInBytes)
// Extract torrent URLs from web page contents
var torrentURLs []string
re := regexp.MustCompile(`(http|ftp|https):\/\/([\w_-]+(?:(?:\.[\w_-]+)+))([\w.,@?^=%&:\/~+#-]*[\w@?^=%&\/~+#-])`)
match := re.FindAllString(bodyText, 1000)
for _, v := range match {
if strings.Contains(v, ".torrent") {
torrentURLs = append(torrentURLs, v)
}
}
// Add torrents to Transmission instance

View File

@ -1,11 +1,12 @@
package qubes
import (
"fmt"
"log"
"regexp"
"strings"
"tildegit.org/hyperreal/go-torrent-helper/common"
"github.com/hekmon/transmissionrpc"
"tildegit.org/hyperreal/go-torrent-helper/common"
)
type Qubes struct {
@ -16,10 +17,26 @@ type Qubes struct {
func (q Qubes) AddNewTorrents(transmissionbt *transmissionrpc.Client) error {
// Set torrentURLs for Qubes OS
q.URL = "https://mirrors.edge.kernel.org/qubes/iso/Qubes"
torrentURL := fmt.Sprintf("%s-%s-x86_64.torrent", q.URL, q.Relver)
q.URL = "https://mirrors.edge.kernel.org/qubes/iso/Qubes/iso/"
dataInBytes, err := common.GetResponse(q.URL)
if err != nil {
return err
}
// Add torrent to Transmission instance
bodyText := string(dataInBytes)
// Extract torrent URLs from web page contents
var torrentURLs []string
re := regexp.MustCompile(`(http|ftp|https):\/\/([\w_-]+(?:(?:\.[\w_-]+)+))([\w.,@?^=%&:\/~+#-]*[\w@?^=%&\/~+#-])`)
match := re.FindAllString(bodyText, 1000)
for _, v := range match {
if strings.Contains(v, ".torrent") && strings.Contains(v, q.Relver) {
torrentURLs = append(torrentURLs, v)
}
}
// Add torrents to Transmission instance
for _, torrentURL := range torrentURLs {
torrent, err := transmissionbt.TorrentAdd(&transmissionrpc.TorrentAddPayload{
Filename: &torrentURL,
})
@ -28,6 +45,7 @@ func (q Qubes) AddNewTorrents(transmissionbt *transmissionrpc.Client) error {
}
log.Printf("%s added\n", *torrent.Name)
}
return nil
}

View File

@ -3,9 +3,11 @@ package rocky
import (
"fmt"
"log"
"regexp"
"strings"
"tildegit.org/hyperreal/go-torrent-helper/common"
"github.com/hekmon/transmissionrpc"
"tildegit.org/hyperreal/go-torrent-helper/common"
)
type Rocky struct {
@ -16,12 +18,26 @@ type Rocky struct {
func (r Rocky) AddNewTorrents(transmissionbt *transmissionrpc.Client) error {
// Set torrentURLs for Rocky Linux mirror
r.URL = "https://download.rockylinux.org/pub/rocky/"
torrentURLs := []string{
fmt.Sprintf("%s/%s/isos/x86_64/Rocky-%s-x86_64-dvd.torrent", r.URL, r.Relver, r.Relver),
fmt.Sprintf("%s/%s/isos/aarch64/Rocky-%s-aarch64-dvd.torrent", r.URL, r.Relver, r.Relver),
fmt.Sprintf("%s/%s/isos/ppc64le/Rocky-%s-ppc64le-dvd.torrent", r.URL, r.Relver, r.Relver),
fmt.Sprintf("%s/%s/isos/s390x/Rocky-%s-s390x-dvd.torrent", r.URL, r.Relver, r.Relver),
archs := []string{"aarch64", "ppc64le", "s390x", "x86_64"}
var torrentURLs []string
for _, arch := range archs {
r.URL = fmt.Sprintf("https://download.rockylinux.org/pub/rocky/%s/isos/%s/", r.Relver, arch)
dataInBytes, err := common.GetResponse(r.URL)
if err != nil {
return err
}
bodyText := string(dataInBytes)
// Extract torrent URLs from web page contents
re := regexp.MustCompile(`(http|ftp|https):\/\/([\w_-]+(?:(?:\.[\w_-]+)+))([\w.,@?^=%&:\/~+#-]*[\w@?^=%&\/~+#-])`)
match := re.FindAllString(bodyText, 1000)
for _, v := range match {
if strings.Contains(v, ".torrent") {
torrentURLs = append(torrentURLs, v)
}
}
}
// Add torrents to Transmission instance