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
|
@ -11,48 +11,65 @@ import (
|
|||
)
|
||||
|
||||
func (s *service) qbittorrent(ctx context.Context, action *domain.Action, release domain.Release) ([]string, error) {
|
||||
s.log.Debug().Msgf("action qBittorrent: %v", action.Name)
|
||||
s.log.Debug().Msgf("action qBittorrent: %s", action.Name)
|
||||
|
||||
c := s.clientSvc.GetCachedClient(ctx, action.ClientID)
|
||||
|
||||
rejections, err := s.qbittorrentCheckRulesCanDownload(ctx, action, c.Dc, c.Qbt)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "error checking client rules: %v", action.Name)
|
||||
return nil, errors.Wrap(err, "error checking client rules: %s", action.Name)
|
||||
}
|
||||
|
||||
if len(rejections) > 0 {
|
||||
return rejections, nil
|
||||
}
|
||||
|
||||
if release.TorrentTmpFile == "" {
|
||||
if err := release.DownloadTorrentFileCtx(ctx); err != nil {
|
||||
return nil, errors.Wrap(err, "error downloading torrent file for release: %v", release.TorrentName)
|
||||
if release.HasMagnetUri() {
|
||||
options, err := s.prepareQbitOptions(action)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "could not prepare options")
|
||||
}
|
||||
}
|
||||
|
||||
options, err := s.prepareQbitOptions(action)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "could not prepare options")
|
||||
}
|
||||
s.log.Trace().Msgf("action qBittorrent options: %+v", options)
|
||||
|
||||
s.log.Trace().Msgf("action qBittorrent options: %+v", options)
|
||||
|
||||
if err = c.Qbt.AddTorrentFromFileCtx(ctx, release.TorrentTmpFile, options); err != nil {
|
||||
return nil, errors.Wrap(err, "could not add torrent %v to client: %v", release.TorrentTmpFile, c.Dc.Name)
|
||||
}
|
||||
|
||||
if !action.Paused && !action.ReAnnounceSkip && release.TorrentHash != "" {
|
||||
opts := qbittorrent.ReannounceOptions{
|
||||
Interval: int(action.ReAnnounceInterval),
|
||||
MaxAttempts: int(action.ReAnnounceMaxAttempts),
|
||||
DeleteOnFailure: action.ReAnnounceDelete,
|
||||
if err = c.Qbt.AddTorrentFromUrlCtx(ctx, release.MagnetURI, options); err != nil {
|
||||
return nil, errors.Wrap(err, "could not add torrent %s to client: %s", release.MagnetURI, c.Dc.Name)
|
||||
}
|
||||
if err := c.Qbt.ReannounceTorrentWithRetry(ctx, opts, release.TorrentHash); err != nil {
|
||||
return nil, errors.Wrap(err, "could not reannounce torrent: %v", release.TorrentHash)
|
||||
}
|
||||
}
|
||||
|
||||
s.log.Info().Msgf("torrent with hash %v successfully added to client: '%v'", release.TorrentHash, c.Dc.Name)
|
||||
s.log.Info().Msgf("torrent from magnet successfully added to client: '%s'", c.Dc.Name)
|
||||
|
||||
return nil, nil
|
||||
} else {
|
||||
if release.TorrentTmpFile == "" {
|
||||
if err := release.DownloadTorrentFileCtx(ctx); err != nil {
|
||||
return nil, errors.Wrap(err, "error downloading torrent file for release: %s", release.TorrentName)
|
||||
}
|
||||
}
|
||||
|
||||
options, err := s.prepareQbitOptions(action)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "could not prepare options")
|
||||
}
|
||||
|
||||
s.log.Trace().Msgf("action qBittorrent options: %+v", options)
|
||||
|
||||
if err = c.Qbt.AddTorrentFromFileCtx(ctx, release.TorrentTmpFile, options); err != nil {
|
||||
return nil, errors.Wrap(err, "could not add torrent %s to client: %s", release.TorrentTmpFile, c.Dc.Name)
|
||||
}
|
||||
|
||||
if !action.Paused && !action.ReAnnounceSkip && release.TorrentHash != "" {
|
||||
opts := qbittorrent.ReannounceOptions{
|
||||
Interval: int(action.ReAnnounceInterval),
|
||||
MaxAttempts: int(action.ReAnnounceMaxAttempts),
|
||||
DeleteOnFailure: action.ReAnnounceDelete,
|
||||
}
|
||||
if err := c.Qbt.ReannounceTorrentWithRetry(ctx, opts, release.TorrentHash); err != nil {
|
||||
return nil, errors.Wrap(err, "could not reannounce torrent: %s", release.TorrentHash)
|
||||
}
|
||||
}
|
||||
|
||||
s.log.Info().Msgf("torrent with hash %s successfully added to client: '%s'", release.TorrentHash, c.Dc.Name)
|
||||
}
|
||||
|
||||
return nil, nil
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue