diff --git a/go.mod b/go.mod index ba8ff58..c1952ca 100644 --- a/go.mod +++ b/go.mod @@ -15,6 +15,7 @@ require ( github.com/go-chi/chi v1.5.4 github.com/gorilla/sessions v1.2.1 github.com/gosimple/slug v1.12.0 + github.com/hekmon/transmissionrpc/v2 v2.0.1 github.com/lib/pq v1.10.4 github.com/mattn/go-shellwords v1.0.12 github.com/moistari/rls v0.2.6 @@ -44,7 +45,9 @@ require ( github.com/google/uuid v1.3.0 // indirect github.com/gorilla/securecookie v1.1.1 // indirect github.com/gosimple/unidecode v1.0.1 // indirect + github.com/hashicorp/go-cleanhttp v0.5.2 // indirect github.com/hashicorp/hcl v1.0.0 // indirect + github.com/hekmon/cunits/v2 v2.1.0 // indirect github.com/huandu/xstrings v1.3.2 // indirect github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect github.com/lann/builder v0.0.0-20180802200727-47ae307949d0 // indirect diff --git a/go.sum b/go.sum index 17934eb..a70af24 100644 --- a/go.sum +++ b/go.sum @@ -275,10 +275,16 @@ github.com/gosuri/uilive v0.0.0-20170323041506-ac356e6e42cd/go.mod h1:qkLSc0A5EX github.com/gosuri/uilive v0.0.3/go.mod h1:qkLSc0A5EXSP6B04TrN4oQoxqFI7A8XvoXSlJi8cwk8= github.com/gosuri/uiprogress v0.0.0-20170224063937-d0567a9d84a1/go.mod h1:C1RTYn4Sc7iEyf6j8ft5dyoZ4212h8G1ol9QQluh5+0= github.com/gosuri/uiprogress v0.0.1/go.mod h1:C1RTYn4Sc7iEyf6j8ft5dyoZ4212h8G1ol9QQluh5+0= +github.com/hashicorp/go-cleanhttp v0.5.2 h1:035FKYIWjmULyFRBKPs8TBQoi0x6d9G4xc9neXJWAZQ= +github.com/hashicorp/go-cleanhttp v0.5.2/go.mod h1:kO/YDlP8L1346E6Sodw+PrpBSV4/SoxCXGY6BqNFT48= github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4= github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= +github.com/hekmon/cunits/v2 v2.1.0 h1:k6wIjc4PlacNOHwKEMBgWV2/c8jyD4eRMs5mR1BBhI0= +github.com/hekmon/cunits/v2 v2.1.0/go.mod h1:9r1TycXYXaTmEWlAIfFV8JT+Xo59U96yUJAYHxzii2M= +github.com/hekmon/transmissionrpc/v2 v2.0.1 h1:WkILCEdbNy3n/N/w7mi449waMPdH2AA1THyw7TfnN/w= +github.com/hekmon/transmissionrpc/v2 v2.0.1/go.mod h1:+s96Pkg7dIP3h2PT3fzhXPvNb3OdLryh5J8PIvQg3aA= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= github.com/huandu/xstrings v1.0.0/go.mod h1:4qWG/gcEcfX4z/mBDHJ++3ReCw9ibxbsNJbcucJdbSo= github.com/huandu/xstrings v1.2.0/go.mod h1:DvyZB1rfVYsBIigL8HwpZgxHwXozlTgGqn63UyNX5k4= diff --git a/internal/action/run.go b/internal/action/run.go index eb92a88..7c47246 100644 --- a/internal/action/run.go +++ b/internal/action/run.go @@ -48,6 +48,9 @@ func (s *service) RunAction(action *domain.Action, release domain.Release) ([]st case domain.ActionTypeQbittorrent: rejections, err = s.qbittorrent(*action, release) + case domain.ActionTypeTransmission: + rejections, err = s.transmission(*action, release) + case domain.ActionTypeRadarr: rejections, err = s.radarr(*action, release) diff --git a/internal/action/transmission.go b/internal/action/transmission.go new file mode 100644 index 0000000..4ba9a8b --- /dev/null +++ b/internal/action/transmission.go @@ -0,0 +1,70 @@ +package action + +import ( + "context" + + "github.com/autobrr/autobrr/internal/domain" + "github.com/autobrr/autobrr/pkg/errors" + + "github.com/hekmon/transmissionrpc/v2" +) + +func (s *service) transmission(action domain.Action, release domain.Release) ([]string, error) { + s.log.Debug().Msgf("action Transmission: %v", action.Name) + + var err error + + // get client for action + client, err := s.clientSvc.FindByID(context.TODO(), action.ClientID) + if err != nil { + s.log.Error().Stack().Err(err).Msgf("error finding client: %v", action.ClientID) + return nil, err + } + + if client == nil { + return nil, errors.New("could not find client by id: %v", action.ClientID) + } + + var rejections []string + + if release.TorrentTmpFile == "" { + err = release.DownloadTorrentFile() + if 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) + } + + b64, err := transmissionrpc.File2Base64(release.TorrentTmpFile) + if err != nil { + return nil, errors.Wrap(err, "cant encode file %v 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(context.TODO(), 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: '%v'", torrent.HashString, client.Name) + + return rejections, nil +} diff --git a/internal/domain/action.go b/internal/domain/action.go index 4f79379..3aaa84e 100644 --- a/internal/domain/action.go +++ b/internal/domain/action.go @@ -47,15 +47,16 @@ type Action struct { type ActionType string const ( - ActionTypeTest ActionType = "TEST" - ActionTypeExec ActionType = "EXEC" - ActionTypeQbittorrent ActionType = "QBITTORRENT" - ActionTypeDelugeV1 ActionType = "DELUGE_V1" - ActionTypeDelugeV2 ActionType = "DELUGE_V2" - ActionTypeWatchFolder ActionType = "WATCH_FOLDER" - ActionTypeWebhook ActionType = "WEBHOOK" - ActionTypeRadarr ActionType = "RADARR" - ActionTypeSonarr ActionType = "SONARR" - ActionTypeLidarr ActionType = "LIDARR" - ActionTypeWhisparr ActionType = "WHISPARR" + ActionTypeTest ActionType = "TEST" + ActionTypeExec ActionType = "EXEC" + ActionTypeQbittorrent ActionType = "QBITTORRENT" + ActionTypeDelugeV1 ActionType = "DELUGE_V1" + ActionTypeDelugeV2 ActionType = "DELUGE_V2" + ActionTypeTransmission ActionType = "TRANSMISSION" + ActionTypeWatchFolder ActionType = "WATCH_FOLDER" + ActionTypeWebhook ActionType = "WEBHOOK" + ActionTypeRadarr ActionType = "RADARR" + ActionTypeSonarr ActionType = "SONARR" + ActionTypeLidarr ActionType = "LIDARR" + ActionTypeWhisparr ActionType = "WHISPARR" ) diff --git a/internal/domain/client.go b/internal/domain/client.go index f7bacea..5accf9c 100644 --- a/internal/domain/client.go +++ b/internal/domain/client.go @@ -46,11 +46,12 @@ type BasicAuth struct { type DownloadClientType string const ( - DownloadClientTypeQbittorrent DownloadClientType = "QBITTORRENT" - DownloadClientTypeDelugeV1 DownloadClientType = "DELUGE_V1" - DownloadClientTypeDelugeV2 DownloadClientType = "DELUGE_V2" - DownloadClientTypeRadarr DownloadClientType = "RADARR" - DownloadClientTypeSonarr DownloadClientType = "SONARR" - DownloadClientTypeLidarr DownloadClientType = "LIDARR" - DownloadClientTypeWhisparr DownloadClientType = "WHISPARR" + DownloadClientTypeQbittorrent DownloadClientType = "QBITTORRENT" + DownloadClientTypeDelugeV1 DownloadClientType = "DELUGE_V1" + DownloadClientTypeDelugeV2 DownloadClientType = "DELUGE_V2" + DownloadClientTypeTransmission DownloadClientType = "TRANSMISSION" + DownloadClientTypeRadarr DownloadClientType = "RADARR" + DownloadClientTypeSonarr DownloadClientType = "SONARR" + DownloadClientTypeLidarr DownloadClientType = "LIDARR" + DownloadClientTypeWhisparr DownloadClientType = "WHISPARR" ) diff --git a/internal/download_client/connection.go b/internal/download_client/connection.go index 14f4d94..a264fd2 100644 --- a/internal/download_client/connection.go +++ b/internal/download_client/connection.go @@ -1,6 +1,7 @@ package download_client import ( + "context" "time" "github.com/autobrr/autobrr/internal/domain" @@ -12,6 +13,7 @@ import ( "github.com/autobrr/autobrr/pkg/whisparr" delugeClient "github.com/gdm85/go-libdeluge" + "github.com/hekmon/transmissionrpc/v2" ) func (s *service) testConnection(client domain.DownloadClient) error { @@ -22,6 +24,9 @@ func (s *service) testConnection(client domain.DownloadClient) error { case domain.DownloadClientTypeDelugeV1, domain.DownloadClientTypeDelugeV2: return s.testDelugeConnection(client) + case domain.DownloadClientTypeTransmission: + return s.testTransmissionConnection(client) + case domain.DownloadClientTypeRadarr: return s.testRadarrConnection(client) @@ -114,6 +119,31 @@ func (s *service) testDelugeConnection(client domain.DownloadClient) error { return nil } +func (s *service) testTransmissionConnection(client domain.DownloadClient) error { + tbt, err := transmissionrpc.New(client.Host, client.Username, client.Password, &transmissionrpc.AdvancedConfig{ + HTTPS: client.TLS, + Port: uint16(client.Port), + }) + if err != nil { + return errors.Wrap(err, "error logging into client: %v", client.Host) + } + + ok, version, _, err := tbt.RPCVersion(context.TODO()) + if err != nil { + return errors.Wrap(err, "error getting rpc info: %v", client.Host) + } + + if !ok { + return errors.Wrap(err, "error getting rpc info: %v", client.Host) + } + + s.log.Debug().Msgf("test client connection for Transmission: got version: %v", version) + + s.log.Debug().Msgf("test client connection for Transmission: success") + + return nil +} + func (s *service) testRadarrConnection(client domain.DownloadClient) error { r := radarr.New(radarr.Config{ Hostname: client.Host, diff --git a/web/src/domain/constants.ts b/web/src/domain/constants.ts index ef72277..8680675 100644 --- a/web/src/domain/constants.ts +++ b/web/src/domain/constants.ts @@ -176,6 +176,11 @@ export const DownloadClientTypeOptions: RadioFieldsetOption[] = [ description: "Add torrents directly to Deluge 2", value: "DELUGE_V2" }, + { + label: "Transmission", + description: "Add torrents directly to Transmission", + value: "TRANSMISSION" + }, { label: "Radarr", description: "Send to Radarr and let it decide", @@ -202,6 +207,7 @@ export const DownloadClientTypeNameMap: Record(); + + return ( + + + + + +
+ + + {tls && ( + + + + )} +
+ + + +
+ ); +} + export interface componentMapType { [key: string]: React.ReactElement; } @@ -145,6 +171,7 @@ export const componentMap: componentMapType = { DELUGE_V1: , DELUGE_V2: , QBITTORRENT: , + TRANSMISSION: , RADARR: , SONARR: , LIDARR: , @@ -221,7 +248,7 @@ function FormFieldsRules() { export const rulesComponentMap: componentMapType = { DELUGE_V1: , DELUGE_V2: , - QBITTORRENT: + QBITTORRENT: , }; interface formButtonsProps { diff --git a/web/src/screens/filters/details.tsx b/web/src/screens/filters/details.tsx index a3076b9..07ea6bf 100644 --- a/web/src/screens/filters/details.tsx +++ b/web/src/screens/filters/details.tsx @@ -819,6 +819,35 @@ function FilterActionsItem({ action, clients, idx, remove }: FilterActionsItemPr ); + case "TRANSMISSION": + return ( +
+
+ + +
+ +
+
+ +
+
+ +
+
+
+ ); case "RADARR": case "SONARR": case "LIDARR": diff --git a/web/src/types/Download.d.ts b/web/src/types/Download.d.ts index 93bc964..8062e70 100644 --- a/web/src/types/Download.d.ts +++ b/web/src/types/Download.d.ts @@ -2,6 +2,7 @@ type DownloadClientType = "QBITTORRENT" | "DELUGE_V1" | "DELUGE_V2" | + "TRANSMISSION" | "RADARR" | "SONARR" | "LIDARR" |