mirror of
https://github.com/idanoo/autobrr
synced 2025-07-23 00:39:13 +00:00
feat(releases): support magnet links (#730)
* feat(releases): support magnet links * feat(feeds): support magnet links * feat(actions): log messages * fix: component warning * fix: check hasprefix instead of hassuffix for magnet * feat(release): resolve magnet uri from link * fix(actions): deluge use magnet uri * fix(macros): add `MagnetURI` var * fix(actions): run magnet resolving before macros * feat(feeds): set download type on creation
This commit is contained in:
parent
c6101cc765
commit
ca196f0bf1
32 changed files with 770 additions and 260 deletions
|
@ -10,60 +10,83 @@ import (
|
|||
)
|
||||
|
||||
func (s *service) transmission(ctx context.Context, action *domain.Action, release domain.Release) ([]string, error) {
|
||||
s.log.Debug().Msgf("action Transmission: %v", action.Name)
|
||||
s.log.Debug().Msgf("action Transmission: %s", action.Name)
|
||||
|
||||
var err error
|
||||
|
||||
// get client for action
|
||||
client, err := s.clientSvc.FindByID(ctx, action.ClientID)
|
||||
if err != nil {
|
||||
s.log.Error().Stack().Err(err).Msgf("error finding client: %v", action.ClientID)
|
||||
s.log.Error().Stack().Err(err).Msgf("error finding client: %d", action.ClientID)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if client == nil {
|
||||
return nil, errors.New("could not find client by id: %v", action.ClientID)
|
||||
return nil, errors.New("could not find client by id: %d", action.ClientID)
|
||||
}
|
||||
|
||||
var rejections []string
|
||||
|
||||
if release.TorrentTmpFile == "" {
|
||||
if err := release.DownloadTorrentFileCtx(ctx); err != nil {
|
||||
s.log.Error().Err(err).Msgf("could not download torrent file for release: %v", release.TorrentName)
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
tbt, err := transmissionrpc.New(client.Host, client.Username, client.Password, &transmissionrpc.AdvancedConfig{
|
||||
HTTPS: client.TLS,
|
||||
Port: uint16(client.Port),
|
||||
})
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "error logging into client: %v", client.Host)
|
||||
return nil, errors.Wrap(err, "error logging into client: %s", client.Host)
|
||||
}
|
||||
|
||||
b64, err := transmissionrpc.File2Base64(release.TorrentTmpFile)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "cant encode file %v into base64", release.TorrentTmpFile)
|
||||
}
|
||||
if release.HasMagnetUri() {
|
||||
payload := transmissionrpc.TorrentAddPayload{
|
||||
Filename: &release.MagnetURI,
|
||||
}
|
||||
if action.SavePath != "" {
|
||||
payload.DownloadDir = &action.SavePath
|
||||
}
|
||||
if action.Paused {
|
||||
payload.Paused = &action.Paused
|
||||
}
|
||||
|
||||
payload := transmissionrpc.TorrentAddPayload{
|
||||
MetaInfo: &b64,
|
||||
}
|
||||
if action.SavePath != "" {
|
||||
payload.DownloadDir = &action.SavePath
|
||||
}
|
||||
if action.Paused {
|
||||
payload.Paused = &action.Paused
|
||||
}
|
||||
// Prepare and send payload
|
||||
torrent, err := tbt.TorrentAdd(ctx, payload)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "could not add torrent from magnet %s to client: %s", release.MagnetURI, client.Host)
|
||||
}
|
||||
|
||||
// Prepare and send payload
|
||||
torrent, err := tbt.TorrentAdd(ctx, payload)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "could not add torrent %v to client: %v", release.TorrentTmpFile, client.Host)
|
||||
}
|
||||
s.log.Info().Msgf("torrent from magnet with hash %v successfully added to client: '%s'", torrent.HashString, client.Name)
|
||||
|
||||
s.log.Info().Msgf("torrent with hash %v successfully added to client: '%v'", torrent.HashString, client.Name)
|
||||
return nil, nil
|
||||
|
||||
} else {
|
||||
if release.TorrentTmpFile == "" {
|
||||
if err := release.DownloadTorrentFileCtx(ctx); err != nil {
|
||||
s.log.Error().Err(err).Msgf("could not download torrent file for release: %s", release.TorrentName)
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
b64, err := transmissionrpc.File2Base64(release.TorrentTmpFile)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "cant encode file %s into base64", release.TorrentTmpFile)
|
||||
}
|
||||
|
||||
payload := transmissionrpc.TorrentAddPayload{
|
||||
MetaInfo: &b64,
|
||||
}
|
||||
if action.SavePath != "" {
|
||||
payload.DownloadDir = &action.SavePath
|
||||
}
|
||||
if action.Paused {
|
||||
payload.Paused = &action.Paused
|
||||
}
|
||||
|
||||
// Prepare and send payload
|
||||
torrent, err := tbt.TorrentAdd(ctx, payload)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "could not add torrent %v to client: %v", release.TorrentTmpFile, client.Host)
|
||||
}
|
||||
|
||||
s.log.Info().Msgf("torrent with hash %v successfully added to client: '%s'", torrent.HashString, client.Name)
|
||||
}
|
||||
|
||||
return rejections, nil
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue