mirror of
https://codeberg.org/hyperreal/go-torrent-helper
synced 2024-11-01 16:53:09 +01:00
Fix torrent URL extraction
This commit is contained in:
parent
eedd50a88f
commit
9822eaedc4
@ -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
|
||||
|
@ -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,18 +17,35 @@ 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)
|
||||
|
||||
// Add torrent to Transmission instance
|
||||
torrent, err := transmissionbt.TorrentAdd(&transmissionrpc.TorrentAddPayload{
|
||||
Filename: &torrentURL,
|
||||
})
|
||||
q.URL = "https://mirrors.edge.kernel.org/qubes/iso/Qubes/iso/"
|
||||
dataInBytes, err := common.GetResponse(q.URL)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
log.Printf("%s added\n", *torrent.Name)
|
||||
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,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
log.Printf("%s added\n", *torrent.Name)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user