mirror of
https://github.com/idanoo/autobrr
synced 2025-07-22 16:29:12 +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
|
@ -48,44 +48,69 @@ func (s *service) porla(ctx context.Context, action *domain.Action, release doma
|
|||
return rejections, nil
|
||||
}
|
||||
|
||||
if release.TorrentTmpFile == "" {
|
||||
if err := release.DownloadTorrentFile(); err != nil {
|
||||
return nil, errors.Wrap(err, "error downloading torrent file for release: %s", release.TorrentName)
|
||||
if release.HasMagnetUri() {
|
||||
opts := &porla.TorrentsAddReq{
|
||||
DownloadLimit: -1,
|
||||
UploadLimit: -1,
|
||||
SavePath: action.SavePath,
|
||||
MagnetUri: release.MagnetURI,
|
||||
}
|
||||
}
|
||||
|
||||
file, err := os.Open(release.TorrentTmpFile)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "error opening file %s", release.TorrentTmpFile)
|
||||
}
|
||||
defer file.Close()
|
||||
if action.LimitDownloadSpeed > 0 {
|
||||
opts.DownloadLimit = action.LimitDownloadSpeed * 1000
|
||||
}
|
||||
|
||||
reader := bufio.NewReader(file)
|
||||
content, err := io.ReadAll(reader)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed to read file: %s", release.TorrentTmpFile)
|
||||
}
|
||||
if action.LimitUploadSpeed > 0 {
|
||||
opts.UploadLimit = action.LimitUploadSpeed * 1000
|
||||
}
|
||||
|
||||
opts := &porla.TorrentsAddReq{
|
||||
DownloadLimit: -1,
|
||||
SavePath: action.SavePath,
|
||||
Ti: base64.StdEncoding.EncodeToString(content),
|
||||
UploadLimit: -1,
|
||||
}
|
||||
if err = prl.TorrentsAdd(ctx, opts); err != nil {
|
||||
return nil, errors.Wrap(err, "could not add torrent from magnet %s to client: %s", release.MagnetURI, client.Name)
|
||||
}
|
||||
|
||||
if action.LimitDownloadSpeed > 0 {
|
||||
opts.DownloadLimit = action.LimitDownloadSpeed * 1000
|
||||
}
|
||||
s.log.Info().Msgf("torrent with hash %s successfully added to client: '%s'", release.TorrentHash, client.Name)
|
||||
|
||||
if action.LimitUploadSpeed > 0 {
|
||||
opts.UploadLimit = action.LimitUploadSpeed * 1000
|
||||
}
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
if err = prl.TorrentsAdd(ctx, opts); err != nil {
|
||||
return nil, errors.Wrap(err, "could not add torrent %v to client: %v", release.TorrentTmpFile, client.Name)
|
||||
}
|
||||
file, err := os.Open(release.TorrentTmpFile)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "error opening file %s", release.TorrentTmpFile)
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
s.log.Info().Msgf("torrent with hash %v successfully added to client: '%v'", release.TorrentHash, client.Name)
|
||||
reader := bufio.NewReader(file)
|
||||
content, err := io.ReadAll(reader)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed to read file: %s", 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(ctx, opts); err != nil {
|
||||
return nil, errors.Wrap(err, "could not add torrent %s to client: %s", release.TorrentTmpFile, client.Name)
|
||||
}
|
||||
|
||||
s.log.Info().Msgf("torrent with hash %s successfully added to client: '%s'", release.TorrentHash, client.Name)
|
||||
}
|
||||
|
||||
return nil, nil
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue