mirror of
https://github.com/idanoo/autobrr
synced 2025-07-22 16:29:12 +00:00

* Add support for the 'Test' button to work * Make Porla show up in filter actions select * Add an empty Porla action * Make Porla action find download client * Make implementation actually add torrent to Porla * Fix qBittorrent import * Finish up Porla action * Check length on commitish before slicing * Move Porla to the other DL clients * Add Porla to type name map * Move Porla to beneath the other download clients
79 lines
2.1 KiB
Go
79 lines
2.1 KiB
Go
package action
|
|
|
|
import (
|
|
"bufio"
|
|
"context"
|
|
"encoding/base64"
|
|
"io/ioutil"
|
|
"os"
|
|
|
|
"github.com/autobrr/autobrr/internal/domain"
|
|
"github.com/autobrr/autobrr/pkg/errors"
|
|
"github.com/autobrr/autobrr/pkg/porla"
|
|
"github.com/dcarbone/zadapters/zstdlog"
|
|
"github.com/rs/zerolog"
|
|
)
|
|
|
|
func (s *service) porla(action domain.Action, release domain.Release) ([]string, error) {
|
|
s.log.Debug().Msgf("action Porla: %v", action.Name)
|
|
|
|
client, err := s.clientSvc.FindByID(context.TODO(), action.ClientID)
|
|
if err != nil {
|
|
return nil, errors.Wrap(err, "error finding client: %v", action.ClientID)
|
|
}
|
|
|
|
if client == nil {
|
|
return nil, errors.New("could not find client by id: %v", action.ClientID)
|
|
}
|
|
|
|
porlaSettings := porla.Settings{
|
|
Hostname: client.Host,
|
|
AuthToken: client.Settings.APIKey,
|
|
}
|
|
|
|
porlaSettings.Log = zstdlog.NewStdLoggerWithLevel(s.log.With().Str("type", "Porla").Str("client", client.Name).Logger(), zerolog.TraceLevel)
|
|
|
|
prl := porla.NewClient(porlaSettings)
|
|
|
|
if release.TorrentTmpFile == "" {
|
|
if err := release.DownloadTorrentFile(); err != nil {
|
|
return nil, errors.Wrap(err, "error downloading torrent file for release: %v", release.TorrentName)
|
|
}
|
|
}
|
|
|
|
file, err := os.Open(release.TorrentTmpFile)
|
|
if err != nil {
|
|
return nil, errors.Wrap(err, "error opening file %v", release.TorrentTmpFile)
|
|
}
|
|
defer file.Close()
|
|
|
|
reader := bufio.NewReader(file)
|
|
content, err := ioutil.ReadAll(reader)
|
|
|
|
if err != nil {
|
|
return nil, errors.Wrap(err, "failed to read file: %v", release.TorrentTmpFile)
|
|
}
|
|
|
|
opts := &porla.TorrentsAddReq{
|
|
DownloadLimit: -1,
|
|
SavePath: action.SavePath,
|
|
Ti: base64.StdEncoding.EncodeToString(content),
|
|
UploadLimit: -1,
|
|
}
|
|
|
|
if action.LimitDownloadSpeed > 0 {
|
|
opts.DownloadLimit = action.LimitDownloadSpeed * 1000
|
|
}
|
|
|
|
if action.LimitUploadSpeed > 0 {
|
|
opts.UploadLimit = action.LimitUploadSpeed * 1000
|
|
}
|
|
|
|
if err = prl.TorrentsAdd(opts); err != nil {
|
|
return nil, errors.Wrap(err, "could not add torrent %v to client: %v", release.TorrentTmpFile, client.Name)
|
|
}
|
|
|
|
s.log.Info().Msgf("torrent with hash %v successfully added to client: '%v'", release.TorrentHash, client.Name)
|
|
|
|
return nil, nil
|
|
}
|