2023-06-24 04:33:24 +02:00
|
|
|
package parrot
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"log"
|
2023-07-17 04:28:25 +02:00
|
|
|
"regexp"
|
|
|
|
"strings"
|
2023-06-24 04:33:24 +02:00
|
|
|
|
|
|
|
"github.com/hekmon/transmissionrpc"
|
2023-07-17 04:28:25 +02:00
|
|
|
"tildegit.org/hyperreal/go-torrent-helper/common"
|
2023-06-24 04:33:24 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
type Parrot struct {
|
|
|
|
NameSubstr string
|
|
|
|
Relver string
|
|
|
|
URL string
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p Parrot) AddNewTorrents(transmissionbt *transmissionrpc.Client) error {
|
|
|
|
// Set torrentURLs for Parrot Security
|
2023-07-17 04:28:25 +02:00
|
|
|
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)
|
|
|
|
}
|
2023-06-24 04:33:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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 (p Parrot) RemoveOldTorrents(transmissionbt *transmissionrpc.Client) error {
|
|
|
|
if err := common.RemoveTorrents(p.NameSubstr, p.Relver, transmissionbt); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|