refactor: download torrent files (#144)

* refactor: download torrent file

* refactor: remove return struct

* chore: remove unused method
This commit is contained in:
Ludvig Lundgren 2022-02-17 19:08:29 +01:00 committed by GitHub
parent 43c42a7ee8
commit a18e2bc09d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 31 additions and 69 deletions

View file

@ -13,7 +13,7 @@ import (
const ReannounceMaxAttempts = 50
const ReannounceInterval = 7000
func (s *service) qbittorrent(qbt *qbittorrent.Client, action domain.Action, hash string, torrentFile string) error {
func (s *service) qbittorrent(qbt *qbittorrent.Client, action domain.Action, torrentFile string, hash string) error {
log.Debug().Msgf("action qBittorrent: %v", action.Name)
options := map[string]string{}

View file

@ -47,8 +47,6 @@ func (s *service) RunActions(actions []domain.Action, release domain.Release) er
func (s *service) runAction(action domain.Action, release domain.Release) error {
var err error
var tmpFile string
var hash string
var rejections []string
switch action.Type {
@ -57,33 +55,23 @@ func (s *service) runAction(action domain.Action, release domain.Release) error
case domain.ActionTypeExec:
if release.TorrentTmpFile == "" {
t, err := release.DownloadTorrentFile(nil)
if err != nil {
if err := release.DownloadTorrentFile(nil); err != nil {
log.Error().Stack().Err(err)
return err
}
tmpFile = t.TmpFileName
} else {
tmpFile = release.TorrentTmpFile
}
s.execCmd(release, action, tmpFile)
s.execCmd(release, action, release.TorrentTmpFile)
case domain.ActionTypeWatchFolder:
if release.TorrentTmpFile == "" {
t, err := release.DownloadTorrentFile(nil)
if err != nil {
if err := release.DownloadTorrentFile(nil); err != nil {
log.Error().Stack().Err(err)
return err
}
tmpFile = t.TmpFileName
} else {
tmpFile = release.TorrentTmpFile
}
s.watchFolder(action.WatchFolder, tmpFile)
s.watchFolder(action.WatchFolder, release.TorrentTmpFile)
case domain.ActionTypeDelugeV1, domain.ActionTypeDelugeV2:
canDownload, err := s.delugeCheckRulesCanDownload(action)
@ -97,18 +85,13 @@ func (s *service) runAction(action domain.Action, release domain.Release) error
}
if release.TorrentTmpFile == "" {
t, err := release.DownloadTorrentFile(nil)
if err != nil {
if err := release.DownloadTorrentFile(nil); err != nil {
log.Error().Stack().Err(err)
return err
}
tmpFile = t.TmpFileName
} else {
tmpFile = release.TorrentTmpFile
}
err = s.deluge(action, tmpFile)
err = s.deluge(action, release.TorrentTmpFile)
if err != nil {
log.Error().Stack().Err(err).Msg("error sending torrent to Deluge")
return err
@ -126,19 +109,13 @@ func (s *service) runAction(action domain.Action, release domain.Release) error
}
if release.TorrentTmpFile == "" {
t, err := release.DownloadTorrentFile(nil)
if err != nil {
if err := release.DownloadTorrentFile(nil); err != nil {
log.Error().Stack().Err(err)
return err
}
tmpFile = t.TmpFileName
hash = t.MetaInfo.HashInfoBytes().String()
} else {
tmpFile = release.TorrentTmpFile
}
err = s.qbittorrent(client, action, hash, tmpFile)
err = s.qbittorrent(client, action, release.TorrentTmpFile, release.TorrentHash)
if err != nil {
log.Error().Stack().Err(err).Msg("error sending torrent to qBittorrent")
return err