package qubes import ( "log" "regexp" "strings" "github.com/hekmon/transmissionrpc" "tildegit.org/hyperreal/go-torrent-helper/common" ) type Qubes struct { NameSubstr string Relver string URL string } func (q Qubes) AddNewTorrents(transmissionbt *transmissionrpc.Client) error { // Set torrentURLs for Qubes OS q.URL = "https://mirrors.edge.kernel.org/qubes/iso/Qubes/iso/" dataInBytes, err := common.GetResponse(q.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") && 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 } func (q Qubes) RemoveOldTorrents(transmissionbt *transmissionrpc.Client) error { if err := common.RemoveTorrents(q.NameSubstr, q.Relver, transmissionbt); err != nil { return err } return nil }