2023-10-26 02:45:21 +02:00
|
|
|
qpackage qubes
|
2023-06-24 04:33:24 +02:00
|
|
|
|
|
|
|
import (
|
2023-07-18 04:54:36 +02:00
|
|
|
"fmt"
|
2023-06-24 04:33:24 +02:00
|
|
|
"log"
|
2023-07-17 04:28:25 +02:00
|
|
|
"strings"
|
2023-06-24 04:33:24 +02:00
|
|
|
|
2023-07-18 04:54:36 +02:00
|
|
|
"github.com/PuerkitoBio/goquery"
|
2023-06-24 04:33:24 +02:00
|
|
|
"github.com/hekmon/transmissionrpc"
|
2023-10-26 02:45:21 +02:00
|
|
|
"git.sr.ht/~hyperreal/go-torrent-helper/common"
|
2023-06-24 04:33:24 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
type Qubes struct {
|
|
|
|
NameSubstr string
|
|
|
|
Relver string
|
|
|
|
URL string
|
|
|
|
}
|
|
|
|
|
|
|
|
func (q Qubes) AddNewTorrents(transmissionbt *transmissionrpc.Client) error {
|
|
|
|
// Set torrentURLs for Qubes OS
|
2023-07-18 04:54:36 +02:00
|
|
|
q.URL = "https://mirrors.edge.kernel.org/qubes/iso/"
|
|
|
|
respBody, err := common.GetResponse(q.URL)
|
2023-06-24 04:33:24 +02:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2023-07-18 04:54:36 +02:00
|
|
|
// Get a goquery doc from response body
|
|
|
|
doc, err := goquery.NewDocumentFromReader(respBody)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2023-07-17 04:28:25 +02:00
|
|
|
|
|
|
|
// Extract torrent URLs from web page contents
|
|
|
|
var torrentURLs []string
|
2023-07-18 04:54:36 +02:00
|
|
|
doc.Find("a").Each(func(i int, s *goquery.Selection) {
|
2023-07-25 03:43:53 +02:00
|
|
|
if strings.Contains(s.Text(), q.Relver) && strings.Contains(s.Text(), "torrent") && !strings.Contains(s.Text(), "rc") {
|
2023-07-18 04:54:36 +02:00
|
|
|
torrentURLs = append(torrentURLs, fmt.Sprintf("%s/%s", q.URL, s.Text()))
|
2023-07-17 04:28:25 +02:00
|
|
|
}
|
2023-07-18 04:54:36 +02:00
|
|
|
})
|
2023-07-17 04:28:25 +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)
|
|
|
|
}
|
2023-06-24 04:33:24 +02:00
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (q Qubes) RemoveOldTorrents(transmissionbt *transmissionrpc.Client) error {
|
|
|
|
if err := common.RemoveTorrents(q.NameSubstr, q.Relver, transmissionbt); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|